diff options
author | Philip Rauwolf <rauwolf@itestra.de> | 2013-03-11 11:20:26 +0100 |
---|---|---|
committer | Philip Rauwolf <rauwolf@itestra.de> | 2013-03-11 11:20:26 +0100 |
commit | 8f8c18821eda6976719256c03b502e40459079b9 (patch) | |
tree | 9a5561a9c7b7b52ec8ce96f1aa9db56f92571f6a /src | |
parent | b0e8f1826aac575fe198494f16ea8b87f6f94525 (diff) | |
download | genivi-common-api-dbus-runtime-8f8c18821eda6976719256c03b502e40459079b9.tar.gz |
DBusConnection: Removed unused variable, enabled safe double deletion of
signal handlers.
Diffstat (limited to 'src')
-rw-r--r-- | src/CommonAPI/DBus/DBusConnection.cpp | 40 | ||||
-rw-r--r-- | src/CommonAPI/DBus/DBusConnection.h | 2 |
2 files changed, 19 insertions, 23 deletions
diff --git a/src/CommonAPI/DBus/DBusConnection.cpp b/src/CommonAPI/DBus/DBusConnection.cpp index 4b4c406..d151854 100644 --- a/src/CommonAPI/DBus/DBusConnection.cpp +++ b/src/CommonAPI/DBus/DBusConnection.cpp @@ -38,7 +38,6 @@ DBusConnection::DBusConnection(BusType busType) : busType_(busType), libdbusConnection_(NULL), dbusConnectionStatusEvent_(this), - isLibdbusSignalFilterAdded_(false), stopDispatching_(false) { dbus_threads_init_default(); } @@ -47,7 +46,6 @@ DBusConnection::DBusConnection(::DBusConnection* libDbusConnection) : busType_(WRAPPED), libdbusConnection_(libDbusConnection), dbusConnectionStatusEvent_(this), - isLibdbusSignalFilterAdded_(false), stopDispatching_(false) { dbus_threads_init_default(); } @@ -242,6 +240,8 @@ std::future<CallStatus> DBusConnection::sendDBusMessageWithReplyAsync( DBusMessage DBusConnection::sendDBusMessageWithReplyAndBlock(const DBusMessage& dbusMessage, DBusError& dbusError, int timeoutMilliseconds) const { + auto selfReference = this->shared_from_this(); + assert(dbusMessage); assert(!dbusError); assert(isConnected()); @@ -291,25 +291,23 @@ DBusProxyConnection::DBusSignalHandlerToken DBusConnection::addSignalMemberHandl void DBusConnection::removeSignalMemberHandler(const DBusSignalHandlerToken& dbusSignalHandlerToken) { std::lock_guard<std::mutex> dbusSignalLock(signalGuard_); auto equalRangeIteratorPair = dbusSignalHandlerTable_.equal_range(dbusSignalHandlerToken); + if (equalRangeIteratorPair.first != equalRangeIteratorPair.second) { + // advance to the next element + equalRangeIteratorPair.first++; - // the range can't be empty! - assert(equalRangeIteratorPair.first != equalRangeIteratorPair.second); - - // advance to the next element - equalRangeIteratorPair.first++; + // check if the first element was the only element + const bool isLastSignalMemberHandler = equalRangeIteratorPair.first == equalRangeIteratorPair.second; - // check if the first element was the only element - const bool isLastSignalMemberHandler = equalRangeIteratorPair.first == equalRangeIteratorPair.second; + if (isLastSignalMemberHandler) { + const std::string& objectPath = std::get<0>(dbusSignalHandlerToken); + const std::string& interfaceName = std::get<1>(dbusSignalHandlerToken); + const std::string& interfaceMemberName = std::get<2>(dbusSignalHandlerToken); - if (isLastSignalMemberHandler) { - const std::string& objectPath = std::get<0>(dbusSignalHandlerToken); - const std::string& interfaceName = std::get<1>(dbusSignalHandlerToken); - const std::string& interfaceMemberName = std::get<2>(dbusSignalHandlerToken); + removeLibdbusSignalMatchRule(objectPath, interfaceName, interfaceMemberName); + } - removeLibdbusSignalMatchRule(objectPath, interfaceName, interfaceMemberName); + dbusSignalHandlerTable_.erase(dbusSignalHandlerToken); } - - dbusSignalHandlerTable_.erase(dbusSignalHandlerToken); } void DBusConnection::registerObjectPath(const std::string& objectPath) { @@ -446,8 +444,9 @@ void DBusConnection::initLibdbusObjectPathHandlerAfterConnect() { assert(isConnected()); // nothing to do if there aren't any registered object path handlers - if (libdbusRegisteredObjectPaths_.empty()) + if (libdbusRegisteredObjectPaths_.empty()) { return; + } DBusError dbusError; dbus_bool_t libdbusSuccess; @@ -511,8 +510,9 @@ void DBusConnection::initLibdbusSignalFilterAfterConnect() { auto selfReference = this->shared_from_this(); // handle only signal messages - if (dbus_message_get_type(libdbusMessage) != DBUS_MESSAGE_TYPE_SIGNAL) + if (dbus_message_get_type(libdbusMessage) != DBUS_MESSAGE_TYPE_SIGNAL) { return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; + } const char* objectPath = dbus_message_get_path(libdbusMessage); const char* interfaceName = dbus_message_get_interface(libdbusMessage); @@ -536,9 +536,7 @@ void DBusConnection::initLibdbusSignalFilterAfterConnect() { const SubscriptionStatus dbusSignalHandlerSubscriptionStatus = dbusSignalHandler->onSignalDBusMessage(dbusMessage); if (dbusSignalHandlerSubscriptionStatus == SubscriptionStatus::CANCEL) { - auto dbusSignalHandlerSubscription = equalRangeIteratorPair.first; - equalRangeIteratorPair.first++; - dbusSignalHandlerTable_.erase(dbusSignalHandlerSubscription); + equalRangeIteratorPair.first = dbusSignalHandlerTable_.erase(equalRangeIteratorPair.first); } else { equalRangeIteratorPair.first++; } diff --git a/src/CommonAPI/DBus/DBusConnection.h b/src/CommonAPI/DBus/DBusConnection.h index 8e95296..a9c1044 100644 --- a/src/CommonAPI/DBus/DBusConnection.h +++ b/src/CommonAPI/DBus/DBusConnection.h @@ -147,8 +147,6 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from typedef std::unordered_map<DBusSignalMatchRuleTuple, DBusSignalMatchRuleMapping> DBusSignalMatchRulesMap; DBusSignalMatchRulesMap dbusSignalMatchRulesMap_; - bool isLibdbusSignalFilterAdded_; - DBusSignalHandlerTable dbusSignalHandlerTable_; // referenceCount, objectPath |