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_Object()
11 #include <ModelAPI_Object.h>
12 // to avoid unresolved ModelAPI_Plugin()
13 #include <ModelAPI_Plugin.h>
14 // to avoid unresolved ModelAPI_Iterator()
15 #include <ModelAPI_Iterator.h>
16 // to avoid unresolved ModelAPI_Iterator()
17 #include <ModelAPI_Iterator.h>
18 #include <ModelAPI_Attribute.h>
19 #include <ModelAPI_AttributeDocRef.h>
20 #include <ModelAPI_AttributeDouble.h>
30 /// Converts library name to the operation system file name
31 string library(const string& theLibName);
33 /// Manager that will be initialized from Model package, one per application
34 std::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
36 ModelAPI_PluginManager::ModelAPI_PluginManager()
40 void ModelAPI_PluginManager::SetPluginManager(
41 std::shared_ptr<ModelAPI_PluginManager> theManager)
43 MY_MANAGER = theManager;
46 std::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
48 if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
54 string library(const string& theLibName)
56 string aLibName = theLibName;
59 static string aLibExt( ".so" );
60 if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib")
61 aLibName = ".lib" + aLibName;
63 static string aLibExt( ".dll" );
66 string anExt = aLibName.substr(aLibName.size() - 4);
68 if ( anExt != aLibExt)
74 // for debug purpose only (cerr), before the error management system is implemented
76 void ModelAPI_PluginManager::loadLibrary(const string theLibName)
78 string aFileName = library(theLibName);
79 if ( aFileName.empty() )
81 cerr<<"Library "<<theLibName.c_str()<<" can not be imported"<<endl;
86 HINSTANCE aModLib = ::LoadLibrary( aFileName.c_str() );
88 cerr<<"Failed to load "<<aFileName.c_str()<<endl;
90 void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
92 cerr<<"Failed to load "<<aFileName.c_str()<<endl;