##// END OF EJS Templates
Removed _d for debug binaries, moved plugin to default location...
Jeandet Alexis -
r65:7f2fbf718320 default
parent child
Show More
@@ -0,0 +1,3
1 /usr/lib/SocExplorer/plugins
2 /usr/lib64/SocExplorer/plugins
3
@@ -1,86 +1,88
1 #-------------------------------------------------
1 #-------------------------------------------------
2 #
2 #
3 # Project created by QtCreator 2011-09-19T22:52:10
3 # Project created by QtCreator 2011-09-19T22:52:10
4 #
4 #
5 #-------------------------------------------------
5 #-------------------------------------------------
6
6
7 TEMPLATE = subdirs
7 TEMPLATE = subdirs
8 CONFIG += ordered release
8 CONFIG += ordered release
9
9
10 SUBDIRS = \
10 SUBDIRS = \
11 src/common \
11 src/common \
12 src/SocExplorerEngine \
12 src/SocExplorerEngine \
13 src \
13 src \
14 src/SocExplorer_TCP_Terminal
14 src/SocExplorer_TCP_Terminal
15
15
16
16
17 socexplorercfg.path = $$[QT_INSTALL_PREFIX]/mkspecs/features
17 socexplorercfg.path = $$[QT_INSTALL_PREFIX]/mkspecs/features
18 socexplorercfg.files = \
18 socexplorercfg.files = \
19 src/SocExplorerEngine/plugins/socexplorerplugin.prf
19 src/SocExplorerEngine/plugins/socexplorerplugin.prf
20
20
21
21
22 unix{
22 unix{
23 SocExplorer.path = /usr/share/applications/
23 SocExplorer.path = /usr/share/applications/
24 SocExplorer.files = unixcfg/SocExplorer.desktop
24 SocExplorer.files = unixcfg/SocExplorer.desktop
25 PluginConfPath.path = /etc/SocExplorer/plugin.conf.d/
26 PluginConfPath.files = unixcfg/plugins.conf
25 icon.path = /usr/share/SocExplorer
27 icon.path = /usr/share/SocExplorer
26 icon.files = ressources/images/Indiana_Jones_cappello.png
28 icon.files = ressources/images/Indiana_Jones_cappello.png
27 Wizard.path = /usr/share/qtcreator/templates/wizards/SocExplorerPlugin
29 Wizard.path = /usr/share/qtcreator/templates/wizards/SocExplorerPlugin
28 Wizard.files = Qt_Creator_Wizard/SocExplorerPlugin/logo-lpp-cutted.png \
30 Wizard.files = Qt_Creator_Wizard/SocExplorerPlugin/logo-lpp-cutted.png \
29 Qt_Creator_Wizard/SocExplorerPlugin/plugin.cpp \
31 Qt_Creator_Wizard/SocExplorerPlugin/plugin.cpp \
30 Qt_Creator_Wizard/SocExplorerPlugin/plugin.h \
32 Qt_Creator_Wizard/SocExplorerPlugin/plugin.h \
31 Qt_Creator_Wizard/SocExplorerPlugin/project.pro \
33 Qt_Creator_Wizard/SocExplorerPlugin/project.pro \
32 Qt_Creator_Wizard/SocExplorerPlugin/wizard.xml
34 Qt_Creator_Wizard/SocExplorerPlugin/wizard.xml
33 INSTALLS+=Wizard SocExplorer icon
35 INSTALLS+=Wizard SocExplorer icon PluginConfPath
34 }
36 }
35 INSTALLS+=socexplorercfg
37 INSTALLS+=socexplorercfg
36
38
37
39
38
40
39
41
40
42
41
43
42
44
43
45
44
46
45
47
46
48
47
49
48
50
49
51
50
52
51
53
52
54
53
55
54
56
55
57
56
58
57
59
58
60
59
61
60
62
61
63
62
64
63
65
64
66
65
67
66
68
67
69
68
70
69
71
70
72
71
73
72
74
73
75
74
76
75
77
76
78
77
79
78
80
79
81
80
82
81
83
82
84
83
85
84
86
85
87
86
88
@@ -1,27 +1,22
1
1
2 QT += core gui xml svg network
2 QT += core gui xml svg network
3 contains(QT_MAJOR_VERSION, 5) {
3 contains(QT_MAJOR_VERSION, 5) {
4 QT += widgets
4 QT += widgets
5 QT += printsupport
5 QT += printsupport
6 }
6 }
7 CONFIG(debug, debug|release) {
8 DEBUG_EXT = _d
9 } else {
10 DEBUG_EXT =
11 }
12
7
13 SOCEXPLORER_SDK_BUILD="SOCEXPLORER_SDK_BUILD"
8 SOCEXPLORER_SDK_BUILD="SOCEXPLORER_SDK_BUILD"
14 DEFINES += SOCEXPLORER_SDK_BUILD
9 DEFINES += SOCEXPLORER_SDK_BUILD
15
10
16 MOC_DIR = moc
11 MOC_DIR = moc
17 RCC_DIR = resources
12 RCC_DIR = resources
18 OBJECTS_DIR = obj
13 OBJECTS_DIR = obj
19
14
20 win32:DESTDIR = $${SOCEXPLORER_ROOT}/bin/win32/
15 win32:DESTDIR = $${SOCEXPLORER_ROOT}/bin/win32/
21 unix:DESTDIR = $${SOCEXPLORER_ROOT}/bin/linux/
16 unix:DESTDIR = $${SOCEXPLORER_ROOT}/bin/linux/
22
17
23
18
24 metrics_cccc.target = metrics_cccc
19 metrics_cccc.target = metrics_cccc
25 metrics_cccc.commands = cccc $(SOURCES) $(HEADERS)
20 metrics_cccc.commands = cccc $(SOURCES) $(HEADERS)
26
21
27 QMAKE_EXTRA_TARGETS += metrics_cccc
22 QMAKE_EXTRA_TARGETS += metrics_cccc
@@ -1,251 +1,285
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "socexplorerengine.h"
22 #include "socexplorerengine.h"
23 #include <proxy/socexplorerproxy.h>
23 #include <proxy/socexplorerproxy.h>
24
24
25 SocExplorerEngine* SocExplorerEngine::_self = NULL;
25 SocExplorerEngine* SocExplorerEngine::_self = NULL;
26 socExplorerXmlModel* SocExplorerEngine::p_xmlmodel=NULL;
26 socExplorerXmlModel* SocExplorerEngine::p_xmlmodel=NULL;
27 QMainWindow* SocExplorerEngine::mainWindow=NULL;
27 QMainWindow* SocExplorerEngine::mainWindow=NULL;
28 QList<SOCModel*>* SocExplorerEngine::SOCs=NULL;
28 QList<SOCModel*>* SocExplorerEngine::SOCs=NULL;
29 int SocExplorerEngine::loglvl=1;
29 int SocExplorerEngine::loglvl=1;
30
30
31 SocExplorerEngine::SocExplorerEngine(QObject *parent) :
31 SocExplorerEngine::SocExplorerEngine(QObject *parent) :
32 QObject(parent)
32 QObject(parent)
33 {
33 {
34 if(SOCs==NULL)
34 if(SOCs==NULL)
35 {
35 {
36 SOCs = new QList<SOCModel*>;
36 SOCs = new QList<SOCModel*>;
37 }
37 }
38
38
39 }
39 }
40
40
41
41
42 void SocExplorerEngine::init()
42 void SocExplorerEngine::init()
43 {
43 {
44 QDir dir;
44 QDir dir;
45 if(!_self)
45 if(!_self)
46 {
46 {
47 _self= new SocExplorerEngine;
47 _self= new SocExplorerEngine;
48 }
48 }
49 if(!dir.exists(configFolder()))
49 if(!dir.exists(configFolder()))
50 dir.mkdir(configFolder());
50 dir.mkdir(configFolder());
51 p_xmlmodel = new socExplorerXmlModel(_self);
51 p_xmlmodel = new socExplorerXmlModel(_self);
52 p_xmlmodel->updateSOClist();
52 p_xmlmodel->updateSOClist();
53 }
53 }
54
54
55 QString SocExplorerEngine::configFolder()
55 QString SocExplorerEngine::configFolder()
56 {
56 {
57 return QString(SOCEXPLORER_CONFIG_PATH);
57 return QString(SOCEXPLORER_CONFIG_PATH);
58 }
58 }
59
59
60 QStringList SocExplorerEngine::pluginFolders()
61 {
62 if(!_self)
63 init();
64 QStringList folders;
65 QDir pluginFolders(QString(SOCEXPLORER_CONFIG_PATH)+"/plugin.conf.d");
66 if(pluginFolders.exists())
67 {
68 pluginFolders.setFilter(QDir::Files | QDir::NoSymLinks);
69 QFileInfoList list = pluginFolders.entryInfoList();
70 for (int i = 0; i < list.size(); ++i)
71 {
72 QFileInfo fileInfo = list.at(i);
73 if(fileInfo.suffix()=="conf")
74 {
75 QFile confFile(fileInfo.absoluteFilePath());
76 if(confFile.open(QIODevice::ReadOnly))
77 {
78 while (!confFile.atEnd())
79 {
80 QString line = confFile.readLine();
81 QDir plugDir(line.remove("\n"));
82 if(plugDir.exists() && !folders.contains(plugDir.absolutePath()))
83 {
84 folders.append(plugDir.absolutePath());
85 }
86 }
87 }
88 }
89 }
90 }
91 return folders;
92 }
93
60 SOCModel *SocExplorerEngine::plugin2Soc(socexplorerplugin *plugin)
94 SOCModel *SocExplorerEngine::plugin2Soc(socexplorerplugin *plugin)
61 {
95 {
62 if(!_self)
96 if(!_self)
63 init();
97 init();
64 if(plugin)
98 if(plugin)
65 {
99 {
66 while (plugin->parent!=NULL) {
100 while (plugin->parent!=NULL) {
67 plugin = plugin->parent;
101 plugin = plugin->parent;
68 }
102 }
69 for(int i=0;i<SOCs->count();i++)
103 for(int i=0;i<SOCs->count();i++)
70 {
104 {
71 if(SOCs->at(i)->isRootDev(plugin))
105 if(SOCs->at(i)->isRootDev(plugin))
72 return SOCs->at(i);
106 return SOCs->at(i);
73 }
107 }
74 //no soc found so create a new one
108 //no soc found so create a new one
75 SOCModel* soc=new SOCModel(plugin);
109 SOCModel* soc=new SOCModel(plugin);
76 SOCs->append(soc);
110 SOCs->append(soc);
77 return soc;
111 return soc;
78 }
112 }
79 return NULL;
113 return NULL;
80 }
114 }
81
115
82
116
83 int SocExplorerEngine::addEnumDevice(socexplorerplugin* rootPlugin,int VID, int PID, qint32 baseAddress, const QString &name)
117 int SocExplorerEngine::addEnumDevice(socexplorerplugin* rootPlugin,int VID, int PID, qint32 baseAddress, const QString &name)
84 {
118 {
85 if(!_self)
119 if(!_self)
86 init();
120 init();
87 SOCModel* soc = plugin2Soc(rootPlugin);
121 SOCModel* soc = plugin2Soc(rootPlugin);
88 if(soc && !soc->enumDeviceExists(baseAddress))
122 if(soc && !soc->enumDeviceExists(baseAddress))
89 {
123 {
90 emit _self->enumDeviceAdded(soc->addEnumDevice(VID,PID,baseAddress,name));
124 emit _self->enumDeviceAdded(soc->addEnumDevice(VID,PID,baseAddress,name));
91 return 1;
125 return 1;
92 }
126 }
93 return 0;
127 return 0;
94 }
128 }
95
129
96 QList<SOCModel *> *SocExplorerEngine::getSOCs()
130 QList<SOCModel *> *SocExplorerEngine::getSOCs()
97 {
131 {
98 if(!_self)
132 if(!_self)
99 init();
133 init();
100 return SOCs;
134 return SOCs;
101 }
135 }
102
136
103 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(const QString& rootPlugin,int VID, int PID, int count)
137 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(const QString& rootPlugin,int VID, int PID, int count)
104 {
138 {
105 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
139 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
106 if(plugin==NULL)return -1;
140 if(plugin==NULL)return -1;
107 SOCModel* soc = plugin2Soc(plugin);
141 SOCModel* soc = plugin2Soc(plugin);
108 if(soc==NULL)
142 if(soc==NULL)
109 return -1;
143 return -1;
110 return soc->getEnumDeviceBaseAddress(VID,PID,count);
144 return soc->getEnumDeviceBaseAddress(VID,PID,count);
111 }
145 }
112
146
113 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(socexplorerplugin *plugin, int VID, int PID, int count)
147 qint32 SocExplorerEngine::getEnumDeviceBaseAddress(socexplorerplugin *plugin, int VID, int PID, int count)
114 {
148 {
115 if(plugin==NULL)return -1;
149 if(plugin==NULL)return -1;
116 SOCModel* soc = plugin2Soc(plugin);
150 SOCModel* soc = plugin2Soc(plugin);
117 if(soc==NULL)
151 if(soc==NULL)
118 return -1;
152 return -1;
119 return soc->getEnumDeviceBaseAddress(VID,PID,count);
153 return soc->getEnumDeviceBaseAddress(VID,PID,count);
120 }
154 }
121
155
122 qint32 SocExplorerEngine::getEnumDeviceCount(socexplorerplugin *plugin, int VID, int PID)
156 qint32 SocExplorerEngine::getEnumDeviceCount(socexplorerplugin *plugin, int VID, int PID)
123 {
157 {
124 if(plugin==NULL)return 0;
158 if(plugin==NULL)return 0;
125 SOCModel* soc = plugin2Soc(plugin);
159 SOCModel* soc = plugin2Soc(plugin);
126 if(soc==NULL)
160 if(soc==NULL)
127 return 0;
161 return 0;
128 return soc->getEnumDeviceCount(VID,PID);
162 return soc->getEnumDeviceCount(VID,PID);
129 }
163 }
130
164
131 qint32 SocExplorerEngine::getEnumDeviceCount(const QString &rootPlugin, int VID, int PID)
165 qint32 SocExplorerEngine::getEnumDeviceCount(const QString &rootPlugin, int VID, int PID)
132 {
166 {
133 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
167 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
134 if(plugin==NULL)return 0;
168 if(plugin==NULL)return 0;
135 SOCModel* soc = plugin2Soc(plugin);
169 SOCModel* soc = plugin2Soc(plugin);
136 if(soc==NULL)
170 if(soc==NULL)
137 return 0;
171 return 0;
138 return soc->getEnumDeviceCount(VID,PID);
172 return soc->getEnumDeviceCount(VID,PID);
139 }
173 }
140
174
141 int SocExplorerEngine::addEnumDevice(const QString &rootPlugin, int VID, int PID, qint32 baseAddress, const QString &name)
175 int SocExplorerEngine::addEnumDevice(const QString &rootPlugin, int VID, int PID, qint32 baseAddress, const QString &name)
142 {
176 {
143 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
177 socexplorerplugin* plugin = socexplorerproxy::findPlugin(rootPlugin);
144 if(plugin==NULL)return -1;
178 if(plugin==NULL)return -1;
145 SOCModel* soc = plugin2Soc(plugin);
179 SOCModel* soc = plugin2Soc(plugin);
146 if(soc==NULL)
180 if(soc==NULL)
147 return -1;
181 return -1;
148 soc->addEnumDevice(VID,PID,baseAddress,name);
182 soc->addEnumDevice(VID,PID,baseAddress,name);
149 return 1;
183 return 1;
150 }
184 }
151
185
152
186
153 QString SocExplorerEngine::getDevName(int VID, int PID)
187 QString SocExplorerEngine::getDevName(int VID, int PID)
154 {
188 {
155 QList<QDomNodeList> list=p_xmlmodel->getAllNodes("peripheral");
189 QList<QDomNodeList> list=p_xmlmodel->getAllNodes("peripheral");
156 for(int i=0;i<list.count();i++)
190 for(int i=0;i<list.count();i++)
157 {
191 {
158 QDomNodeList nodes=list.at(i);
192 QDomNodeList nodes=list.at(i);
159 for(int l=0;l<nodes.count();l++)
193 for(int l=0;l<nodes.count();l++)
160 {
194 {
161 QDomElement node=nodes.at(l).toElement();
195 QDomElement node=nodes.at(l).toElement();
162 int nodeVID=node.attribute("vid","0").toInt();
196 int nodeVID=node.attribute("vid","0").toInt();
163 int nodePID=node.attribute("pid","0").toInt();
197 int nodePID=node.attribute("pid","0").toInt();
164 if((nodeVID==VID)&&(nodePID==PID))
198 if((nodeVID==VID)&&(nodePID==PID))
165 {
199 {
166 return node.attribute("name","Unknow device");
200 return node.attribute("name","Unknow device");
167 }
201 }
168 }
202 }
169 }
203 }
170 return QString("Unknow device");
204 return QString("Unknow device");
171 }
205 }
172
206
173 QString SocExplorerEngine::SocExplorerVersion(){return QString(SOCEXPLORER_VERSION);}
207 QString SocExplorerEngine::SocExplorerVersion(){return QString(SOCEXPLORER_VERSION);}
174
208
175 QString SocExplorerEngine::SocExplorerChangeset(){return QString(SOCEXPLORER_CHAGESET).split(" ").at(0);}
209 QString SocExplorerEngine::SocExplorerChangeset(){return QString(SOCEXPLORER_CHAGESET).split(" ").at(0);}
176
210
177 QString SocExplorerEngine::SocExplorerBranch(){return QString(SOCEXPLORER_BRANCH);}
211 QString SocExplorerEngine::SocExplorerBranch(){return QString(SOCEXPLORER_BRANCH);}
178
212
179 socExplorerXmlModel *SocExplorerEngine::xmlModel()
213 socExplorerXmlModel *SocExplorerEngine::xmlModel()
180 {
214 {
181 if(!_self)
215 if(!_self)
182 init();
216 init();
183 return p_xmlmodel;
217 return p_xmlmodel;
184 }
218 }
185
219
186 void SocExplorerEngine::setMainWindow(QMainWindow *Mainwindow)
220 void SocExplorerEngine::setMainWindow(QMainWindow *Mainwindow)
187 {
221 {
188 if(!_self)
222 if(!_self)
189 init();
223 init();
190 mainWindow=Mainwindow;
224 mainWindow=Mainwindow;
191 }
225 }
192
226
193 QProgressBar *SocExplorerEngine::getProgressBar(const QString& format, int max)
227 QProgressBar *SocExplorerEngine::getProgressBar(const QString& format, int max)
194 {
228 {
195 if(!_self)
229 if(!_self)
196 init();
230 init();
197 QProgressBar* progressBar;
231 QProgressBar* progressBar;
198 if(mainWindow!=NULL)
232 if(mainWindow!=NULL)
199 {
233 {
200 progressBar = new QProgressBar(mainWindow);
234 progressBar = new QProgressBar(mainWindow);
201 mainWindow->statusBar()->addWidget(progressBar);
235 mainWindow->statusBar()->addWidget(progressBar);
202 }
236 }
203 else
237 else
204 {
238 {
205 progressBar = new QProgressBar();
239 progressBar = new QProgressBar();
206 }
240 }
207 progressBar->setMaximum(max);
241 progressBar->setMaximum(max);
208 progressBar->setFormat(format);
242 progressBar->setFormat(format);
209 return progressBar;
243 return progressBar;
210 }
244 }
211
245
212 void SocExplorerEngine::deleteProgressBar(QProgressBar *progressBar)
246 void SocExplorerEngine::deleteProgressBar(QProgressBar *progressBar)
213 {
247 {
214 if(mainWindow!=NULL)
248 if(mainWindow!=NULL)
215 {
249 {
216 mainWindow->statusBar()->removeWidget(progressBar);
250 mainWindow->statusBar()->removeWidget(progressBar);
217 }
251 }
218 delete progressBar;
252 delete progressBar;
219 }
253 }
220
254
221 void SocExplorerEngine::addSOC(socexplorerplugin *rootPlugin)
255 void SocExplorerEngine::addSOC(socexplorerplugin *rootPlugin)
222 {
256 {
223 plugin2Soc(rootPlugin);
257 plugin2Soc(rootPlugin);
224 }
258 }
225
259
226 void SocExplorerEngine::removeSOC(socexplorerplugin *rootPlugin)
260 void SocExplorerEngine::removeSOC(socexplorerplugin *rootPlugin)
227 {
261 {
228 SOCModel* soc=plugin2Soc(rootPlugin);
262 SOCModel* soc=plugin2Soc(rootPlugin);
229 SOCs->removeAll(soc);
263 SOCs->removeAll(soc);
230 delete soc;
264 delete soc;
231 }
265 }
232
266
233 void SocExplorerEngine::message(socexplorerplugin *sender, const QString &message, int debugLevel)
267 void SocExplorerEngine::message(socexplorerplugin *sender, const QString &message, int debugLevel)
234 {
268 {
235 // TODO add multi output message manager IE also log in files
269 // TODO add multi output message manager IE also log in files
236 if(!_self)
270 if(!_self)
237 init();
271 init();
238 if(loglvl>=debugLevel)
272 if(loglvl>=debugLevel)
239 qDebug()<< QTime::currentTime().toString()+" " + sender->instanceName()+":"+message;
273 qDebug()<< QTime::currentTime().toString()+" " + sender->instanceName()+":"+message;
240 }
274 }
241
275
242 void SocExplorerEngine::setLogLevel(int level)
276 void SocExplorerEngine::setLogLevel(int level)
243 {
277 {
244 if(!_self)
278 if(!_self)
245 init();
279 init();
246 printf("Set log level to %d\n",level);
280 printf("Set log level to %d\n",level);
247 loglvl = level;
281 loglvl = level;
248 }
282 }
249
283
250
284
251
285
@@ -1,136 +1,137
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2012, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef SOCEXPLORERENGINE_H
22 #ifndef SOCEXPLORERENGINE_H
23 #define SOCEXPLORERENGINE_H
23 #define SOCEXPLORERENGINE_H
24
24
25 #include <stdint.h>
25 #include <stdint.h>
26 #include <QObject>
26 #include <QObject>
27 #include <QtWidgets>
27 #include <QtWidgets>
28 #include <QStringList>
28 #include <QStringList>
29 #include <QDomDocument>
29 #include <QDomDocument>
30 #include <QDomElement>
30 #include <QDomElement>
31 #include <QDomNodeList>
31 #include <QDomNodeList>
32 #include <QFile>
32 #include <QFile>
33 #include <QTextStream>
33 #include <QTextStream>
34 #include <QDir>
34 #include <QDir>
35 #include <QApplication>
35 #include <QApplication>
36 #include <QtCore/qglobal.h>
36 #include <QtCore/qglobal.h>
37 #include <QFileDialog>
37 #include <QFileDialog>
38 #include <socexplorerxmlfile.h>
38 #include <socexplorerxmlfile.h>
39 #include <socexplorerenumdevice.h>
39 #include <socexplorerenumdevice.h>
40 #include <XMLmodel.h>
40 #include <XMLmodel.h>
41 #include <peripheralwidget.h>
41 #include <peripheralwidget.h>
42 #include <registerwidget.h>
42 #include <registerwidget.h>
43 #include <socmodel.h>
43 #include <socmodel.h>
44
44
45 #if defined(SOCEXPLORER_SDK_BUILD)
45 #if defined(SOCEXPLORER_SDK_BUILD)
46 # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT
46 # define SOCEXPLORER_SDK_EXPORT Q_DECL_EXPORT
47 #else
47 #else
48 # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT
48 # define SOCEXPLORER_SDK_EXPORT Q_DECL_IMPORT
49 #endif
49 #endif
50
50
51
51
52 class SOCEXPLORER_SDK_EXPORT SocExplorerAutoProgressBar
52 class SOCEXPLORER_SDK_EXPORT SocExplorerAutoProgressBar
53 {
53 {
54 public:
54 public:
55 SocExplorerAutoProgressBar(QProgressBar* progressBar=NULL)
55 SocExplorerAutoProgressBar(QProgressBar* progressBar=NULL)
56 {
56 {
57 this->p_progressbar=progressBar;
57 this->p_progressbar=progressBar;
58 }
58 }
59 ~SocExplorerAutoProgressBar()
59 ~SocExplorerAutoProgressBar()
60 {
60 {
61 if(p_progressbar)
61 if(p_progressbar)
62 {
62 {
63 delete p_progressbar;
63 delete p_progressbar;
64 }
64 }
65 }
65 }
66 void setProgressBar(QProgressBar* progressBar)
66 void setProgressBar(QProgressBar* progressBar)
67 {
67 {
68 this->p_progressbar=progressBar;
68 this->p_progressbar=progressBar;
69 }
69 }
70 void setValue(int value)
70 void setValue(int value)
71 {
71 {
72 p_progressbar->setValue(value);
72 p_progressbar->setValue(value);
73 }
73 }
74 private:
74 private:
75 QProgressBar* p_progressbar;
75 QProgressBar* p_progressbar;
76 };
76 };
77
77
78 //! SocExplorerEngine is a pure static class which aims to provide services for both SocExplorer software and plugins.
78 //! SocExplorerEngine is a pure static class which aims to provide services for both SocExplorer software and plugins.
79
79
80 class SOCEXPLORER_SDK_EXPORT SocExplorerEngine : public QObject
80 class SOCEXPLORER_SDK_EXPORT SocExplorerEngine : public QObject
81 {
81 {
82 Q_OBJECT
82 Q_OBJECT
83 private:
83 private:
84 static SocExplorerEngine* _self;
84 static SocExplorerEngine* _self;
85 SocExplorerEngine(QObject *parent = 0);
85 SocExplorerEngine(QObject *parent = 0);
86 static void init();
86 static void init();
87
87
88 public:
88 public:
89 static SocExplorerEngine* self(){ if(!_self){_self= new SocExplorerEngine;}return _self;}
89 static SocExplorerEngine* self(){ if(!_self){_self= new SocExplorerEngine;}return _self;}
90 //! Return the configuration folder path, OS dependant.
90 //! Return the configuration folder path, OS dependant.
91 SOCEXPLORER_SDK_EXPORT static QString configFolder();
91 SOCEXPLORER_SDK_EXPORT static QString configFolder();
92 //! Return the default plugin folder path, OS dependant.
92 //! Return the default plugin folder path, OS dependant.
93 static QString pluginFolder(){return QString(SOCEXPLORER_PLUGINS_INSTALL_PATH);}
93 //static QString pluginFolder(){return QString(SOCEXPLORER_PLUGINS_INSTALL_PATH);}
94
94 static QStringList pluginFolders();
95 static QString configPath(){return QString(SOCEXPLORER_CONFIG_PATH);}
95 static int addEnumDevice(socexplorerplugin* rootPlugin,int VID,int PID,qint32 baseAddress,const QString& name);
96 static int addEnumDevice(socexplorerplugin* rootPlugin,int VID,int PID,qint32 baseAddress,const QString& name);
96 static QList<SOCModel*>* getSOCs();
97 static QList<SOCModel*>* getSOCs();
97 static QString getDevName(int VID, int PID);
98 static QString getDevName(int VID, int PID);
98 static QString SocExplorerVersion();
99 static QString SocExplorerVersion();
99 static QString SocExplorerChangeset();
100 static QString SocExplorerChangeset();
100 static QString SocExplorerBranch();
101 static QString SocExplorerBranch();
101 static socExplorerXmlModel* xmlModel();
102 static socExplorerXmlModel* xmlModel();
102 static void setMainWindow(QMainWindow* Mainwindow);
103 static void setMainWindow(QMainWindow* Mainwindow);
103 static QProgressBar* getProgressBar(const QString &format, int max);
104 static QProgressBar* getProgressBar(const QString &format, int max);
104 static void deleteProgressBar(QProgressBar* progressBar);
105 static void deleteProgressBar(QProgressBar* progressBar);
105 static void addSOC(socexplorerplugin* rootPlugin);
106 static void addSOC(socexplorerplugin* rootPlugin);
106 static void removeSOC(socexplorerplugin* rootPlugin);
107 static void removeSOC(socexplorerplugin* rootPlugin);
107 static void message(socexplorerplugin* sender,const QString& message,int debugLevel=0);
108 static void message(socexplorerplugin* sender,const QString& message,int debugLevel=0);
108 static void setLogLevel(int level);
109 static void setLogLevel(int level);
109 signals:
110 signals:
110 void enumDeviceAdded(socExplorerEnumDevice* device);
111 void enumDeviceAdded(socExplorerEnumDevice* device);
111 public slots:
112 public slots:
112 QString getSocExplorerVersion(){return SocExplorerEngine::SocExplorerVersion();}
113 QString getSocExplorerVersion(){return SocExplorerEngine::SocExplorerVersion();}
113 QString getSocExplorerChangeset(){return SocExplorerEngine::SocExplorerChangeset();}
114 QString getSocExplorerChangeset(){return SocExplorerEngine::SocExplorerChangeset();}
114 QString getSocExplorerBranch(){return SocExplorerEngine::SocExplorerBranch();}
115 QString getSocExplorerBranch(){return SocExplorerEngine::SocExplorerBranch();}
115 qint32 getEnumDeviceBaseAddress(const QString& rootPlugin,int VID,int PID,int count=0);
116 qint32 getEnumDeviceBaseAddress(const QString& rootPlugin,int VID,int PID,int count=0);
116 qint32 getEnumDeviceBaseAddress(socexplorerplugin* plugin,int VID,int PID,int count=0);
117 qint32 getEnumDeviceBaseAddress(socexplorerplugin* plugin,int VID,int PID,int count=0);
117 qint32 getEnumDeviceCount(socexplorerplugin* plugin,int VID,int PID);
118 qint32 getEnumDeviceCount(socexplorerplugin* plugin,int VID,int PID);
118 qint32 getEnumDeviceCount(const QString& rootPlugin,int VID,int PID);
119 qint32 getEnumDeviceCount(const QString& rootPlugin,int VID,int PID);
119 int addEnumDevice(const QString& rootPlugin,int VID,int PID,qint32 baseAddress,const QString& name);
120 int addEnumDevice(const QString& rootPlugin,int VID,int PID,qint32 baseAddress,const QString& name);
120
121
121 private:
122 private:
122 static SOCModel* plugin2Soc(socexplorerplugin* plugin);
123 static SOCModel* plugin2Soc(socexplorerplugin* plugin);
123 static socExplorerXmlModel* p_xmlmodel;
124 static socExplorerXmlModel* p_xmlmodel;
124 static QMainWindow* mainWindow;
125 static QMainWindow* mainWindow;
125 static QList<SOCModel*>* SOCs;
126 static QList<SOCModel*>* SOCs;
126 static int loglvl;
127 static int loglvl;
127 };
128 };
128
129
129 #endif // SOCEXPLORERENGINE_H
130 #endif // SOCEXPLORERENGINE_H
130
131
131
132
132
133
133
134
134
135
135
136
136
137
@@ -1,142 +1,143
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2011, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #include "pluginmanagerWDGT.h"
22 #include "pluginmanagerWDGT.h"
23 #include "pluginloader.h"
23 #include "pluginloader.h"
24 #include <QFileDialog>
24 #include <QFileDialog>
25 #include <unistd.h>
25 #include <unistd.h>
26 #include <qsvgicon.h>
26 #include <qsvgicon.h>
27 #include <socexplorerengine.h>
27 #include <socexplorerengine.h>
28
28
29 #define mkbutton(button,text,image)button = new QPushButton();\
29 #define mkbutton(button,text,image)button = new QPushButton();\
30 button->setIcon(QSvgIcon(image));\
30 button->setIcon(QSvgIcon(image));\
31 button->setIconSize(QSize(16,16));\
31 button->setIconSize(QSize(16,16));\
32 button->setToolTip(text)
32 button->setToolTip(text)
33
33
34
34
35
35
36 pluginmanagerWDGT::pluginmanagerWDGT(QWidget *parent) :
36 pluginmanagerWDGT::pluginmanagerWDGT(QWidget *parent) :
37 QSplitter(parent)
37 QSplitter(parent)
38 {
38 {
39 this->setWindowTitle("Plugin Manager");
39 this->setWindowTitle("Plugin Manager");
40 this->setOrientation(Qt::Vertical);
40 this->setOrientation(Qt::Vertical);
41 this->pluginListWidgetContainer = new QWidget();
41 this->pluginListWidgetContainer = new QWidget();
42 this->mainlayoutSpliter = new QSplitter;
42 this->mainlayoutSpliter = new QSplitter;
43 this->pluginListLayout = new QVBoxLayout();
43 this->pluginListLayout = new QVBoxLayout();
44 this->mainlayoutSpliter->setOrientation(Qt::Vertical);
44 this->mainlayoutSpliter->setOrientation(Qt::Vertical);
45 this->treeview = new plugintree();
45 this->treeview = new plugintree();
46 this->pluginTable = new PluginList;
46 this->pluginTable = new PluginList;
47 this->ButtonsLayout = new QHBoxLayout();
47 this->ButtonsLayout = new QHBoxLayout();
48 this->ButtonsLayout->addStretch();
48 this->ButtonsLayout->addStretch();
49 this->pluginListLayout->addLayout(this->ButtonsLayout);
49 this->pluginListLayout->addLayout(this->ButtonsLayout);
50 this->addWidget(this->treeview);
50 this->addWidget(this->treeview);
51 this->pluginListWidgetContainer->setLayout(this->pluginListLayout);
51 this->pluginListWidgetContainer->setLayout(this->pluginListLayout);
52 this->addWidget(this->pluginListWidgetContainer);
52 this->addWidget(this->pluginListWidgetContainer);
53 this->pluginListLayout->addWidget(this->pluginTable);
53 this->pluginListLayout->addWidget(this->pluginTable);
54 this->pluginInfos = new pluginInfosWdgt;
54 this->pluginInfos = new pluginInfosWdgt;
55
55
56 mkbutton(this->addPluginBt,tr("add plugin"),":/images/open.svg");
56 mkbutton(this->addPluginBt,tr("add plugin"),":/images/open.svg");
57 mkbutton(this->removePluginBt,tr("remove plugin(s)"),":/images/trash.svg");
57 mkbutton(this->removePluginBt,tr("remove plugin(s)"),":/images/trash.svg");
58 mkbutton(this->refreshPluginListBt,tr("Refresh Plugin(s) list"),":/images/refresh.svg");
58 mkbutton(this->refreshPluginListBt,tr("Refresh Plugin(s) list"),":/images/refresh.svg");
59
59
60 this->ButtonsLayout->addWidget(this->addPluginBt);
60 this->ButtonsLayout->addWidget(this->addPluginBt);
61 this->ButtonsLayout->addWidget(this->refreshPluginListBt);
61 this->ButtonsLayout->addWidget(this->refreshPluginListBt);
62 this->ButtonsLayout->addWidget(this->removePluginBt);
62 this->ButtonsLayout->addWidget(this->removePluginBt);
63
63
64 this->addWidget(this->pluginInfos);
64 this->addWidget(this->pluginInfos);
65
65
66 connect(this->treeview,SIGNAL(geteplugintree()),this,SIGNAL(geteplugintree()));
66 connect(this->treeview,SIGNAL(geteplugintree()),this,SIGNAL(geteplugintree()));
67 connect(this,SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->treeview,SLOT(treeChanged(QList<socexplorerplugin*>)));
67 connect(this,SIGNAL(treeChanged(QList<socexplorerplugin*>)),this->treeview,SLOT(treeChanged(QList<socexplorerplugin*>)));
68 connect(this->pluginTable,SIGNAL(currentRowChanged(int)),this,SLOT(libselected(int)));
68 connect(this->pluginTable,SIGNAL(currentRowChanged(int)),this,SLOT(libselected(int)));
69 connect(this->pluginTable,SIGNAL(itemSelectionChanged(QStringList)),this->pluginInfos,SLOT(updateInfos(QStringList)));
69 connect(this->pluginTable,SIGNAL(itemSelectionChanged(QStringList)),this->pluginInfos,SLOT(updateInfos(QStringList)));
70 connect(this->addPluginBt,SIGNAL(clicked()),this,SLOT(addPlugin()));
70 connect(this->addPluginBt,SIGNAL(clicked()),this,SLOT(addPlugin()));
71 connect(this->removePluginBt,SIGNAL(clicked()),this,SLOT(removePlugin()));
71 connect(this->removePluginBt,SIGNAL(clicked()),this,SLOT(removePlugin()));
72 connect(this->pluginTable,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(loadplugin(QListWidgetItem*)));
72 connect(this->pluginTable,SIGNAL(itemDoubleClicked(QListWidgetItem*)),this,SLOT(loadplugin(QListWidgetItem*)));
73 connect(this->refreshPluginListBt,SIGNAL(clicked()),this->pluginTable,SLOT(refreshPluginList()));
73 connect(this->refreshPluginListBt,SIGNAL(clicked()),this->pluginTable,SLOT(refreshPluginList()));
74 connect(this->treeview,SIGNAL(loadSysDriver(QString)),this,SIGNAL(loadSysDrviver(QString)));
74 connect(this->treeview,SIGNAL(loadSysDriver(QString)),this,SIGNAL(loadSysDrviver(QString)));
75 connect(this->treeview,SIGNAL(loadSysDriverToParent(QString,QString)),this,SIGNAL(loadSysDriverToParent(QString,QString)));
75 connect(this->treeview,SIGNAL(loadSysDriverToParent(QString,QString)),this,SIGNAL(loadSysDriverToParent(QString,QString)));
76 connect(this->treeview,SIGNAL(changeSysDriverInstName(QString,QString)),this,SIGNAL(changeSysDriverInstName(QString,QString)));
76 connect(this->treeview,SIGNAL(changeSysDriverInstName(QString,QString)),this,SIGNAL(changeSysDriverInstName(QString,QString)));
77 connect(this->treeview,SIGNAL(closeSysDriver(QString)),this,SIGNAL(closeSysDriver(QString)));
77 connect(this->treeview,SIGNAL(closeSysDriver(QString)),this,SIGNAL(closeSysDriver(QString)));
78 connect(this->treeview,SIGNAL(pluginselected(QString)),this,SIGNAL(pluginselected(QString)));
78 connect(this->treeview,SIGNAL(pluginselected(QString)),this,SIGNAL(pluginselected(QString)));
79 this->rootLoadable = false;
79 this->rootLoadable = false;
80 this->childLoadable = false;
80 this->childLoadable = false;
81 this->pluginTable->refreshPluginList();
81 this->pluginTable->refreshPluginList();
82 this->pluginTable->refreshPluginList();
82 this->pluginTable->refreshPluginList();
83 }
83 }
84
84
85
85
86 void pluginmanagerWDGT::setRootLoadable(bool flag)
86 void pluginmanagerWDGT::setRootLoadable(bool flag)
87 {
87 {
88 this->rootLoadable = flag;
88 this->rootLoadable = flag;
89 }
89 }
90
90
91
91
92 void pluginmanagerWDGT::setChildLoadable(bool flag)
92 void pluginmanagerWDGT::setChildLoadable(bool flag)
93 {
93 {
94 this->childLoadable = flag;
94 this->childLoadable = flag;
95 }
95 }
96
96
97
97
98
98
99
99
100 void pluginmanagerWDGT::addPlugin()
100 void pluginmanagerWDGT::addPlugin()
101 {
101 {
102 QString fileName = QFileDialog::getOpenFileName(this,tr("Open Plugin"), QDir::homePath(), tr("Plugin Files Files (*.dll *.so *.so.*)"));
102 // /!\ TODO update it remove maximum operation from widget
103 if(pluginloader::checklibrary(fileName))
103 // QString fileName = QFileDialog::getOpenFileName(this,tr("Open Plugin"), QDir::homePath(), tr("Plugin Files Files (*.dll *.so *.so.*)"));
104 {
104 // if(pluginloader::checklibrary(fileName))
105 QFile::copy(fileName,QString(SocExplorerEngine::pluginFolder())+"/"+ fileName.section('/',-1));
105 // {
106 }
106 // QFile::copy(fileName,QString(SocExplorerEngine::pluginFolder())+"/"+ fileName.section('/',-1));
107 this->pluginTable->refreshPluginList();
107 // }
108 // this->pluginTable->refreshPluginList();
108 }
109 }
109
110
110
111
111 void pluginmanagerWDGT::removePlugin()
112 void pluginmanagerWDGT::removePlugin()
112 {
113 {
113 for(int i=0;i<this->pluginTable->selectedItems().count();i++)
114 // for(int i=0;i<this->pluginTable->selectedItems().count();i++)
114 {
115 // {
115 QListWidgetItem* item = this->pluginTable->selectedItems().at(i);
116 // QListWidgetItem* item = this->pluginTable->selectedItems().at(i);
116 if(item!=NULL)
117 // if(item!=NULL)
117 {
118 // {
118 QFile::remove(QString(SocExplorerEngine::pluginFolder())+"/"+item->text());
119 // QFile::remove(QString(SocExplorerEngine::pluginFolder())+"/"+item->text());
119 }
120 // }
120 }
121 // }
121 this->pluginTable->refreshPluginList();
122 // this->pluginTable->refreshPluginList();
122 }
123 }
123
124
124
125
125
126
126 void pluginmanagerWDGT::loadplugin()
127 void pluginmanagerWDGT::loadplugin()
127 {
128 {
128 for(int i=0;i<this->pluginTable->selectedItems().count();i++)
129 // for(int i=0;i<this->pluginTable->selectedItems().count();i++)
129 {
130 // {
130 QListWidgetItem* item = this->pluginTable->selectedItems().at(i);
131 // QListWidgetItem* item = this->pluginTable->selectedItems().at(i);
131 if(item!=NULL)
132 // if(item!=NULL)
132 {
133 // {
133 QString plugin = QString(SocExplorerEngine::pluginFolder())+"/"+item->text();
134 // QString plugin = QString(SocExplorerEngine::pluginFolder())+"/"+item->text();
134 emit this->loadSysDrviver(plugin);
135 // emit this->loadSysDrviver(plugin);
135 }
136 // }
136 }
137 // }
137 this->pluginTable->refreshPluginList();
138 // this->pluginTable->refreshPluginList();
138 }
139 }
139
140
140
141
141
142
142
143
@@ -1,572 +1,560
1 #include "pluginloader.h"
1 #include "pluginloader.h"
2 #include <QDir>
2 #include <QDir>
3 #include <QFile>
3 #include <QFile>
4 #include <QFileInfoList>
4 #include <QFileInfoList>
5 #include <QFileInfo>
5 #include <QFileInfo>
6 #include <QString>
6 #include <QString>
7 #include <QStringList>
7 #include <QStringList>
8 #include <QLabel>
8 #include <QLabel>
9 #include <QSettings>
9 #include <QSettings>
10 #include <QApplication>
10 #include <QApplication>
11 #include <QCoreApplication>
11 #include <QCoreApplication>
12 #include <socexplorerengine.h>
12 #include <socexplorerengine.h>
13 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
13 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
14 #include "unix/unixpluginloader.h"
14 #include "unix/unixpluginloader.h"
15 #endif
15 #endif
16
16
17 pluginloader* pluginloader::_self = NULL;
17 pluginloader* pluginloader::_self = NULL;
18 PluginsCache* pluginloader::_cache = NULL;
18 PluginsCache* pluginloader::_cache = NULL;
19 QStringList* pluginloader::_folderList = NULL;
19 QStringList* pluginloader::_folderList = NULL;
20
20
21
21
22 pluginloader::pluginloader()
22 pluginloader::pluginloader()
23 {
23 {
24 _cache = new PluginsCache();
24 _cache = new PluginsCache();
25 _folderList = new QStringList();
25 _folderList = new QStringList();
26 QDir pluginPath(QString(SocExplorerEngine::pluginFolder()));
26 _folderList->append(SocExplorerEngine::pluginFolders());
27 if(!pluginPath.exists())
28 {
29 pluginPath.mkpath(QString(SocExplorerEngine::pluginFolder()));
30 }
31 QFile pluginsFolders(QString(SocExplorerEngine::pluginFolder())+"/plugins.conf");
32 *_folderList << QString(SocExplorerEngine::pluginFolder()); //default place
33 if(!pluginsFolders.exists())
34 {
35 pluginsFolders.open(QIODevice::WriteOnly); //if file doesn't exist create it
36 pluginsFolders.close();
37 }
38 *_folderList<< readFoldersList(QStringList()<< QString(SocExplorerEngine::pluginFolder())+"/plugins.conf");
39 scanFolders();
27 scanFolders();
40 }
28 }
41
29
42
30
43 QStringList pluginloader::readFoldersList(const QStringList confFiles)
31 QStringList pluginloader::readFoldersList(const QStringList confFiles)
44 {
32 {
45 QDir testDir;
33 QDir testDir;
46 QStringList folders;
34 QStringList folders;
47 QFile confFile;
35 QFile confFile;
48 for(int i=0;i<confFiles.count();i++)
36 for(int i=0;i<confFiles.count();i++)
49 {
37 {
50 confFile.setFileName(confFiles.at(i));
38 confFile.setFileName(confFiles.at(i));
51 if(confFile.exists())
39 if(confFile.exists())
52 {
40 {
53 if (confFile.open(QIODevice::ReadOnly | QIODevice::Text))
41 if (confFile.open(QIODevice::ReadOnly | QIODevice::Text))
54 {
42 {
55 QTextStream in(&confFile);
43 QTextStream in(&confFile);
56 QString line = in.readLine();
44 QString line = in.readLine();
57 while (!line.isNull())
45 while (!line.isNull())
58 {
46 {
59 testDir.setPath(line);
47 testDir.setPath(line);
60 if(testDir.exists())
48 if(testDir.exists())
61 {
49 {
62 if(!folders.contains(line))
50 if(!folders.contains(line))
63 folders << line;
51 folders << line;
64 }
52 }
65 line = in.readLine();
53 line = in.readLine();
66 }
54 }
67 }
55 }
68 }
56 }
69 }
57 }
70 return folders;
58 return folders;
71 }
59 }
72
60
73
61
74 void pluginloader::scanFolders()
62 void pluginloader::scanFolders()
75 {
63 {
76 QDir dir;
64 QDir dir;
77 QStringList filters;
65 QStringList filters;
78 filters <<"*.so"<< "*.dll";
66 filters <<"*.so"<< "*.dll";
79 _cache->flush();
67 _cache->flush();
80 for(int d=0;d<_folderList->count();d++)
68 for(int d=0;d<_folderList->count();d++)
81 {
69 {
82 dir.setPath(_folderList->at(d));
70 dir.setPath(_folderList->at(d));
83 dir.setFilter(QDir::Files);
71 dir.setFilter(QDir::Files);
84 dir.setNameFilters(filters);
72 dir.setNameFilters(filters);
85 QFileInfoList list = dir.entryInfoList();
73 QFileInfoList list = dir.entryInfoList();
86 for (int i = 0; i < list.size(); ++i)
74 for (int i = 0; i < list.size(); ++i)
87 {
75 {
88 QFileInfo fileInfo = list.at(i);
76 QFileInfo fileInfo = list.at(i);
89 if(checklibrary(fileInfo.filePath())!=0)
77 if(checklibrary(fileInfo.filePath())!=0)
90 {
78 {
91 _cache->append(fileInfo.fileName(),fileInfo.path(),_getlibName(fileInfo.filePath()),_getlibPID(fileInfo.filePath()),_getlibPID(fileInfo.filePath()));
79 _cache->append(fileInfo.fileName(),fileInfo.path(),_getlibName(fileInfo.filePath()),_getlibPID(fileInfo.filePath()),_getlibPID(fileInfo.filePath()));
92 }
80 }
93 }
81 }
94 }
82 }
95 }
83 }
96
84
97 int pluginloader::p_checklibraryQlib(const QString fileName)
85 int pluginloader::p_checklibraryQlib(const QString fileName)
98 {
86 {
99 QLibrary* lib = new QLibrary;
87 QLibrary* lib = new QLibrary;
100 lib->setFileName(fileName);
88 lib->setFileName(fileName);
101 lib->setLoadHints(QLibrary::PreventUnloadHint);
89 lib->setLoadHints(QLibrary::PreventUnloadHint);
102 lib->load();
90 lib->load();
103 if(!lib->isLoaded())
91 if(!lib->isLoaded())
104 {
92 {
105 qDebug()<<lib->errorString();
93 qDebug()<<lib->errorString();
106 lib->~QLibrary();
94 lib->~QLibrary();
107 lib = new QLibrary(fileName);
95 lib = new QLibrary(fileName);
108 lib->load();
96 lib->load();
109 }
97 }
110 delete lib;
98 delete lib;
111 if(QLibrary::resolve(fileName,"socexplorerpluginCreateObject"))
99 if(QLibrary::resolve(fileName,"socexplorerpluginCreateObject"))
112 {
100 {
113 if(QLibrary::resolve(fileName,"socexplorerpluginpid"))
101 if(QLibrary::resolve(fileName,"socexplorerpluginpid"))
114 {
102 {
115 if(QLibrary::resolve(fileName,"socexplorerpluginvid"))
103 if(QLibrary::resolve(fileName,"socexplorerpluginvid"))
116 {
104 {
117 if(QLibrary::resolve(fileName,"socexplorerpluginVersion"))
105 if(QLibrary::resolve(fileName,"socexplorerpluginVersion"))
118 {
106 {
119 if(QLibrary::resolve(fileName,"socexplorerpluginAuthor"))
107 if(QLibrary::resolve(fileName,"socexplorerpluginAuthor"))
120 {
108 {
121 if(QLibrary::resolve(fileName,"socexplorerpluginDescription"))
109 if(QLibrary::resolve(fileName,"socexplorerpluginDescription"))
122 {
110 {
123 return 1;
111 return 1;
124 }
112 }
125 }
113 }
126 }
114 }
127 }
115 }
128 }
116 }
129 }
117 }
130 return 0;
118 return 0;
131 }
119 }
132
120
133 int pluginloader::p_checklibraryCustom(const QString fileName)
121 int pluginloader::p_checklibraryCustom(const QString fileName)
134 {
122 {
135 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
123 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
136 unixPluginLoader lib(fileName);
124 unixPluginLoader lib(fileName);
137 if(NULL!=lib.resolve("socexplorerpluginCreateObject"))
125 if(NULL!=lib.resolve("socexplorerpluginCreateObject"))
138 {
126 {
139 if(NULL!=lib.resolve("socexplorerpluginpid"))
127 if(NULL!=lib.resolve("socexplorerpluginpid"))
140 {
128 {
141 if(NULL!=lib.resolve("socexplorerpluginvid"))
129 if(NULL!=lib.resolve("socexplorerpluginvid"))
142 {
130 {
143 if(NULL!=lib.resolve("socexplorerpluginVersion"))
131 if(NULL!=lib.resolve("socexplorerpluginVersion"))
144 {
132 {
145 if(NULL!=lib.resolve("socexplorerpluginAuthor"))
133 if(NULL!=lib.resolve("socexplorerpluginAuthor"))
146 {
134 {
147 if(NULL!=lib.resolve("socexplorerpluginDescription"))
135 if(NULL!=lib.resolve("socexplorerpluginDescription"))
148 {
136 {
149 return 1;
137 return 1;
150 }
138 }
151 }
139 }
152 }
140 }
153 }
141 }
154 }
142 }
155 }
143 }
156 #endif
144 #endif
157 return 0;
145 return 0;
158 }
146 }
159
147
160 socexplorerplugin *pluginloader::p_newsocexplorerpluginQlib(const QString Name)
148 socexplorerplugin *pluginloader::p_newsocexplorerpluginQlib(const QString Name)
161 {
149 {
162 QString* libfile= _cacheLookup(Name);
150 QString* libfile= _cacheLookup(Name);
163 if(libfile==NULL)return NULL;
151 if(libfile==NULL)return NULL;
164 QLibrary* lib = new QLibrary(*libfile);
152 QLibrary* lib = new QLibrary(*libfile);
165 delete libfile;
153 delete libfile;
166 socexplorerpluginCreateObjectT newDrvr = NULL;
154 socexplorerpluginCreateObjectT newDrvr = NULL;
167 newDrvr=(socexplorerpluginCreateObjectT)lib->resolve("socexplorerpluginCreateObject");
155 newDrvr=(socexplorerpluginCreateObjectT)lib->resolve("socexplorerpluginCreateObject");
168 if(newDrvr==NULL)
156 if(newDrvr==NULL)
169 {
157 {
170 return NULL;
158 return NULL;
171 }
159 }
172 return (socexplorerplugin*) newDrvr();
160 return (socexplorerplugin*) newDrvr();
173 }
161 }
174
162
175 socexplorerplugin *pluginloader::p_newsocexplorerpluginCustom(const QString Name)
163 socexplorerplugin *pluginloader::p_newsocexplorerpluginCustom(const QString Name)
176 {
164 {
177 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
165 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
178 QString* libfile= _cacheLookup(Name);
166 QString* libfile= _cacheLookup(Name);
179 if(libfile==NULL)return NULL;
167 if(libfile==NULL)return NULL;
180 unixPluginLoader lib(*libfile);
168 unixPluginLoader lib(*libfile);
181 delete libfile;
169 delete libfile;
182 socexplorerpluginCreateObjectT newDrvr = NULL;
170 socexplorerpluginCreateObjectT newDrvr = NULL;
183 newDrvr=(socexplorerpluginCreateObjectT)lib.resolve("socexplorerpluginCreateObject");
171 newDrvr=(socexplorerpluginCreateObjectT)lib.resolve("socexplorerpluginCreateObject");
184 if(newDrvr==NULL)
172 if(newDrvr==NULL)
185 {
173 {
186 return NULL;
174 return NULL;
187 }
175 }
188 return (socexplorerplugin*) newDrvr();
176 return (socexplorerplugin*) newDrvr();
189 #endif
177 #endif
190 }
178 }
191
179
192 QList<PluginsCacheItem*> pluginloader::listAvailiables(bool rescan)
180 QList<PluginsCacheItem*> pluginloader::listAvailiables(bool rescan)
193 {
181 {
194 if(_self==NULL)
182 if(_self==NULL)
195 {
183 {
196 init();
184 init();
197 return _cache->listDrivers();
185 return _cache->listDrivers();
198 }
186 }
199 if(rescan)
187 if(rescan)
200 {
188 {
201 scanFolders();
189 scanFolders();
202 }
190 }
203
191
204 return _cache->listDrivers();
192 return _cache->listDrivers();
205 }
193 }
206
194
207
195
208 void pluginloader::init()
196 void pluginloader::init()
209 {
197 {
210 if(_self==NULL)
198 if(_self==NULL)
211 {
199 {
212 _self=new pluginloader();
200 _self=new pluginloader();
213 }
201 }
214 }
202 }
215
203
216
204
217 pluginloader* pluginloader::self()
205 pluginloader* pluginloader::self()
218 {
206 {
219 if(_self==NULL)
207 if(_self==NULL)
220 {
208 {
221 init();
209 init();
222 }
210 }
223 return _self;
211 return _self;
224 }
212 }
225
213
226 bool pluginloader::isvalid(QString Name)
214 bool pluginloader::isvalid(QString Name)
227 {
215 {
228 if(_self==NULL)init();
216 if(_self==NULL)init();
229 QString* libfile= _cacheLookup(Name);
217 QString* libfile= _cacheLookup(Name);
230 if(libfile==NULL)return false;
218 if(libfile==NULL)return false;
231 else
219 else
232 {
220 {
233 delete libfile;
221 delete libfile;
234 return true;
222 return true;
235 }
223 }
236
224
237 }
225 }
238
226
239 int pluginloader::checklibrary(const QString fileName)
227 int pluginloader::checklibrary(const QString fileName)
240 {
228 {
241 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
229 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
242 return _self->p_checklibraryCustom(fileName);
230 return _self->p_checklibraryCustom(fileName);
243 #else
231 #else
244 return _self->p_checklibraryQlib(fileName);
232 return _self->p_checklibraryQlib(fileName);
245 #endif
233 #endif
246 }
234 }
247
235
248
236
249
237
250
238
251
239
252 socexplorerplugin* pluginloader::newsocexplorerplugin(const QString Name)
240 socexplorerplugin* pluginloader::newsocexplorerplugin(const QString Name)
253 {
241 {
254 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
242 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
255 return _self->p_newsocexplorerpluginCustom(Name);
243 return _self->p_newsocexplorerpluginCustom(Name);
256 #else
244 #else
257 return _self->p_newsocexplorerpluginQlib(Name);
245 return _self->p_newsocexplorerpluginQlib(Name);
258 #endif
246 #endif
259 }
247 }
260
248
261
249
262 QString pluginloader::getlibTypeStr(QString Name)
250 QString pluginloader::getlibTypeStr(QString Name)
263 {
251 {
264 if(_self==NULL)init();
252 if(_self==NULL)init();
265 QString* libfile= _cacheLookup(Name);
253 QString* libfile= _cacheLookup(Name);
266 if(libfile==NULL)return NULL;
254 if(libfile==NULL)return NULL;
267 QLibrary* lib = new QLibrary(*libfile);
255 QLibrary* lib = new QLibrary(*libfile);
268 delete libfile;
256 delete libfile;
269 lib->load();
257 lib->load();
270 if(lib->isLoaded())
258 if(lib->isLoaded())
271 {
259 {
272 socexplorerpluginTypeT plugintype = (socexplorerpluginTypeT)lib->resolve("socexplorerpluginType");
260 socexplorerpluginTypeT plugintype = (socexplorerpluginTypeT)lib->resolve("socexplorerpluginType");
273 if(plugintype!=NULL)
261 if(plugintype!=NULL)
274 {
262 {
275 pluginT type = plugintype();
263 pluginT type = plugintype();
276 switch(type)
264 switch(type)
277 {
265 {
278 case ComDriverT:
266 case ComDriverT:
279 ////lib->unload();
267 ////lib->unload();
280 lib->~QLibrary();
268 lib->~QLibrary();
281 return QObject::tr("Comunaication Driver Plugin.");
269 return QObject::tr("Comunaication Driver Plugin.");
282 break;
270 break;
283 case PerifDriverT:
271 case PerifDriverT:
284 ////lib->unload();
272 ////lib->unload();
285 lib->~QLibrary();
273 lib->~QLibrary();
286 return QObject::tr("Periferial Driver Plugin.");
274 return QObject::tr("Periferial Driver Plugin.");
287 break;
275 break;
288 default:
276 default:
289 ////lib->unload();
277 ////lib->unload();
290 lib->~QLibrary();
278 lib->~QLibrary();
291 return QObject::tr("Unknow Plugin.");
279 return QObject::tr("Unknow Plugin.");
292 break;
280 break;
293 }
281 }
294 }
282 }
295 }
283 }
296 lib->~QLibrary();
284 lib->~QLibrary();
297 return QObject::tr("Can't load Plugin.");
285 return QObject::tr("Can't load Plugin.");
298 }
286 }
299
287
300
288
301
289
302
290
303 pluginT pluginloader::getlibType(QString Name)
291 pluginT pluginloader::getlibType(QString Name)
304 {
292 {
305 if(_self==NULL)init();
293 if(_self==NULL)init();
306 QString* libfile= _cacheLookup(Name);
294 QString* libfile= _cacheLookup(Name);
307 if(libfile==NULL)return (pluginT)NULL;
295 if(libfile==NULL)return (pluginT)NULL;
308 QLibrary* lib = new QLibrary(*libfile);
296 QLibrary* lib = new QLibrary(*libfile);
309 delete libfile;
297 delete libfile;
310 lib->load();
298 lib->load();
311 if(lib->isLoaded())
299 if(lib->isLoaded())
312 {
300 {
313 socexplorerpluginTypeT plugintype = (socexplorerpluginTypeT)lib->resolve("socexplorerpluginType");
301 socexplorerpluginTypeT plugintype = (socexplorerpluginTypeT)lib->resolve("socexplorerpluginType");
314 if(plugintype!=NULL)
302 if(plugintype!=NULL)
315 {
303 {
316 return plugintype();
304 return plugintype();
317 }
305 }
318 }
306 }
319 lib->~QLibrary();
307 lib->~QLibrary();
320 return -1;
308 return -1;
321 }
309 }
322
310
323
311
324 QString pluginloader::getlibVersion(const QString Name)
312 QString pluginloader::getlibVersion(const QString Name)
325 {
313 {
326 if(_self==NULL)init();
314 if(_self==NULL)init();
327 QString* libfile= _cacheLookup(Name);
315 QString* libfile= _cacheLookup(Name);
328 if(libfile==NULL)return NULL;
316 if(libfile==NULL)return NULL;
329 QLibrary* lib = new QLibrary(*libfile);
317 QLibrary* lib = new QLibrary(*libfile);
330 delete libfile;
318 delete libfile;
331 lib->load();
319 lib->load();
332 if(lib->isLoaded())
320 if(lib->isLoaded())
333 {
321 {
334 socexplorerpluginVersionT pluginversion = (socexplorerpluginVersionT)lib->resolve("socexplorerpluginVersion");
322 socexplorerpluginVersionT pluginversion = (socexplorerpluginVersionT)lib->resolve("socexplorerpluginVersion");
335 if(pluginversion!=NULL)
323 if(pluginversion!=NULL)
336 {
324 {
337 QString version = pluginversion();
325 QString version = pluginversion();
338 ////lib->unload();
326 ////lib->unload();
339 lib->~QLibrary();
327 lib->~QLibrary();
340 return version;
328 return version;
341 }
329 }
342 }
330 }
343 lib->~QLibrary();
331 lib->~QLibrary();
344 return QObject::tr("Can't load Plugin.");
332 return QObject::tr("Can't load Plugin.");
345 }
333 }
346
334
347
335
348
336
349 QString pluginloader::getlibPIDstr(const QString Name)
337 QString pluginloader::getlibPIDstr(const QString Name)
350 {
338 {
351 return QString("0x" + QString::number(pluginloader::getlibPID(Name) , 16));
339 return QString("0x" + QString::number(pluginloader::getlibPID(Name) , 16));
352 }
340 }
353
341
354 QString pluginloader::getlibVIDstr(const QString Name)
342 QString pluginloader::getlibVIDstr(const QString Name)
355 {
343 {
356 return QString("0x" + QString::number(pluginloader::getlibVID(Name) , 16));
344 return QString("0x" + QString::number(pluginloader::getlibVID(Name) , 16));
357 }
345 }
358
346
359
347
360
348
361 int pluginloader::libcanbechild(const QString Name)
349 int pluginloader::libcanbechild(const QString Name)
362 {
350 {
363 if(_self==NULL)init();
351 if(_self==NULL)init();
364 QString* libfile= _cacheLookup(Name);
352 QString* libfile= _cacheLookup(Name);
365 if(libfile==NULL)return (int)NULL;
353 if(libfile==NULL)return (int)NULL;
366 QLibrary* lib = new QLibrary(*libfile);
354 QLibrary* lib = new QLibrary(*libfile);
367 delete libfile;
355 delete libfile;
368 lib->load();
356 lib->load();
369 if(lib->isLoaded())
357 if(lib->isLoaded())
370 {
358 {
371 socexplorerplugincanbechildT canbechild = (socexplorerplugincanbechildT)lib->resolve("socexplorerplugincanbechild");
359 socexplorerplugincanbechildT canbechild = (socexplorerplugincanbechildT)lib->resolve("socexplorerplugincanbechild");
372 if(canbechild!=NULL)
360 if(canbechild!=NULL)
373 {
361 {
374 int value = canbechild();
362 int value = canbechild();
375 ////lib->unload();
363 ////lib->unload();
376 //lib->~QLibrary();
364 //lib->~QLibrary();
377 return value;
365 return value;
378 }
366 }
379 }
367 }
380 //lib->~QLibrary();
368 //lib->~QLibrary();
381 return 0;
369 return 0;
382 }
370 }
383
371
384
372
385
373
386
374
387 int pluginloader::libcanberoot(const QString Name)
375 int pluginloader::libcanberoot(const QString Name)
388 {
376 {
389 if(_self==NULL)init();
377 if(_self==NULL)init();
390 QString* libfile= _cacheLookup(Name);
378 QString* libfile= _cacheLookup(Name);
391 if(libfile==NULL)return (int)NULL;
379 if(libfile==NULL)return (int)NULL;
392 QLibrary* lib = new QLibrary(*libfile);
380 QLibrary* lib = new QLibrary(*libfile);
393 delete libfile;
381 delete libfile;
394 lib->load();
382 lib->load();
395 if(lib->isLoaded())
383 if(lib->isLoaded())
396 {
384 {
397 socexplorerplugincanberootT canberoot = (socexplorerplugincanberootT)lib->resolve("socexplorerplugincanberoot");
385 socexplorerplugincanberootT canberoot = (socexplorerplugincanberootT)lib->resolve("socexplorerplugincanberoot");
398 if(canberoot!=NULL)
386 if(canberoot!=NULL)
399 {
387 {
400 int value = canberoot();
388 int value = canberoot();
401 ////lib->unload();
389 ////lib->unload();
402 //lib->~QLibrary();
390 //lib->~QLibrary();
403 return value;
391 return value;
404 }
392 }
405 }
393 }
406 delete lib;
394 delete lib;
407 //lib->~QLibrary();
395 //lib->~QLibrary();
408 return 0;
396 return 0;
409 }
397 }
410
398
411 int pluginloader::getlibVID(const QString Name)
399 int pluginloader::getlibVID(const QString Name)
412 {
400 {
413 if(_self==NULL)init();
401 if(_self==NULL)init();
414 QString* libfile= _cacheLookup(Name);
402 QString* libfile= _cacheLookup(Name);
415 if(libfile==NULL)return 0;
403 if(libfile==NULL)return 0;
416 QString file(*libfile);
404 QString file(*libfile);
417 delete libfile;
405 delete libfile;
418 return _getlibVID(file);
406 return _getlibVID(file);
419 }
407 }
420
408
421
409
422 int pluginloader::getlibPID(const QString Name)
410 int pluginloader::getlibPID(const QString Name)
423 {
411 {
424 if(_self==NULL)init();
412 if(_self==NULL)init();
425 QString* libfile= _cacheLookup(Name);
413 QString* libfile= _cacheLookup(Name);
426 if(libfile==NULL)return 0;
414 if(libfile==NULL)return 0;
427 QString file(*libfile);
415 QString file(*libfile);
428 delete libfile;
416 delete libfile;
429 return _getlibPID(file);
417 return _getlibPID(file);
430 }
418 }
431
419
432 QString pluginloader::getlibAuthor(const QString Name)
420 QString pluginloader::getlibAuthor(const QString Name)
433 {
421 {
434 if(_self==NULL)init();
422 if(_self==NULL)init();
435 QString* libfile= _cacheLookup(Name);
423 QString* libfile= _cacheLookup(Name);
436 if(libfile==NULL)return NULL;
424 if(libfile==NULL)return NULL;
437 QLibrary* lib = new QLibrary(*libfile);
425 QLibrary* lib = new QLibrary(*libfile);
438 delete libfile;
426 delete libfile;
439 lib->load();
427 lib->load();
440 if(lib->isLoaded())
428 if(lib->isLoaded())
441 {
429 {
442 socexplorerpluginAuthorT pluginauthor = (socexplorerpluginAuthorT)lib->resolve("socexplorerpluginAuthor");
430 socexplorerpluginAuthorT pluginauthor = (socexplorerpluginAuthorT)lib->resolve("socexplorerpluginAuthor");
443 if(pluginauthor!=NULL)
431 if(pluginauthor!=NULL)
444 {
432 {
445 QString author = pluginauthor();
433 QString author = pluginauthor();
446 ////lib->unload();
434 ////lib->unload();
447 lib->~QLibrary();
435 lib->~QLibrary();
448 return author;
436 return author;
449 }
437 }
450 }
438 }
451 lib->~QLibrary();
439 lib->~QLibrary();
452 return QObject::tr("Can't load Plugin.");
440 return QObject::tr("Can't load Plugin.");
453 }
441 }
454
442
455 QString pluginloader::getlibName(const QString Name)
443 QString pluginloader::getlibName(const QString Name)
456 {
444 {
457 if(_self==NULL)init();
445 if(_self==NULL)init();
458 QString* libfile= _cacheLookup(Name);
446 QString* libfile= _cacheLookup(Name);
459 if(libfile==NULL)return QString("");
447 if(libfile==NULL)return QString("");
460 QString file(*libfile);
448 QString file(*libfile);
461 delete libfile;
449 delete libfile;
462 return _getlibName(file);
450 return _getlibName(file);
463 }
451 }
464
452
465 QString pluginloader::getlibDescription(const QString Name)
453 QString pluginloader::getlibDescription(const QString Name)
466 {
454 {
467 if(_self==NULL)init();
455 if(_self==NULL)init();
468 QString* libfile= _cacheLookup(Name);
456 QString* libfile= _cacheLookup(Name);
469 if(libfile==NULL)return NULL;
457 if(libfile==NULL)return NULL;
470 QLibrary* lib = new QLibrary(*libfile);
458 QLibrary* lib = new QLibrary(*libfile);
471 delete libfile;
459 delete libfile;
472 lib->load();
460 lib->load();
473 if(lib->isLoaded())
461 if(lib->isLoaded())
474 {
462 {
475 socexplorerpluginDescriptionT plugindescription = (socexplorerpluginDescriptionT)lib->resolve("socexplorerpluginDescription");
463 socexplorerpluginDescriptionT plugindescription = (socexplorerpluginDescriptionT)lib->resolve("socexplorerpluginDescription");
476 if(plugindescription!=NULL)
464 if(plugindescription!=NULL)
477 {
465 {
478 QString description = plugindescription();
466 QString description = plugindescription();
479 ////lib->unload();
467 ////lib->unload();
480 lib->~QLibrary();
468 lib->~QLibrary();
481 return description;
469 return description;
482 }
470 }
483 }
471 }
484 lib->~QLibrary();
472 lib->~QLibrary();
485 return QObject::tr("Can't load Plugin.");
473 return QObject::tr("Can't load Plugin.");
486 }
474 }
487
475
488 QString pluginloader::getlibDir(const QString Name)
476 QString pluginloader::getlibDir(const QString Name)
489 {
477 {
490 if(_self==NULL)init();
478 if(_self==NULL)init();
491 return *_cacheLookup(Name);
479 return *_cacheLookup(Name);
492 }
480 }
493
481
494 QString pluginloader::_getlibName(const QString fileName)
482 QString pluginloader::_getlibName(const QString fileName)
495 {
483 {
496 QLibrary* lib = new QLibrary(fileName);
484 QLibrary* lib = new QLibrary(fileName);
497 lib->load();
485 lib->load();
498 if(lib->isLoaded())
486 if(lib->isLoaded())
499 {
487 {
500 socexplorerpluginNameT pluginName = (socexplorerpluginAuthorT)lib->resolve("socexplorerpluginName");
488 socexplorerpluginNameT pluginName = (socexplorerpluginAuthorT)lib->resolve("socexplorerpluginName");
501 if(pluginName!=NULL)
489 if(pluginName!=NULL)
502 {
490 {
503 QString name = pluginName();
491 QString name = pluginName();
504 //lib->unload();
492 //lib->unload();
505 lib->~QLibrary();
493 lib->~QLibrary();
506 return name;
494 return name;
507 }
495 }
508 }
496 }
509 lib->~QLibrary();
497 lib->~QLibrary();
510 return QObject::tr("Can't load Plugin.");
498 return QObject::tr("Can't load Plugin.");
511 }
499 }
512
500
513 int pluginloader::_getlibPID(const QString fileName)
501 int pluginloader::_getlibPID(const QString fileName)
514 {
502 {
515 QLibrary* lib = new QLibrary(fileName);
503 QLibrary* lib = new QLibrary(fileName);
516 lib->load();
504 lib->load();
517 if(lib->isLoaded())
505 if(lib->isLoaded())
518 {
506 {
519 socexplorerpluginpidT pluginpid = (socexplorerpluginpidT)lib->resolve("socexplorerpluginpid");
507 socexplorerpluginpidT pluginpid = (socexplorerpluginpidT)lib->resolve("socexplorerpluginpid");
520 if(pluginpid!=NULL)
508 if(pluginpid!=NULL)
521 {
509 {
522 int pid = pluginpid();
510 int pid = pluginpid();
523 //lib->unload();
511 //lib->unload();
524 lib->~QLibrary();
512 lib->~QLibrary();
525 return pid;
513 return pid;
526 }
514 }
527 }
515 }
528 lib->~QLibrary();
516 lib->~QLibrary();
529 return 0;
517 return 0;
530 }
518 }
531
519
532 int pluginloader::_getlibVID(const QString fileName)
520 int pluginloader::_getlibVID(const QString fileName)
533 {
521 {
534 QLibrary* lib = new QLibrary(fileName);
522 QLibrary* lib = new QLibrary(fileName);
535 lib->load();
523 lib->load();
536 if(lib->isLoaded())
524 if(lib->isLoaded())
537 {
525 {
538 socexplorerpluginvidT pluginvid = (socexplorerpluginvidT)lib->resolve("socexplorerpluginvid");
526 socexplorerpluginvidT pluginvid = (socexplorerpluginvidT)lib->resolve("socexplorerpluginvid");
539 if(pluginvid!=NULL)
527 if(pluginvid!=NULL)
540 {
528 {
541 int vid = pluginvid();
529 int vid = pluginvid();
542 //lib->unload();
530 //lib->unload();
543 lib->~QLibrary();
531 lib->~QLibrary();
544 return vid;
532 return vid;
545 }
533 }
546 }
534 }
547 lib->~QLibrary();
535 lib->~QLibrary();
548 return 0;
536 return 0;
549 }
537 }
550
538
551 QString* pluginloader::_cacheLookup(const QString Name)
539 QString* pluginloader::_cacheLookup(const QString Name)
552 {
540 {
553 QString* libfile= new QString(_cache->first(Name));
541 QString* libfile= new QString(_cache->first(Name));
554 if(!QFile::exists(*libfile))
542 if(!QFile::exists(*libfile))
555 {
543 {
556 scanFolders();
544 scanFolders();
557 *libfile = _cache->first(Name);
545 *libfile = _cache->first(Name);
558 if(QFile::exists(*libfile))return libfile;
546 if(QFile::exists(*libfile))return libfile;
559 }
547 }
560 else
548 else
561 {
549 {
562 return libfile;
550 return libfile;
563 }
551 }
564 delete libfile;
552 delete libfile;
565 return NULL;
553 return NULL;
566 }
554 }
567
555
568 /*QString findlib(QString name)
556 /*QString findlib(QString name)
569 {
557 {
570
558
571 }*/
559 }*/
572
560
@@ -1,70 +1,71
1
1
2
2
3 win32 {
3 win32 {
4 DEFINES += WIN32
4 DEFINES += WIN32
5 DEFINES += WINTRANSLATIONPATH
5 DEFINES += WINTRANSLATIONPATH
6 DEFINES += SOCEXPLORER_TRANSLATION_PATH="\"\\\"./translations"\\\"\"
6 DEFINES += SOCEXPLORER_TRANSLATION_PATH="\"\\\"./translations"\\\"\"
7 SOCEXPLORER_TRANSLATION_INSTALL_PATH = translations
7 SOCEXPLORER_TRANSLATION_INSTALL_PATH = translations
8 SOCEXPLORER_INSTALL_PATH =
8 SOCEXPLORER_INSTALL_PATH =
9 SOCEXPLORER_PLUGINS_INSTALL_PATH = $$SOCEXPLORER_PLUGIN_PATH
9 SOCEXPLORER_PLUGINS_INSTALL_PATH = $$SOCEXPLORER_PLUGIN_PATH
10 }
10 }
11
11
12 unix {
12 unix {
13 DEFINES += UNIX
13 DEFINES += UNIX
14 DEFINES += UNIXTRANSLATIONPATH
14 DEFINES += UNIXTRANSLATIONPATH
15 DEFINES += SOCEXPLORER_TRANSLATION_PATH="\"\\\"/etc/SocExplorer/translations"\\\"\"
15 DEFINES += SOCEXPLORER_TRANSLATION_PATH="\"\\\"/etc/SocExplorer/translations"\\\"\"
16 SOCEXPLORER_TRANSLATION_INSTALL_PATH = /etc/SocExplorer/translations
16 SOCEXPLORER_TRANSLATION_INSTALL_PATH = /etc/SocExplorer/translations
17 SOCEXPLORER_INSTALL_PATH = /usr/local/SocExplorer
17 SOCEXPLORER_INSTALL_PATH = /usr/local/SocExplorer
18 SOCEXPLORER_ROOT_PLUGINS_INSTALL_PATH = $$system(echo $HOME)
18 SOCEXPLORER_PLUGINS_INSTALL_PATH = $$[QT_INSTALL_LIBS]"/SocExplorer/plugins"
19 SOCEXPLORER_PLUGINS_INSTALL_PATH = $${SOCEXPLORER_ROOT_PLUGINS_INSTALL_PATH}"/.SocExplorer/plugins"
19 DEFINES += SOCEXPLORER_CONFIG_PATH="\"\\\"/etc/SocExplorer"\\\"\"
20 SOCEXPLORER_CONFIG_PATH=/etc/SocExplorer
20 }
21 }
21
22
22 isEmpty( SOCEXPLORER_SDK_BUILD ){
23 isEmpty( SOCEXPLORER_SDK_BUILD ){
23 message( "building a plugin" )
24 message( "building a plugin" )
24 QT += core gui xml
25 QT += core gui xml
25 contains(QT_MAJOR_VERSION, 5) {
26 contains(QT_MAJOR_VERSION, 5) {
26 QT += widgets
27 QT += widgets
27 }
28 }
28 CONFIG += pythonqt
29 CONFIG += pythonqt
29 TEMPLATE = lib
30 TEMPLATE = lib
30 win32:CONFIG += dll
31 win32:CONFIG += dll
31 win32:CONFIG -= static
32 win32:CONFIG -= static
32 OBJECTS_DIR = obj
33 OBJECTS_DIR = obj
33 MOC_DIR = moc
34 MOC_DIR = moc
34 DESTDIR = bin
35 DESTDIR = bin
35 CONFIG(debug, debug|release) {
36 # CONFIG(debug, debug|release) {
36 DEBUG_EXT = _d
37 # DEBUG_EXT = _d
37 } else {
38 # } else {
38 DEBUG_EXT =
39 # DEBUG_EXT =
39 }
40 # }
40 unix{
41 unix{
41 target.path = $${SOCEXPLORER_PLUGINS_INSTALL_PATH}
42 target.path = $${SOCEXPLORER_PLUGINS_INSTALL_PATH}
42 INSTALLS += target
43 INSTALLS += target
43 LIBS+= -lsocexplorerengine$${DEBUG_EXT} -lsocexplorercommon$${DEBUG_EXT}
44 LIBS+= -lsocexplorerengine$${DEBUG_EXT} -lsocexplorercommon$${DEBUG_EXT}
44 }
45 }
45 win32{
46 win32{
46 INCLUDEPATH += $$[QT_INSTALL_HEADERS]/SocExplorer/common/libelf
47 INCLUDEPATH += $$[QT_INSTALL_HEADERS]/SocExplorer/common/libelf
47 LIBS+=$$[QT_INSTALL_LIBS]/socexplorerengine$${DEBUG_EXT}.dll $$[QT_INSTALL_LIBS]/socexplorercommon$${DEBUG_EXT}.dll
48 LIBS+=$$[QT_INSTALL_LIBS]/socexplorerengine$${DEBUG_EXT}.dll $$[QT_INSTALL_LIBS]/socexplorercommon$${DEBUG_EXT}.dll
48 }
49 }
49 DEFINES += SOCEXPLORER_LIBRARY
50 DEFINES += SOCEXPLORER_LIBRARY
50
51
51 SOURCES += \
52 SOURCES += \
52 $$[QT_INSTALL_HEADERS]/SocExplorer/pluginsInterface/socexplorerplugininterface.cpp
53 $$[QT_INSTALL_HEADERS]/SocExplorer/pluginsInterface/socexplorerplugininterface.cpp
53
54
54 HEADERS += \
55 HEADERS += \
55 $$[QT_INSTALL_HEADERS]/SocExplorer/genericPySysdriver.h \
56 $$[QT_INSTALL_HEADERS]/SocExplorer/genericPySysdriver.h \
56 $$[QT_INSTALL_HEADERS]/SocExplorer/socexplorerplugin.h
57 $$[QT_INSTALL_HEADERS]/SocExplorer/socexplorerplugin.h
57
58
58 INCLUDEPATH += $$[QT_INSTALL_HEADERS]/SocExplorer/common \
59 INCLUDEPATH += $$[QT_INSTALL_HEADERS]/SocExplorer/common \
59 $$[QT_INSTALL_HEADERS]/SocExplorer \
60 $$[QT_INSTALL_HEADERS]/SocExplorer \
60 $$[QT_INSTALL_HEADERS]/SocExplorer/pluginsInterface
61 $$[QT_INSTALL_HEADERS]/SocExplorer/pluginsInterface
61
62
62
63
63 }else{
64 }else{
64 message( "building SocExplorer" )
65 message( "building SocExplorer" )
65 HEADERS += \
66 HEADERS += \
66 $$[QT_INSTALL_HEADERS]/SocExplorer/genericPySysdriver.h \
67 $$[QT_INSTALL_HEADERS]/SocExplorer/genericPySysdriver.h \
67 $$[QT_INSTALL_HEADERS]/SocExplorer/socexplorerplugin.h
68 $$[QT_INSTALL_HEADERS]/SocExplorer/socexplorerplugin.h
68 }
69 }
69
70
70
71
@@ -1,57 +1,57
1 /*------------------------------------------------------------------------------
1 /*------------------------------------------------------------------------------
2 -- This file is a part of the SocExplorer Software
2 -- This file is a part of the SocExplorer Software
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
3 -- Copyright (C) 2013, Plasma Physics Laboratory - CNRS
4 --
4 --
5 -- This program is free software; you can redistribute it and/or modify
5 -- This program is free software; you can redistribute it and/or modify
6 -- it under the terms of the GNU General Public License as published by
6 -- it under the terms of the GNU General Public License as published by
7 -- the Free Software Foundation; either version 2 of the License, or
7 -- the Free Software Foundation; either version 2 of the License, or
8 -- (at your option) any later version.
8 -- (at your option) any later version.
9 --
9 --
10 -- This program is distributed in the hope that it will be useful,
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
13 -- GNU General Public License for more details.
14 --
14 --
15 -- You should have received a copy of the GNU General Public License
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 -------------------------------------------------------------------------------*/
18 -------------------------------------------------------------------------------*/
19 /*-- Author : Alexis Jeandet
19 /*-- Author : Alexis Jeandet
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
20 -- Mail : alexis.jeandet@lpp.polytechnique.fr
21 ----------------------------------------------------------------------------*/
21 ----------------------------------------------------------------------------*/
22 #ifndef SOCEXPLORER_H
22 #ifndef SOCEXPLORER_H
23 #define SOCEXPLORER_H
23 #define SOCEXPLORER_H
24
24
25 #ifdef WIN32
25 #ifdef WIN32
26 #ifdef SOCEXPLORER_EXPORTS
26 #ifdef SOCEXPLORER_EXPORTS
27 #define SOCEXPLORER_EXPORT __declspec(dllexport)
27 #define SOCEXPLORER_EXPORT __declspec(dllexport)
28 #else
28 #else
29 #define SOCEXPLORER_EXPORT __declspec(dllimport)
29 #define SOCEXPLORER_EXPORT __declspec(dllimport)
30 #endif
30 #endif
31 #else
31 #else
32 #define SOCEXPLORER_EXPORT
32 #define SOCEXPLORER_EXPORT
33 #endif
33 #endif
34
34
35 #ifdef WIN32
35 #ifdef WIN32
36 #include <stdlib.h>
36 #include <stdlib.h>
37 #define socexplorerBswap32(X) _byteswap_ulong(X)
37 #define socexplorerBswap32(X) _byteswap_ulong(X)
38 #else
38 #else
39 #ifdef UNIX
39 #ifdef UNIX
40 #include <byteswap.h>
40 #include <byteswap.h>
41 #define socexplorerBswap32(X) bswap_32(X)
41 #define socexplorerBswap32(X) bswap_32(X)
42 #endif
42 #endif
43 #endif
43 #endif
44
44
45
45
46 #ifdef WIN32
46 #ifdef WIN32
47 #define SOCEXPLORER_PLUGINS_INSTALL_PATH qApp->applicationDirPath()+"/plugins"
47 #define SOCEXPLORER_PLUGINS_INSTALL_PATH qApp->applicationDirPath()+"/plugins"
48 #define SOCEXPLORER_CONFIG_PATH qApp->applicationDirPath()+"/config"
48 #define SOCEXPLORER_CONFIG_PATH qApp->applicationDirPath()+"/config"
49 #define PYMODULES qApp->applicationDirPath()+"/python"
49 #define PYMODULES qApp->applicationDirPath()+"/python"
50 #else
50 #else
51 #ifdef UNIX
51 #ifdef UNIX
52 #define SOCEXPLORER_PLUGINS_INSTALL_PATH QDir::homePath()+"/.SocExplorer/plugins"
52 #define SOCEXPLORER_PLUGINS_INSTALL_PATH QDir::homePath()+"/.SocExplorer/plugins"
53 #define SOCEXPLORER_CONFIG_PATH QDir::homePath()+"/.SocExplorer/config"
53 //#define SOCEXPLORER_CONFIG_PATH QDir::homePath()+"/.SocExplorer/config"
54 #define PYMODULES "/etc/SocExplorer/python"
54 #define PYMODULES "/etc/SocExplorer/python"
55 #endif
55 #endif
56 #endif
56 #endif
57 #endif // SOCEXPLORER_H
57 #endif // SOCEXPLORER_H
General Comments 0
You need to be logged in to leave comments. Login now