CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkEventBusManager.h
Go to the documentation of this file.
1 /*
2  * ctkEventBusManager.h
3  * ctkEventBus
4  *
5  * Created by Paolo Quadrani on 27/03/09.
6  * Copyright 2010 B3C. All rights reserved.
7  *
8  * See Licence at: http://tiny.cc/QXJ4D
9  *
10  */
11 
12 #ifndef CTKEVENTBUSMANAGER_H
13 #define CTKEVENTBUSMANAGER_H
14 
15 // Includes list
16 #include "ctkEventDefinitions.h"
19 #include "ctkBusEvent.h"
20 
21 namespace ctkEventBus {
22 
23 // Class forwarding list
24 
30 class org_commontk_eventbus_EXPORT ctkEventBusManager : public QObject {
31  Q_OBJECT
32 
33 public:
36 
38 
40  bool addEventProperty(ctkBusEvent &props) const;
41 
43  bool removeEventProperty(ctkBusEvent &props) const;
44 
46 
49  void removeObserver(const QObject *obj, const QString topic = "", bool qt_disconnect = true);
50 
52 
55  void removeSignal(const QObject *obj, QString topic = "", bool qt_disconnect = true);
56 
58  void notifyEvent(ctkBusEvent &event_dictionary, ctkEventArgumentsList *argList = NULL, ctkGenericReturnArgument *returnArg = NULL) const;
59 
61  void notifyEvent(const QString topic, ctkEventType ev_type = ctkEventTypeLocal, ctkEventArgumentsList *argList = NULL, ctkGenericReturnArgument *returnArg = NULL) const;
62 
64  void enableEventLogging(bool enable = true);
65 
67  void logEventTopic(const QString topic);
68 
70  void logAllEvents();
71 
73  void shutdown();
74 
77 
79  bool isLocalSignalPresent(const QString topic) const;
80 
82  void plugNetworkConnector(const QString &protocol, ctkNetworkConnector *connector);
83 
85  bool createServer(const QString &communication_protocol, unsigned int listen_port);
86 
88  void startListen();
89 
91  bool createClient(const QString &communication_protocol, const QString &server_host, unsigned int port);
92 
93 public Q_SLOTS:
96 
97 private:
100 
103 
104  ctkEventDispatcherLocal *m_LocalDispatcher;
105  ctkEventDispatcherRemote *m_RemoteDispatcher;
106 
107  bool m_EnableEventLogging;
108  QString m_LogEventTopic;
109  ctkNetworkConnectorHash m_NetworkConnectorHash;
110 
111  bool m_SkipDetach;
112 
113 };
114 
115 } // namespace ctkEventBus
116 
117 #endif // CTKEVENTBUSMANAGER
ctkEventBus::ctkEventBusManager::removeObserver
void removeObserver(const QObject *obj, const QString topic="", bool qt_disconnect=true)
Remove the object passed as argument from the observer's hash.
ctkEventBus::ctkEventBusManager::logEventTopic
void logEventTopic(const QString topic)
When logging is enabled, allows logging events releted to specific id (require a valid topic).
ctkEventDefinitions.h
ctkEventBus::ctkEventBusManager::isLocalSignalPresent
bool isLocalSignalPresent(const QString topic) const
Retrieve if the signal has been registered previously.
ctkEventBus::ctkEventType
ctkEventType
Definition: ctkEventDefinitions.h:92
ctkEventBus::ctkEventBusManager::shutdown
void shutdown()
Destroy the singleton instance. To be called at the end of the application.
QList
Definition: ctkCmdLineModuleBackend.h:30
ctkEventBus::ctkEventBusManager::instance
static ctkEventBusManager * instance()
Return an instance of the event bus.
ctkEventBus::ctkEventBusManager::initializeNetworkConnectors
void initializeNetworkConnectors()
initialize NetworkConnectors
ctkGenericReturnArgument
#define ctkGenericReturnArgument
Definition: ctkEventDefinitions.h:107
ctkEventBus::ctkEventBusManager::removeEventProperty
bool removeEventProperty(ctkBusEvent &props) const
Remove the event property from the event bus hash.
ctkEventBus::ctkEventBusManager::detachObjectFromBus
void detachObjectFromBus()
Intercepts objects deletation and detach them from the event bus.
ctkBusEvent.h
ctkEventBus::ctkEventDispatcherLocal
Definition: ctkEventDispatcherLocal.h:24
ctkEventBus::ctkEventBusManager::enableEventLogging
void enableEventLogging(bool enable=true)
Enable/Disable event logging to allow dumping events notification into the selected logging output st...
ctkEventBus::ctkEventBusManager::plugNetworkConnector
void plugNetworkConnector(const QString &protocol, ctkNetworkConnector *connector)
Plug a new network connector into the connector hash for the given network protocol (protocol eg....
QHash< QString, ctkNetworkConnector * >
ctkEventBus::ctkEventBusManager
Definition: ctkEventBusManager.h:30
ctkEventBus::ctkEventBusManager::createServer
bool createServer(const QString &communication_protocol, unsigned int listen_port)
Create the server for remote communication according to the given protocol and listen port.
ctkEventDispatcherLocal.h
ctkEventBus::ctkEventBusManager::addEventProperty
bool addEventProperty(ctkBusEvent &props) const
Add a new event property (observer or event) to the event bus hash.
ctkEventBus::ctkNetworkConnector
Definition: ctkNetworkConnector.h:24
ctkEventBus::ctkEventBusManager::logAllEvents
void logAllEvents()
When enabled, allows logging all events. It reset the value for m_LogEventId to -1 (the default)
ctkEventBus::ctkEventBusManager::createClient
bool createClient(const QString &communication_protocol, const QString &server_host, unsigned int port)
Create the client for remote communication according to the given protocol, server host and port.
ctkEventBus::ctkEventTypeLocal
@ ctkEventTypeLocal
Definition: ctkEventDefinitions.h:93
ctkEventBus::ctkEventDispatcherRemote
Definition: ctkEventDispatcherRemote.h:27
ctkBusEvent
Definition: ctkBusEvent.h:41
ctkEventDispatcherRemote.h
ctkEventBus::ctkEventBusManager::removeSignal
void removeSignal(const QObject *obj, QString topic="", bool qt_disconnect=true)
Remove the object passed as argument from the signal emitter's hash.
ctkEventBus::ctkEventBusManager::startListen
void startListen()
Allow to start server listening.
ctkEventBus
Definition: ctkEventBusManager.h:21
ctkEventBus::ctkEventBusManager::notifyEvent
void notifyEvent(ctkBusEvent &event_dictionary, ctkEventArgumentsList *argList=NULL, QGenericReturnArgument *returnArg=NULL) const
Notify events associated to the given id locally to the application.
ctkEventBus::ctkEventBusManager::notifyEvent
void notifyEvent(const QString topic, ctkEventType ev_type=ctkEventTypeLocal, ctkEventArgumentsList *argList=NULL, QGenericReturnArgument *returnArg=NULL) const
Notify event associated to the given id locally to the application.