1 // File: Model_PluginManager.cxx
2 // Created: 20 Mar 2014
3 // Author: Mikhail PONIKAROV
5 #include <Model_PluginManager.h>
6 #include <ModelAPI_Feature.h>
7 #include <ModelAPI_Plugin.h>
8 #include <Model_Feature.h>
9 #include <Event_Loop.h>
10 #include <Config_FeatureMessage.h>
11 #include <Config_ModuleReader.h>
15 static Model_PluginManager* myImpl = new Model_PluginManager();
17 boost::shared_ptr<ModelAPI_Feature> Model_PluginManager::createFeature(string theFeatureID)
19 if (this != myImpl) return myImpl->createFeature(theFeatureID);
22 if (myPlugins.find(theFeatureID) != myPlugins.end()) {
23 if (myPluginObjs.find(myPlugins[theFeatureID]) == myPluginObjs.end()) {
24 // load plugin library if not yet done
25 myCurrentPluginName = myPlugins[theFeatureID];
26 loadLibrary(myCurrentPluginName);
28 if (myPluginObjs.find(myCurrentPluginName) != myPluginObjs.end()) {
29 return myPluginObjs[myCurrentPluginName]->createFeature(theFeatureID);
33 return boost::shared_ptr<ModelAPI_Feature>(); // return nothing
36 Model_PluginManager::Model_PluginManager()
38 myPluginsInfoLoaded = false;
39 //TODO(sbh): Implement static method to extract event id [SEID]
40 static Event_ID aFeatureEvent = Event_Loop::eventByName("FeatureEvent");
42 ModelAPI_PluginManager::SetPluginManager(boost::shared_ptr<ModelAPI_PluginManager>(this));
43 // register the configuration reading listener
44 Event_Loop* aLoop = Event_Loop::loop();
45 aLoop->registerListener(this, aFeatureEvent);
48 void Model_PluginManager::processEvent(const Event_Message* theMessage)
50 const Config_FeatureMessage* aMsg =
51 dynamic_cast<const Config_FeatureMessage*>(theMessage);
53 // proccess the plugin info, load plugin
54 if (myPlugins.find(aMsg->id()) == myPlugins.end()) {
55 myPlugins[aMsg->id()] = aMsg->pluginLibrary(); // TO DO: plugin name must be also imported from XMLs
58 // plugins information was started to load, so, it will be loaded
59 myPluginsInfoLoaded = true;
62 void Model_PluginManager::LoadPluginsInfo()
64 if (myPluginsInfoLoaded) // nothing to do
67 // Read plugins information from XML files
68 Config_ModuleReader aXMLReader;
69 aXMLReader.setAutoImport(true);
73 void Model_PluginManager::registerPlugin(ModelAPI_Plugin* thePlugin)
75 myPluginObjs[myCurrentPluginName] = thePlugin;