1 // File: ModelAPI_PluginManager.hxx
2 // Created: 20 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #include <ModelAPI_PluginManager.h>
6 // to avoid unresolved ModelAPI_Document()
7 #include <ModelAPI_Document.h>
8 // to avoid unresolved ModelAPI_Feature()
9 #include <ModelAPI_Feature.h>
10 // to avoid unresolved ModelAPI_Data()
11 #include <ModelAPI_Data.h>
12 // to avoid unresolved ModelAPI_Plugin()
13 #include <ModelAPI_Plugin.h>
14 #include <ModelAPI_Attribute.h>
15 #include <ModelAPI_AttributeDocRef.h>
16 #include <ModelAPI_AttributeDouble.h>
17 #include <ModelAPI_AttributeReference.h>
18 #include <ModelAPI_AttributeRefAttr.h>
28 /// Converts library name to the operation system file name
29 string library(const string& theLibName);
31 /// Manager that will be initialized from Model package, one per application
32 boost::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
34 ModelAPI_PluginManager::ModelAPI_PluginManager()
38 void ModelAPI_PluginManager::SetPluginManager(
39 boost::shared_ptr<ModelAPI_PluginManager> theManager)
41 MY_MANAGER = theManager;
44 boost::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
46 if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
52 string library(const string& theLibName)
54 string aLibName = theLibName;
57 static string aLibExt( ".so" );
58 if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib")
59 aLibName = "lib" + aLibName;
61 static string aLibExt( ".dll" );
64 string anExt = aLibName.substr(aLibName.size() - 4);
66 if ( anExt != aLibExt)
72 // for debug purpose only (cerr), before the error management system is implemented
74 void ModelAPI_PluginManager::loadLibrary(const string theLibName)
76 string aFileName = library(theLibName);
77 if ( aFileName.empty() )
79 cerr<<"Library "<<theLibName.c_str()<<" can not be imported"<<endl;
84 HINSTANCE aModLib = ::LoadLibrary( aFileName.c_str() );
86 cerr<<"Failed to load "<<aFileName.c_str()<<endl;
88 void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
90 cerr<<"Failed to load "<<aFileName.c_str()<<endl;