ctkEventBusDemoMain.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) 2010 BioComputing Competence Centre - Super Computing Solutions
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =============================================================================*/
  14. #include <ctkConfig.h>
  15. #include <ctkPluginFrameworkFactory.h>
  16. #include <ctkPluginFramework.h>
  17. #include <ctkPluginException.h>
  18. #include <ctkPluginContext.h>
  19. #include <ctkServiceReference.h>
  20. #include "ctkEventAdminBus.h"
  21. #include <QApplication>
  22. #include <QString>
  23. #include <QStringList>
  24. #include <QDirIterator>
  25. #include <QWidget>
  26. #include <QFileInfo>
  27. #include "ctkEventBusDemoMainWindow.h"
  28. int main(int argv, char** argc) {
  29. QApplication app(argv, argc);
  30. qDebug() << "################################################################";
  31. qApp->setOrganizationName("CTK");
  32. qApp->setOrganizationDomain("commontk.org");
  33. qApp->setApplicationName("ctkEventBusDemoApp");
  34. qDebug() << "################################################################";
  35. // setup the plugin framework
  36. ctkPluginFrameworkFactory fwFactory;
  37. QSharedPointer<ctkPluginFramework> framework = fwFactory.getFramework();
  38. try {
  39. framework->init();
  40. } catch (const ctkPluginException& exc) {
  41. qCritical() << "Failed to initialize the plug-in framework:" << exc;
  42. exit(2);
  43. }
  44. #ifdef CMAKE_INTDIR
  45. QString pluginPath = CTK_PLUGIN_DIR CMAKE_INTDIR "/";
  46. #else
  47. QString pluginPath = CTK_PLUGIN_DIR;
  48. #endif
  49. qApp->addLibraryPath(pluginPath);
  50. QStringList libFilter;
  51. libFilter << "*.dll" << "*.so" << "*.dylib";
  52. QDirIterator dirIter(pluginPath, libFilter, QDir::Files);
  53. QStringList pluginsToInstall;
  54. pluginsToInstall << "org_commontk_eventbus";
  55. qDebug() << pluginPath;
  56. QList<QSharedPointer<ctkPlugin> > installedPlugins;
  57. while(dirIter.hasNext())
  58. {
  59. try
  60. {
  61. QString fileLocation = dirIter.next();
  62. foreach(QString pluginToInstall, pluginsToInstall)
  63. {
  64. if (fileLocation.contains(pluginToInstall))
  65. {
  66. QSharedPointer<ctkPlugin> plugin = framework->getPluginContext()->installPlugin(QUrl::fromLocalFile(fileLocation));
  67. installedPlugins << plugin;
  68. break;
  69. }
  70. }
  71. }
  72. catch (const ctkPluginException& e)
  73. {
  74. qCritical() << e.what();
  75. }
  76. }
  77. framework->start();
  78. foreach(QSharedPointer<ctkPlugin> plugin, installedPlugins)
  79. {
  80. plugin->start(ctkPlugin::START_TRANSIENT);
  81. }
  82. ctkServiceReference ebr = framework->getPluginContext()->getServiceReference("ctkEventAdminBus");
  83. ctkEventAdminBus *eb = framework->getPluginContext()->getService<ctkEventAdminBus>(ebr);
  84. ctkEventBusDemoMainWindow win(eb);
  85. win.show();
  86. return app.exec();
  87. }