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>
26 /// Converts library name to the operation system file name
27 string library(const string& theLibName);
29 /// Manager that will be initialized from Model package, one per application
30 boost::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
32 ModelAPI_PluginManager::ModelAPI_PluginManager()
36 void ModelAPI_PluginManager::SetPluginManager(
37 boost::shared_ptr<ModelAPI_PluginManager> theManager)
39 MY_MANAGER = theManager;
42 boost::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
44 if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
50 string library(const string& theLibName)
52 string aLibName = theLibName;
55 static string aLibExt( ".so" );
56 if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib")
57 aLibName = "lib" + aLibName;
59 static string aLibExt( ".dll" );
62 string anExt = aLibName.substr(aLibName.size() - 4);
64 if ( anExt != aLibExt)
70 // for debug purpose only (cerr), before the error management system is implemented
72 void ModelAPI_PluginManager::loadLibrary(const string theLibName)
74 string aFileName = library(theLibName);
75 if ( aFileName.empty() )
77 cerr<<"Library "<<theLibName.c_str()<<" can not be imported"<<endl;
82 HINSTANCE aModLib = ::LoadLibrary( aFileName.c_str() );
84 cerr<<"Failed to load "<<aFileName.c_str()<<endl;
86 void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
88 cerr<<"Failed to load "<<aFileName.c_str()<<endl;