summaryrefslogtreecommitdiff
path: root/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp')
-rw-r--r--src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp203
1 files changed, 203 insertions, 0 deletions
diff --git a/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp b/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp
new file mode 100644
index 0000000..1a3a6dc
--- /dev/null
+++ b/src/test/commonapi/tests/managed/RootInterfaceDBusStubAdapter.cpp
@@ -0,0 +1,203 @@
+/*
+* This file was generated by the CommonAPI Generators.
+* Used org.genivi.commonapi.core 2.1.0.qualifier.
+* Used org.franca.core 0.8.9.201308271211.
+*
+* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
+* If a copy of the MPL was not distributed with this file, You can obtain one at
+* http://mozilla.org/MPL/2.0/.
+*/
+#include "RootInterfaceDBusStubAdapter.h"
+#include <commonapi/tests/managed/RootInterface.h>
+
+namespace commonapi {
+namespace tests {
+namespace managed {
+
+std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> createRootInterfaceDBusStubAdapter(
+ const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory,
+ const std::string& commonApiAddress,
+ const std::string& interfaceName,
+ const std::string& busName,
+ const std::string& objectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusProxyConnection,
+ const std::shared_ptr<CommonAPI::StubBase>& stubBase) {
+ return std::make_shared<RootInterfaceDBusStubAdapter>(factory, commonApiAddress, interfaceName, busName, objectPath, dbusProxyConnection, stubBase);
+}
+
+__attribute__((constructor)) void registerRootInterfaceDBusStubAdapter(void) {
+ CommonAPI::DBus::DBusFactory::registerAdapterFactoryMethod(RootInterface::getInterfaceId(),
+ &createRootInterfaceDBusStubAdapter);
+}
+
+RootInterfaceDBusStubAdapter::RootInterfaceDBusStubAdapter(
+ const std::shared_ptr<CommonAPI::DBus::DBusFactory>& factory,
+ const std::string& commonApiAddress,
+ const std::string& dbusInterfaceName,
+ const std::string& dbusBusName,
+ const std::string& dbusObjectPath,
+ const std::shared_ptr<CommonAPI::DBus::DBusProxyConnection>& dbusConnection,
+ const std::shared_ptr<CommonAPI::StubBase>& stub):
+ RootInterfaceDBusStubAdapterHelper(factory, commonApiAddress, dbusInterfaceName, dbusBusName, dbusObjectPath,
+ dbusConnection, std::dynamic_pointer_cast<RootInterfaceStub>(stub),
+ new CommonAPI::DBus::DBusObjectManagerStub(dbusObjectPath, dbusConnection))
+ {
+}
+
+RootInterfaceDBusStubAdapter::~RootInterfaceDBusStubAdapter() {
+ deactivateManagedInstances();
+ deinit();
+ stub_.reset();
+}
+
+void RootInterfaceDBusStubAdapter::deactivateManagedInstances() {
+ for(std::set<std::string>::iterator iter = registeredLeafInterfaceInstances.begin();
+ iter != registeredLeafInterfaceInstances.end(); ++iter) {
+ deregisterManagedStubLeafInterface(*iter);
+ }
+ for(std::set<std::string>::iterator iter = registeredBranchInterfaceInstances.begin();
+ iter != registeredBranchInterfaceInstances.end(); ++iter) {
+ deregisterManagedStubBranchInterface(*iter);
+ }
+}
+
+const char* RootInterfaceDBusStubAdapter::getMethodsDBusIntrospectionXmlData() const {
+ static const char* introspectionData =
+ "<method name=\"testRootMethod\">\n"
+ "<arg name=\"inInt\" type=\"i\" direction=\"in\" />\n"
+ "<arg name=\"inString\" type=\"s\" direction=\"in\" />\n"
+ "<arg name=\"methodError\" type=\"i\" direction=\"out\" />\n"
+ "<arg name=\"outInt\" type=\"i\" direction=\"out\" />\n"
+ "<arg name=\"outString\" type=\"s\" direction=\"out\" />\n"
+ "</method>\n"
+ ;
+ return introspectionData;
+}
+
+
+
+static CommonAPI::DBus::DBusMethodWithReplyStubDispatcher<
+ RootInterfaceStub,
+ std::tuple<int32_t, std::string>,
+ std::tuple<RootInterface::testRootMethodError, int32_t, std::string>
+ > testRootMethodStubDispatcher(&RootInterfaceStub::testRootMethod, "iis");
+
+
+
+const RootInterfaceDBusStubAdapter::StubDispatcherTable& RootInterfaceDBusStubAdapter::getStubDispatcherTable() {
+ static const RootInterfaceDBusStubAdapter::StubDispatcherTable stubDispatcherTable = {
+ { { "testRootMethod", "is" }, &commonapi::tests::managed::testRootMethodStubDispatcher }
+ };
+ return stubDispatcherTable;
+}
+
+
+bool RootInterfaceDBusStubAdapter::registerManagedStubLeafInterface(std::shared_ptr<LeafInterfaceStub> stub, const std::string& instance) {
+ if (registeredLeafInterfaceInstances.find(instance) == registeredLeafInterfaceInstances.end()) {
+ std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance;
+
+ std::string interfaceName;
+ std::string connectionName;
+ std::string objectPath;
+
+ CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress(
+ commonApiAddress,
+ interfaceName,
+ connectionName,
+ objectPath);
+
+ if (objectPath.compare(0, dbusObjectPath_.length(), dbusObjectPath_) == 0) {
+ auto dbusStubAdapter = factory_->createDBusStubAdapter(stub, "commonapi.tests.managed.LeafInterface",
+ instance, "commonapi.tests.managed.LeafInterface", "local");
+ bool ok = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerManagedService(dbusStubAdapter);
+ if (ok) {
+ bool isServiceExportSuccessful = managerStub->exportDBusStubAdapter(dbusStubAdapter.get());
+ if (isServiceExportSuccessful) {
+ registeredLeafInterfaceInstances.insert(instance);
+ return true;
+ } else {
+ const bool isManagedDeregistrationSuccessful =
+ CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(
+ commonApiAddress);
+ }
+ }
+ }
+ }
+ return false;
+}
+
+bool RootInterfaceDBusStubAdapter::deregisterManagedStubLeafInterface(const std::string& instance) {
+ std::string commonApiAddress = "local:commonapi.tests.managed.LeafInterface:" + instance;
+ if (registeredLeafInterfaceInstances.find(instance) != registeredLeafInterfaceInstances.end()) {
+ std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> adapter =
+ CommonAPI::DBus::DBusServicePublisher::getInstance()->getRegisteredService(commonApiAddress);
+ if (adapter != nullptr) {
+ managerStub->unexportDBusStubAdapter(adapter.get());
+ CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress);
+ registeredLeafInterfaceInstances.erase(instance);
+ return true;
+ }
+ }
+ return false;
+}
+
+std::set<std::string>& RootInterfaceDBusStubAdapter::getLeafInterfaceInstances() {
+ return registeredLeafInterfaceInstances;
+}
+
+bool RootInterfaceDBusStubAdapter::registerManagedStubBranchInterface(std::shared_ptr<BranchInterfaceStub> stub, const std::string& instance) {
+ if (registeredBranchInterfaceInstances.find(instance) == registeredBranchInterfaceInstances.end()) {
+ std::string commonApiAddress = "local:commonapi.tests.managed.BranchInterface:" + instance;
+
+ std::string interfaceName;
+ std::string connectionName;
+ std::string objectPath;
+
+ CommonAPI::DBus::DBusAddressTranslator::getInstance().searchForDBusAddress(
+ commonApiAddress,
+ interfaceName,
+ connectionName,
+ objectPath);
+
+ if (objectPath.compare(0, dbusObjectPath_.length(), dbusObjectPath_) == 0) {
+ auto dbusStubAdapter = factory_->createDBusStubAdapter(stub, "commonapi.tests.managed.BranchInterface",
+ instance, "commonapi.tests.managed.BranchInterface", "local");
+ bool ok = CommonAPI::DBus::DBusServicePublisher::getInstance()->registerManagedService(dbusStubAdapter);
+ if (ok) {
+ bool isServiceExportSuccessful = managerStub->exportDBusStubAdapter(dbusStubAdapter.get());
+ if (isServiceExportSuccessful) {
+ registeredBranchInterfaceInstances.insert(instance);
+ return true;
+ } else {
+ const bool isManagedDeregistrationSuccessful =
+ CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(
+ commonApiAddress);
+ }
+ }
+ }
+ }
+ return false;
+}
+
+bool RootInterfaceDBusStubAdapter::deregisterManagedStubBranchInterface(const std::string& instance) {
+ std::string commonApiAddress = "local:commonapi.tests.managed.BranchInterface:" + instance;
+ if (registeredBranchInterfaceInstances.find(instance) != registeredBranchInterfaceInstances.end()) {
+ std::shared_ptr<CommonAPI::DBus::DBusStubAdapter> adapter =
+ CommonAPI::DBus::DBusServicePublisher::getInstance()->getRegisteredService(commonApiAddress);
+ if (adapter != nullptr) {
+ managerStub->unexportDBusStubAdapter(adapter.get());
+ CommonAPI::DBus::DBusServicePublisher::getInstance()->unregisterManagedService(commonApiAddress);
+ registeredBranchInterfaceInstances.erase(instance);
+ return true;
+ }
+ }
+ return false;
+}
+
+std::set<std::string>& RootInterfaceDBusStubAdapter::getBranchInterfaceInstances() {
+ return registeredBranchInterfaceInstances;
+}
+
+} // namespace managed
+} // namespace tests
+} // namespace commonapi