From fecdeb35e0558e525b6d50acf7db3a561f1fb13e Mon Sep 17 00:00:00 2001 From: Philip Rauwolf Date: Tue, 4 Jun 2013 13:15:59 +0200 Subject: 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. --- Makefile.am | 2 + src/CommonAPI/Factory.h | 75 ++++++----------------------- src/CommonAPI/Factory.hpp | 96 ++++++++++++++++++++++++++++++++++++++ src/CommonAPI/ServicePublisher.h | 23 +++++---- src/CommonAPI/ServicePublisher.hpp | 43 +++++++++++++++++ 5 files changed, 165 insertions(+), 74 deletions(-) create mode 100644 src/CommonAPI/Factory.hpp create mode 100644 src/CommonAPI/ServicePublisher.hpp 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 class _ProxyType, template 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 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 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::class_t> buildProxyWithDefaultAttributeExtension(const std::string& participantId, const std::string& serviceName, - const std::string& domain) { - - std::shared_ptr abstractMiddlewareProxy = createProxy(DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t::getInterfaceId(), participantId, serviceName, domain); - return std::make_shared::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 class _ProxyClass, template class _AttributeExtension> std::shared_ptr::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 getRuntime() { - return runtime_; - } + inline std::shared_ptr 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 = std::dynamic_pointer_cast(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 - 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 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 abstractMiddlewareProxy = createProxy(_ProxyClass<_AttributeExtensions...>::getInterfaceId(), participantId, serviceName, domain); + return std::make_shared<_ProxyClass<_AttributeExtensions...>>(abstractMiddlewareProxy); +} + +template 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 class _ProxyClass, template class _AttributeExtension> +std::shared_ptr::class_t> +Factory::buildProxyWithDefaultAttributeExtension(const std::string& participantId, + const std::string& serviceName, + const std::string& domain) { + + std::shared_ptr abstractMiddlewareProxy = createProxy(DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t::getInterfaceId(), participantId, serviceName, domain); + return std::make_shared::class_t>(abstractMiddlewareProxy); +} + +template class _ProxyClass, template class _AttributeExtension> +std::shared_ptr::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 Factory::getRuntime() { + return runtime_; +} + +template +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 = std::dynamic_pointer_cast(stub); + return registerAdapter(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain); +} + +template +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 = std::dynamic_pointer_cast(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 +#include namespace CommonAPI { +class Factory; + /** * \brief Manages all services that shall be published by the application. * @@ -48,9 +49,7 @@ class ServicePublisher { template bool registerService(std::shared_ptr<_Stub> stub, const std::string& serviceAddress, - std::shared_ptr factory) { - return factory->registerService<_Stub>(stub, serviceAddress); - } + std::shared_ptr 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) { - - return factory->registerService<_Stub>(stub, participantId, serviceName, domain); - } + std::shared_ptr 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 +bool ServicePublisher::registerService(std::shared_ptr<_Stub> stub, + const std::string& participantId, + const std::string& serviceName, + const std::string& domain, + std::shared_ptr factory) { + + std::shared_ptr stubBase = std::dynamic_pointer_cast(stub); + return factory->registerAdapter(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain); +} + +template +bool ServicePublisher::registerService(std::shared_ptr<_Stub> stub, + const std::string& serviceAddress, + std::shared_ptr 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_ */ -- cgit v1.2.1