ctkEventHandlerWrapper_p.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef CTKEVENTHANDLERWRAPPER_P_H
  2. #define CTKEVENTHANDLERWRAPPER_P_H
  3. #include <QStringList>
  4. #include <EventBus/ctkEventBus.h>
  5. #include <EventBus/ctkEventConstants.h>
  6. #include <ctkLDAPSearchFilter.h>
  7. #include <iostream>
  8. class ctkEventHandlerWrapper : public QObject {
  9. Q_OBJECT
  10. private:
  11. ctkEventBus::Properties properties;
  12. QStringList topicList;
  13. ctkLDAPSearchFilter filter;
  14. public:
  15. ctkEventHandlerWrapper(const QObject* subscriber, const char* handler, const ctkEventBus::Properties& properties)
  16. : properties(properties)
  17. {
  18. connect(this, SIGNAL(notifySubscriber(Event)), subscriber, handler);
  19. }
  20. QStringList topics() const
  21. {
  22. return topicList;
  23. }
  24. bool init()
  25. {
  26. topicList.clear();
  27. // Get topic names
  28. QVariant v = properties[EventConstants::EVENT_TOPIC];
  29. topicList = v.toStringList();
  30. if (topicList.empty())
  31. {
  32. return false;
  33. }
  34. v = properties[EventConstants::EVENT_FILTER];
  35. filter = ctkLDAPSearchFilter(v.toString());
  36. }
  37. void handleEvent(const ctkEvent& event /*, const Permission& perm */)
  38. {
  39. if (!event.matches(filter)) return;
  40. // should do permissions checks now somehow
  41. // ...
  42. try {
  43. emit notifySubscriber(event);
  44. }
  45. catch (const std::exception& e)
  46. {
  47. // TODO logging
  48. std::cerr << "Exception occured during publishing " << qPrintable(event.topic()) << ": " << e.what() << std::endl;
  49. }
  50. }
  51. signals:
  52. void notifySubscriber(const ctkEvent&);
  53. };
  54. #endif // CTKEVENTHANDLERWRAPPER_P_H