1616
1717using namespace mafEventBus ;
1818
19-
2019mafEventBusManager::mafEventBusManager () : m_EnableEventLogging(false ), m_LogEventTopic(" *" ), m_SkipDetach(false ) {
2120 // Create local event dispatcher.
2221 m_LocalDispatcher = new mafEventDispatcherLocal ();
@@ -39,6 +38,9 @@ mafEventBusManager::~mafEventBusManager() {
3938 delete i.value ();
4039 ++i;
4140 }
41+ // clean connection info vector.
42+ m_ConnectionInfoHash.clear ();
43+ // clean hash for network connectors.
4244 m_NetworkConnectorHash.clear ();
4345
4446 // disconnect detachFromEventBus
@@ -81,6 +83,34 @@ bool mafEventBusManager::addEventProperty(const mafEvent &props) const {
8183 QString topic = props[TOPIC].toString ();
8284 QObject *obj = props[OBJECT].value <QObject*>();
8385
86+ // / add to connection infos array this connection
87+ // / chek also if already exists and one of observer or signal is empty
88+ if (!m_ConnectionInfoHash.contains (topic)) {
89+ mafEventBusConnectionInfo info;
90+ info.type = (mafEventType) props[TYPE].toInt ();
91+ if (props[SIGTYPE].toInt () == mafSignatureTypeCallback) {
92+ info.slotName .push_back (props[SIGNATURE].toString ());
93+ info.observers .push_back (obj);
94+ } else { // is a signal
95+ info.emitter = obj;
96+ info.signalName .append (props[SIGNATURE].toString ());
97+ }
98+ // info.callers;
99+ // info.counter;
100+ m_ConnectionInfoHash.insert (topic,info);
101+ } else {
102+ // check the type, and complete the information
103+ mafEventBusConnectionInfo info = m_ConnectionInfoHash.value (topic);
104+ if (info.type == mafSignatureTypeCallback) {
105+ info.slotName .push_back (props[SIGNATURE].toString ());
106+ info.observers .push_back (obj);
107+ m_ConnectionInfoHash.insert (topic,info);
108+ } else { // no sense if is a signal
109+ }
110+ }
111+
112+
113+
84114 if (props[TYPE].toInt () == mafEventTypeLocal) {
85115 // Local event dispatching.
86116 if (props[SIGTYPE].toInt () == mafSignatureTypeCallback) {
@@ -122,6 +152,19 @@ void mafEventBusManager::detachObjectFromBus() {
122152}
123153
124154void mafEventBusManager::removeObserver (const QObject *obj, const QString topic, bool qt_disconnect) {
155+ // / remove to connection infos array this connection
156+ mafEventBusConnectionInfo info = m_ConnectionInfoHash.value (topic);
157+ int counter = 0 ;
158+ foreach (QObject *o, info.observers ) {
159+ if (o == obj) {
160+ info.observers .remove (counter);
161+ info.slotName .remove (counter);
162+ break ;
163+ }
164+ counter++;
165+ }
166+
167+
125168 if (obj == NULL ) {
126169 return ;
127170 }
@@ -130,6 +173,12 @@ void mafEventBusManager::removeObserver(const QObject *obj, const QString topic,
130173}
131174
132175void mafEventBusManager::removeSignal (const QObject *obj, QString topic, bool qt_disconnect) {
176+ // / remove to connection infos array this connection
177+ mafEventBusConnectionInfo info = m_ConnectionInfoHash.value (topic);
178+ info.emitter = NULL ;
179+ info.signalName = " " ;
180+
181+
133182 if (obj == NULL ) {
134183 return ;
135184 }
@@ -146,7 +195,27 @@ void mafEventBusManager::removeSignal(const QObject *obj, QString topic, bool qt
146195bool mafEventBusManager::removeEventProperty (const mafEvent &props) const {
147196 bool result (false );
148197 QString topic = props[TOPIC].toString ();
149-
198+ QObject *obj = props[OBJECT].value <QObject*>();
199+
200+ // / remove from connection info
201+ if (props[SIGTYPE].toInt () == mafSignatureTypeCallback) {
202+ mafEventBusConnectionInfo info = m_ConnectionInfoHash.value (topic);
203+ int counter = 0 ;
204+ foreach (QObject *o, info.observers ) {
205+ if (o == obj) {
206+ info.observers .remove (counter);
207+ info.slotName .remove (counter);
208+ break ;
209+ }
210+ counter++;
211+ }
212+ } else {
213+ mafEventBusConnectionInfo info = m_ConnectionInfoHash.value (topic);
214+ info.emitter = NULL ;
215+ info.signalName = " " ;
216+ }
217+
218+
150219 if (props.eventType () == mafEventTypeLocal) {
151220 // Local event dispatching.
152221 if (props[SIGTYPE].toInt () == mafSignatureTypeCallback) {
@@ -180,6 +249,11 @@ void mafEventBusManager::notifyEvent(const QString topic, mafEventType ev_type,
180249 }
181250 }
182251
252+ // / increment in correct connection info item inside the array, the counter and insert the caller if possible
253+ mafEventBusConnectionInfo info = m_ConnectionInfoHash.value (topic);
254+ info.counter ++;
255+
256+
183257 // event dispatched in local channel
184258 mafEvent *event_dic = new mafEvent (topic, ev_type, synch);
185259 notifyEvent (*event_dic, argList, returnArg);
@@ -253,3 +327,7 @@ bool mafEventBusManager::createClient(const QString &communication_protocol, con
253327 }
254328 return res;
255329}
330+
331+ const mafEventBusConnectionInfoHash &mafEventBusManager::connectionInfosDump () {
332+ return m_ConnectionInfoHash;
333+ }
0 commit comments