1 /* Copyright (C) 2013 BMW Group
2 * Author: Manfred Bathelt (manfred.bathelt@bmw.de)
3 * Author: Juergen Gehring (juergen.gehring@bmw.de)
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #if !defined (COMMONAPI_INTERNAL_COMPILATION)
9 #error "Only <CommonAPI/CommonAPI.h> can be included directly, this file may disappear or change contents."
12 #ifndef COMMONAPI_SERVICE_PUBLISHER_H_
13 #define COMMONAPI_SERVICE_PUBLISHER_H_
24 * \brief Manages all services that shall be published by the application.
26 * Stubs for all services that shall be published will be registered here.
27 * This class is defined as singleton per loaded runtime (i.e. per loaded middleware).
29 class ServicePublisher {
31 virtual ~ServicePublisher() {}
34 * \brief Registers and publishes a service.
36 * Registers and publishes a service. Which service is to be published is defined
37 * by the stub-pointer that is given as parameter. The given factory will be used
38 * to construct all necessary middleware specific objects to do the publishing.
40 * \note Note that a call to this method will always result in a registration
41 * with the middleware the given factory was instantiated for, not the middleware
42 * that matches the runtime this ServicePublisher was retrieved from. Accordingly,
43 * unregistering the service will have to be done by using the ServicePublisher
44 * that is provided by the runtime matching the middleware that also provided
47 * @param serviceAddress The CommonAPI address the service shall be reachable at
48 * @param stub The stub that provides an implementation for the service
49 * @param factory The factory that will be used to construct all necessary middleware specific objects
51 * @return 'true' if the service was published successfully, 'false' if not or if another service that uses
52 * the exact same address already is registered.
54 template<typename _Stub>
55 bool registerService(std::shared_ptr<_Stub> stub,
56 const std::string& serviceAddress,
57 std::shared_ptr<Factory> factory);
60 * \brief Registers and publishes a service.
62 * Registers and publishes a service. Which service is to be published is defined
63 * by the stub-pointer that is given as parameter. The given factory will be used
64 * to construct all necessary middleware specific objects to do the publishing.
66 * \note Note that a call to this method will always result in a registration
67 * with the middleware the given factory was instantiated for, not the middleware
68 * that matches the runtime this ServicePublisher was retrieved from. Accordingly,
69 * unregistering the service will have to be done by using the ServicePublisher
70 * that is provided by the runtime matching the middleware that also provided
73 * @param participantId The CommonAPI participant ID the service shall be identified with
74 * @param serviceName The CommonAPI service name the service shall provide
75 * @param domain The CommonAPI domain the service shall be reachable at
76 * @param stub The stub that provides an implementation for the service
77 * @param factory The factory that will be used to construct all necessary middleware specific objects
79 * @return 'true' if the service was published successfully, 'false' if not or if another service that uses
80 * the exact same address already is registered.
82 template<typename _Stub>
83 bool registerService(std::shared_ptr<_Stub> stub,
84 const std::string& participantId,
85 const std::string& serviceName,
86 const std::string& domain,
87 std::shared_ptr<Factory> factory);
90 * \brief Unregisters and depublishes the service that was published for the given address.
92 * Unregisters and depublishes the service that was published for the given CommonAPI address.
94 * @param The CommonAPI address the service was registered for
96 * @return 'true' if there was a service for the given address and depublishing
97 * was successful, 'false' otherwise
99 virtual bool unregisterService(const std::string& serviceAddress) = 0;
102 * \brief Unregisters and depublishes the service that was published for the given address.
104 * Unregisters and depublishes the service that was published for the given CommonAPI address.
106 * @param The CommonAPI participant ID the service was identified with
107 * @param The CommonAPI service name the service provided
108 * @param The CommonAPI domain the service was registered for
110 * @return 'true' if there was a service for the given address and depublishing
111 * was successful, 'false' otherwise
113 bool unregisterService(const std::string& participantId,
114 const std::string& serviceName,
115 const std::string& domain) {
116 std::string serviceAddress(participantId + ":" + serviceName + ":" + domain);
117 return unregisterService(serviceAddress);
122 * Register stubBase service within a factory.
124 * This is a new API which deprecates the old Factory::registerAdapter() method.
125 * For compatibility reasons a default implementation is provided. New middleware
126 * implementations should override this method.
128 virtual bool registerService(const std::shared_ptr<StubBase>& stubBase,
129 const char* interfaceId,
130 const std::string& participantId,
131 const std::string& serviceName,
132 const std::string& domain,
133 const std::shared_ptr<Factory>& factory);
136 } // namespace CommonAPI
138 #include "ServicePublisher.hpp"
140 #endif /* COMMONAPI_SERVICE_PUBLISHER_H_ */