ctkEventBusImpl.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #include "ctkEventBusImpl_p.h"
  2. #include <QSetIterator>
  3. #include "ctkEventHandlerWrapper_p.h"
  4. ctkEventBusImpl* ctkEventBusImpl::instance()
  5. {
  6. static ctkEventBusImpl inst;
  7. return &inst;
  8. }
  9. ctkEventBusImpl::ctkEventBusImpl()
  10. {
  11. }
  12. void ctkEventBusImpl::postEvent(const ctkEvent& event)
  13. {
  14. dispatchEvent(event, true);
  15. }
  16. void ctkEventBusImpl::sendEvent(const ctkEvent& event)
  17. {
  18. dispatchEvent(event, false);
  19. }
  20. void ctkEventBusImpl::publishSignal(const QObject* publisher, const char* signal, const QString& topic,
  21. Qt::ConnectionType type)
  22. {
  23. Q_UNUSED(publisher)
  24. Q_UNUSED(signal)
  25. Q_UNUSED(topic)
  26. Q_UNUSED(type)
  27. }
  28. QString ctkEventBusImpl::subscribeSlot(const QObject* subscriber, const char* member, const ctkProperties& properties)
  29. {
  30. // TODO check for duplicates
  31. ctkEventHandlerWrapper* wrapper = new ctkEventHandlerWrapper(subscriber, member, properties);
  32. if (wrapper->init())
  33. {
  34. bucket(wrapper);
  35. }
  36. // TODO return id
  37. return QString();
  38. }
  39. void ctkEventBusImpl::updateProperties(const QString& subscriptionId, const ctkProperties& properties)
  40. {
  41. Q_UNUSED(subscriptionId)
  42. Q_UNUSED(properties)
  43. }
  44. void ctkEventBusImpl::dispatchEvent(const ctkEvent& event, bool isAsync)
  45. {
  46. Q_UNUSED(isAsync)
  47. QString topic = event.topic();
  48. QSet<ctkEventHandlerWrapper*> eventHandlers = this->handlers(topic);
  49. if (eventHandlers.empty()) return;
  50. QSetIterator<ctkEventHandlerWrapper*> iter(eventHandlers);
  51. while (iter.hasNext())
  52. {
  53. iter.next()->handleEvent(event);
  54. }
  55. }
  56. void ctkEventBusImpl::bucket(ctkEventHandlerWrapper* wrapper)
  57. {
  58. // TODO bucket logic
  59. globalWildcard.push_back(wrapper);
  60. }
  61. QSet<ctkEventHandlerWrapper*> ctkEventBusImpl::handlers(const QString& topic)
  62. {
  63. Q_UNUSED(topic)
  64. // TODO
  65. return globalWildcard.toSet();
  66. }