ctkEventHandlerWrapper_p.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. return true;
  37. }
  38. void handleEvent(const ctkEvent& event /*, const Permission& perm */)
  39. {
  40. if (!event.matches(filter)) return;
  41. // should do permissions checks now somehow
  42. // ...
  43. try {
  44. emit notifySubscriber(event);
  45. }
  46. catch (const std::exception& e)
  47. {
  48. // TODO logging
  49. std::cerr << "Exception occured during publishing " << qPrintable(event.topic()) << ": " << e.what() << std::endl;
  50. }
  51. }
  52. signals:
  53. void notifySubscriber(const ctkEvent&);
  54. };
  55. #endif // CTKEVENTHANDLERWRAPPER_P_H