summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Schanda <schanda@itestra.de>2013-09-17 12:57:12 +0200
committerPhilip Rauwolf <rauwolf@itestra.de>2013-09-18 18:42:05 +0200
commit3dd6d41f84bbb79607779883d9b9befeaac7352d (patch)
tree2c82ada36ea27782d472c66284ac052312caf169 /src
parent5cfaec7f21db9fa62061b4c87f91bcb2d441603f (diff)
downloadgenivi-common-api-runtime-3dd6d41f84bbb79607779883d9b9befeaac7352d.tar.gz
Add managed services
- Correct issues with selective broadcasts - Add proxy manager as member of managing proxies offering api for interrogation and building proxies of managed services - Make isAvailableblocking public api in proxies Change-Id: I52826e0634d7257deeaa145f9f912e4a7149f30d
Diffstat (limited to 'src')
-rw-r--r--src/CommonAPI/CommonAPI.h2
-rw-r--r--src/CommonAPI/Factory.h12
-rw-r--r--src/CommonAPI/Proxy.h2
-rw-r--r--src/CommonAPI/ProxyManager.h80
-rw-r--r--src/CommonAPI/ServicePublisher.cpp22
-rw-r--r--src/CommonAPI/ServicePublisher.h16
-rw-r--r--src/CommonAPI/ServicePublisher.hpp2
7 files changed, 134 insertions, 2 deletions
diff --git a/src/CommonAPI/CommonAPI.h b/src/CommonAPI/CommonAPI.h
index e9beb77..27c0767 100644
--- a/src/CommonAPI/CommonAPI.h
+++ b/src/CommonAPI/CommonAPI.h
@@ -9,7 +9,9 @@
#define COMMONAPI_H_
+#ifndef COMMONAPI_INTERNAL_COMPILATION
#define COMMONAPI_INTERNAL_COMPILATION
+#endif
#include "Runtime.h"
#include "Factory.h"
diff --git a/src/CommonAPI/Factory.h b/src/CommonAPI/Factory.h
index 91bafda..ba48bf4 100644
--- a/src/CommonAPI/Factory.h
+++ b/src/CommonAPI/Factory.h
@@ -285,7 +285,17 @@ class Factory {
protected:
virtual std::shared_ptr<Proxy> createProxy(const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain) = 0;
- virtual bool registerAdapter(std::shared_ptr<StubBase> stubBase, const char* interfaceId, const std::string& participantId, const std::string& serviceName, const std::string& domain) = 0;
+
+ /**
+ * @deprecated Use CommonAPI::ServicePublisher::registerService() instead.
+ */
+ COMMONAPI_DEPRECATED virtual bool registerAdapter(std::shared_ptr<StubBase> stubBase,
+ const char* interfaceId,
+ const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain) {
+ return false;
+ }
private:
std::shared_ptr<Runtime> runtime_;
diff --git a/src/CommonAPI/Proxy.h b/src/CommonAPI/Proxy.h
index 59575ff..b427824 100644
--- a/src/CommonAPI/Proxy.h
+++ b/src/CommonAPI/Proxy.h
@@ -42,6 +42,8 @@ class Proxy {
virtual bool isAvailable() const = 0;
+ virtual bool isAvailableBlocking() const = 0;
+
virtual ProxyStatusEvent& getProxyStatusEvent() = 0;
virtual InterfaceVersionAttribute& getInterfaceVersionAttribute() = 0;
diff --git a/src/CommonAPI/ProxyManager.h b/src/CommonAPI/ProxyManager.h
new file mode 100644
index 0000000..e967852
--- /dev/null
+++ b/src/CommonAPI/ProxyManager.h
@@ -0,0 +1,80 @@
+/* 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/. */
+
+#if !defined (COMMONAPI_INTERNAL_COMPILATION)
+#error "Only <CommonAPI/CommonAPI.h> can be included directly, this file may disappear or change contents."
+#endif
+
+#ifndef COMMONAPI_PROXY_MANAGER_H_
+#define COMMONAPI_PROXY_MANAGER_H_
+
+#include "types.h"
+#include "Event.h"
+#include "Proxy.h"
+#include "Factory.h"
+
+#include <functional>
+#include <future>
+#include <string>
+#include <vector>
+
+
+namespace CommonAPI {
+
+class ProxyManager {
+ public:
+ typedef std::function<void(const CallStatus&, const std::vector<std::string>&)> GetAvailableInstancesCallback;
+ typedef std::function<void(const CallStatus&, const AvailabilityStatus&)> GetInstanceAvailabilityStatusCallback;
+
+ typedef Event<std::string, AvailabilityStatus> InstanceAvailabilityStatusChangedEvent;
+
+ ProxyManager() { };
+ ProxyManager(ProxyManager&&) = delete;
+ ProxyManager(const ProxyManager&) = delete;
+
+ virtual ~ProxyManager() { }
+
+ virtual void getAvailableInstances(CommonAPI::CallStatus&, std::vector<std::string>& availableInstances) = 0;
+ virtual std::future<CallStatus> getAvailableInstancesAsync(GetAvailableInstancesCallback callback) = 0;
+
+ virtual void getInstanceAvailabilityStatus(const std::string& instanceAddress,
+ CallStatus& callStatus,
+ AvailabilityStatus& availabilityStatus) = 0;
+
+ virtual std::future<CallStatus> getInstanceAvailabilityStatusAsync(const std::string&,
+ GetInstanceAvailabilityStatusCallback callback) = 0;
+
+ virtual InstanceAvailabilityStatusChangedEvent& getInstanceAvailabilityStatusChangedEvent() = 0;
+
+ template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions>
+ std::shared_ptr<_ProxyClass<_AttributeExtensions...> >
+ buildProxy(const std::string& instanceName) {
+ std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(instanceName);
+ if (abstractMiddlewareProxy) {
+ return std::make_shared<_ProxyClass<_AttributeExtensions...>>(abstractMiddlewareProxy);
+ }
+ return NULL;
+
+ }
+
+ template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension>
+ std::shared_ptr<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t>
+ buildProxyWithDefaultAttributeExtension(const std::string& instanceName) {
+ std::shared_ptr<Proxy> abstractMiddlewareProxy = createProxy(instanceName);
+ if (abstractMiddlewareProxy) {
+ return std::make_shared<typename DefaultAttributeProxyFactoryHelper<_ProxyClass, _AttributeExtension>::class_t>(abstractMiddlewareProxy);
+ }
+ return NULL;
+ }
+
+ protected:
+ virtual std::shared_ptr<Proxy> createProxy(const std::string& instanceName) = 0;
+};
+
+} // namespace CommonAPI
+
+#endif // COMMONAPI_PROXY_MANAGER_H_
diff --git a/src/CommonAPI/ServicePublisher.cpp b/src/CommonAPI/ServicePublisher.cpp
new file mode 100644
index 0000000..dc89b2b
--- /dev/null
+++ b/src/CommonAPI/ServicePublisher.cpp
@@ -0,0 +1,22 @@
+/* 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/. */
+#include "ServicePublisher.h"
+#include "Stub.h"
+#include "Factory.h"
+
+namespace CommonAPI {
+
+bool ServicePublisher::registerService(const std::shared_ptr<StubBase>& stubBase,
+ const char* interfaceId,
+ const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain,
+ const std::shared_ptr<Factory>& factory) {
+ return factory->registerAdapter(stubBase, interfaceId, participantId, serviceName, domain);
+}
+
+} // namespace CommonAPI
diff --git a/src/CommonAPI/ServicePublisher.h b/src/CommonAPI/ServicePublisher.h
index 0fce54f..3dd6a65 100644
--- a/src/CommonAPI/ServicePublisher.h
+++ b/src/CommonAPI/ServicePublisher.h
@@ -17,6 +17,7 @@
namespace CommonAPI {
+class StubBase;
class Factory;
/**
@@ -115,6 +116,21 @@ class ServicePublisher {
std::string serviceAddress(participantId + ":" + serviceName + ":" + domain);
return unregisterService(serviceAddress);
}
+
+ protected:
+ /**
+ * Register stubBase service within a factory.
+ *
+ * This is a new API which deprecates the old Factory::registerAdapter() method.
+ * For compatibility reasons a default implementation is provided. New middleware
+ * implementations should override this method.
+ */
+ virtual bool registerService(const std::shared_ptr<StubBase>& stubBase,
+ const char* interfaceId,
+ const std::string& participantId,
+ const std::string& serviceName,
+ const std::string& domain,
+ const std::shared_ptr<Factory>& factory);
};
} // namespace CommonAPI
diff --git a/src/CommonAPI/ServicePublisher.hpp b/src/CommonAPI/ServicePublisher.hpp
index 059e1a3..604bf07 100644
--- a/src/CommonAPI/ServicePublisher.hpp
+++ b/src/CommonAPI/ServicePublisher.hpp
@@ -20,7 +20,7 @@ bool ServicePublisher::registerService(std::shared_ptr<_Stub> stub,
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);
+ return registerService(stubBase, _Stub::StubAdapterType::getInterfaceId(), participantId, serviceName, domain, factory);
}
template<typename _Stub>