main.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include <ctkPluginConstants.h>
  2. #include <service/event/ctkEventConstants.h>
  3. #include <QCoreApplication>
  4. #include <QDir>
  5. #include "ctkSnippetReportManager.h"
  6. // dummy main
  7. int main(int argc, char** argv)
  8. {
  9. QCoreApplication myApp(argc, argv);
  10. QString tmpPath = QDir::tempPath() + "/snippet-eventadmin-intro";
  11. ctkProperties fwProps;
  12. fwProps[ctkPluginConstants::FRAMEWORK_STORAGE] = tmpPath;
  13. fwProps[ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN] = ctkPluginConstants::FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT;
  14. fwProps["org.commontk.pluginfw.debug.resolve"] = true;
  15. fwProps["org.commontk.pluginfw.debug.service_reference"] = true;
  16. fwProps["org.commontk.pluginfw.debug.errors"] = true;
  17. fwProps["org.commontk.pluginfw.debug.pluginfw"] = true;
  18. fwProps["org.commontk.pluginfw.debug.lazy_activation"] = true;
  19. ctkPluginFrameworkLauncher::setFrameworkProperties(fwProps);
  20. ctkPluginFrameworkLauncher::start("org.commontk.eventadmin");
  21. ctkPluginContext* pluginContext = ctkPluginFrameworkLauncher::getPluginContext();
  22. ReportManager reportManager(pluginContext);
  23. //! [Event Handler service registration]
  24. ReportEventHandler eventHandler;
  25. ctkDictionary props;
  26. props[ctkEventConstants::EVENT_TOPIC] = "com/acme/reportgenerator/GENERATED";
  27. pluginContext->registerService<ctkEventHandler>(&eventHandler, props);
  28. //! [Event Handler service registration]
  29. // You can also use a wildcard in the final character of the EVENT_TOPIC
  30. //! [Event Handler service registration wildcard]
  31. props[ctkEventConstants::EVENT_TOPIC] = "com/acme/reportgenerator/*";
  32. pluginContext->registerService<ctkEventHandler>(&eventHandler, props);
  33. //! [Event Handler service registration wildcard]
  34. // Or you could use a filter expression (using LDAP syntax)
  35. //! [Event Handler service registration filter]
  36. props[ctkEventConstants::EVENT_TOPIC] = "com/acme/reportgenerator/GENERATED";
  37. props[ctkEventConstants::EVENT_FILTER] = "(title=samplereport)";
  38. pluginContext->registerService<ctkEventHandler>(&eventHandler, props);
  39. //! [Event Handler service registration filter]
  40. //! [Event Handler service registration slot]
  41. ReportEventHandlerUsingSlots eventHandlerUsingSlots;
  42. ctkDictionary propsForSlot;
  43. propsForSlot[ctkEventConstants::EVENT_TOPIC] = "com/acme/reportgenerator/*";
  44. ctkServiceReference ref = pluginContext->getServiceReference<ctkEventAdmin>();
  45. if (ref)
  46. {
  47. ctkEventAdmin* eventAdmin = pluginContext->getService<ctkEventAdmin>(ref);
  48. eventAdmin->subscribeSlot(&eventHandlerUsingSlots, SLOT(handleEvent(ctkEvent)), propsForSlot);
  49. }
  50. //! [Event Handler service registration slot]
  51. reportManager.reportGenerated(Report());
  52. }