ctkEventBusImpl_p.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef CTKEVENTBUSIMPL_H
  2. #define CTKEVENTBUSIMPL_H
  3. #include <EventBus/ctkEventBus.h>
  4. #include <QList>
  5. #include <QHash>
  6. #include <QSet>
  7. class ctkEventHandlerWrapper;
  8. class ctkEventBusImpl : public QObject,
  9. public ctkEventBus
  10. {
  11. Q_OBJECT
  12. Q_INTERFACES(ctkEventBus)
  13. public:
  14. static ctkEventBusImpl* instance();
  15. void postEvent(const ctkEvent& event);
  16. void sendEvent(const ctkEvent& event);
  17. void publishSignal(const QObject* publisher, const char* signal, const QString& topic, Qt::ConnectionType type = Qt::QueuedConnection);
  18. QString subscribeSlot(const QObject* subscriber, const char* member, const ctkProperties& properties);
  19. void updateProperties(const QString& subscriptionId, const ctkProperties& properties);
  20. protected:
  21. typedef QList<ctkEventHandlerWrapper*> HandlerList;
  22. HandlerList globalWildcard;
  23. QHash<QString, HandlerList> topicName;
  24. void dispatchEvent(const ctkEvent& event, bool isAsync);
  25. void bucket(ctkEventHandlerWrapper* wrapper);
  26. QSet<ctkEventHandlerWrapper*> handlers(const QString& topic);
  27. private:
  28. ctkEventBusImpl();
  29. };
  30. #endif // CTKEVENTBUSIMPL_H