##// END OF EJS Templates
Some more cleaning....
Jeandet Alexis -
r100:11a895cff789 pre-0.7
parent child
Show More
@@ -1,315 +1,331
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "socexplorerengine.h"
23 23 #include <proxy/socexplorerproxy.h>
24 24 #include <socexplorersettings.h>
25 25 #include <socexplorercoresettingsgui.h>
26 26 #include <socexplorerconfigkeys.h>
27 27
28 28 SocExplorerEngine* SocExplorerEngine::_self = NULL;
29 29 socExplorerXmlModel* SocExplorerEngine::p_xmlmodel=NULL;
30 30 QMainWindow* SocExplorerEngine::mainWindow=NULL;
31 31 QList<SOCModel*>* SocExplorerEngine::SOCs=NULL;
32 32 QSettings* SocExplorerEngine::m_settings=NULL;
33 33 int SocExplorerEngine::loglvl=1;
34 34
35 35
36 36 SocExplorerEngine::SocExplorerEngine(QObject *parent) :
37 37 QObject(parent)
38 38 {
39 39 if(SOCs==NULL)
40 40 {
41 41 SOCs = new QList<SOCModel*>;
42 42 }
43 43 m_settings = new QSettings();
44 44 SocExplorerCoreSettingsGUI* cfggui=new SocExplorerCoreSettingsGUI();
45 45 SocExplorerSettings::registerConfigEntry(cfggui,QIcon(":/images/config.svg"),"SocExplorer Core");
46 46 }
47 47
48 48
49 49 void SocExplorerEngine::init()
50 50 {
51 51 QDir dir;
52 52 if(!_self)
53 53 {
54 54 _self= new SocExplorerEngine;
55 55 }
56 56 if(!dir.exists(configFolder()))
57 57 dir.mkdir(configFolder());
58 58 p_xmlmodel = new socExplorerXmlModel(_self);
59 59 p_xmlmodel->updateSOClist();
60 60 }
61 61
62 62 QString SocExplorerEngine::configFolder()
63 63 {
64 64 return QString(SOCEXPLORER_CONFIG_PATH);
65 65 }
66 66
67 67 QStringList SocExplorerEngine::pluginFolders()
68 68 {
69 69 if(!_self)
70 70 init();
71 71 QStringList folders;
72 72 QDir pluginFolders(QString(SOCEXPLORER_CONFIG_PATH)+"/plugin.conf.d");
73 73 if(pluginFolders.exists())
74 74 {
75 75 pluginFolders.setFilter(QDir::Files | QDir::NoSymLinks);
76 76 QFileInfoList list = pluginFolders.entryInfoList();
77 77 for (int i = 0; i < list.size(); ++i)
78 78 {
79 79 QFileInfo fileInfo = list.at(i);
80 80 if(fileInfo.suffix()=="conf")
81 81 {
82 82 QFile confFile(fileInfo.absoluteFilePath());
83 83 if(confFile.open(QIODevice::ReadOnly))
84 84 {
85 85 while (!confFile.atEnd())
86 86 {
87 87 QString line = confFile.readLine();
88 88 QDir plugDir(line.remove("\n"));
89 89 if(plugDir.exists() && !folders.contains(plugDir.absolutePath()))
90 90 {
91 91 folders.append(plugDir.absolutePath());
92 92 }
93 93 }
94 94 }
95 95 }
96 96 }
97 97 }
98 98 QStringList localCfg = SocExplorerSettings::value(SOCEXPLORERENGINE_SETTINGS_SCOPE,SOCEXPLORERENGINE_SETTINGS_PLUGINS_LOOKUP_PATH).toString().split(";");
99 99 QString dir;
100 100 foreach (dir, localCfg)
101 101 {
102 102 QDir plugDir(dir);
103 103 if(plugDir.exists())
104 104 folders.append(dir);
105 105 }
106 106 return folders;
107 107 }
108 108
109 109 SOCModel *SocExplorerEngine::plugin2Soc(socexplorerplugin *plugin)
110 110 {
111 111 if(!_self)
112 112 init();
113 113 if(plugin)
114 114 {
115 115 while (plugin->parent!=NULL) {
116 116 plugin = plugin->parent;
117 117 }
118 118 for(int i=0;i<SOCs->count();i++)
119 119 {
120 120 if(SOCs->at(i)->isRootDev(plugin))
121 121 return SOCs->at(i);
122 122 }
123 123 //no soc found so create a new one
124 124 SOCModel* soc=new SOCModel(plugin);
125 125 SOCs->append(soc);
126 126 return soc;
127 127 }
128 128 return NULL;
129 129 }
130 130
131 131
132 132 int SocExplorerEngine::addEnumDevice(socexplorerplugin* rootPlugin,int VID, int PID, qint32 baseAddress, const QString &name)
133 133 {
134 134 if(!_self)
135 135 init();
136 136 SOCModel* soc = plugin2Soc(rootPlugin);
137 137 if(soc && !soc->enumDeviceExists(baseAddress))
138 138 {
139 139 emit _self->enumDeviceAdded(soc->addEnumDevice(VID,PID,baseAddress,name));
140 140 return 1;
141 141 }
142 142 return 0;
143 143 }
144 144
145 145 QList<SOCModel *> *SocExplorerEngine::getSOCs()
146 146 {
147 147 if(!_self)
148 148 init();
149 149 return SOCs;
150 150 }
151 151
152 152 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(const QString& rootPlugin,int VID, int PID, int count)
153 153 {
154 154 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
155 155 if(plugin==NULL)return -1;
156 156 SOCModel* soc = plugin2Soc(plugin);
157 157 if(soc==NULL)
158 158 return -1;
159 159 return soc->getEnumDeviceBaseAddress(VID,PID,count);
160 160 }
161 161
162 162 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(socexplorerplugin *plugin, int VID, int PID, int count)
163 163 {
164 164 if(plugin==NULL)return -1;
165 165 SOCModel* soc = plugin2Soc(plugin);
166 166 if(soc==NULL)
167 167 return -1;
168 168 return soc->getEnumDeviceBaseAddress(VID,PID,count);
169 169 }
170 170
171 171 qint32 SocExplorerEngine::getEnumDeviceCount(socexplorerplugin *plugin, int VID, int PID)
172 172 {
173 173 if(plugin==NULL)return 0;
174 174 SOCModel* soc = plugin2Soc(plugin);
175 175 if(soc==NULL)
176 176 return 0;
177 177 return soc->getEnumDeviceCount(VID,PID);
178 178 }
179 179
180 180 qint32 SocExplorerEngine::getEnumDeviceCount(const QString &rootPlugin, int VID, int PID)
181 181 {
182 182 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
183 183 if(plugin==NULL)return 0;
184 184 SOCModel* soc = plugin2Soc(plugin);
185 185 if(soc==NULL)
186 186 return 0;
187 187 return soc->getEnumDeviceCount(VID,PID);
188 188 }
189 189
190 190 int SocExplorerEngine::addEnumDevice(const QString &rootPlugin, int VID, int PID, qint32 baseAddress, const QString &name)
191 191 {
192 192 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
193 193 if(plugin==NULL)return -1;
194 194 SOCModel* soc = plugin2Soc(plugin);
195 195 if(soc==NULL)
196 196 return -1;
197 197 soc->addEnumDevice(VID,PID,baseAddress,name);
198 198 return 1;
199 199 }
200 200
201 201 unsigned int SocExplorerEngine::memMeasureSize(socexplorerplugin *plugin, unsigned int address, unsigned int maxSize)
202 202 {
203 203 return MemTester::measureMemSize(plugin,address,maxSize);
204 204 }
205 205
206 206 unsigned int SocExplorerEngine::memMeasureSize(const QString &plugin, unsigned int address, unsigned int maxSize)
207 207 {
208 208 return MemTester::measureMemSize(plugin,address,maxSize);
209 209 }
210 210
211 211
212 212 QString SocExplorerEngine::getDevName(int VID, int PID)
213 213 {
214 214 QList<QDomNodeList> list=p_xmlmodel->getAllNodes("peripheral");
215 215 for(int i=0;i<list.count();i++)
216 216 {
217 217 QDomNodeList nodes=list.at(i);
218 218 for(int l=0;l<nodes.count();l++)
219 219 {
220 220 QDomElement node=nodes.at(l).toElement();
221 221 int nodeVID=node.attribute("vid","0").toInt();
222 222 int nodePID=node.attribute("pid","0").toInt();
223 223 if((nodeVID==VID)&&(nodePID==PID))
224 224 {
225 225 return node.attribute("name","Unknow device");
226 226 }
227 227 }
228 228 }
229 229 return QString("Unknow device");
230 230 }
231 231
232 232 QString SocExplorerEngine::SocExplorerVersion(){return QString(SOCEXPLORER_VERSION);}
233 233
234 234 QString SocExplorerEngine::SocExplorerChangeset(){return QString(SOCEXPLORER_CHAGESET).split(" ").at(0);}
235 235
236 236 QString SocExplorerEngine::SocExplorerBranch(){return QString(SOCEXPLORER_BRANCH);}
237 237
238 238 socExplorerXmlModel *SocExplorerEngine::xmlModel()
239 239 {
240 240 if(!_self)
241 241 init();
242 242 return p_xmlmodel;
243 243 }
244 244
245 245 void SocExplorerEngine::setMainWindow(QMainWindow *Mainwindow)
246 246 {
247 247 if(!_self)
248 248 init();
249 249 mainWindow=Mainwindow;
250 250 }
251 251
252 252 QProgressBar *SocExplorerEngine::getProgressBar(const QString& format, int max)
253 253 {
254 254 if(!_self)
255 255 init();
256 256 QProgressBar* progressBar;
257 257 if(mainWindow!=NULL)
258 258 {
259 259 progressBar = new QProgressBar(mainWindow);
260 260 mainWindow->statusBar()->addWidget(progressBar);
261 261 }
262 262 else
263 263 {
264 264 progressBar = new QProgressBar();
265 265 }
266 266 progressBar->setMaximum(max);
267 267 progressBar->setFormat(format);
268 268 return progressBar;
269 269 }
270 270
271 271 void SocExplorerEngine::deleteProgressBar(QProgressBar *progressBar)
272 272 {
273 273 if(mainWindow!=NULL)
274 274 {
275 275 mainWindow->statusBar()->removeWidget(progressBar);
276 276 }
277 277 delete progressBar;
278 278 }
279 279
280 280 void SocExplorerEngine::addSOC(socexplorerplugin *rootPlugin)
281 281 {
282 282 plugin2Soc(rootPlugin);
283 283 }
284 284
285 285 void SocExplorerEngine::removeSOC(socexplorerplugin *rootPlugin)
286 286 {
287 287 SOCModel* soc=plugin2Soc(rootPlugin);
288 288 SOCs->removeAll(soc);
289 289 delete soc;
290 290 }
291 291
292
292 293 void SocExplorerEngine::message(socexplorerplugin *sender, const QString &message, int debugLevel)
293 294 {
295 if(!_self)
296 init();
297 SocExplorerEngine::message(sender->instanceName(),message,debugLevel);
298 }
299
300 void SocExplorerEngine::message(QObject *sender, const QString &message, int debugLevel)
301 {
302 if(!_self)
303 init();
304 SocExplorerEngine::message(sender->objectName(),message,debugLevel);
305 }
306
307 void SocExplorerEngine::message(const QString &sender, const QString &message, int debugLevel)
308 {
294 309 // TODO add multi output message manager IE also log in files
310 static QTextStream SocExplorerEngineStdout(stdout);
295 311 if(!_self)
296 312 init();
297 313 if(loglvl>=debugLevel)
298 qDebug()<< QTime::currentTime().toString()+" " + sender->instanceName()+":"+message;
314 SocExplorerEngineStdout << QTime::currentTime().toString()+" " + sender+":"+message << endl;
299 315 }
300 316
301 317 void SocExplorerEngine::setLogLevel(int level)
302 318 {
303 319 if(!_self)
304 320 init();
305 321 printf("Set log level to %d\n",level);
306 322 loglvl = level;
307 323 }
308 324
309 325 bool SocExplorerEngine::isSocLitleEndian(socexplorerplugin *plugin)
310 326 {
311 327 return plugin2Soc(plugin)->isLitleEndian();
312 328 }
313 329
314 330
315 331
@@ -1,143 +1,145
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef SOCEXPLORERENGINE_H
23 23 #define SOCEXPLORERENGINE_H
24 24
25 25 #include <stdint.h>
26 26 #include <QObject>
27 27 #include <QtWidgets>
28 28 #include <QStringList>
29 29 #include <QDomDocument>
30 30 #include <QDomElement>
31 31 #include <QDomNodeList>
32 32 #include <QFile>
33 33 #include <QTextStream>
34 34 #include <QDir>
35 35 #include <QApplication>
36 36 #include <QtCore/qglobal.h>
37 37 #include <QFileDialog>
38 38 #include <socexplorerxmlfile.h>
39 39 #include <socexplorerenumdevice.h>
40 40 #include <XMLmodel.h>
41 41 #include <peripheralwidget.h>
42 42 #include <registerwidget.h>
43 43 #include <socmodel.h>
44 44 #include <memtester.h>
45 45 #include <QSettings>
46 46
47 47 #if defined(SOCEXPLORER_SDK_BUILD)
48 48 # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT
49 49 #else
50 50 # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT
51 51 #endif
52 52
53 53
54 54 class SOCEXPLORER_SDK_EXPORT SocExplorerAutoProgressBar
55 55 {
56 56 public:
57 57 SocExplorerAutoProgressBar(QProgressBar* progressBar=NULL)
58 58 {
59 59 this->p_progressbar=progressBar;
60 60 }
61 61 ~SocExplorerAutoProgressBar()
62 62 {
63 63 if(p_progressbar)
64 64 {
65 65 delete p_progressbar;
66 66 }
67 67 }
68 68 void setProgressBar(QProgressBar* progressBar)
69 69 {
70 70 this->p_progressbar=progressBar;
71 71 }
72 72 void setValue(int value)
73 73 {
74 74 p_progressbar->setValue(value);
75 75 }
76 76 private:
77 77 QProgressBar* p_progressbar;
78 78 };
79 79
80 80 //! SocExplorerEngine is a pure static class which aims to provide services for both SocExplorer software and plugins.
81 81
82 82 class SOCEXPLORER_SDK_EXPORT SocExplorerEngine : public QObject
83 83 {
84 84 Q_OBJECT
85 85 private:
86 86 static SocExplorerEngine* _self;
87 87 static QSettings* m_settings;
88 88 SocExplorerEngine(QObject *parent = 0);
89 89 static void init();
90 90
91 91 public:
92 92 static SocExplorerEngine* self(){ if(!_self){_self= new SocExplorerEngine;}return _self;}
93 93 //! Return the configuration folder path, OS dependant.
94 94 SOCEXPLORER_SDK_EXPORT static QString configFolder();
95 95 //! Return the default plugin folder path, OS dependant.
96 96 static QStringList pluginFolders();
97 97 static QString configPath(){return QString(SOCEXPLORER_CONFIG_PATH);}
98 98 static QString sharePath(){return QString(SOCEXPLORER_SHARE_PATH);}
99 99 static int addEnumDevice(socexplorerplugin* rootPlugin,int VID,int PID,qint32 baseAddress,const QString& name);
100 100 static QList<SOCModel*>* getSOCs();
101 101 static QString getDevName(int VID, int PID);
102 102 static QString SocExplorerVersion();
103 103 static QString SocExplorerChangeset();
104 104 static QString SocExplorerBranch();
105 105 static socExplorerXmlModel* xmlModel();
106 106 static void setMainWindow(QMainWindow* Mainwindow);
107 107 static QProgressBar* getProgressBar(const QString &format, int max);
108 108 static void deleteProgressBar(QProgressBar* progressBar);
109 109 static void addSOC(socexplorerplugin* rootPlugin);
110 110 static void removeSOC(socexplorerplugin* rootPlugin);
111 111 static void message(socexplorerplugin* sender,const QString& message,int debugLevel=0);
112 static void message(QObject* sender,const QString& message,int debugLevel=0);
113 static void message(const QString& sender,const QString& message,int debugLevel=0);
112 114 static void setLogLevel(int level);
113 115 static bool isSocLitleEndian(socexplorerplugin* plugin);
114 116 signals:
115 117 void enumDeviceAdded(socExplorerEnumDevice* device);
116 118 public slots:
117 119 QString getSocExplorerVersion(){return SocExplorerEngine::SocExplorerVersion();}
118 120 QString getSocExplorerChangeset(){return SocExplorerEngine::SocExplorerChangeset();}
119 121 QString getSocExplorerBranch(){return SocExplorerEngine::SocExplorerBranch();}
120 122 qint32 getEnumDeviceBaseAddress(const QString& rootPlugin,int VID,int PID,int count=0);
121 123 qint32 getEnumDeviceBaseAddress(socexplorerplugin* plugin,int VID,int PID,int count=0);
122 124 qint32 getEnumDeviceCount(socexplorerplugin* plugin,int VID,int PID);
123 125 qint32 getEnumDeviceCount(const QString& rootPlugin,int VID,int PID);
124 126 int addEnumDevice(const QString& rootPlugin,int VID,int PID,qint32 baseAddress,const QString& name);
125 127 unsigned int memMeasureSize(socexplorerplugin* plugin, unsigned int address,unsigned int maxSize=0xFFFFFFFF);
126 128 unsigned int memMeasureSize(const QString& plugin, unsigned int address,unsigned int maxSize=0xFFFFFFFF);
127 129
128 130 private:
129 131 static SOCModel* plugin2Soc(socexplorerplugin* plugin);
130 132 static socExplorerXmlModel* p_xmlmodel;
131 133 static QMainWindow* mainWindow;
132 134 static QList<SOCModel*>* SOCs;
133 135 static int loglvl;
134 136 };
135 137
136 138 #endif // SOCEXPLORERENGINE_H
137 139
138 140
139 141
140 142
141 143
142 144
143 145
@@ -1,321 +1,321
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2015, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #include "socexplorersettings.h"
23 23
24 24 SocExplorerSettings* SocExplorerSettings::_self=NULL;
25 25 QSettings* SocExplorerSettings::m_settings=NULL;
26 26 QSettings* SocExplorerSettings::m_sessionSettings=NULL;
27 27 SocExplorerSettingsDialog* SocExplorerSettings::m_configDialog = NULL;
28 28 #include <socexplorergui.h>
29 29 #include <QFile>
30 30 #include <QFileInfo>
31 31 #include <QDir>
32 32 #include <QDebug>
33 33
34 34 #define INIT() \
35 35 if(Q_UNLIKELY(_self==NULL))\
36 36 {\
37 37 init();\
38 38 }
39 39
40 40
41 41 SocExplorerSettings::SocExplorerSettings(QObject *parent) : QObject(parent)
42 42 {
43 43 m_settings = new QSettings();
44 44 m_configDialog = new SocExplorerSettingsDialog();
45 45 QAction* trigerGUI = new QAction(tr("Settings"),this);
46 46 connect(trigerGUI,SIGNAL(triggered()),this,SLOT(popConfigDialog()));
47 47 SocExplorerGUI::addSettingsAction(trigerGUI);
48 48 }
49 49
50 50 SocExplorerSettings::~SocExplorerSettings()
51 51 {
52 52 if(m_settings)
53 53 {
54 54 m_settings->sync();
55 55 delete m_settings;
56 56 }
57 57 if(m_sessionSettings)
58 58 {
59 59 m_sessionSettings->sync();
60 60 delete m_sessionSettings;
61 61 }
62 62 }
63 63
64 64 void SocExplorerSettings::init()
65 65 {
66 66 if(!_self)
67 67 {
68 68 _self= new SocExplorerSettings();
69 69 }
70 70 }
71 71
72 72 void SocExplorerSettings::setValue(QObject *object, const QString &key, const QVariant &value, SettingScope Sscope)
73 73 {
74 74 INIT();
75 75 setValue(object->metaObject()->className(),key,value,Sscope);
76 76 }
77 77
78 78 QVariant SocExplorerSettings::value(QObject *object, const QString &key, const QVariant &defaultValue, SettingScope Sscope)
79 79 {
80 80 INIT();
81 81 return value(object->metaObject()->className(),key,defaultValue,Sscope);
82 82 }
83 83
84 84 void SocExplorerSettings::setValue(const QString scope, const QString &key, const QVariant &value, SettingScope Sscope)
85 85 {
86 86 INIT();
87 87 switch (Sscope)
88 88 {
89 89 case SystemWide:
90 90 if(m_settings)
91 91 m_settings->setValue(scope+"/"+key,value);
92 92 break;
93 93 case Session:
94 94 if(m_sessionSettings)
95 95 m_sessionSettings->setValue(scope+"/"+key,value);
96 96 break;
97 97 default:
98 98 break;
99 99 }
100 100 }
101 101
102 102 QVariant SocExplorerSettings::value(const QString scope, const QString &key, const QVariant &defaultValue, SettingScope Sscope)
103 103 {
104 104 INIT();
105 105 switch (Sscope)
106 106 {
107 107 case SystemWide:
108 108 if(m_settings)
109 109 return m_settings->value(scope+"/"+key,defaultValue);
110 110 break;
111 111 case Session:
112 112 if(m_sessionSettings)
113 113 return m_sessionSettings->value(scope+"/"+key,defaultValue);
114 114 break;
115 115 default:
116 116 break;
117 117 }
118 118 return defaultValue;
119 119 }
120 120
121 121 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, SocExplorerSettings::SettingScope Sscope)
122 122 {
123 123 INIT();
124 124 QList<QList<QVariant> > defaultValue;
125 125 switch (Sscope)
126 126 {
127 127 case SystemWide:
128 128 if(m_settings)
129 129 return arrays(prefix,keys,m_settings);
130 130 break;
131 131 case Session:
132 132 if(m_sessionSettings)
133 133 return arrays(prefix,keys,m_sessionSettings);
134 134 break;
135 135 default:
136 136 break;
137 137 }
138 138 return defaultValue;
139 139 }
140 140
141 141 void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, SocExplorerSettings::SettingScope Sscope)
142 142 {
143 143 INIT();
144 144 switch (Sscope)
145 145 {
146 146 case SystemWide:
147 147 if(m_settings)
148 148 return setArrays(prefix,keys,values,m_settings);
149 149 break;
150 150 case Session:
151 151 if(m_sessionSettings)
152 152 return setArrays(prefix,keys,values,m_sessionSettings);
153 153 break;
154 154 default:
155 155 break;
156 156 }
157 157
158 158 }
159 159
160 160 void SocExplorerSettings::sync()
161 161 {
162 162 INIT();
163 163 if(m_settings)
164 164 {
165 165 m_settings->sync();
166 166 }
167 167 if(m_sessionSettings)
168 168 {
169 169 m_sessionSettings->sync();
170 170 }
171 171 }
172 172
173 173 bool SocExplorerSettings::registerConfigEntry(SocExplorerSettingsItem *configEntry, QIcon icon, QString text)
174 174 {
175 175 INIT();
176 176 return m_configDialog->registerConfigEntry(configEntry,icon,text);
177 177 }
178 178
179 179 bool SocExplorerSettings::loadSession(const QString &session)
180 180 {
181 181 INIT();
182 182 QFileInfo sessionInfo(m_settings->fileName());
183 183 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
184 184 if(m_sessionSettings)
185 185 {
186 186 delete m_sessionSettings;
187 187 m_sessionSettings = NULL;
188 188 }
189 189 m_sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self());
190 190 qDebug()<< m_sessionSettings->fileName();
191 191 if(m_sessionSettings->status()==QSettings::NoError)
192 192 {
193 193 return true;
194 194 }
195 195 delete m_sessionSettings;
196 196 m_sessionSettings = NULL;
197 197 return false;
198 198 }
199 199
200 200 bool SocExplorerSettings::renameSession(const QString &session, const QString &newName)
201 201 {
202 202 INIT();
203 203 sync();
204 204 QFileInfo sessionInfo(m_settings->fileName());
205 205 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
206 206 QString newFullpath=sessionInfo.absoluteDir().absolutePath() +"/"+newName+".conf";
207 207 if(m_sessionSettings && m_sessionSettings->fileName()==fullpath)
208 208 {
209 209 delete m_sessionSettings;
210 210 QFile::rename(fullpath,newFullpath);
211 211 m_sessionSettings = new QSettings(newFullpath,QSettings::NativeFormat,self());
212 212 }
213 213 else
214 214 {
215 215 QFile::rename(fullpath,newFullpath);
216 216 }
217 217 return true;
218 218 }
219 219
220 220 bool SocExplorerSettings::deleteSession()
221 221 {
222 222 INIT();
223 223 if(m_sessionSettings)
224 224 {
225 225 m_sessionSettings->clear();
226 226 QString filename= m_sessionSettings->fileName();
227 227 if(QFile::exists(filename))
228 228 {
229 229 delete m_sessionSettings;
230 230 QFile::remove(filename);
231 231 }
232 232 else
233 233 delete m_sessionSettings;
234 234 m_sessionSettings = NULL;
235 235 return true;
236 236 }
237 237 return false;
238 238 }
239 239
240 240 bool SocExplorerSettings::deleteSession(const QString &session)
241 241 {
242 242 QFileInfo sessionInfo(m_settings->fileName());
243 243 QString fullpath=sessionInfo.absoluteDir().absolutePath() +"/"+session+".conf";
244 244 if(m_sessionSettings)
245 245 {
246 246 if(m_sessionSettings->fileName()==fullpath)
247 247 {
248 248 deleteSession();
249 249 return true;
250 250 }
251 251 }
252 252 QSettings* sessionSettings = new QSettings(fullpath,QSettings::NativeFormat,self());
253 253 if(sessionSettings)
254 254 {
255 255 if(sessionSettings->status()==QSettings::NoError)
256 256 {
257 257 sessionSettings->clear();
258 258 QString filename= m_sessionSettings->fileName();
259 259 if(QFile::exists(filename))
260 260 {
261 261 delete sessionSettings;
262 262 QFile::remove(filename);
263 263 }
264 264 else
265 265 delete sessionSettings;
266 266 return true;
267 267 }
268 268 delete sessionSettings;
269 269 }
270 270 return false;
271 271 }
272 272
273 273 void SocExplorerSettings::popConfigDialog()
274 274 {
275 275 m_configDialog->popConfigDialog(NULL);
276 276 }
277 277
278 278 QList<QList<QVariant> > SocExplorerSettings::arrays(const QString &prefix, QStringList keys, QSettings *settings)
279 279 {
280 280 QList<QList<QVariant> > result;
281 281 if(settings)
282 282 {
283 283 int size = settings->beginReadArray(prefix);
284 284 for (int i = 0; i < size; ++i)
285 285 {
286 286 result.append(QList<QVariant>());
287 287 settings->setArrayIndex(i);
288 288 for(int l=0;l<keys.count();l++)
289 289 {
290 290 result[i].append(settings->value(keys.at(l)));
291 291 }
292 292 }
293 293 settings->endArray();
294 294 }
295 295 return result;
296 296 }
297 297
298 298 void SocExplorerSettings::setArrays(const QString &prefix, QStringList keys, QList<QList<QVariant> > values, QSettings *settings)
299 299 {
300 300 if(settings)
301 301 {
302 302 QString key;
303 303 foreach (key, keys)
304 304 {
305 305
306 306 settings->remove(prefix+"/"+key);
307 307 }
308 308 settings->beginWriteArray(prefix);
309 309 for (int i = 0; i < values.size(); ++i)
310 310 {
311 311 settings->setArrayIndex(i);
312 312 for(int l=0;l<keys.count();l++)
313 313 {
314 314 settings->setValue(keys[l], values.at(i).at(l));
315 315 }
316 316 }
317 317 settings->endArray();
318 318
319 319 }
320 320 }
321 321
@@ -1,560 +1,531
1 1 #include "pluginloader.h"
2 2 #include <QDir>
3 3 #include <QFile>
4 4 #include <QFileInfoList>
5 5 #include <QFileInfo>
6 6 #include <QString>
7 7 #include <QStringList>
8 8 #include <QLabel>
9 9 #include <QSettings>
10 10 #include <QApplication>
11 11 #include <QCoreApplication>
12 12 #include <socexplorerengine.h>
13 13 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
14 14 #include "unix/unixpluginloader.h"
15 15 #endif
16 #include <socexplorerengine.h>
17 #include <socexplorersettings.h>
16 18
17 19 pluginloader* pluginloader::_self = NULL;
18 20 PluginsCache* pluginloader::_cache = NULL;
19 21 QStringList* pluginloader::_folderList = NULL;
20 22
21 23
22 24 pluginloader::pluginloader()
23 25 {
24 26 _cache = new PluginsCache();
25 27 _folderList = new QStringList();
26 28 _folderList->append(SocExplorerEngine::pluginFolders());
27 29 scanFolders();
28 30 }
29 31
30
31 QStringList pluginloader::readFoldersList(const QStringList confFiles)
32 {
33 QDir testDir;
34 QStringList folders;
35 QFile confFile;
36 for(int i=0;i<confFiles.count();i++)
37 {
38 confFile.setFileName(confFiles.at(i));
39 if(confFile.exists())
40 {
41 if (confFile.open(QIODevice::ReadOnly | QIODevice::Text))
42 {
43 QTextStream in(&confFile);
44 QString line = in.readLine();
45 while (!line.isNull())
46 {
47 testDir.setPath(line);
48 if(testDir.exists())
49 {
50 if(!folders.contains(line))
51 folders << line;
52 }
53 line = in.readLine();
54 }
55 }
56 }
57 }
58 return folders;
59 }
60
61
62 32 void pluginloader::scanFolders()
63 33 {
64 34 QDir dir;
65 35 QStringList filters;
66 36 filters <<"*.so"<< "*.dll";
67 37 _cache->flush();
68 38 for(int d=0;d<_folderList->count();d++)
69 39 {
70 40 dir.setPath(_folderList->at(d));
71 41 dir.setFilter(QDir::Files);
72 42 dir.setNameFilters(filters);
73 43 QFileInfoList list = dir.entryInfoList();
74 44 for (int i = 0; i < list.size(); ++i)
75 45 {
76 46 QFileInfo fileInfo = list.at(i);
47 SocExplorerEngine::message("pluginloader::scanFolders","Checking "+ fileInfo.filePath(),3);
77 48 if(checklibrary(fileInfo.filePath())!=0)
78 49 {
79 50 _cache->append(fileInfo.fileName(),fileInfo.path(),_getlibName(fileInfo.filePath()),_getlibPID(fileInfo.filePath()),_getlibPID(fileInfo.filePath()));
80 51 }
81 52 }
82 53 }
83 54 }
84 55
85 56 int pluginloader::p_checklibraryQlib(const QString fileName)
86 57 {
87 58 QLibrary* lib = new QLibrary;
88 59 lib->setFileName(fileName);
89 60 lib->setLoadHints(QLibrary::PreventUnloadHint);
90 61 lib->load();
91 62 if(!lib->isLoaded())
92 63 {
93 qDebug()<<lib->errorString();
64 SocExplorerEngine::message("pluginloader::p_checklibraryQlib",lib->errorString(),3);
94 65 lib->~QLibrary();
95 66 lib = new QLibrary(fileName);
96 67 lib->load();
97 68 }
98 69 delete lib;
99 70 if(QLibrary::resolve(fileName,"socexplorerpluginCreateObject"))
100 71 {
101 72 if(QLibrary::resolve(fileName,"socexplorerpluginpid"))
102 73 {
103 74 if(QLibrary::resolve(fileName,"socexplorerpluginvid"))
104 75 {
105 76 if(QLibrary::resolve(fileName,"socexplorerpluginVersion"))
106 77 {
107 78 if(QLibrary::resolve(fileName,"socexplorerpluginAuthor"))
108 79 {
109 80 if(QLibrary::resolve(fileName,"socexplorerpluginDescription"))
110 81 {
111 82 return 1;
112 83 }
113 84 }
114 85 }
115 86 }
116 87 }
117 88 }
118 89 return 0;
119 90 }
120 91
121 92 int pluginloader::p_checklibraryCustom(const QString fileName)
122 93 {
123 94 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
124 95 unixPluginLoader lib(fileName);
125 96 if(NULL!=lib.resolve("socexplorerpluginCreateObject"))
126 97 {
127 98 if(NULL!=lib.resolve("socexplorerpluginpid"))
128 99 {
129 100 if(NULL!=lib.resolve("socexplorerpluginvid"))
130 101 {
131 102 if(NULL!=lib.resolve("socexplorerpluginVersion"))
132 103 {
133 104 if(NULL!=lib.resolve("socexplorerpluginAuthor"))
134 105 {
135 106 if(NULL!=lib.resolve("socexplorerpluginDescription"))
136 107 {
137 108 return 1;
138 109 }
139 110 }
140 111 }
141 112 }
142 113 }
143 114 }
144 115 #endif
145 116 return 0;
146 117 }
147 118
148 119 socexplorerplugin *pluginloader::p_newsocexplorerpluginQlib(const QString Name)
149 120 {
150 121 QString* libfile= _cacheLookup(Name);
151 122 if(libfile==NULL)return NULL;
152 123 QLibrary* lib = new QLibrary(*libfile);
153 124 delete libfile;
154 125 socexplorerpluginCreateObjectT newDrvr = NULL;
155 126 newDrvr=(socexplorerpluginCreateObjectT)lib->resolve("socexplorerpluginCreateObject");
156 127 if(newDrvr==NULL)
157 128 {
158 129 return NULL;
159 130 }
160 131 return (socexplorerplugin*) newDrvr();
161 132 }
162 133
163 134 socexplorerplugin *pluginloader::p_newsocexplorerpluginCustom(const QString Name)
164 135 {
165 136 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
166 137 QString* libfile= _cacheLookup(Name);
167 138 if(libfile==NULL)return NULL;
168 139 unixPluginLoader lib(*libfile);
169 140 delete libfile;
170 141 socexplorerpluginCreateObjectT newDrvr = NULL;
171 142 newDrvr=(socexplorerpluginCreateObjectT)lib.resolve("socexplorerpluginCreateObject");
172 143 if(newDrvr==NULL)
173 144 {
174 145 return NULL;
175 146 }
176 147 return (socexplorerplugin*) newDrvr();
177 148 #endif
178 149 }
179 150
180 151 QList<PluginsCacheItem*> pluginloader::listAvailiables(bool rescan)
181 152 {
182 153 if(_self==NULL)
183 154 {
184 155 init();
185 156 return _cache->listDrivers();
186 157 }
187 158 if(rescan)
188 159 {
189 160 scanFolders();
190 161 }
191 162
192 163 return _cache->listDrivers();
193 164 }
194 165
195 166
196 167 void pluginloader::init()
197 168 {
198 169 if(_self==NULL)
199 170 {
200 171 _self=new pluginloader();
201 172 }
202 173 }
203 174
204 175
205 176 pluginloader* pluginloader::self()
206 177 {
207 178 if(_self==NULL)
208 179 {
209 180 init();
210 181 }
211 182 return _self;
212 183 }
213 184
214 185 bool pluginloader::isvalid(QString Name)
215 186 {
216 187 if(_self==NULL)init();
217 188 QString* libfile= _cacheLookup(Name);
218 189 if(libfile==NULL)return false;
219 190 else
220 191 {
221 192 delete libfile;
222 193 return true;
223 194 }
224 195
225 196 }
226 197
227 198 int pluginloader::checklibrary(const QString fileName)
228 199 {
229 200 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
230 201 return _self->p_checklibraryCustom(fileName);
231 202 #else
232 203 return _self->p_checklibraryQlib(fileName);
233 204 #endif
234 205 }
235 206
236 207
237 208
238 209
239 210
240 211 socexplorerplugin* pluginloader::newsocexplorerplugin(const QString Name)
241 212 {
242 213 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
243 214 return _self->p_newsocexplorerpluginCustom(Name);
244 215 #else
245 216 return _self->p_newsocexplorerpluginQlib(Name);
246 217 #endif
247 218 }
248 219
249 220
250 221 QString pluginloader::getlibTypeStr(QString Name)
251 222 {
252 223 if(_self==NULL)init();
253 224 QString* libfile= _cacheLookup(Name);
254 225 if(libfile==NULL)return NULL;
255 226 QLibrary* lib = new QLibrary(*libfile);
256 227 delete libfile;
257 228 lib->load();
258 229 if(lib->isLoaded())
259 230 {
260 231 socexplorerpluginTypeT plugintype = (socexplorerpluginTypeT)lib->resolve("socexplorerpluginType");
261 232 if(plugintype!=NULL)
262 233 {
263 234 pluginT type = plugintype();
264 235 switch(type)
265 236 {
266 237 case ComDriverT:
267 238 ////lib->unload();
268 239 lib->~QLibrary();
269 240 return QObject::tr("Comunaication Driver Plugin.");
270 241 break;
271 242 case PerifDriverT:
272 243 ////lib->unload();
273 244 lib->~QLibrary();
274 245 return QObject::tr("Periferial Driver Plugin.");
275 246 break;
276 247 default:
277 248 ////lib->unload();
278 249 lib->~QLibrary();
279 250 return QObject::tr("Unknow Plugin.");
280 251 break;
281 252 }
282 253 }
283 254 }
284 255 lib->~QLibrary();
285 256 return QObject::tr("Can't load Plugin.");
286 257 }
287 258
288 259
289 260
290 261
291 262 pluginT pluginloader::getlibType(QString Name)
292 263 {
293 264 if(_self==NULL)init();
294 265 QString* libfile= _cacheLookup(Name);
295 266 if(libfile==NULL)return (pluginT)NULL;
296 267 QLibrary* lib = new QLibrary(*libfile);
297 268 delete libfile;
298 269 lib->load();
299 270 if(lib->isLoaded())
300 271 {
301 272 socexplorerpluginTypeT plugintype = (socexplorerpluginTypeT)lib->resolve("socexplorerpluginType");
302 273 if(plugintype!=NULL)
303 274 {
304 275 return plugintype();
305 276 }
306 277 }
307 278 lib->~QLibrary();
308 279 return -1;
309 280 }
310 281
311 282
312 283 QString pluginloader::getlibVersion(const QString Name)
313 284 {
314 285 if(_self==NULL)init();
315 286 QString* libfile= _cacheLookup(Name);
316 287 if(libfile==NULL)return NULL;
317 288 QLibrary* lib = new QLibrary(*libfile);
318 289 delete libfile;
319 290 lib->load();
320 291 if(lib->isLoaded())
321 292 {
322 293 socexplorerpluginVersionT pluginversion = (socexplorerpluginVersionT)lib->resolve("socexplorerpluginVersion");
323 294 if(pluginversion!=NULL)
324 295 {
325 296 QString version = pluginversion();
326 297 ////lib->unload();
327 298 lib->~QLibrary();
328 299 return version;
329 300 }
330 301 }
331 302 lib->~QLibrary();
332 303 return QObject::tr("Can't load Plugin.");
333 304 }
334 305
335 306
336 307
337 308 QString pluginloader::getlibPIDstr(const QString Name)
338 309 {
339 310 return QString("0x" + QString::number(pluginloader::getlibPID(Name) , 16));
340 311 }
341 312
342 313 QString pluginloader::getlibVIDstr(const QString Name)
343 314 {
344 315 return QString("0x" + QString::number(pluginloader::getlibVID(Name) , 16));
345 316 }
346 317
347 318
348 319
349 320 int pluginloader::libcanbechild(const QString Name)
350 321 {
351 322 if(_self==NULL)init();
352 323 QString* libfile= _cacheLookup(Name);
353 324 if(libfile==NULL)return (int)NULL;
354 325 QLibrary* lib = new QLibrary(*libfile);
355 326 delete libfile;
356 327 lib->load();
357 328 if(lib->isLoaded())
358 329 {
359 330 socexplorerplugincanbechildT canbechild = (socexplorerplugincanbechildT)lib->resolve("socexplorerplugincanbechild");
360 331 if(canbechild!=NULL)
361 332 {
362 333 int value = canbechild();
363 334 ////lib->unload();
364 335 //lib->~QLibrary();
365 336 return value;
366 337 }
367 338 }
368 339 //lib->~QLibrary();
369 340 return 0;
370 341 }
371 342
372 343
373 344
374 345
375 346 int pluginloader::libcanberoot(const QString Name)
376 347 {
377 348 if(_self==NULL)init();
378 349 QString* libfile= _cacheLookup(Name);
379 350 if(libfile==NULL)return (int)NULL;
380 351 QLibrary* lib = new QLibrary(*libfile);
381 352 delete libfile;
382 353 lib->load();
383 354 if(lib->isLoaded())
384 355 {
385 356 socexplorerplugincanberootT canberoot = (socexplorerplugincanberootT)lib->resolve("socexplorerplugincanberoot");
386 357 if(canberoot!=NULL)
387 358 {
388 359 int value = canberoot();
389 360 ////lib->unload();
390 361 //lib->~QLibrary();
391 362 return value;
392 363 }
393 364 }
394 365 delete lib;
395 366 //lib->~QLibrary();
396 367 return 0;
397 368 }
398 369
399 370 int pluginloader::getlibVID(const QString Name)
400 371 {
401 372 if(_self==NULL)init();
402 373 QString* libfile= _cacheLookup(Name);
403 374 if(libfile==NULL)return 0;
404 375 QString file(*libfile);
405 376 delete libfile;
406 377 return _getlibVID(file);
407 378 }
408 379
409 380
410 381 int pluginloader::getlibPID(const QString Name)
411 382 {
412 383 if(_self==NULL)init();
413 384 QString* libfile= _cacheLookup(Name);
414 385 if(libfile==NULL)return 0;
415 386 QString file(*libfile);
416 387 delete libfile;
417 388 return _getlibPID(file);
418 389 }
419 390
420 391 QString pluginloader::getlibAuthor(const QString Name)
421 392 {
422 393 if(_self==NULL)init();
423 394 QString* libfile= _cacheLookup(Name);
424 395 if(libfile==NULL)return NULL;
425 396 QLibrary* lib = new QLibrary(*libfile);
426 397 delete libfile;
427 398 lib->load();
428 399 if(lib->isLoaded())
429 400 {
430 401 socexplorerpluginAuthorT pluginauthor = (socexplorerpluginAuthorT)lib->resolve("socexplorerpluginAuthor");
431 402 if(pluginauthor!=NULL)
432 403 {
433 404 QString author = pluginauthor();
434 405 ////lib->unload();
435 406 lib->~QLibrary();
436 407 return author;
437 408 }
438 409 }
439 410 lib->~QLibrary();
440 411 return QObject::tr("Can't load Plugin.");
441 412 }
442 413
443 414 QString pluginloader::getlibName(const QString Name)
444 415 {
445 416 if(_self==NULL)init();
446 417 QString* libfile= _cacheLookup(Name);
447 418 if(libfile==NULL)return QString("");
448 419 QString file(*libfile);
449 420 delete libfile;
450 421 return _getlibName(file);
451 422 }
452 423
453 424 QString pluginloader::getlibDescription(const QString Name)
454 425 {
455 426 if(_self==NULL)init();
456 427 QString* libfile= _cacheLookup(Name);
457 428 if(libfile==NULL)return NULL;
458 429 QLibrary* lib = new QLibrary(*libfile);
459 430 delete libfile;
460 431 lib->load();
461 432 if(lib->isLoaded())
462 433 {
463 434 socexplorerpluginDescriptionT plugindescription = (socexplorerpluginDescriptionT)lib->resolve("socexplorerpluginDescription");
464 435 if(plugindescription!=NULL)
465 436 {
466 437 QString description = plugindescription();
467 438 ////lib->unload();
468 439 lib->~QLibrary();
469 440 return description;
470 441 }
471 442 }
472 443 lib->~QLibrary();
473 444 return QObject::tr("Can't load Plugin.");
474 445 }
475 446
476 447 QString pluginloader::getlibDir(const QString Name)
477 448 {
478 449 if(_self==NULL)init();
479 450 return *_cacheLookup(Name);
480 451 }
481 452
482 453 QString pluginloader::_getlibName(const QString fileName)
483 454 {
484 455 QLibrary* lib = new QLibrary(fileName);
485 456 lib->load();
486 457 if(lib->isLoaded())
487 458 {
488 459 socexplorerpluginNameT pluginName = (socexplorerpluginAuthorT)lib->resolve("socexplorerpluginName");
489 460 if(pluginName!=NULL)
490 461 {
491 462 QString name = pluginName();
492 463 //lib->unload();
493 464 lib->~QLibrary();
494 465 return name;
495 466 }
496 467 }
497 468 lib->~QLibrary();
498 469 return QObject::tr("Can't load Plugin.");
499 470 }
500 471
501 472 int pluginloader::_getlibPID(const QString fileName)
502 473 {
503 474 QLibrary* lib = new QLibrary(fileName);
504 475 lib->load();
505 476 if(lib->isLoaded())
506 477 {
507 478 socexplorerpluginpidT pluginpid = (socexplorerpluginpidT)lib->resolve("socexplorerpluginpid");
508 479 if(pluginpid!=NULL)
509 480 {
510 481 int pid = pluginpid();
511 482 //lib->unload();
512 483 lib->~QLibrary();
513 484 return pid;
514 485 }
515 486 }
516 487 lib->~QLibrary();
517 488 return 0;
518 489 }
519 490
520 491 int pluginloader::_getlibVID(const QString fileName)
521 492 {
522 493 QLibrary* lib = new QLibrary(fileName);
523 494 lib->load();
524 495 if(lib->isLoaded())
525 496 {
526 497 socexplorerpluginvidT pluginvid = (socexplorerpluginvidT)lib->resolve("socexplorerpluginvid");
527 498 if(pluginvid!=NULL)
528 499 {
529 500 int vid = pluginvid();
530 501 //lib->unload();
531 502 lib->~QLibrary();
532 503 return vid;
533 504 }
534 505 }
535 506 lib->~QLibrary();
536 507 return 0;
537 508 }
538 509
539 510 QString* pluginloader::_cacheLookup(const QString Name)
540 511 {
541 512 QString* libfile= new QString(_cache->first(Name));
542 513 if(!QFile::exists(*libfile))
543 514 {
544 515 scanFolders();
545 516 *libfile = _cache->first(Name);
546 517 if(QFile::exists(*libfile))return libfile;
547 518 }
548 519 else
549 520 {
550 521 return libfile;
551 522 }
552 523 delete libfile;
553 524 return NULL;
554 525 }
555 526
556 527 /*QString findlib(QString name)
557 528 {
558 529
559 530 }*/
560 531
@@ -1,90 +1,89
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the SocExplorer Software
3 3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 2 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------*/
19 19 /*-- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 21 ----------------------------------------------------------------------------*/
22 22 #ifndef PLUGINLOADER_H
23 23 #define PLUGINLOADER_H
24 24
25 25 #include <QString>
26 26 #include <QLibrary>
27 27 #include <QObject>
28 28 #include <QStringList>
29 29 #include <socexplorerplugininterface.h>
30 30 #include <socexplorerplugin.h>
31 31 #include <pluginscache.h>
32 32 /*
33 33 Debug
34 34 */
35 35 #include <stdio.h>
36 36
37 37 #define loadlib(filename) QLibrary* lib = new QLibrary((fileName));\
38 38 lib->load();\
39 39 if(!lib->isLoaded())\
40 40 {\
41 41 return 0;\
42 42 }
43 43
44 44
45 45 class pluginloader
46 46 {
47 47
48 48 private:
49 49 static pluginloader* _self;
50 50 static PluginsCache* _cache;
51 51 static QStringList* _folderList;
52 52 ~pluginloader();
53 53 pluginloader();
54 54 public:
55 55
56 56 static void init();
57 57 static pluginloader* self();
58 58
59 59 static int checklibrary(const QString fileName);
60 60 static bool isvalid(QString Name);
61 61 static socexplorerplugin* newsocexplorerplugin(const QString Name);
62 62 static QString getlibTypeStr(QString Name);
63 63 static pluginT getlibType(QString Name);
64 64 static QString getlibVersion(const QString Name);
65 65 static QString getlibPIDstr(const QString Name);
66 66 static QString getlibVIDstr(const QString Name);
67 67 static int getlibPID(const QString Name);
68 68 static int getlibVID(const QString Name);
69 69 static int libcanbechild(const QString Name);
70 70 static int libcanberoot(const QString Name);
71 71 static QString getlibAuthor(const QString Name);
72 72 static QString getlibName(const QString Name);
73 73 static QString getlibDescription(const QString Name);
74 74 static QString getlibDir(const QString Name);
75 75 static QString findlib(QString name);
76 76 static QList<PluginsCacheItem *> listAvailiables(bool rescan=true);
77 77 static void scanFolders();
78 78 static void showCache(){_cache->show();}
79 79 private:
80 80 int p_checklibraryQlib(const QString fileName);
81 81 int p_checklibraryCustom(const QString fileName);
82 82 socexplorerplugin* p_newsocexplorerpluginQlib(const QString Name);
83 83 socexplorerplugin* p_newsocexplorerpluginCustom(const QString Name);
84 static QStringList readFoldersList(const QStringList confFiles);
85 84 static QString* _cacheLookup(const QString Name);
86 85 static QString _getlibName(const QString fileName);
87 86 static int _getlibPID(const QString fileName);
88 87 static int _getlibVID(const QString fileName);
89 88 };
90 89 #endif
@@ -1,164 +1,165
1 1 #include "pluginscache.h"
2 2 #include <QDebug>
3 #include <socexplorerengine.h>
3 4
4 5 PluginsCacheItem::PluginsCacheItem(const QString &fileName, const QString &path, const QString &pluginName, int VID, int PID)
5 6 {
6 7 this->fileName = new QString(fileName);
7 8 this->path = new QString(path);
8 9 this->pluginName = new QString(pluginName);
9 10 this->VID = VID;
10 11 this->PID = PID;
11 12 }
12 13
13 14 bool PluginsCacheItem::comparePluginName(const QString& pluginName)
14 15 {
15 16 return (!this->pluginName->compare(pluginName));
16 17 }
17 18
18 19 bool PluginsCacheItem::comparefileName(const QString &fileName)
19 20 {
20 21 bool same=false;
21 22 same|=!(this->fileName->compare(fileName));
22 23 same|=!(this->fileName->compare(fileName+".so"));
23 24 same|=!(this->fileName->compare("lib"+fileName+".so"));
24 25 return same;
25 26 }
26 27
27 28 bool PluginsCacheItem::comparefilePath(const QString &filePath)
28 29 {
29 30 return (!QString::compare(*this->path +"/"+*this->fileName,filePath));
30 31 }
31 32
32 33 bool PluginsCacheItem::compareIDs(int VID,int PID)
33 34 {
34 35 return (VID==this->VID && PID==this->PID);
35 36 }
36 37
37 38 bool PluginsCacheItem::compare(PluginsCacheItem *item)
38 39 {
39 40 return comparefilePath(item->getpath()+"/"+item->getfileName());
40 41 }
41 42
42 43
43 44
44 45 PluginsCache::PluginsCache(QObject* parent)
45 46 :QObject(parent)
46 47 {
47 48 this->items = new QList<PluginsCacheItem*>;
48 49 this->__view =NULL;
49 50 }
50 51
51 52
52 53 void PluginsCache::append(const QString &fileName, const QString &path, const QString &pluginName, int VID, int PID)
53 54 {
54 55 PluginsCacheItem* item=new PluginsCacheItem(fileName,path,pluginName, VID, PID);
55 56 for(int i=0;i<this->items->count();i++)
56 57 {
57 58 if(this->items->at(i)->compare(item))
58 59 {
59 qDebug()<< fileName << "already in the cache";
60 SocExplorerEngine::message("PluginsCache",fileName + " already in the cache",3);
60 61 delete item;
61 62 return;
62 63 }
63 64 }
64 qDebug()<< fileName << "added to cache";
65 SocExplorerEngine::message("PluginsCache",fileName + " added to cache",3);
65 66 this->items->append(item);
66 67 }
67 68
68 69
69 70 QString PluginsCache::first(const QString& pluginName)
70 71 {
71 72 for(int i=0;i<this->items->count();i++)
72 73 {
73 74 if(this->items->at(i)->comparePluginName(pluginName))
74 75 {
75 76 return QString(this->items->at(i)->getpath()+"/"+this->items->at(i)->getfileName());
76 77 }
77 78 if(this->items->at(i)->comparefileName(pluginName))
78 79 {
79 80 return QString(this->items->at(i)->getpath()+"/"+this->items->at(i)->getfileName());
80 81 }
81 82 if(this->items->at(i)->comparefilePath(pluginName))
82 83 {
83 84 return QString(this->items->at(i)->getpath()+"/"+this->items->at(i)->getfileName());
84 85 }
85 86
86 87 }
87 88 return QString("");
88 89 }
89 90
90 91
91 92
92 93
93 94 QString PluginsCache::first(int VID,int PID)
94 95 {
95 96 for(int i=0;i<this->items->count();i++)
96 97 {
97 98 if(this->items->at(i)->compareIDs(VID,PID))
98 99 {
99 100 return QString(this->items->at(i)->getpath()+"/"+this->items->at(i)->getfileName());
100 101 }
101 102 }
102 103 return QString("");
103 104 }
104 105
105 106
106 107
107 108 QList<PluginsCacheItem *> PluginsCache::listDrivers()
108 109 {
109 110 return *items;
110 111 }
111 112
112 113
113 114 void PluginsCache::flush()
114 115 {
115 116 PluginsCacheItem* ptr;
116 117 for(int i=0;i<this->items->count();i++)
117 118 {
118 119 ptr=this->items->at(i);
119 120 this->items->removeAt(i);
120 121 delete ptr;
121 122 }
122 123 }
123 124
124 125
125 126
126 127 void PluginsCache::show()
127 128 {
128 129 if(this->__view==NULL)this->__view = new QTableWidget(0,5);
129 130 if(!this->__view->isVisible())
130 131 {
131 132 this->__view->clear();
132 133 this->__view->setHorizontalHeaderLabels(QStringList()<<"File Name"<<"Path"<<"PluginName"<<"VID"<<"PID");
133 134 QTableWidgetItem* item;
134 135 this->__view->setRowCount(this->items->count());
135 136 for(int i=0;i<this->items->count();i++)
136 137 {
137 138 item = new QTableWidgetItem(items->at(i)->getfileName());
138 139 item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
139 140 this->__view->setItem(i,0,item);
140 141 item = new QTableWidgetItem(items->at(i)->getpath());
141 142 item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
142 143 this->__view->setItem(i,1,item);
143 144 item = new QTableWidgetItem(items->at(i)->getpluginName());
144 145 item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
145 146 this->__view->setItem(i,2,item);
146 147 item = new QTableWidgetItem(QString::number(items->at(i)->getVID()));
147 148 item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
148 149 this->__view->setItem(i,3,item);
149 150 item = new QTableWidgetItem(QString::number(items->at(i)->getPID()));
150 151 item->setFlags(Qt::ItemIsEnabled|Qt::ItemIsSelectable);
151 152 this->__view->setItem(i,4,item);
152 153 }
153 154 this->__view->resizeRowsToContents();
154 155 this->__view->resizeColumnsToContents();
155 156 this->__view->show();
156 157 }
157 158 }
158 159
159 160
160 161
161 162
162 163
163 164
164 165
@@ -1,38 +1,39
1 1 #include "unixpluginloader.h"
2 2 #include <stdio.h>
3 3 #include <QDebug>
4 #include <socexplorerengine.h>
4 5
5 6 unixPluginLoader::unixPluginLoader(const QString &libPath)
6 7 {
7 qDebug()<<"try to open "+libPath;
8 SocExplorerEngine::message("unixPluginLoader::unixPluginLoader","try to open "+libPath,3);
8 9 dlHandle = dlopen(libPath.toStdString().c_str(),RTLD_LAZY|RTLD_GLOBAL);
9 10 if(dlHandle==NULL)
10 qDebug() << "Failed"<< dlerror();
11 SocExplorerEngine::message("unixPluginLoader::unixPluginLoader",QString("Failed ") + dlerror(),3);
11 12 else
12 qDebug() << "Success";
13 SocExplorerEngine::message("unixPluginLoader::unixPluginLoader","Success " ,3);
13 14 this->libPath = libPath;
14 15 }
15 16
16 17 void *unixPluginLoader::resolve(const QString &symbol)
17 18 {
18 19 if(dlHandle!=NULL)
19 20 {
20 qDebug()<<"try to resolve "+symbol+" in "+libPath;
21 SocExplorerEngine::message("unixPluginLoader::resolve","try to resolve "+symbol+" in "+libPath ,3);
21 22 void* sym = dlsym (dlHandle, symbol.toStdString().c_str());
22 23 if(sym==NULL)
23 qDebug() << "Failed"<< dlerror();
24 SocExplorerEngine::message("unixPluginLoader::resolve",QString("Failed")+ dlerror() ,3);
24 25 else
25 qDebug() << "Success";
26 SocExplorerEngine::message("unixPluginLoader::resolve","Success",3);
26 27 return sym;
27 28 }
28 29 return NULL;
29 30 }
30 31
31 32 void unixPluginLoader::close()
32 33 {
33 34 if(dlHandle!=NULL)
34 35 {
35 36 dlclose(dlHandle);
36 qDebug() << dlerror();
37 SocExplorerEngine::message("unixPluginLoader::close",dlerror(),3);
37 38 }
38 39 }
General Comments 0
You need to be logged in to leave comments. Login now