|
2 | 2 | *
|
3 | 3 | * This file is part of GLogiK project.
|
4 | 4 | * GLogiK, daemon to handle special features on gaming keyboards
|
5 |
| - * Copyright (C) 2016-2020 Fabrice Delliaux <[email protected]> |
| 5 | + * Copyright (C) 2016-2021 Fabrice Delliaux <[email protected]> |
6 | 6 | *
|
7 | 7 | * This program is free software: you can redistribute it and/or modify
|
8 | 8 | * it under the terms of the GNU General Public License as published by
|
@@ -164,6 +164,66 @@ void GKDBus::checkForMessages(void) noexcept
|
164 | 164 | * --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
|
165 | 165 | */
|
166 | 166 |
|
| 167 | +void GKDBus::checkDBusMessage(DBusConnection* connection) |
| 168 | +{ |
| 169 | + const std::string object = this->getObjectFromObjectPath(toString(dbus_message_get_path(_message))); |
| 170 | + |
| 171 | + for(const auto & objectPair : _DBusEvents.at(GKDBusEvents::currentBus)) { |
| 172 | + /* handle root node introspection special case */ |
| 173 | + if( object != this->getRootNode() ) |
| 174 | + /* object must match */ |
| 175 | + if(object != objectPair.first) { |
| 176 | +#if 0 && DEBUGGING_ON |
| 177 | + LOG(DEBUG3) << "skipping " << objectPair.first << " object - not " << object; |
| 178 | +#endif |
| 179 | + continue; |
| 180 | + } |
| 181 | + |
| 182 | + for(const auto & interfacePair : objectPair.second) { |
| 183 | + const char* interface = interfacePair.first.c_str(); |
| 184 | +#if 0 && DEBUGGING_ON |
| 185 | + LOG(DEBUG2) << "checking " << interface << " interface"; |
| 186 | +#endif |
| 187 | + |
| 188 | + for(const auto & DBusEvent : interfacePair.second) { /* vector of pointers */ |
| 189 | + const char* eventName = DBusEvent->eventName.c_str(); |
| 190 | +#if 0 && DEBUGGING_ON |
| 191 | + LOG(DEBUG3) << "checking " << eventName << " event"; |
| 192 | +#endif |
| 193 | + switch(DBusEvent->eventType) { |
| 194 | + case GKDBusEventType::GKDBUS_EVENT_METHOD: |
| 195 | + { |
| 196 | + if( dbus_message_is_method_call(_message, interface, eventName) ) |
| 197 | + { |
| 198 | +#if DEBUGGING_ON |
| 199 | + LOG(DEBUG1) << "DBus " << eventName << " method called !"; |
| 200 | +#endif |
| 201 | + DBusEvent->runCallback(connection, _message); |
| 202 | + return; |
| 203 | + } |
| 204 | + break; |
| 205 | + } |
| 206 | + case GKDBusEventType::GKDBUS_EVENT_SIGNAL: |
| 207 | + { |
| 208 | + if( dbus_message_is_signal(_message, interface, eventName) ) |
| 209 | + { |
| 210 | +#if DEBUGGING_ON |
| 211 | + LOG(DEBUG1) << "DBus " << eventName << " signal receipted !"; |
| 212 | +#endif |
| 213 | + DBusEvent->runCallback(connection, _message); |
| 214 | + return; |
| 215 | + } |
| 216 | + break; |
| 217 | + } |
| 218 | + default: |
| 219 | + throw GLogiKExcept("wrong event type"); |
| 220 | + break; |
| 221 | + } |
| 222 | + } |
| 223 | + } |
| 224 | + } |
| 225 | +} |
| 226 | + |
167 | 227 | /* -- */
|
168 | 228 | /*
|
169 | 229 | * check if :
|
@@ -192,67 +252,11 @@ void GKDBus::checkForBusMessages(const BusConnection bus, DBusConnection* connec
|
192 | 252 | }
|
193 | 253 |
|
194 | 254 | try {
|
195 |
| - const std::string object = this->getObjectFromObjectPath(toString(dbus_message_get_path(_message))); |
196 |
| - |
197 |
| - for(const auto & objectPair : _DBusEvents.at(GKDBusEvents::currentBus)) { |
198 |
| - /* handle root node introspection special case */ |
199 |
| - if( object != this->getRootNode() ) |
200 |
| - /* object must match */ |
201 |
| - if(object != objectPair.first) { |
202 |
| -#if 0 && DEBUGGING_ON |
203 |
| - LOG(DEBUG3) << "skipping " << objectPair.first << " object - not " << object; |
204 |
| -#endif |
205 |
| - continue; |
206 |
| - } |
207 |
| - |
208 |
| - for(const auto & interfacePair : objectPair.second) { |
209 |
| - const char* interface = interfacePair.first.c_str(); |
210 |
| -#if 0 && DEBUGGING_ON |
211 |
| - LOG(DEBUG2) << "checking " << interface << " interface"; |
212 |
| -#endif |
213 |
| - |
214 |
| - for(const auto & DBusEvent : interfacePair.second) { /* vector of pointers */ |
215 |
| - const char* eventName = DBusEvent->eventName.c_str(); |
216 |
| -#if 0 && DEBUGGING_ON |
217 |
| - LOG(DEBUG3) << "checking " << eventName << " event"; |
218 |
| -#endif |
219 |
| - switch(DBusEvent->eventType) { |
220 |
| - case GKDBusEventType::GKDBUS_EVENT_METHOD: { |
221 |
| - if( dbus_message_is_method_call(_message, interface, eventName) ) { |
222 |
| -#if DEBUGGING_ON |
223 |
| - LOG(DEBUG1) << "DBus " << eventName << " method called !"; |
224 |
| -#endif |
225 |
| - DBusEvent->runCallback(connection, _message); |
226 |
| - throw GKDBusEventFound(); |
227 |
| - } |
228 |
| - break; |
229 |
| - } |
230 |
| - case GKDBusEventType::GKDBUS_EVENT_SIGNAL: { |
231 |
| - if( dbus_message_is_signal(_message, interface, eventName) ) { |
232 |
| -#if DEBUGGING_ON |
233 |
| - LOG(DEBUG1) << "DBus " << eventName << " signal receipted !"; |
234 |
| -#endif |
235 |
| - DBusEvent->runCallback(connection, _message); |
236 |
| - throw GKDBusEventFound(); |
237 |
| - } |
238 |
| - break; |
239 |
| - } |
240 |
| - default: |
241 |
| - throw GLogiKExcept("wrong event type"); |
242 |
| - break; |
243 |
| - } |
244 |
| - } |
245 |
| - } |
246 |
| - } |
| 255 | + this->checkDBusMessage(connection); |
247 | 256 | }
|
248 | 257 | catch (const std::out_of_range& oor) {
|
249 | 258 | LOG(ERROR) << "current bus connection oor";
|
250 | 259 | }
|
251 |
| - catch ( const GKDBusEventFound & e ) { |
252 |
| -#if 0 && DEBUGGING_ON |
253 |
| - LOG(DEBUG2) << e.what(); |
254 |
| -#endif |
255 |
| - } |
256 | 260 | catch ( const GLogiKExcept & e ) {
|
257 | 261 | LOG(ERROR) << e.what();
|
258 | 262 | }
|
|
0 commit comments