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
void notifyEvent(ctkBusEvent &event_dictionary, ctkEventArgumentsList *argList=NULL, QGenericReturnArgument *returnArg=NULL) const
Notify events associated to the given id locally to the application.
bool removeEventProperty(ctkBusEvent &props) const
Remove the event property from the event bus hash.
void startListen()
Allow to start server listening.
bool isLocalSignalPresent(const QString topic) const
Retrieve if the signal has been registered previously.
bool addEventProperty(ctkBusEvent &props) const
Add a new event property (observer or event) to the event bus hash.
void shutdown()
Destroy the singleton instance. To be called at the end of the application.
static ctkEventBusManager * instance()
Return an instance of the event bus.
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.
void plugNetworkConnector(const QString &protocol, ctkNetworkConnector *connector)
Plug a new network connector into the connector hash for the given network protocol (protocol eg....
void initializeNetworkConnectors()
initialize NetworkConnectors
void logAllEvents()
When enabled, allows logging all events. It reset the value for m_LogEventId to -1 (the default)
void removeObserver(const QObject *obj, const QString topic="", bool qt_disconnect=true)
Remove the object passed as argument from the observer's hash.
bool createServer(const QString &communication_protocol, unsigned int listen_port)
Create the server for remote communication according to the given protocol and listen port.
void logEventTopic(const QString topic)
When logging is enabled, allows logging events releted to specific id (require a valid topic).
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.
void enableEventLogging(bool enable=true)
Enable/Disable event logging to allow dumping events notification into the selected logging output st...
void removeSignal(const QObject *obj, QString topic="", bool qt_disconnect=true)
Remove the object passed as argument from the signal emitter's hash.
void detachObjectFromBus()
Intercepts objects deletation and detach them from the event bus.
#define ctkGenericReturnArgument