MNE-CPP  beta 1.0
pluginmanager.cpp
Go to the documentation of this file.
1 //=============================================================================================================
36 //*************************************************************************************************************
37 //=============================================================================================================
38 // INCLUDES
39 //=============================================================================================================
40 
41 #include "pluginmanager.h"
42 
43 #include "../Interfaces/IPlugin.h"
44 #include "../Interfaces/ISensor.h"
45 #include "../Interfaces/IAlgorithm.h"
46 #include "../Interfaces/IIO.h"
47 
48 
49 //*************************************************************************************************************
50 //=============================================================================================================
51 // QT INCLUDES
52 //=============================================================================================================
53 
54 #include <QDir>
55 #include <QDebug>
56 
57 
58 //*************************************************************************************************************
59 //=============================================================================================================
60 // USED NAMESPACES
61 //=============================================================================================================
62 
63 using namespace MNEX;
64 
65 
66 //*************************************************************************************************************
67 //=============================================================================================================
68 // DEFINE MEMBER METHODS
69 //=============================================================================================================
70 
72 : QPluginLoader(parent)
73 {
74 
75 }
76 
77 
78 //*************************************************************************************************************
79 
81 {
82 }
83 
84 
85 //*************************************************************************************************************
86 
87 void PluginManager::loadPlugins(const QString& dir)
88 {
89  QDir PluginsDir(dir);
90 
91  foreach(QString fileName, PluginsDir.entryList(QDir::Files))
92  {
93  this->setFileName(PluginsDir.absoluteFilePath(fileName));
94  QObject *pPlugin = this->instance();
95 
96  // IPlugin
97  if(pPlugin)
98  {
99  qDebug() << "try to load Plugin " << fileName;
100 
101  // plugins are always disabled when they are first loaded
102  m_qVecPlugins.push_back(qobject_cast<IPlugin*>(pPlugin));
103 
104  IPlugin::PluginType pluginType = qobject_cast<IPlugin*>(pPlugin)->getType();
105 
106  // ISensor
107  if(pluginType == IPlugin::_ISensor)
108  {
109  ISensor* pSensor = qobject_cast<ISensor*>(pPlugin);
110  if(pSensor)
111  {
112  m_qVecSensorPlugins.push_back(pSensor);
113  qDebug() << "Sensor " << pSensor->getName() << " loaded.";
114  }
115  }
116  // IAlgorithm
117  else if(pluginType == IPlugin::_IAlgorithm)
118  {
119  IAlgorithm* pAlgorithm = qobject_cast<IAlgorithm*>(pPlugin);
120  if(pAlgorithm)
121  {
122  m_qVecAlgorithmPlugins.push_back(pAlgorithm);
123  qDebug() << "RTAlgorithm " << pAlgorithm->getName() << " loaded.";
124  }
125  }
126  // IIO
127  else if(pluginType == IPlugin::_IIO)
128  {
129  IIO* pIO = qobject_cast<IIO*>(pPlugin);
130  if(pIO)
131  {
132  m_qVecIOPlugins.push_back(pIO);
133  qDebug() << "RTVisualization " << pIO->getName() << " loaded.";
134  }
135  }
136 
137  //ToDo other Plugins - like Visualization
138 
139  }
140  else
141  qDebug() << "Plugin " << fileName << " could not be instantiated!";
142  }
143 
144 }
145 
146 
147 //*************************************************************************************************************
148 
149 int PluginManager::findByName(const QString& name)
150 {
151  QVector<IPlugin*>::const_iterator it = m_qVecPlugins.begin();
152  for(int i = 0; it != m_qVecPlugins.end(); ++i, ++it)
153  if((*it)->getName() == name)
154  return i;
155 
156  return -1;
157 }
void loadPlugins(const QString &dir)
int findByName(const QString &name)
Contains the declaration of the PluginManager class.
virtual QString getName() const =0
The IPlugin class is the base interface class of all plugins.
Definition: IPlugin.h:92
The ISensor class provides an interface for a sensor plugin.
Definition: ISensor.h:63
PluginManager(QObject *parent=0)
virtual QString getName() const =0
The IAlgorithm class provides an interface for a real-time algorithm plugin.
Definition: IAlgorithm.h:70
Definition: arrow.h:75
The IIO class provides an interface for a real-time record plugin.
Definition: IIO.h:83
virtual QString getName() const =0