ctkEventBusImpl_p.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*=============================================================================
  2. Library: CTK
  3. Copyright (c) German Cancer Research Center,
  4. Division of Medical and Biological Informatics
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. =============================================================================*/
  15. #ifndef CTKEVENTBUSIMPL_H
  16. #define CTKEVENTBUSIMPL_H
  17. #include <EventBus/ctkEventBus.h>
  18. #include <QList>
  19. #include <QHash>
  20. #include <QSet>
  21. class ctkEventHandlerWrapper;
  22. class ctkEventBusImpl : public QObject,
  23. public ctkEventBus
  24. {
  25. Q_OBJECT
  26. Q_INTERFACES(ctkEventBus)
  27. public:
  28. static ctkEventBusImpl* instance();
  29. void postEvent(const ctkEvent& event);
  30. void sendEvent(const ctkEvent& event);
  31. void publishSignal(const QObject* publisher, const char* signal, const QString& topic, Qt::ConnectionType type = Qt::QueuedConnection);
  32. QString subscribeSlot(const QObject* subscriber, const char* member, const ctkProperties& properties);
  33. void updateProperties(const QString& subscriptionId, const ctkProperties& properties);
  34. protected:
  35. typedef QList<ctkEventHandlerWrapper*> HandlerList;
  36. HandlerList globalWildcard;
  37. QHash<QString, HandlerList> topicName;
  38. void dispatchEvent(const ctkEvent& event, bool isAsync);
  39. void bucket(ctkEventHandlerWrapper* wrapper);
  40. QSet<ctkEventHandlerWrapper*> handlers(const QString& topic);
  41. private:
  42. ctkEventBusImpl();
  43. };
  44. #endif // CTKEVENTBUSIMPL_H