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