summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Rauwolf <rauwolf@itestra.de>2013-02-28 16:39:13 +0100
committerPhilip Rauwolf <rauwolf@itestra.de>2013-02-28 16:39:13 +0100
commit7f8deb5c071537d08c3c31081db48079f525c9f2 (patch)
tree1afde48d793c1290857322e384ae96766bb19d97
parent29eb93d4f68a346fe6559dbb5dc0217bde0703b2 (diff)
downloadgenivi-common-api-dbus-runtime-7f8deb5c071537d08c3c31081db48079f525c9f2.tar.gz
Solved circular dependencies between DBusConnection and
DBusServiceRegistry/DBusObjectManager, removed DBusDaemonProxy entirely from DBusConnection
-rw-r--r--src/CommonAPI/DBus/DBusConnection.cpp9
-rw-r--r--src/CommonAPI/DBus/DBusConnection.h3
-rw-r--r--src/CommonAPI/DBus/DBusDaemonProxy.cpp50
-rw-r--r--src/CommonAPI/DBus/DBusDaemonProxy.h1
-rw-r--r--src/CommonAPI/DBus/DBusObjectManager.cpp17
-rw-r--r--src/CommonAPI/DBus/DBusObjectManager.h2
-rw-r--r--src/CommonAPI/DBus/DBusProxy.cpp8
-rw-r--r--src/CommonAPI/DBus/DBusProxy.h3
8 files changed, 30 insertions, 63 deletions
diff --git a/src/CommonAPI/DBus/DBusConnection.cpp b/src/CommonAPI/DBus/DBusConnection.cpp
index 71e5cbf..e0a32e0 100644
--- a/src/CommonAPI/DBus/DBusConnection.cpp
+++ b/src/CommonAPI/DBus/DBusConnection.cpp
@@ -117,11 +117,14 @@ DBusProxyConnection::ConnectionStatusEvent& DBusConnection::getConnectionStatusE
}
const std::shared_ptr<DBusServiceRegistry> DBusConnection::getDBusServiceRegistry() {
- if (!dbusServiceRegistry_) {
- dbusServiceRegistry_ = std::make_shared<DBusServiceRegistry>(std::make_shared<DBusDaemonProxy>(this->shared_from_this()));
+ std::shared_ptr<DBusServiceRegistry> serviceRegistry = dbusServiceRegistry_.lock();
+ if (!serviceRegistry) {
+ auto blub = this->shared_from_this();
+ serviceRegistry = std::make_shared<DBusServiceRegistry>(blub);
+ dbusServiceRegistry_ = serviceRegistry;
}
- return dbusServiceRegistry_;
+ return serviceRegistry;
}
const std::shared_ptr<DBusObjectManager> DBusConnection::getDBusObjectManager() {
diff --git a/src/CommonAPI/DBus/DBusConnection.h b/src/CommonAPI/DBus/DBusConnection.h
index 522b11c..6337b9c 100644
--- a/src/CommonAPI/DBus/DBusConnection.h
+++ b/src/CommonAPI/DBus/DBusConnection.h
@@ -135,8 +135,7 @@ class DBusConnection: public DBusProxyConnection, public std::enable_shared_from
::DBusConnection* libdbusConnection_;
- std::weak_ptr<DBusDaemonProxy> dbusDaemonProxy_;
- std::shared_ptr<DBusServiceRegistry> dbusServiceRegistry_;
+ std::weak_ptr<DBusServiceRegistry> dbusServiceRegistry_;
std::shared_ptr<DBusObjectManager> dbusObjectManager_;
DBusConnectionStatusEvent dbusConnectionStatusEvent_;
diff --git a/src/CommonAPI/DBus/DBusDaemonProxy.cpp b/src/CommonAPI/DBus/DBusDaemonProxy.cpp
index 5c0a91e..728b330 100644
--- a/src/CommonAPI/DBus/DBusDaemonProxy.cpp
+++ b/src/CommonAPI/DBus/DBusDaemonProxy.cpp
@@ -132,18 +132,6 @@ std::future<CallStatus> DBusDaemonProxy::nameHasOwnerAsync(const std::string& bu
DBusProxyAsyncCallbackHandler<bool>::create(nameHasOwnerAsyncCallback));
}
-
-
-
-
-
-
-
-
-
-
-
-
std::future<CallStatus> DBusDaemonProxy::getManagedObjectsAsync(const std::string& forDBusServiceName, GetManagedObjectsAsyncCallback callback) const {
// resolve remote objects
auto dbusMethodCallMessage = DBusMessage::createMethodCall(
@@ -162,43 +150,5 @@ std::future<CallStatus> DBusDaemonProxy::getManagedObjectsAsync(const std::strin
}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
} // namespace DBus
} // namespace CommonAPI
diff --git a/src/CommonAPI/DBus/DBusDaemonProxy.h b/src/CommonAPI/DBus/DBusDaemonProxy.h
index ed54ed9..aeb2feb 100644
--- a/src/CommonAPI/DBus/DBusDaemonProxy.h
+++ b/src/CommonAPI/DBus/DBusDaemonProxy.h
@@ -63,7 +63,6 @@ class DBusDaemonProxy: public DBusProxyBase {
private:
DBusEvent<NameOwnerChangedEvent> nameOwnerChangedEvent_;
-
static StaticInterfaceVersionAttribute interfaceVersionAttribute_;
};
diff --git a/src/CommonAPI/DBus/DBusObjectManager.cpp b/src/CommonAPI/DBus/DBusObjectManager.cpp
index 04abb76..57c0727 100644
--- a/src/CommonAPI/DBus/DBusObjectManager.cpp
+++ b/src/CommonAPI/DBus/DBusObjectManager.cpp
@@ -29,7 +29,10 @@ DBusInterfaceHandlerToken DBusObjectManager::registerInterfaceHandler(const std:
assert(noSuchHandlerRegistered);
dbusRegisteredObjectsTable_.insert({handlerPath, dbusMessageInterfaceHandler});
- dbusConnection_->registerObjectPath(objectPath);
+ std::shared_ptr<DBusConnection> lockedConnection = dbusConnection_.lock();
+ if(lockedConnection) {
+ lockedConnection->registerObjectPath(objectPath);
+ }
return handlerPath;
}
@@ -37,7 +40,10 @@ DBusInterfaceHandlerToken DBusObjectManager::registerInterfaceHandler(const std:
void DBusObjectManager::unregisterInterfaceHandler(const DBusInterfaceHandlerToken& dbusInterfaceHandlerToken) {
const std::string& objectPath = dbusInterfaceHandlerToken.first;
- dbusConnection_->unregisterObjectPath(objectPath);
+ std::shared_ptr<DBusConnection> lockedConnection = dbusConnection_.lock();
+ if(lockedConnection) {
+ lockedConnection->unregisterObjectPath(objectPath);
+ }
dbusRegisteredObjectsTable_.erase(dbusInterfaceHandlerToken);
}
@@ -93,7 +99,12 @@ bool DBusObjectManager::onGetDBusObjectManagerData(const DBusMessage& callMessag
DBusOutputStream outStream(replyMessage);
outStream << dictToSend;
outStream.flush();
- return dbusConnection_->sendDBusMessage(replyMessage);
+
+ std::shared_ptr<DBusConnection> lockedConnection = dbusConnection_.lock();
+ if(lockedConnection) {
+ return lockedConnection->sendDBusMessage(replyMessage);
+ }
+ return false;
}
diff --git a/src/CommonAPI/DBus/DBusObjectManager.h b/src/CommonAPI/DBus/DBusObjectManager.h
index 712605a..bfd2a71 100644
--- a/src/CommonAPI/DBus/DBusObjectManager.h
+++ b/src/CommonAPI/DBus/DBusObjectManager.h
@@ -48,7 +48,7 @@ class DBusObjectManager {
typedef std::unordered_map<DBusInterfaceHandlerPath, DBusMessageInterfaceHandler> DBusRegisteredObjectsTable;
DBusRegisteredObjectsTable dbusRegisteredObjectsTable_;
- std::shared_ptr<DBusConnection> dbusConnection_;
+ std::weak_ptr<DBusConnection> dbusConnection_;
};
} // namespace DBus
diff --git a/src/CommonAPI/DBus/DBusProxy.cpp b/src/CommonAPI/DBus/DBusProxy.cpp
index 842e258..314c63f 100644
--- a/src/CommonAPI/DBus/DBusProxy.cpp
+++ b/src/CommonAPI/DBus/DBusProxy.cpp
@@ -41,17 +41,19 @@ DBusProxy::DBusProxy(const std::string& commonApiAddress,
dbusConnection),
dbusProxyStatusEvent_(this),
availabilityStatus_(AvailabilityStatus::UNKNOWN),
- interfaceVersionAttribute_(*this, "getInterfaceVersion") {
+ interfaceVersionAttribute_(*this, "getInterfaceVersion"),
+ dbusServiceRegistry_(dbusConnection->getDBusServiceRegistry()) {
+
const std::string commonApiDomain = split(commonApiAddress, ':')[0];
assert(commonApiDomain == "local");
- dbusServiceRegistrySubscription_ = dbusConnection->getDBusServiceRegistry()->subscribeAvailabilityListener(
+ dbusServiceRegistrySubscription_ = dbusServiceRegistry_->subscribeAvailabilityListener(
commonApiAddress,
std::bind(&DBusProxy::onDBusServiceInstanceStatus, this, std::placeholders::_1));
}
DBusProxy::~DBusProxy() {
- getDBusConnection()->getDBusServiceRegistry()->unsubscribeAvailabilityListener(
+ dbusServiceRegistry_->unsubscribeAvailabilityListener(
getAddress(),
dbusServiceRegistrySubscription_);
}
diff --git a/src/CommonAPI/DBus/DBusProxy.h b/src/CommonAPI/DBus/DBusProxy.h
index 76e1526..6021a01 100644
--- a/src/CommonAPI/DBus/DBusProxy.h
+++ b/src/CommonAPI/DBus/DBusProxy.h
@@ -59,8 +59,11 @@ class DBusProxy: public DBusProxyBase {
AvailabilityStatus availabilityStatus_;
DBusReadonlyAttribute<InterfaceVersionAttribute> interfaceVersionAttribute_;
+
+ std::shared_ptr<DBusServiceRegistry> dbusServiceRegistry_;
};
+
} // namespace DBus
} // namespace CommonAPI