##// END OF EJS Templates
Working snapshot.
jeandet -
r5:483cfe27e044 Working snapshot default
parent child
Show More
@@ -1,86 +1,86
1 1 #-------------------------------------------------
2 2 #
3 3 # Project created by QtCreator 2011-09-19T22:52:10
4 4 #
5 5 #-------------------------------------------------
6 6
7 7 TEMPLATE = subdirs
8 8 CONFIG += ordered release
9 9
10 10 SUBDIRS = \
11 11 src/common \
12 12 src/SocExplorerEngine \
13 13 src \
14 14 src/SocExplorer_TCP_Terminal
15 15
16 16
17 SocExplorer.path = $$[QT_INSTALL_PREFIX]/mkspecs/features
18 SocExplorer.files = \
17 socexplorercfg.path = $$[QT_INSTALL_PREFIX]/mkspecs/features
18 socexplorercfg.files = \
19 19 src/SocExplorerEngine/plugins/socexplorerplugin.prf
20 20
21 21
22 22 unix{
23 23 SocExplorer.path = /usr/share/applications/
24 24 SocExplorer.files = unixcfg/SocExplorer.desktop
25 25 icon.path = /etc/SocExplorer
26 26 icon.files = ressources/images/logo-lpp-cutted.png
27 27 Wizard.path = /usr/share/qtcreator/templates/wizards/SocExplorerPlugin
28 28 Wizard.files = Qt_Creator_Wizard/SocExplorerPlugin/logo-lpp-cutted.png \
29 29 Qt_Creator_Wizard/SocExplorerPlugin/plugin.cpp \
30 30 Qt_Creator_Wizard/SocExplorerPlugin/plugin.h \
31 31 Qt_Creator_Wizard/SocExplorerPlugin/project.pro \
32 32 Qt_Creator_Wizard/SocExplorerPlugin/wizard.xml
33 33 INSTALLS+=Wizard SocExplorer icon
34 34 }
35 INSTALLS+=SocExplorer
35 INSTALLS+=socexplorercfg
36 36
37 37
38 38
39 39
40 40
41 41
42 42
43 43
44 44
45 45
46 46
47 47
48 48
49 49
50 50
51 51
52 52
53 53
54 54
55 55
56 56
57 57
58 58
59 59
60 60
61 61
62 62
63 63
64 64
65 65
66 66
67 67
68 68
69 69
70 70
71 71
72 72
73 73
74 74
75 75
76 76
77 77
78 78
79 79
80 80
81 81
82 82
83 83
84 84
85 85
86 86
@@ -1,572 +1,572
1 1 #include "pluginloader.h"
2 2 #include <QDir>
3 3 #include <QFile>
4 4 #include <QFileInfoList>
5 5 #include <QFileInfo>
6 6 #include <QString>
7 7 #include <QStringList>
8 8 #include <QLabel>
9 9 #include <QSettings>
10 10 #include <QApplication>
11 11 #include <QCoreApplication>
12 12 #include <socexplorerengine.h>
13 13 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
14 14 #include "unix/unixpluginloader.h"
15 15 #endif
16 16
17 17 pluginloader* pluginloader::_self = NULL;
18 18 PluginsCache* pluginloader::_cache = NULL;
19 19 QStringList* pluginloader::_folderList = NULL;
20 20
21 21
22 22 pluginloader::pluginloader()
23 23 {
24 24 _cache = new PluginsCache();
25 25 _folderList = new QStringList();
26 26 QDir pluginPath(QString(SocExplorerEngine::pluginFolder()));
27 27 if(!pluginPath.exists())
28 28 {
29 29 pluginPath.mkpath(QString(SocExplorerEngine::pluginFolder()));
30 30 }
31 31 QFile pluginsFolders(QString(SocExplorerEngine::pluginFolder())+"/plugins.conf");
32 32 *_folderList << QString(SocExplorerEngine::pluginFolder()); //default place
33 33 if(!pluginsFolders.exists())
34 34 {
35 35 pluginsFolders.open(QIODevice::WriteOnly); //if file doesn't exist create it
36 36 pluginsFolders.close();
37 37 }
38 38 *_folderList<< readFoldersList(QStringList()<< QString(SocExplorerEngine::pluginFolder())+"/plugins.conf");
39 39 scanFolders();
40 40 }
41 41
42 42
43 43 QStringList pluginloader::readFoldersList(const QStringList confFiles)
44 44 {
45 45 QDir testDir;
46 46 QStringList folders;
47 47 QFile confFile;
48 48 for(int i=0;i<confFiles.count();i++)
49 49 {
50 50 confFile.setFileName(confFiles.at(i));
51 51 if(confFile.exists())
52 52 {
53 53 if (confFile.open(QIODevice::ReadOnly | QIODevice::Text))
54 54 {
55 55 QTextStream in(&confFile);
56 56 QString line = in.readLine();
57 57 while (!line.isNull())
58 58 {
59 59 testDir.setPath(line);
60 60 if(testDir.exists())
61 61 {
62 62 if(!folders.contains(line))
63 63 folders << line;
64 64 }
65 65 line = in.readLine();
66 66 }
67 67 }
68 68 }
69 69 }
70 70 return folders;
71 71 }
72 72
73 73
74 74 void pluginloader::scanFolders()
75 75 {
76 76 QDir dir;
77 77 QStringList filters;
78 78 filters <<"*.so"<< "*.dll";
79 79 _cache->flush();
80 80 for(int d=0;d<_folderList->count();d++)
81 81 {
82 82 dir.setPath(_folderList->at(d));
83 83 dir.setFilter(QDir::Files);
84 84 dir.setNameFilters(filters);
85 85 QFileInfoList list = dir.entryInfoList();
86 86 for (int i = 0; i < list.size(); ++i)
87 87 {
88 88 QFileInfo fileInfo = list.at(i);
89 89 if(checklibrary(fileInfo.filePath())!=0)
90 90 {
91 91 _cache->append(fileInfo.fileName(),fileInfo.path(),_getlibName(fileInfo.filePath()),_getlibPID(fileInfo.filePath()),_getlibPID(fileInfo.filePath()));
92 92 }
93 93 }
94 94 }
95 95 }
96 96
97 97 int pluginloader::p_checklibraryQlib(const QString fileName)
98 98 {
99 99 QLibrary* lib = new QLibrary;
100 100 lib->setFileName(fileName);
101 101 lib->setLoadHints(QLibrary::PreventUnloadHint);
102 102 lib->load();
103 103 if(!lib->isLoaded())
104 104 {
105 105 qDebug()<<lib->errorString();
106 106 lib->~QLibrary();
107 107 lib = new QLibrary(fileName);
108 108 lib->load();
109 109 }
110 110 delete lib;
111 111 if(QLibrary::resolve(fileName,"socexplorerpluginCreateObject"))
112 112 {
113 113 if(QLibrary::resolve(fileName,"socexplorerpluginpid"))
114 114 {
115 115 if(QLibrary::resolve(fileName,"socexplorerpluginvid"))
116 116 {
117 117 if(QLibrary::resolve(fileName,"socexplorerpluginVersion"))
118 118 {
119 119 if(QLibrary::resolve(fileName,"socexplorerpluginAuthor"))
120 120 {
121 121 if(QLibrary::resolve(fileName,"socexplorerpluginDescription"))
122 122 {
123 123 return 1;
124 124 }
125 125 }
126 126 }
127 127 }
128 128 }
129 129 }
130 130 return 0;
131 131 }
132 132
133 133 int pluginloader::p_checklibraryCustom(const QString fileName)
134 134 {
135 135 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
136 136 unixPluginLoader lib(fileName);
137 137 if(NULL!=lib.resolve("socexplorerpluginCreateObject"))
138 138 {
139 if(NULL!=lib.resolve("socexplorernpluginpid"))
139 if(NULL!=lib.resolve("socexplorerpluginpid"))
140 140 {
141 141 if(NULL!=lib.resolve("socexplorerpluginvid"))
142 142 {
143 143 if(NULL!=lib.resolve("socexplorerpluginVersion"))
144 144 {
145 145 if(NULL!=lib.resolve("socexplorerpluginAuthor"))
146 146 {
147 147 if(NULL!=lib.resolve("socexplorerpluginDescription"))
148 148 {
149 149 return 1;
150 150 }
151 151 }
152 152 }
153 153 }
154 154 }
155 155 }
156 156 #endif
157 157 return 0;
158 158 }
159 159
160 160 socexplorerplugin *pluginloader::p_newsocexplorerpluginQlib(const QString Name)
161 161 {
162 162 QString* libfile= _cacheLookup(Name);
163 163 if(libfile==NULL)return NULL;
164 164 QLibrary* lib = new QLibrary(*libfile);
165 165 delete libfile;
166 166 socexplorerpluginCreateObjectT newDrvr = NULL;
167 167 newDrvr=(socexplorerpluginCreateObjectT)lib->resolve("socexplorerpluginCreateObject");
168 168 if(newDrvr==NULL)
169 169 {
170 170 return NULL;
171 171 }
172 172 return (socexplorerplugin*) newDrvr();
173 173 }
174 174
175 175 socexplorerplugin *pluginloader::p_newsocexplorerpluginCustom(const QString Name)
176 176 {
177 177 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
178 178 QString* libfile= _cacheLookup(Name);
179 179 if(libfile==NULL)return NULL;
180 180 unixPluginLoader lib(*libfile);
181 181 delete libfile;
182 182 socexplorerpluginCreateObjectT newDrvr = NULL;
183 183 newDrvr=(socexplorerpluginCreateObjectT)lib.resolve("socexplorerpluginCreateObject");
184 184 if(newDrvr==NULL)
185 185 {
186 186 return NULL;
187 187 }
188 188 return (socexplorerplugin*) newDrvr();
189 189 #endif
190 190 }
191 191
192 192 QList<PluginsCacheItem*> pluginloader::listAvailiables(bool rescan)
193 193 {
194 194 if(_self==NULL)
195 195 {
196 196 init();
197 197 return _cache->listDrivers();
198 198 }
199 199 if(rescan)
200 200 {
201 201 scanFolders();
202 202 }
203 203
204 204 return _cache->listDrivers();
205 205 }
206 206
207 207
208 208 void pluginloader::init()
209 209 {
210 210 if(_self==NULL)
211 211 {
212 212 _self=new pluginloader();
213 213 }
214 214 }
215 215
216 216
217 217 pluginloader* pluginloader::self()
218 218 {
219 219 if(_self==NULL)
220 220 {
221 221 init();
222 222 }
223 223 return _self;
224 224 }
225 225
226 226 bool pluginloader::isvalid(QString Name)
227 227 {
228 228 if(_self==NULL)init();
229 229 QString* libfile= _cacheLookup(Name);
230 230 if(libfile==NULL)return false;
231 231 else
232 232 {
233 233 delete libfile;
234 234 return true;
235 235 }
236 236
237 237 }
238 238
239 239 int pluginloader::checklibrary(const QString fileName)
240 240 {
241 241 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
242 242 return _self->p_checklibraryCustom(fileName);
243 243 #else
244 244 return _self->p_checklibraryQlib(fileName);
245 245 #endif
246 246 }
247 247
248 248
249 249
250 250
251 251
252 252 socexplorerplugin* pluginloader::newsocexplorerplugin(const QString Name)
253 253 {
254 254 #ifdef SOCEXPLORER_CUSTOM_PLUGIN_LOADER
255 255 return _self->p_newsocexplorerpluginCustom(Name);
256 256 #else
257 257 return _self->p_newsocexplorerpluginQlib(Name);
258 258 #endif
259 259 }
260 260
261 261
262 262 QString pluginloader::getlibTypeStr(QString Name)
263 263 {
264 264 if(_self==NULL)init();
265 265 QString* libfile= _cacheLookup(Name);
266 266 if(libfile==NULL)return NULL;
267 267 QLibrary* lib = new QLibrary(*libfile);
268 268 delete libfile;
269 269 lib->load();
270 270 if(lib->isLoaded())
271 271 {
272 272 socexplorerpluginTypeT plugintype = (socexplorerpluginTypeT)lib->resolve("socexplorerpluginType");
273 273 if(plugintype!=NULL)
274 274 {
275 275 pluginT type = plugintype();
276 276 switch(type)
277 277 {
278 278 case ComDriverT:
279 279 ////lib->unload();
280 280 lib->~QLibrary();
281 281 return QObject::tr("Comunaication Driver Plugin.");
282 282 break;
283 283 case PerifDriverT:
284 284 ////lib->unload();
285 285 lib->~QLibrary();
286 286 return QObject::tr("Periferial Driver Plugin.");
287 287 break;
288 288 default:
289 289 ////lib->unload();
290 290 lib->~QLibrary();
291 291 return QObject::tr("Unknow Plugin.");
292 292 break;
293 293 }
294 294 }
295 295 }
296 296 lib->~QLibrary();
297 297 return QObject::tr("Can't load Plugin.");
298 298 }
299 299
300 300
301 301
302 302
303 303 pluginT pluginloader::getlibType(QString Name)
304 304 {
305 305 if(_self==NULL)init();
306 306 QString* libfile= _cacheLookup(Name);
307 307 if(libfile==NULL)return (pluginT)NULL;
308 308 QLibrary* lib = new QLibrary(*libfile);
309 309 delete libfile;
310 310 lib->load();
311 311 if(lib->isLoaded())
312 312 {
313 313 socexplorerpluginTypeT plugintype = (socexplorerpluginTypeT)lib->resolve("socexplorerpluginType");
314 314 if(plugintype!=NULL)
315 315 {
316 316 return plugintype();
317 317 }
318 318 }
319 319 lib->~QLibrary();
320 320 return -1;
321 321 }
322 322
323 323
324 324 QString pluginloader::getlibVersion(const QString Name)
325 325 {
326 326 if(_self==NULL)init();
327 327 QString* libfile= _cacheLookup(Name);
328 328 if(libfile==NULL)return NULL;
329 329 QLibrary* lib = new QLibrary(*libfile);
330 330 delete libfile;
331 331 lib->load();
332 332 if(lib->isLoaded())
333 333 {
334 334 socexplorerpluginVersionT pluginversion = (socexplorerpluginVersionT)lib->resolve("socexplorerpluginVersion");
335 335 if(pluginversion!=NULL)
336 336 {
337 337 QString version = pluginversion();
338 338 ////lib->unload();
339 339 lib->~QLibrary();
340 340 return version;
341 341 }
342 342 }
343 343 lib->~QLibrary();
344 344 return QObject::tr("Can't load Plugin.");
345 345 }
346 346
347 347
348 348
349 349 QString pluginloader::getlibPIDstr(const QString Name)
350 350 {
351 351 return QString("0x" + QString::number(pluginloader::getlibPID(Name) , 16));
352 352 }
353 353
354 354 QString pluginloader::getlibVIDstr(const QString Name)
355 355 {
356 356 return QString("0x" + QString::number(pluginloader::getlibVID(Name) , 16));
357 357 }
358 358
359 359
360 360
361 361 int pluginloader::libcanbechild(const QString Name)
362 362 {
363 363 if(_self==NULL)init();
364 364 QString* libfile= _cacheLookup(Name);
365 365 if(libfile==NULL)return (int)NULL;
366 366 QLibrary* lib = new QLibrary(*libfile);
367 367 delete libfile;
368 368 lib->load();
369 369 if(lib->isLoaded())
370 370 {
371 371 socexplorerplugincanbechildT canbechild = (socexplorerplugincanbechildT)lib->resolve("socexplorerplugincanbechild");
372 372 if(canbechild!=NULL)
373 373 {
374 374 int value = canbechild();
375 375 ////lib->unload();
376 376 //lib->~QLibrary();
377 377 return value;
378 378 }
379 379 }
380 380 //lib->~QLibrary();
381 381 return 0;
382 382 }
383 383
384 384
385 385
386 386
387 387 int pluginloader::libcanberoot(const QString Name)
388 388 {
389 389 if(_self==NULL)init();
390 390 QString* libfile= _cacheLookup(Name);
391 391 if(libfile==NULL)return (int)NULL;
392 392 QLibrary* lib = new QLibrary(*libfile);
393 393 delete libfile;
394 394 lib->load();
395 395 if(lib->isLoaded())
396 396 {
397 397 socexplorerplugincanberootT canberoot = (socexplorerplugincanberootT)lib->resolve("socexplorerplugincanberoot");
398 398 if(canberoot!=NULL)
399 399 {
400 400 int value = canberoot();
401 401 ////lib->unload();
402 402 //lib->~QLibrary();
403 403 return value;
404 404 }
405 405 }
406 406 delete lib;
407 407 //lib->~QLibrary();
408 408 return 0;
409 409 }
410 410
411 411 int pluginloader::getlibVID(const QString Name)
412 412 {
413 413 if(_self==NULL)init();
414 414 QString* libfile= _cacheLookup(Name);
415 415 if(libfile==NULL)return 0;
416 416 QString file(*libfile);
417 417 delete libfile;
418 418 return _getlibVID(file);
419 419 }
420 420
421 421
422 422 int pluginloader::getlibPID(const QString Name)
423 423 {
424 424 if(_self==NULL)init();
425 425 QString* libfile= _cacheLookup(Name);
426 426 if(libfile==NULL)return 0;
427 427 QString file(*libfile);
428 428 delete libfile;
429 429 return _getlibPID(file);
430 430 }
431 431
432 432 QString pluginloader::getlibAuthor(const QString Name)
433 433 {
434 434 if(_self==NULL)init();
435 435 QString* libfile= _cacheLookup(Name);
436 436 if(libfile==NULL)return NULL;
437 437 QLibrary* lib = new QLibrary(*libfile);
438 438 delete libfile;
439 439 lib->load();
440 440 if(lib->isLoaded())
441 441 {
442 442 socexplorerpluginAuthorT pluginauthor = (socexplorerpluginAuthorT)lib->resolve("socexplorerpluginAuthor");
443 443 if(pluginauthor!=NULL)
444 444 {
445 445 QString author = pluginauthor();
446 446 ////lib->unload();
447 447 lib->~QLibrary();
448 448 return author;
449 449 }
450 450 }
451 451 lib->~QLibrary();
452 452 return QObject::tr("Can't load Plugin.");
453 453 }
454 454
455 455 QString pluginloader::getlibName(const QString Name)
456 456 {
457 457 if(_self==NULL)init();
458 458 QString* libfile= _cacheLookup(Name);
459 459 if(libfile==NULL)return QString("");
460 460 QString file(*libfile);
461 461 delete libfile;
462 462 return _getlibName(file);
463 463 }
464 464
465 465 QString pluginloader::getlibDescription(const QString Name)
466 466 {
467 467 if(_self==NULL)init();
468 468 QString* libfile= _cacheLookup(Name);
469 469 if(libfile==NULL)return NULL;
470 470 QLibrary* lib = new QLibrary(*libfile);
471 471 delete libfile;
472 472 lib->load();
473 473 if(lib->isLoaded())
474 474 {
475 475 socexplorerpluginDescriptionT plugindescription = (socexplorerpluginDescriptionT)lib->resolve("socexplorerpluginDescription");
476 476 if(plugindescription!=NULL)
477 477 {
478 478 QString description = plugindescription();
479 479 ////lib->unload();
480 480 lib->~QLibrary();
481 481 return description;
482 482 }
483 483 }
484 484 lib->~QLibrary();
485 485 return QObject::tr("Can't load Plugin.");
486 486 }
487 487
488 488 QString pluginloader::getlibDir(const QString Name)
489 489 {
490 490 if(_self==NULL)init();
491 491 return *_cacheLookup(Name);
492 492 }
493 493
494 494 QString pluginloader::_getlibName(const QString fileName)
495 495 {
496 496 QLibrary* lib = new QLibrary(fileName);
497 497 lib->load();
498 498 if(lib->isLoaded())
499 499 {
500 500 socexplorerpluginNameT pluginName = (socexplorerpluginAuthorT)lib->resolve("socexplorerpluginName");
501 501 if(pluginName!=NULL)
502 502 {
503 503 QString name = pluginName();
504 504 //lib->unload();
505 505 lib->~QLibrary();
506 506 return name;
507 507 }
508 508 }
509 509 lib->~QLibrary();
510 510 return QObject::tr("Can't load Plugin.");
511 511 }
512 512
513 513 int pluginloader::_getlibPID(const QString fileName)
514 514 {
515 515 QLibrary* lib = new QLibrary(fileName);
516 516 lib->load();
517 517 if(lib->isLoaded())
518 518 {
519 519 socexplorerpluginpidT pluginpid = (socexplorerpluginpidT)lib->resolve("socexplorerpluginpid");
520 520 if(pluginpid!=NULL)
521 521 {
522 522 int pid = pluginpid();
523 523 //lib->unload();
524 524 lib->~QLibrary();
525 525 return pid;
526 526 }
527 527 }
528 528 lib->~QLibrary();
529 529 return 0;
530 530 }
531 531
532 532 int pluginloader::_getlibVID(const QString fileName)
533 533 {
534 534 QLibrary* lib = new QLibrary(fileName);
535 535 lib->load();
536 536 if(lib->isLoaded())
537 537 {
538 538 socexplorerpluginvidT pluginvid = (socexplorerpluginvidT)lib->resolve("socexplorerpluginvid");
539 539 if(pluginvid!=NULL)
540 540 {
541 541 int vid = pluginvid();
542 542 //lib->unload();
543 543 lib->~QLibrary();
544 544 return vid;
545 545 }
546 546 }
547 547 lib->~QLibrary();
548 548 return 0;
549 549 }
550 550
551 551 QString* pluginloader::_cacheLookup(const QString Name)
552 552 {
553 553 QString* libfile= new QString(_cache->first(Name));
554 554 if(!QFile::exists(*libfile))
555 555 {
556 556 scanFolders();
557 557 *libfile = _cache->first(Name);
558 558 if(QFile::exists(*libfile))return libfile;
559 559 }
560 560 else
561 561 {
562 562 return libfile;
563 563 }
564 564 delete libfile;
565 565 return NULL;
566 566 }
567 567
568 568 /*QString findlib(QString name)
569 569 {
570 570
571 571 }*/
572 572
General Comments 0
You need to be logged in to leave comments. Login now