summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Schanda <schanda@itestra.de>2013-04-05 11:45:12 +0200
committerJohannes Schanda <schanda@itestra.de>2013-04-05 11:45:12 +0200
commita17556636366fdc7797ac66f0b73bc3da7521f62 (patch)
tree38ab19ea5ed358a773f949855e26afb9fc82cb8c
parent63e47b3f4996ac0e838b163e5b7f7865517c5515 (diff)
downloadgenivi-common-api-dbus-runtime-a17556636366fdc7797ac66f0b73bc3da7521f62.tar.gz
Provide a clean API for setting the object path handler function
-rw-r--r--src/CommonAPI/DBus/DBusConnection.cpp46
-rw-r--r--src/CommonAPI/DBus/DBusConnection.h8
-rw-r--r--src/CommonAPI/DBus/DBusObjectManager.cpp8
-rw-r--r--src/CommonAPI/DBus/DBusProxyConnection.h5
4 files changed, 31 insertions, 36 deletions
diff --git a/src/CommonAPI/DBus/DBusConnection.cpp b/src/CommonAPI/DBus/DBusConnection.cpp
index d5bb78a..af259fd 100644
--- a/src/CommonAPI/DBus/DBusConnection.cpp
+++ b/src/CommonAPI/DBus/DBusConnection.cpp
@@ -62,7 +62,8 @@ DBusConnection::DBusConnection(BusType busType) :
libdbusConnection_(NULL),
dbusConnectionStatusEvent_(this),
stopDispatching_(false),
- pauseDispatching_(false) {
+ pauseDispatching_(false),
+ dbusObjectMessageHandler_() {
dbus_threads_init_default();
}
@@ -71,10 +72,19 @@ DBusConnection::DBusConnection(::DBusConnection* libDbusConnection) :
libdbusConnection_(libDbusConnection),
dbusConnectionStatusEvent_(this),
stopDispatching_(false),
- pauseDispatching_(false) {
+ pauseDispatching_(false),
+ dbusObjectMessageHandler_() {
dbus_threads_init_default();
}
+void DBusConnection::setObjectPathMessageHandler(DBusObjectPathMessageHandler handler) {
+ dbusObjectMessageHandler_ = handler;
+}
+
+bool DBusConnection::isObjectPathMessageHandlerSet() {
+ return dbusObjectMessageHandler_.operator bool();
+}
+
DBusConnection::~DBusConnection() {
disconnect();
}
@@ -373,36 +383,6 @@ void DBusConnection::registerObjectPath(const std::string& objectPath) {
}
}
-void DBusConnection::registerObjectPath(const std::string& objectPath, void* clas, DBusObjectPathVTable* table) {
- assert(!objectPath.empty());
- assert(objectPath[0] == '/');
-
- auto handlerIterator = libdbusRegisteredObjectPaths_.find(objectPath);
- const bool foundRegisteredObjectPathHandler = handlerIterator != libdbusRegisteredObjectPaths_.end();
-
- if (foundRegisteredObjectPathHandler) {
- uint32_t& referenceCount = handlerIterator->second;
-
- referenceCount++;
-
- return;
- }
-
- libdbusRegisteredObjectPaths_.insert(LibdbusRegisteredObjectPathHandlersTable::value_type(objectPath, 1));
-
- if (isConnected()) {
- DBusError dbusError;
- const dbus_bool_t libdbusSuccess = dbus_connection_try_register_object_path(libdbusConnection_,
- objectPath.c_str(),
- table,
- clas,
- &dbusError.libdbusError_);
- assert(libdbusSuccess);
- assert(!dbusError);
- }
-}
-
-
void DBusConnection::unregisterObjectPath(const std::string& objectPath) {
assert(!objectPath.empty());
assert(objectPath[0] == '/');
@@ -577,7 +557,7 @@ void DBusConnection::initLibdbusSignalFilterAfterConnect() {
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
- bool isDBusMessageHandled = getDBusObjectManager()->handleMessage(DBusMessage(libdbusMessage));
+ bool isDBusMessageHandled = dbusObjectMessageHandler_(DBusMessage(libdbusMessage));
return isDBusMessageHandled ? DBUS_HANDLER_RESULT_HANDLED : DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
}
diff --git a/src/CommonAPI/DBus/DBusConnection.h b/src/CommonAPI/DBus/DBusConnection.h
index 4831551..06ad2a9 100644
--- a/src/CommonAPI/DBus/DBusConnection.h
+++ b/src/CommonAPI/DBus/DBusConnection.h
@@ -90,11 +90,8 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
void registerObjectPath(const std::string& objectPath);
- void registerObjectPath(const std::string& objectPath, void* clas, DBusObjectPathVTable* table);
-
void unregisterObjectPath(const std::string& objectPath);
-
void removeSignalMemberHandler(const DBusSignalHandlerToken& dbusSignalHandlerToken);
bool readWriteDispatch(int timeoutMilliseconds = -1);
@@ -102,6 +99,9 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
virtual const std::shared_ptr<DBusServiceRegistry> getDBusServiceRegistry();
virtual const std::shared_ptr<DBusObjectManager> getDBusObjectManager();
+ void setObjectPathMessageHandler(DBusObjectPathMessageHandler);
+ bool isObjectPathMessageHandlerSet();
+
private:
void dispatch(std::shared_ptr<DBusConnection> selfReference);
void suspendDispatching() const;
@@ -165,6 +165,8 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
LibdbusRegisteredObjectPathHandlersTable libdbusRegisteredObjectPaths_;
static DBusObjectPathVTable libdbusObjectPathVTable_;
+
+ DBusObjectPathMessageHandler dbusObjectMessageHandler_;
};
std::shared_ptr<DBusConnection> DBusConnection::getBus(const BusType& busType) {
diff --git a/src/CommonAPI/DBus/DBusObjectManager.cpp b/src/CommonAPI/DBus/DBusObjectManager.cpp
index 22bac66..8240065 100644
--- a/src/CommonAPI/DBus/DBusObjectManager.cpp
+++ b/src/CommonAPI/DBus/DBusObjectManager.cpp
@@ -15,6 +15,14 @@ namespace DBus {
DBusObjectManager::DBusObjectManager(const std::shared_ptr<DBusProxyConnection>& dbusConnection):
dbusConnection_(dbusConnection) {
+ std::shared_ptr<DBusProxyConnection> lockedConnection = dbusConnection_.lock();
+ if (lockedConnection) {
+ if (!lockedConnection->isObjectPathMessageHandlerSet()) {
+ lockedConnection->setObjectPathMessageHandler(
+ std::bind(&DBusObjectManager::handleMessage, this, std::placeholders::_1));
+ }
+ }
+
registerInterfaceHandler("/",
"org.freedesktop.DBus.ObjectManager",
std::bind(&DBusObjectManager::onGetDBusObjectManagerData, this, std::placeholders::_1));
diff --git a/src/CommonAPI/DBus/DBusProxyConnection.h b/src/CommonAPI/DBus/DBusProxyConnection.h
index e6ab1a5..8ad6b32 100644
--- a/src/CommonAPI/DBus/DBusProxyConnection.h
+++ b/src/CommonAPI/DBus/DBusProxyConnection.h
@@ -93,6 +93,11 @@ class DBusProxyConnection {
virtual void registerObjectPath(const std::string& objectPath) = 0;
virtual void unregisterObjectPath(const std::string& objectPath) = 0;
+
+ typedef std::function<bool(const DBusMessage&)> DBusObjectPathMessageHandler;
+
+ virtual void setObjectPathMessageHandler(DBusObjectPathMessageHandler) = 0;
+ virtual bool isObjectPathMessageHandlerSet() = 0;
};