cgma
CGMEngineDynamicLoader Class Reference

provides functionality from cgm engines residing in dynamically loadable libraries More...

#include <CGMEngineDynamicLoader.hpp>

List of all members.

Public Member Functions

 CGMEngineDynamicLoader (const CubitString &engine_name)
 create an instance of this engine loader with an engine name
virtual ~CGMEngineDynamicLoader ()
 delete this and unload the library if it is loaded
CubitString get_engine_name ()
 get the name of this engine
void set_library_base_name (const CubitString &libname)
CubitString get_library_base_name ()
CubitBoolean engine_exists ()
 check to see if the engine exists
CubitStatus load_engine ()
 load the engine, returns success or failure
CubitStatus unload_engine ()
 unload the engine, returns success or failure
GeometryQueryEngineget_gqe ()
GeometryModifyEngineget_gme ()

Protected Member Functions

CubitBoolean check_engine_version ()

Protected Attributes

const CubitString mEngineName
CubitString mEngineLibrary
CubitDynamicLoader::LibraryHandle mLibraryHandle
CubitBoolean mLoadAttempted
GeometryQueryEnginemQueryEngine
GeometryModifyEnginemModifyEngine

Detailed Description

provides functionality from cgm engines residing in dynamically loadable libraries

Definition at line 14 of file CGMEngineDynamicLoader.hpp.


Constructor & Destructor Documentation

create an instance of this engine loader with an engine name

Definition at line 16 of file CGMEngineDynamicLoader.cpp.

delete this and unload the library if it is loaded

Definition at line 27 of file CGMEngineDynamicLoader.cpp.


Member Function Documentation

Definition at line 143 of file CGMEngineDynamicLoader.cpp.

{
  // library was already loaded, so just look up the version function

  CubitString symbol = CubitString("dynamic_") + mEngineName + CubitString("_get_cgm_version");

  // Note: this is a nasty hack to avoid the warning:
  // ISO C++ forbids casting between pointer-to-function and pointer-to-object
  // Even with reinterpret_cast, this warning is still generated
  // GCC accepts reinterpret_cast for purposes like in dlsym calls as an extension,
  // but that might not work for other compilers
  // This union-trick has been applied to some open source code, like:
  // https://mail.gnome.org/archives/commits-list/2011-February/msg06409.html
  // http://sourceforge.net/p/scstudio/mailman/message/29083334/
  union {
    void* ptr;
    FpVersion func;
  } cast_u;
  cast_u.ptr = CubitDynamicLoader::get_symbol_address(mLibraryHandle, symbol.c_str());

  FpVersion fp_version = cast_u.func;

  if(!fp_version)
  {
    PRINT_ERROR("Failed to load CGM %s engine : Can't find version\n", mEngineName.c_str());
    return CUBIT_FALSE;
  }

  // TODO -- use real versioning system
  if(strcmp((*fp_version)(), "1.0") != 0)
  {
    PRINT_ERROR("Failed to load CGM %s engine : wrong version number\n", mEngineName.c_str());
    return CUBIT_FALSE;
  }

  return TRUE;
}

check to see if the engine exists

Definition at line 54 of file CGMEngineDynamicLoader.cpp.

get the name of this engine

Definition at line 35 of file CGMEngineDynamicLoader.cpp.

{
  return mEngineName;
}

get the GeometryModifyEngine instance from the engine calls load_engine if it hasn't been called yet returns NULL if library failed to load, or an engine couldn't be made

Definition at line 229 of file CGMEngineDynamicLoader.cpp.

