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>
19 #include <ModelAPI_AttributeRefList.h>
29 /// Converts library name to the operation system file name
30 string library(const string& theLibName);
32 /// Manager that will be initialized from Model package, one per application
33 boost::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
35 ModelAPI_PluginManager::ModelAPI_PluginManager()
39 void ModelAPI_PluginManager::SetPluginManager(
40 boost::shared_ptr<ModelAPI_PluginManager> theManager)
42 MY_MANAGER = theManager;
45 boost::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
47 if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
53 string library(const string& theLibName)
55 string aLibName = theLibName;
58 static string aLibExt( ".so" );
59 if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib")
60 aLibName = "lib" + aLibName;
62 static string aLibExt( ".dll" );
65 string anExt = aLibName.substr(aLibName.size() - 4);
67 if ( anExt != aLibExt)
73 // for debug purpose only (cerr), before the error management system is implemented
75 void ModelAPI_PluginManager::loadLibrary(const string theLibName)
77 string aFileName = library(theLibName);
78 if ( aFileName.empty() )
80 cerr<<"Library "<<theLibName.c_str()<<" can not be imported"<<endl;
85 HINSTANCE aModLib = ::LoadLibrary( aFileName.c_str() );
87 cerr<<"Failed to load "<<aFileName.c_str()<<endl;
89 void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
91 cerr<<"Failed to load "<<aFileName.c_str()<<endl;