cgma
|
provides functionality from cgm engines residing in dynamically loadable libraries More...
#include <CGMEngineDynamicLoader.hpp>
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 | |
GeometryQueryEngine * | get_gqe () |
GeometryModifyEngine * | get_gme () |
Protected Member Functions | |
CubitBoolean | check_engine_version () |
Protected Attributes | |
const CubitString | mEngineName |
CubitString | mEngineLibrary |
CubitDynamicLoader::LibraryHandle | mLibraryHandle |
CubitBoolean | mLoadAttempted |
GeometryQueryEngine * | mQueryEngine |
GeometryModifyEngine * | mModifyEngine |
provides functionality from cgm engines residing in dynamically loadable libraries
Definition at line 14 of file CGMEngineDynamicLoader.hpp.
CGMEngineDynamicLoader::CGMEngineDynamicLoader | ( | const CubitString & | engine_name | ) |
create an instance of this engine loader with an engine name
Definition at line 16 of file CGMEngineDynamicLoader.cpp.
: mEngineName(engine_name), mEngineLibrary(CubitString("CGM") + engine_name), mLibraryHandle(CubitDynamicLoader::InvalidLibraryHandle), mLoadAttempted(CUBIT_FALSE), mQueryEngine(NULL), mModifyEngine(NULL) { }
CGMEngineDynamicLoader::~CGMEngineDynamicLoader | ( | ) | [virtual] |
delete this and unload the library if it is loaded
Definition at line 27 of file CGMEngineDynamicLoader.cpp.
{ if(mLibraryHandle != CubitDynamicLoader::InvalidLibraryHandle) { unload_engine(); } }
CubitBoolean CGMEngineDynamicLoader::check_engine_version | ( | ) | [protected] |
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.
{ if(mLibraryHandle != CubitDynamicLoader::InvalidLibraryHandle) return CUBIT_TRUE; // try for a debug version with _d on it first. #if defined(_WIN32) && defined(_DEBUG) CubitString debug_libname = CubitDynamicLoader::library_prefix() + mEngineLibrary + CubitString("_d") + CubitDynamicLoader::library_extension(); if(CubitDynamicLoader::library_exists(debug_libname.c_str())) return CUBIT_TRUE; #endif CubitString libname = CubitDynamicLoader::library_prefix() + mEngineLibrary + CubitDynamicLoader::library_extension(); if(CubitDynamicLoader::library_exists(libname.c_str())) return CUBIT_TRUE; return CUBIT_FALSE; }
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; }
Definition at line 40 of file CGMEngineDynamicLoader.cpp.
{ return mEngineLibrary; }
load the engine, returns success or failure
Definition at line 78 of file CGMEngineDynamicLoader.cpp.
{ if(mLibraryHandle == CubitDynamicLoader::InvalidLibraryHandle) { // try for a debug version with _d on it first. #if defined(_WIN32) && defined(_DEBUG) CubitString debug_libname = CubitDynamicLoader::library_prefix() + mEngineLibrary + CubitString("_d") + CubitDynamicLoader::library_extension(); mLibraryHandle = CubitDynamicLoader::load_library(debug_libname.c_str()); #endif if(mLibraryHandle == CubitDynamicLoader::InvalidLibraryHandle) { CubitString libname = CubitDynamicLoader::library_prefix() + mEngineLibrary + CubitDynamicLoader::library_extension(); mLibraryHandle = CubitDynamicLoader::load_library(libname.c_str()); } mLoadAttempted = CUBIT_TRUE; if(mLibraryHandle == CubitDynamicLoader::InvalidLibraryHandle) { CubitString error = CubitDynamicLoader::get_error(); if(error != CubitString()) { PRINT_ERROR("%s\n", error.c_str()); } return CUBIT_FAILURE; } } return CUBIT_SUCCESS; }
void CGMEngineDynamicLoader::set_library_base_name | ( | const CubitString & | libname | ) |
can set library name for the engine if it is different than the engine name
Definition at line 45 of file CGMEngineDynamicLoader.cpp.
{ if(mLibraryHandle == CubitDynamicLoader::InvalidLibraryHandle) { mEngineLibrary = libname; mLoadAttempted = CUBIT_FALSE; } }
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; */ }
CubitString CGMEngineDynamicLoader::mEngineLibrary [protected] |
Definition at line 54 of file CGMEngineDynamicLoader.hpp.
const CubitString CGMEngineDynamicLoader::mEngineName [protected] |
Definition at line 51 of file CGMEngineDynamicLoader.hpp.
Definition at line 57 of file CGMEngineDynamicLoader.hpp.
CubitBoolean CGMEngineDynamicLoader::mLoadAttempted [protected] |
Definition at line 60 of file CGMEngineDynamicLoader.hpp.
Definition at line 67 of file CGMEngineDynamicLoader.hpp.
GeometryQueryEngine* CGMEngineDynamicLoader::mQueryEngine [protected] |
Definition at line 66 of file CGMEngineDynamicLoader.hpp.