{
  if(mModifyEngine)
    return mModifyEngine;

  if(mLoadAttempted == CUBIT_FALSE)
    load_engine();

  if(mLibraryHandle == CubitDynamicLoader::InvalidLibraryHandle)
  {
    PRINT_ERROR("Failed to load CGM %s engine\n", mEngineName.c_str());
    return NULL;
  }
  
  // check for incompatible CGM version
  if(check_engine_version() == CUBIT_FALSE)
    return NULL;
  
  CubitString symbol = CubitString("dynamic_") + mEngineName + CubitString("_create_gme");

  // Note: this is a nasty hack to avoid the warning:
  // ISO C++ forbids casting between pointer-to-function and pointer-to-object
  // Even with reinterpret_cast, this warning is still generated
  // GCC accepts reinterpret_cast for purposes like in dlsym calls as an extension,
  // but that might not work for other compilers
  // This union-trick has been applied to some open source code, like:
  // https://mail.gnome.org/archives/commits-list/2011-February/msg06409.html
  // http://sourceforge.net/p/scstudio/mailman/message/29083334/
  union {
    void* ptr;
    CGMEngineCreateModifyEngine func;
  } cast_u;
  cast_u.ptr = CubitDynamicLoader::get_symbol_address(mLibraryHandle, symbol.c_str());

  CGMEngineCreateModifyEngine create_modify_engine = cast_u.func;

  if(!create_modify_engine)
  {
    PRINT_ERROR("Failed to get %s modify engine\n", mEngineName.c_str());
    return NULL;
  }
  
  mModifyEngine = (*create_modify_engine)();

  return mModifyEngine;
}

get the GeometryQueryEngine instance from the engine calls load_engine if it hasn't been called yet returns NULL if library failed to load, or an engine couldn't be made

Definition at line 181 of file CGMEngineDynamicLoader.cpp.

{
  if(mQueryEngine)
    return mQueryEngine;  

  if(mLoadAttempted == CUBIT_FALSE)
    load_engine();

  if(mLibraryHandle == CubitDynamicLoader::InvalidLibraryHandle)
  {
    PRINT_ERROR("Failed to load CGM %s engine\n", mEngineName.c_str());
    return NULL;
  }

  // check for incompatible CGM version
  if(check_engine_version() == CUBIT_FALSE)
    return NULL;

  CubitString symbol = CubitString("dynamic_") + mEngineName + CubitString("_create_gqe");

  // Note: this is a nasty hack to avoid the warning:
  // ISO C++ forbids casting between pointer-to-function and pointer-to-object
  // Even with reinterpret_cast, this warning is still generated
  // GCC accepts reinterpret_cast for purposes like in dlsym calls as an extension,
  // but that might not work for other compilers
  // This union-trick has been applied to some open source code, like:
  // https://mail.gnome.org/archives/commits-list/2011-February/msg06409.html
  // http://sourceforge.net/p/scstudio/mailman/message/29083334/
  union {
    void* ptr;
    CGMEngineCreateQueryEngine func;
  } cast_u;
  cast_u.ptr = CubitDynamicLoader::get_symbol_address(mLibraryHandle, symbol.c_str());

  CGMEngineCreateQueryEngine create_query_engine = cast_u.func;

  if(!create_query_engine)
  {
    PRINT_ERROR("Failed to get %s query engine\n", mEngineName.c_str());
    return NULL;
  }

  mQueryEngine = (*create_query_engine)();

  return mQueryEngine;
}

can set library name for the engine if it is different than the engine name

Definition at line 45 of file CGMEngineDynamicLoader.cpp.

unload the engine, returns success or failure

Definition at line 114 of file CGMEngineDynamicLoader.cpp.

{ 
  return CUBIT_SUCCESS;

  /*

//don't unload cubitcatia.dll
#ifdef CATIA 
  if( mEngineName == "CATIA")
    return CUBIT_SUCCESS;
#endif 

  if(mLibraryHandle != CubitDynamicLoader::InvalidLibraryHandle)
  {
    CubitDynamicLoader::unload_library(mLibraryHandle);
    mLoadAttempted = CUBIT_FALSE;
    mLibraryHandle = CubitDynamicLoader::InvalidLibraryHandle;
    mQueryEngine = NULL;
    mModifyEngine = NULL;
  } 
  return CUBIT_SUCCESS;
  */
}

Member Data Documentation

Definition at line 51 of file CGMEngineDynamicLoader.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines