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_Plugin()
11 #include <ModelAPI_Plugin.h>
21 /// Converts library name to the operation system file name
22 string library(const string& theLibName);
24 /// Manager that will be initialized from Model package, one per application
25 std::shared_ptr<ModelAPI_PluginManager> MY_MANAGER;
27 ModelAPI_PluginManager::ModelAPI_PluginManager()
31 void ModelAPI_PluginManager::SetPluginManager(
32 std::shared_ptr<ModelAPI_PluginManager> theManager)
34 MY_MANAGER = theManager;
37 std::shared_ptr<ModelAPI_PluginManager> ModelAPI_PluginManager::get()
39 if (!MY_MANAGER) { // import Model library that implements this interface of ModelAPI
45 string library(const string& theLibName)
47 string aLibName = theLibName;
50 static string aLibExt( ".so" );
51 if (aLibName.size() < 3 || aLibName.substr(0, 3) !="lib")
52 aLibName = ".lib" + aLibName;
54 static string aLibExt( ".dll" );
57 string anExt = aLibName.substr(aLibName.size() - 4);
59 if ( anExt != aLibExt)
66 void ModelAPI_PluginManager::loadLibrary(const string theLibName)
68 string aFileName = library(theLibName);
69 if ( aFileName.empty() )
71 cerr<<"Library "<<theLibName.c_str()<<" can not be imported"<<endl;
76 HINSTANCE aModLib = ::LoadLibrary( aFileName.c_str() );
78 cerr<<"Failed to load "<<aFileName.c_str()<<endl;
80 void* aModLib = dlopen( aFileName.c_str(), RTLD_LAZY );
82 cerr<<"Failed to load "<<aFileName.c_str()<<endl;