summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilip Rauwolf <rauwolf@itestra.de>2013-06-04 13:15:59 +0200
committerPhilip Rauwolf <rauwolf@itestra.de>2013-06-04 13:15:59 +0200
commitfecdeb35e0558e525b6d50acf7db3a561f1fb13e (patch)
tree1b589f48d89bfe43c823c721d8059211ec9f3487
parentf8f42f23ed8cf0edd0f62bd04c85fff801413200 (diff)
downloadgenivi-common-api-runtime-fecdeb35e0558e525b6d50acf7db3a561f1fb13e.tar.gz
Decoupling of declaration and implementation in Factory and
ServicePublisher plus some dependency refactoring (user interface has not changed) to further separate the new ServicePublisher interface from the deprecated Factory functions.
-rw-r--r--Makefile.am2
-rw-r--r--src/CommonAPI/Factory.h75
-rw-r--r--src/CommonAPI/Factory.hpp96
-rw-r--r--src/CommonAPI/ServicePublisher.h23
-rw-r--r--src/CommonAPI/ServicePublisher.hpp43
5 files changed, 165 insertions, 74 deletions
diff --git a/Makefile.am b/Makefile.am
index 10de2ac..f2937bb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -40,6 +40,7 @@ CommonAPI_include_HEADERS = \
src/CommonAPI/ByteBuffer.h \
src/CommonAPI/Event.h \
src/CommonAPI/Factory.h \
+ src/CommonAPI/Factory.hpp \
src/CommonAPI/InputStream.h \
src/CommonAPI/MainLoopContext.h \
src/CommonAPI/MiddlewareInfo.h \
@@ -50,6 +51,7 @@ CommonAPI_include_HEADERS = \
src/CommonAPI/SerializableVariant.h \
src/CommonAPI/SerializableVariant.hpp \
src/CommonAPI/ServicePublisher.h \
+ src/CommonAPI/ServicePublisher.hpp \
src/CommonAPI/Stub.h \
src/CommonAPI/types.h
diff --git a/src/CommonAPI/Factory.h b/src/CommonAPI/Factory.h
index fa7a8ad..9760d04 100644
--- a/src/CommonAPI/Factory.h
+++ b/src/CommonAPI/Factory.h
@@ -16,7 +16,6 @@
#include "MiddlewareInfo.h"
#include "Proxy.h"
-#include "Runtime.h"
#include "Stub.h"
@@ -24,8 +23,7 @@ namespace CommonAPI {
class Factory;
-class Runtime;
-class MiddlewareInfo;
+class ServicePublisher;
template<template<typename ...> class _ProxyType, template<typename> class _AttributeExtension>
@@ -75,11 +73,7 @@ class Factory {
std::shared_ptr<_ProxyClass<_AttributeExtensions...> >
buildProxy(const std::string& participantId,
const std::string& serviceName,
- const std::string& domain) {
-
- std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(_ProxyClass<_AttributeExtensions...>::getInterfaceId(), participantId, serviceName, domain);
- return std::make_shared<_ProxyClass<_AttributeExtensions...>>(abstractMiddlewareProxy);
- }
+ const std::string& domain);
/**
* \brief Build a proxy for the specified address
@@ -92,17 +86,7 @@ class Factory {
*/
template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions >
std::shared_ptr<_ProxyClass<_AttributeExtensions...> >
- buildProxy(const std::string& serviceAddress) {
-
- std::string domain;
- std::string serviceName;
- std::string participantId;
- if(!splitValidAddress(serviceAddress, domain, serviceName, participantId)) {
- return false;
- }
-
- return buildProxy<_ProxyClass, _AttributeExtensions...>(participantId, serviceName, domain);
- }
+ buildProxy(const std::string& serviceAddress);
/**
* \brief Build a proxy for the specified address with one extension for all attributes
@@ -119,11 +103,7 @@ class Factory {
std::shared_ptr<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t>
buildProxyWithDefaultAttributeExtension(const std::string& participantId,
const std::string& serviceName,
- const std::string& domain) {
-
- std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t::getInterfaceId(), participantId, serviceName, domain);
- return std::make_shared<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t>(abstractMiddlewareProxy);
- }
+ const std::string& domain);
/**
* \brief Build a proxy for the specified address with one extension for all attributes
@@ -136,17 +116,7 @@ class Factory {
*/
template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension>
std::shared_ptr<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t>
- buildProxyWithDefaultAttributeExtension(const std::string& serviceAddress) {
-
- std::string domain;
- std::string serviceName;
- std::string participantId;
- if(!splitValidAddress(serviceAddress, domain, serviceName, participantId)) {
- return false;
- }
-
- return buildProxyWithDefaultAttributeExtension<_ProxyClass, _AttributeExtension>(participantId, serviceName, domain);
- }
+ buildProxyWithDefaultAttributeExtension(const std::string& serviceAddress);
/**
* \brief Get a pointer to the runtime of this factory.
@@ -155,9 +125,7 @@ class Factory {
*
* @return the Runtime
*/
- inline std::shared_ptr<Runtime> getRuntime() {
- return runtime_;
- }
+ inline std::shared_ptr<Runtime> getRuntime();
/**
* \brief Register a service stub under a specified address
@@ -181,11 +149,7 @@ class Factory {
COMMONAPI_DEPRECATED bool registerService(std::shared_ptr<_Stub> stub,
const std::string& participantId,
const std::string& serviceName,
- const std::string& domain) {
-
- std::shared_ptr<StubBase> stubBase = std::dynamic_pointer_cast<StubBase>(stub);
- return registerAdapter(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain);
- }
+ const std::string& domain);
/**
* \brief Register a service stub under a specified address
@@ -204,16 +168,7 @@ class Factory {
* from factory instances.
*/
template<typename _Stub>
- COMMONAPI_DEPRECATED bool registerService(std::shared_ptr<_Stub> stub, const std::string& serviceAddress) {
- std::string domain;
- std::string serviceName;
- std::string participantId;
- if(!splitValidAddress(serviceAddress, domain, serviceName, participantId)) {
- return false;
- }
-
- return registerService<_Stub>(stub, participantId, serviceName, domain);
- }
+ COMMONAPI_DEPRECATED bool registerService(std::shared_ptr<_Stub> stub, const std::string& serviceAddress);
/**
* \brief Unregister a service stub associated with a specified address
@@ -243,15 +198,7 @@ class Factory {
* Purpose for this change is to make service management (esp. deregistering) independent
* from factory instances.
*/
- COMMONAPI_DEPRECATED inline bool unregisterService(const std::string& serviceAddress) {
- std::string domain;
- std::string serviceName;
- std::string participantId;
- if(!splitValidAddress(serviceAddress, domain, serviceName, participantId)) {
- return false;
- }
- return unregisterService(participantId, serviceName, domain);
- }
+ COMMONAPI_DEPRECATED bool unregisterService(const std::string& serviceAddress);
/**
* \brief Get all instances of a specific service name available. Synchronous call.
@@ -341,9 +288,13 @@ class Factory {
}
return true;
}
+
+ friend ServicePublisher;
};
} // namespace CommonAPI
+#include "Factory.hpp"
+
#endif // COMMONAPI_FACTORY_H_
diff --git a/src/CommonAPI/Factory.hpp b/src/CommonAPI/Factory.hpp
new file mode 100644
index 0000000..7468ded
--- /dev/null
+++ b/src/CommonAPI/Factory.hpp
@@ -0,0 +1,96 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * 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/. */
+#ifndef COMMONAPI_FACTORY_IMPL_H_
+#define COMMONAPI_FACTORY_IMPL_H_
+
+#include "Runtime.h"
+#include "ServicePublisher.h"
+
+namespace CommonAPI {
+
+template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions>
+std::shared_ptr<_ProxyClass<_AttributeExtensions...> >
+Factory::buildProxy(const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain) {
+
+ std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(_ProxyClass<_AttributeExtensions...>::getInterfaceId(), participantId, serviceName, domain);
+ return std::make_shared<_ProxyClass<_AttributeExtensions...>>(abstractMiddlewareProxy);
+}
+
+template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions >
+std::shared_ptr<_ProxyClass<_AttributeExtensions...> >
+Factory::buildProxy(const std::string& serviceAddress) {
+
+ std::string domain;
+ std::string serviceName;
+ std::string participantId;
+ if(!splitValidAddress(serviceAddress, domain, serviceName, participantId)) {
+ return false;
+ }
+
+ return buildProxy<_ProxyClass, _AttributeExtensions...>(participantId, serviceName, domain);
+}
+
+template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension>
+std::shared_ptr<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t>
+Factory::buildProxyWithDefaultAttributeExtension(const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain) {
+
+ std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t::getInterfaceId(), participantId, serviceName, domain);
+ return std::make_shared<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t>(abstractMiddlewareProxy);
+}
+
+template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension>
+std::shared_ptr<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t>
+Factory::buildProxyWithDefaultAttributeExtension(const std::string& serviceAddress) {
+
+ std::string domain;
+ std::string serviceName;
+ std::string participantId;
+ if(!splitValidAddress(serviceAddress, domain, serviceName, participantId)) {
+ return false;
+ }
+
+ return buildProxyWithDefaultAttributeExtension<_ProxyClass, _AttributeExtension>(participantId, serviceName, domain);
+}
+
+inline std::shared_ptr<Runtime> Factory::getRuntime() {
+ return runtime_;
+}
+
+template<typename _Stub>
+COMMONAPI_DEPRECATED bool Factory::registerService(std::shared_ptr<_Stub> stub,
+ const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain) {
+
+ std::shared_ptr<StubBase> stubBase = std::dynamic_pointer_cast<StubBase>(stub);
+ return registerAdapter(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain);
+}
+
+template<typename _Stub>
+COMMONAPI_DEPRECATED bool Factory::registerService(std::shared_ptr<_Stub> stub, const std::string& serviceAddress) {
+ std::string domain;
+ std::string serviceName;
+ std::string participantId;
+ if(!splitValidAddress(serviceAddress, domain, serviceName, participantId)) {
+ return false;
+ }
+
+ std::shared_ptr<StubBase> stubBase = std::dynamic_pointer_cast<StubBase>(stub);
+ return registerAdapter(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain);
+}
+
+COMMONAPI_DEPRECATED inline bool Factory::unregisterService(const std::string& serviceAddress) {
+ return runtime_->getServicePublisher()->unregisterService(serviceAddress);
+}
+
+} //namespace CommonAPI
+
+#endif // COMMONAPI_FACTORY_IMPL_H_
diff --git a/src/CommonAPI/ServicePublisher.h b/src/CommonAPI/ServicePublisher.h
index 4d009be..43bbeb9 100644
--- a/src/CommonAPI/ServicePublisher.h
+++ b/src/CommonAPI/ServicePublisher.h
@@ -8,12 +8,13 @@
#ifndef COMMONAPI_SERVICE_PUBLISHER_H_
#define COMMONAPI_SERVICE_PUBLISHER_H_
-
-#include "Factory.h"
-
+#include <memory>
+#include <string>
namespace CommonAPI {
+class Factory;
+
/**
* \brief Manages all services that shall be published by the application.
*
@@ -48,9 +49,7 @@ class ServicePublisher {
template<typename _Stub>
bool registerService(std::shared_ptr<_Stub> stub,
const std::string& serviceAddress,
- std::shared_ptr<Factory> factory) {
- return factory->registerService<_Stub>(stub, serviceAddress);
- }
+ std::shared_ptr<Factory> factory);
/**
* \brief Registers and publishes a service.
@@ -80,10 +79,7 @@ class ServicePublisher {
const std::string& participantId,
const std::string& serviceName,
const std::string& domain,
- std::shared_ptr<Factory> factory) {
-
- return factory->registerService<_Stub>(stub, participantId, serviceName, domain);
- }
+ std::shared_ptr<Factory> factory);
/**
* \brief Unregisters and depublishes the service that was published for the given address.
@@ -109,13 +105,16 @@ class ServicePublisher {
* @return 'true' if there was a service for the given address and depublishing
* was successful, 'false' otherwise
*/
- virtual bool unregisterService(const std::string& participantId, const std::string& serviceName, const std::string& domain) {
- std::string serviceAddress(participantId + ":" + serviceName + ":"+ domain);
+ bool unregisterService(const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain) {
+ std::string serviceAddress(participantId + ":" + serviceName + ":" + domain);
return unregisterService(serviceAddress);
}
};
} // namespace CommonAPI
+#include "ServicePublisher.hpp"
#endif /* COMMONAPI_SERVICE_PUBLISHER_H_ */
diff --git a/src/CommonAPI/ServicePublisher.hpp b/src/CommonAPI/ServicePublisher.hpp
new file mode 100644
index 0000000..059e1a3
--- /dev/null
+++ b/src/CommonAPI/ServicePublisher.hpp
@@ -0,0 +1,43 @@
+/* Copyright (C) 2013 BMW Group
+ * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
+ * Author: Juergen Gehring (juergen.gehring@bmw.de)
+ * 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/. */
+
+#ifndef COMMONAPI_SERVICE_PUBLISHER_IMPL_H_
+#define COMMONAPI_SERVICE_PUBLISHER_IMPL_H_
+
+#include "Factory.h"
+
+namespace CommonAPI {
+
+template<typename _Stub>
+bool ServicePublisher::registerService(std::shared_ptr<_Stub> stub,
+ const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain,
+ std::shared_ptr<Factory> factory) {
+
+ std::shared_ptr<StubBase> stubBase = std::dynamic_pointer_cast<StubBase>(stub);
+ return factory->registerAdapter(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain);
+}
+
+template<typename _Stub>
+bool ServicePublisher::registerService(std::shared_ptr<_Stub> stub,
+ const std::string& serviceAddress,
+ std::shared_ptr<Factory> factory) {
+ std::string domain;
+ std::string serviceName;
+ std::string participantId;
+ if(!factory->splitValidAddress(serviceAddress, domain, serviceName, participantId)) {
+ return false;
+ }
+
+ return registerService<_Stub>(stub, participantId, serviceName, domain, factory);
+}
+
+} // namespace CommonAPI
+
+
+#endif /* COMMONAPI_SERVICE_PUBLISHER_IMPL_H_ */