summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Rauwolf <rauwolf@itestra.de>2013-03-01 10:56:37 +0100
committerPhilip Rauwolf <rauwolf@itestra.de>2013-03-01 10:56:37 +0100
commitabe53c080dd11d37ef513ce17d2caf3b11afb9e1 (patch)
treecc6b70ab625e87cd1dc02174bb907b3c59150868
parent0cfcd00a98bb412e2d930b71bb05fbeccf9f348e (diff)
downloadgenivi-common-api-dbus-runtime-abe53c080dd11d37ef513ce17d2caf3b11afb9e1.tar.gz
Moved service management down to middleware implementation
-rw-r--r--src/CommonAPI/DBus/DBusFactory.cpp33
-rw-r--r--src/CommonAPI/DBus/DBusFactory.h7
-rw-r--r--src/CommonAPI/DBus/DBusStubAdapter.cpp9
-rw-r--r--src/CommonAPI/DBus/DBusStubAdapterHelper.h5
4 files changed, 39 insertions, 15 deletions
diff --git a/src/CommonAPI/DBus/DBusFactory.cpp b/src/CommonAPI/DBus/DBusFactory.cpp
index d921e51..de74ef1 100644
--- a/src/CommonAPI/DBus/DBusFactory.cpp
+++ b/src/CommonAPI/DBus/DBusFactory.cpp
@@ -104,11 +104,11 @@ std::shared_ptr<Proxy> DBusFactory::createProxy(const char* interfaceId,
return NULL;
}
-std::shared_ptr<StubAdapter> DBusFactory::createAdapter(std::shared_ptr<StubBase> stubBase,
- const char* interfaceId,
- const std::string& participantId,
- const std::string& serviceName,
- const std::string& domain) {
+bool DBusFactory::registerAdapter(std::shared_ptr<StubBase> stubBase,
+ const char* interfaceId,
+ const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain) {
assert(dbusConnection_->isConnected());
std::string commonApiAddress = domain + ":" + serviceName + ":" + participantId;
@@ -133,12 +133,29 @@ std::shared_ptr<StubAdapter> DBusFactory::createAdapter(std::shared_ptr<StubBase
for (auto it = registeredAdapterFactoryFunctions_->begin(); it != registeredAdapterFactoryFunctions_->end(); ++it) {
if(it->first == interfaceId) {
std::shared_ptr<DBusStubAdapter> dbusStubAdapter = (it->second)(commonApiAddress, interfaceName, connectionName, objectPath, dbusConnection_, stubBase);
- dbusStubAdapter->init();
- return dbusStubAdapter;
+ if(!dbusStubAdapter) {
+ return false;
+ }
+ std::string address = domain + ":" + serviceName + ":" + participantId;
+ if(registeredServices_.insert( {std::move(address), dbusStubAdapter} ).second) {
+ dbusStubAdapter->init();
+ return true;
+ }
}
}
- return NULL;
+ return false;
+}
+
+bool DBusFactory::unregisterService(const std::string& participantId, const std::string& serviceName, const std::string& domain) {
+ std::string commonApiAddress = domain + ":" + serviceName + ":" + participantId;
+ auto foundStubAdapter = registeredServices_.find(commonApiAddress);
+ if(foundStubAdapter != registeredServices_.end()) {
+ std::shared_ptr<DBusStubAdapter> stubAdapter = foundStubAdapter->second;
+ stubAdapter->deinit();
+ return registeredServices_.erase(commonApiAddress);
+ }
+ return false;
}
diff --git a/src/CommonAPI/DBus/DBusFactory.h b/src/CommonAPI/DBus/DBusFactory.h
index 52db97c..a3edfdc 100644
--- a/src/CommonAPI/DBus/DBusFactory.h
+++ b/src/CommonAPI/DBus/DBusFactory.h
@@ -41,15 +41,18 @@ class DBusFactory: public Factory {
virtual std::vector<std::string> getAvailableServiceInstances(const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local");
virtual bool isServiceInstanceAlive(const std::string& serviceAddress);
- virtual bool isServiceInstanceAlive(const std::string& serviceInstanceID, const std::string& serviceInterfaceName, const std::string& serviceDomainName = "local");
+ virtual bool isServiceInstanceAlive(const std::string& participantId, const std::string& serviceName, const std::string& domain = "local");
+
+ virtual bool unregisterService(const std::string& participantId, const std::string& serviceName, const std::string& domain = "local");
protected:
virtual std::shared_ptr<Proxy> createProxy(const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain);
- virtual std::shared_ptr<StubAdapter> createAdapter(std::shared_ptr<StubBase> stubBase, const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain);
+ virtual bool registerAdapter(std::shared_ptr<StubBase> stubBase, const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain);
private:
std::shared_ptr<CommonAPI::DBus::DBusConnection> dbusConnection_;
std::string acquiredConnectionName_;
+ std::unordered_map<std::string, std::shared_ptr<DBusStubAdapter>> registeredServices_;
};
} // namespace DBus
diff --git a/src/CommonAPI/DBus/DBusStubAdapter.cpp b/src/CommonAPI/DBus/DBusStubAdapter.cpp
index 67cfacd..e230062 100644
--- a/src/CommonAPI/DBus/DBusStubAdapter.cpp
+++ b/src/CommonAPI/DBus/DBusStubAdapter.cpp
@@ -41,14 +41,17 @@ DBusStubAdapter::DBusStubAdapter(const std::string& commonApiAddress,
}
DBusStubAdapter::~DBusStubAdapter() {
+ deinit();
}
void DBusStubAdapter::deinit() {
assert(dbusConnection_);
- assert(isInitialized_);
- dbusConnection_->getDBusObjectManager()->unregisterInterfaceHandler(dbusIntrospectionInterfaceHandlerToken_);
- dbusConnection_->getDBusObjectManager()->unregisterInterfaceHandler(dbusInterfaceHandlerToken_);
+ if(isInitialized_) {
+ dbusConnection_->getDBusObjectManager()->unregisterInterfaceHandler(dbusIntrospectionInterfaceHandlerToken_);
+ dbusConnection_->getDBusObjectManager()->unregisterInterfaceHandler(dbusInterfaceHandlerToken_);
+ isInitialized_ = false;
+ }
}
void DBusStubAdapter::init() {
diff --git a/src/CommonAPI/DBus/DBusStubAdapterHelper.h b/src/CommonAPI/DBus/DBusStubAdapterHelper.h
index a88eeb2..d6e95e3 100644
--- a/src/CommonAPI/DBus/DBusStubAdapterHelper.h
+++ b/src/CommonAPI/DBus/DBusStubAdapterHelper.h
@@ -44,7 +44,8 @@ class DBusStubAdapterHelper: public DBusStubAdapter, public std::enable_shared_f
}
virtual ~DBusStubAdapterHelper() {
- stub_->deinitStubAdapter();
+ DBusStubAdapter::deinit();
+ stub_.reset();
}
virtual void init() {
@@ -54,7 +55,7 @@ class DBusStubAdapterHelper: public DBusStubAdapter, public std::enable_shared_f
virtual void deinit() {
DBusStubAdapter::deinit();
- stub_->deinitStubAdapter();
+ stub_.reset();
}
inline std::shared_ptr<StubAdapterType> getStubAdapter() {