summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLutz Bichler <Lutz.Bichler@bmw.de>2015-06-17 11:29:46 +0200
committerLutz Bichler <Lutz.Bichler@bmw.de>2015-06-17 11:29:46 +0200
commitc52b2b094ef5844c182f097b14923764758dfe80 (patch)
treef4e0446c1f8411dca5336884e2bc10a820ef8722 /include
parent6c463fcc3dcee619925f08ea09e19a86b9e581cc (diff)
downloadgenivi-common-api-runtime-c52b2b094ef5844c182f097b14923764758dfe80.tar.gz
CommonAPI 3.1.2
Diffstat (limited to 'include')
-rw-r--r--include/CommonAPI/Enumeration.hpp30
-rw-r--r--include/CommonAPI/Event.hpp19
-rw-r--r--include/CommonAPI/Runtime.hpp174
-rw-r--r--include/CommonAPI/Struct.hpp10
-rw-r--r--include/CommonAPI/TypeOutputStream.hpp14
-rw-r--r--include/CommonAPI/Variant.hpp21
6 files changed, 161 insertions, 107 deletions
diff --git a/include/CommonAPI/Enumeration.hpp b/include/CommonAPI/Enumeration.hpp
index 1a4d5f4..da0372d 100644
--- a/include/CommonAPI/Enumeration.hpp
+++ b/include/CommonAPI/Enumeration.hpp
@@ -8,11 +8,11 @@
namespace CommonAPI {
-template <typename _Base>
+template<typename _Base>
struct Enumeration {
Enumeration() = default;
- Enumeration(const _Base &_value)
- : value_(_value) {
+ Enumeration(const _Base &_value) :
+ value_(_value) {
}
inline Enumeration &operator=(const _Base &_value) {
@@ -24,12 +24,28 @@ struct Enumeration {
return value_;
}
- inline bool operator == (const Enumeration<_Base> &_other) const {
- return value_ == _other.value_;
+ inline bool operator==(const Enumeration<_Base> &_other) const {
+ return (value_ == _other.value_);
}
- inline bool operator != (const Enumeration<_Base> &_other) const {
- return value_ != _other.value_;
+ inline bool operator!=(const Enumeration<_Base> &_other) const {
+ return (value_ != _other.value_);
+ }
+
+ inline bool operator<(const Enumeration<_Base> &_other) const {
+ return (value_ < _other.value_);
+ }
+
+ inline bool operator<=(const Enumeration<_Base> &_other) const {
+ return (value_ <= _other.value_);
+ }
+
+ inline bool operator>(const Enumeration<_Base> &_other) const {
+ return (value_ > _other.value_);
+ }
+
+ inline bool operator>=(const Enumeration<_Base> &_other) const {
+ return (value_ >= _other.value_);
}
_Base value_;
diff --git a/include/CommonAPI/Event.hpp b/include/CommonAPI/Event.hpp
index 90971f5..982f9a3 100644
--- a/include/CommonAPI/Event.hpp
+++ b/include/CommonAPI/Event.hpp
@@ -106,24 +106,31 @@ typename Event<_Arguments...>::Subscription Event<_Arguments...>::subscribe(List
template<typename ... _Arguments>
void Event<_Arguments...>::unsubscribe(Subscription subscription) {
bool isLastListener(false);
+ bool hasUnsubscribed(false);
subscriptionMutex_.lock();
auto listener = subscriptions_.find(subscription);
if (subscriptions_.end() != listener
&& pendingUnsubscriptions_.end() == pendingUnsubscriptions_.find(subscription)) {
- if (0 == pendingSubscriptions_.erase(subscription)) {
- pendingUnsubscriptions_.insert(subscription);
- isLastListener = (1 == subscriptions_.size());
- } else {
+ pendingUnsubscriptions_.insert(subscription);
+ isLastListener = (1 == subscriptions_.size());
+ hasUnsubscribed = true;
+ }
+ else {
+ listener = pendingSubscriptions_.find(subscription);
+ if (pendingSubscriptions_.end() != listener) {
+ pendingSubscriptions_.erase(subscription);
isLastListener = (0 == subscriptions_.size());
+ hasUnsubscribed = true;
}
}
subscriptionMutex_.unlock();
- if (subscriptions_.end() != listener) {
+ if (hasUnsubscribed) {
onListenerRemoved(listener->second);
- if (isLastListener)
+ if (isLastListener) {
onLastListenerRemoved(listener->second);
+ }
}
}
diff --git a/include/CommonAPI/Runtime.hpp b/include/CommonAPI/Runtime.hpp
index 1cb4f94..8d33d48 100644
--- a/include/CommonAPI/Runtime.hpp
+++ b/include/CommonAPI/Runtime.hpp
@@ -15,6 +15,7 @@
#include <mutex>
#include <set>
+#include <CommonAPI/AttributeExtension.hpp>
#include <CommonAPI/Export.hpp>
#include <CommonAPI/Factory.hpp>
#include <CommonAPI/Types.hpp>
@@ -28,78 +29,65 @@ class Proxy;
class ProxyManager;
class StubBase;
-template<template<typename ...> class _ProxyType, template<typename> class _AttributeExtension>
-struct DefaultAttributeProxyHelper;
-
-template<template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension>
-std::shared_ptr<
- typename DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t
-> createProxyWithDefaultAttributeExtension(
- const std::string &_domain, const std::string &_instance);
-
class Runtime {
public:
- COMMONAPI_EXPORT static std::string getProperty(const std::string &_name);
- COMMONAPI_EXPORT static void setProperty(const std::string &_name, const std::string &_value);
+ COMMONAPI_EXPORT static std::string getProperty(const std::string &_name);
+ COMMONAPI_EXPORT static void setProperty(const std::string &_name, const std::string &_value);
- COMMONAPI_EXPORT static std::shared_ptr<Runtime> get();
+ COMMONAPI_EXPORT static std::shared_ptr<Runtime> get();
- COMMONAPI_EXPORT Runtime();
- COMMONAPI_EXPORT virtual ~Runtime();
+ COMMONAPI_EXPORT Runtime();
+ COMMONAPI_EXPORT virtual ~Runtime();
- COMMONAPI_EXPORT void init();
+ COMMONAPI_EXPORT void init();
template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions>
- COMMONAPI_EXPORT std::shared_ptr<
+ COMMONAPI_EXPORT std::shared_ptr<
_ProxyClass<_AttributeExtensions...>
>
buildProxy(const std::string &_domain,
const std::string &_instance,
const ConnectionId_t &_connectionId = DEFAULT_CONNECTION_ID) {
std::shared_ptr<Proxy> proxy
- = createProxy(_domain,
- _ProxyClass<_AttributeExtensions...>::getInterface(),
- _instance,
- _connectionId);
+ = createProxy(_domain,
+ _ProxyClass<_AttributeExtensions...>::getInterface(),
+ _instance,
+ _connectionId);
if (proxy) {
return std::make_shared<_ProxyClass<_AttributeExtensions...>>(proxy);
}
- else {
- return nullptr;
- }
+ return nullptr;
}
template<template<typename ...> class _ProxyClass, typename ... _AttributeExtensions>
- COMMONAPI_EXPORT std::shared_ptr<
+ COMMONAPI_EXPORT std::shared_ptr<
_ProxyClass<_AttributeExtensions...>
>
buildProxy(const std::string &_domain,
const std::string &_instance,
std::shared_ptr<MainLoopContext> _context) {
std::shared_ptr<Proxy> proxy
- = createProxy(_domain,
- _ProxyClass<_AttributeExtensions...>::getInterface(),
- _instance,
- _context);
+ = createProxy(_domain,
+ _ProxyClass<_AttributeExtensions...>::getInterface(),
+ _instance,
+ _context);
if (proxy) {
return std::make_shared<_ProxyClass<_AttributeExtensions...>>(proxy);
}
- else {
- return nullptr;
- }
+ return nullptr;
}
template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension>
- COMMONAPI_EXPORT std::shared_ptr<typename DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t>
+ COMMONAPI_EXPORT std::shared_ptr<typename DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t>
buildProxyWithDefaultAttributeExtension(const std::string &_domain,
const std::string &_instance,
- const ConnectionId_t &_connectionId = DEFAULT_CONNECTION_ID) {
+ const ConnectionId_t &_connectionId = DEFAULT_CONNECTION_ID) {
std::shared_ptr<Proxy> proxy
- = createProxy(_domain,
- DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t::getInterface(),
- _instance,
- _connectionId);
+ = createProxy(_domain,
+ DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t::getInterface(),
+ _instance,
+ _connectionId);
if (proxy) {
return std::make_shared<typename DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t>(proxy);
}
@@ -107,15 +95,15 @@ public:
}
template <template<typename ...> class _ProxyClass, template<typename> class _AttributeExtension>
- COMMONAPI_EXPORT std::shared_ptr<typename DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t>
+ COMMONAPI_EXPORT std::shared_ptr<typename DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t>
buildProxyWithDefaultAttributeExtension(const std::string &_domain,
const std::string &_instance,
std::shared_ptr<MainLoopContext> _context) {
std::shared_ptr<Proxy> proxy
- = createProxy(_domain,
- DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t::getInterface(),
- _instance,
- _context);
+ = createProxy(_domain,
+ DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t::getInterface(),
+ _instance,
+ _context);
if (proxy) {
return std::make_shared<typename DefaultAttributeProxyHelper<_ProxyClass, _AttributeExtension>::class_t>(proxy);
}
@@ -123,77 +111,77 @@ public:
}
template<typename _Stub>
- COMMONAPI_EXPORT bool registerService(const std::string &_domain,
- const std::string &_instance,
- std::shared_ptr<_Stub> _service,
- const ConnectionId_t &_connectionId = DEFAULT_CONNECTION_ID) {
- return registerStub(_domain, _Stub::StubInterface::getInterface(), _instance, _service, _connectionId);
- }
+ COMMONAPI_EXPORT bool registerService(const std::string &_domain,
+ const std::string &_instance,
+ std::shared_ptr<_Stub> _service,
+ const ConnectionId_t &_connectionId = DEFAULT_CONNECTION_ID) {
+ return registerStub(_domain, _Stub::StubInterface::getInterface(), _instance, _service, _connectionId);
+ }
template<typename _Stub>
- COMMONAPI_EXPORT bool registerService(const std::string &_domain,
- const std::string &_instance,
- std::shared_ptr<_Stub> _service,
- std::shared_ptr<MainLoopContext> _context) {
- return registerStub(_domain, _Stub::StubInterface::getInterface(), _instance, _service, _context);
+ COMMONAPI_EXPORT bool registerService(const std::string &_domain,
+ const std::string &_instance,
+ std::shared_ptr<_Stub> _service,
+ std::shared_ptr<MainLoopContext> _context) {
+ return registerStub(_domain, _Stub::StubInterface::getInterface(), _instance, _service, _context);
}
- COMMONAPI_EXPORT bool unregisterService(const std::string &_domain,
- const std::string &_interface,
- const std::string &_instance) {
- return unregisterStub(_domain, _interface, _instance);
- }
+ COMMONAPI_EXPORT bool unregisterService(const std::string &_domain,
+ const std::string &_interface,
+ const std::string &_instance) {
+ return unregisterStub(_domain, _interface, _instance);
+ }
- COMMONAPI_EXPORT bool registerFactory(const std::string &_ipc, std::shared_ptr<Factory> _factory);
- COMMONAPI_EXPORT bool unregisterFactory(const std::string &_ipc);
+ COMMONAPI_EXPORT bool registerFactory(const std::string &_ipc, std::shared_ptr<Factory> _factory);
+ COMMONAPI_EXPORT bool unregisterFactory(const std::string &_ipc);
inline const std::string &getDefaultBinding() const { return defaultBinding_; };
private:
- COMMONAPI_EXPORT bool readConfiguration();
- COMMONAPI_EXPORT bool splitAddress(const std::string &, std::string &, std::string &, std::string &);
+ COMMONAPI_EXPORT bool readConfiguration();
+ COMMONAPI_EXPORT bool splitAddress(const std::string &, std::string &, std::string &, std::string &);
- COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &, const std::string &, const std::string &,
- const ConnectionId_t &);
- COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &, const std::string &, const std::string &,
- std::shared_ptr<MainLoopContext>);
+ COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &, const std::string &, const std::string &,
+ const ConnectionId_t &);
+ COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &, const std::string &, const std::string &,
+ std::shared_ptr<MainLoopContext>);
- COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxyHelper(const std::string &, const std::string &, const std::string &,
- const ConnectionId_t &);
- COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxyHelper(const std::string &, const std::string &, const std::string &,
- std::shared_ptr<MainLoopContext>);
+ COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxyHelper(const std::string &, const std::string &, const std::string &,
+ const ConnectionId_t &);
+ COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxyHelper(const std::string &, const std::string &, const std::string &,
+ std::shared_ptr<MainLoopContext>);
- COMMONAPI_EXPORT bool registerStub(const std::string &, const std::string &, const std::string &,
- std::shared_ptr<StubBase>, const ConnectionId_t &);
- COMMONAPI_EXPORT bool registerStub(const std::string &, const std::string &, const std::string &,
- std::shared_ptr<StubBase>, std::shared_ptr<MainLoopContext>);
- COMMONAPI_EXPORT bool registerStubHelper(const std::string &, const std::string &, const std::string &,
- std::shared_ptr<StubBase>, const ConnectionId_t &);
- COMMONAPI_EXPORT bool registerStubHelper(const std::string &, const std::string &, const std::string &,
- std::shared_ptr<StubBase>, std::shared_ptr<MainLoopContext>);
+ COMMONAPI_EXPORT bool registerStub(const std::string &, const std::string &, const std::string &,
+ std::shared_ptr<StubBase>, const ConnectionId_t &);
+ COMMONAPI_EXPORT bool registerStub(const std::string &, const std::string &, const std::string &,
+ std::shared_ptr<StubBase>, std::shared_ptr<MainLoopContext>);
+ COMMONAPI_EXPORT bool registerStubHelper(const std::string &, const std::string &, const std::string &,
+ std::shared_ptr<StubBase>, const ConnectionId_t &);
+ COMMONAPI_EXPORT bool registerStubHelper(const std::string &, const std::string &, const std::string &,
+ std::shared_ptr<StubBase>, std::shared_ptr<MainLoopContext>);
- COMMONAPI_EXPORT bool unregisterStub(const std::string &, const std::string &, const std::string &);
+ COMMONAPI_EXPORT bool unregisterStub(const std::string &, const std::string &, const std::string &);
- COMMONAPI_EXPORT std::string getLibrary(const std::string &, const std::string &, const std::string &, bool);
- COMMONAPI_EXPORT bool loadLibrary(const std::string &);
+ COMMONAPI_EXPORT std::string getLibrary(const std::string &, const std::string &, const std::string &, bool);
+ COMMONAPI_EXPORT bool loadLibrary(const std::string &);
private:
- std::string defaultBinding_;
- std::string defaultFolder_;
- std::string defaultConfig_;
+ std::string defaultBinding_;
+ std::string defaultFolder_;
+ std::string defaultConfig_;
- std::map<std::string, std::shared_ptr<Factory>> factories_;
- std::shared_ptr<Factory> defaultFactory_;
- std::map<std::string, std::map<bool, std::string>> libraries_;
- std::set<std::string> loadedLibraries_; // Library name
+ std::map<std::string, std::shared_ptr<Factory>> factories_;
+ std::shared_ptr<Factory> defaultFactory_;
+ std::map<std::string, std::map<bool, std::string>> libraries_;
+ std::set<std::string> loadedLibraries_; // Library name
- std::mutex mutex_;
- std::mutex factoriesMutex_;
- std::mutex loadMutex_;
+ std::mutex mutex_;
+ std::mutex factoriesMutex_;
+ std::mutex loadMutex_;
- static std::map<std::string, std::string> properties_;
- static std::shared_ptr<Runtime> theRuntime__;
+ static std::map<std::string, std::string> properties_;
+ static std::shared_ptr<Runtime> theRuntime__;
friend class ProxyManager;
};
diff --git a/include/CommonAPI/Struct.hpp b/include/CommonAPI/Struct.hpp
index c98b09e..b8d748f 100644
--- a/include/CommonAPI/Struct.hpp
+++ b/include/CommonAPI/Struct.hpp
@@ -4,7 +4,7 @@
// 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."
+#error "Only <CommonAPI/CommonAPI.hpp> can be included directly, this file may disappear or change contents."
#endif
#ifndef COMMONAPI_STRUCT_HPP_
@@ -142,7 +142,11 @@ struct StructTypeWriter<_Index, _TypeOutput, _V<_Values...>> {
void operator()(TypeOutputStream<_TypeOutput> &_output,
const _V<_Values...> &_values) {
StructTypeWriter<_Index-1, _TypeOutput, _V<_Values...>>{}(_output, _values);
+#ifdef WIN32
+ _output.writeType(std::get<_Index>(_values.values_));
+#else
_output.template writeType(std::get<_Index>(_values.values_));
+#endif
}
};
@@ -151,7 +155,11 @@ template<class _TypeOutput,
struct StructTypeWriter<0, _TypeOutput, _V<_Values...>> {
void operator()(TypeOutputStream<_TypeOutput> &_output,
const _V<_Values...> &_values) {
+#ifdef WIN32
+ _output.writeType(std::get<0>(_values.values_));
+#else
_output.template writeType(std::get<0>(_values.values_));
+#endif
}
};
diff --git a/include/CommonAPI/TypeOutputStream.hpp b/include/CommonAPI/TypeOutputStream.hpp
index ec44864..28f9d01 100644
--- a/include/CommonAPI/TypeOutputStream.hpp
+++ b/include/CommonAPI/TypeOutputStream.hpp
@@ -69,6 +69,10 @@ public:
return get()->writeType(_value);
}
+ inline TypeOutputStream &writeType(const Version &_value) {
+ return get()->writeType(_value);
+ }
+
template<typename _Type>
TypeOutputStream &writeType(const Enumeration<_Type> &_value) {
_Type tmpValue;
@@ -80,6 +84,11 @@ public:
return get()->writeType(_value);
}
+ template<class _PolymorphicStruct>
+ TypeOutputStream &writeType(const std::shared_ptr<_PolymorphicStruct> &_value) {
+ return get()->writeType(_value);
+ }
+
template<typename... _Types>
TypeOutputStream &writeType(const Variant<_Types...> &_value) {
return get()->writeType(_value);
@@ -176,6 +185,11 @@ TypeOutputStream<_Derived> &operator<<(TypeOutputStream<_Derived> &_output, cons
return _output.writeType(_value);
}
+template<class _Derived, class _PolymorphicStruct>
+TypeOutputStream<_Derived> &operator<<(TypeOutputStream<_Derived> &_output, const std::shared_ptr<_PolymorphicStruct> &_value) {
+ return _output.writeType(_value);
+}
+
template<class _Derived, typename... _Types>
TypeOutputStream<_Derived> &operator<<(TypeOutputStream<_Derived> &_output, const Variant<_Types...> &_value) {
return _output.writeType(_value);
diff --git a/include/CommonAPI/Variant.hpp b/include/CommonAPI/Variant.hpp
index d7b1088..7af1b81 100644
--- a/include/CommonAPI/Variant.hpp
+++ b/include/CommonAPI/Variant.hpp
@@ -516,6 +516,27 @@ struct TypeSelector<_Type> {
};
template<typename _Type, typename... _Types>
+struct TypeSelector<typename _Type::Literal, _Type, _Types...> {
+ typedef _Type type;
+};
+
+template<typename _Type, typename... _Types>
+struct TypeSelector<typename _Type::Literal &, _Type, _Types...> {
+ typedef _Type type;
+};
+
+
+template<typename _Type, typename... _Types>
+struct TypeSelector<typename _Type::Literal, const _Type&, _Types...> {
+ typedef _Type type;
+};
+
+template<typename _Type, typename... _Types>
+struct TypeSelector<const typename _Type::Literal &, _Type, _Types...> {
+ typedef _Type type;
+};
+
+template<typename _Type, typename... _Types>
struct TypeSelector<_Type, _Type, _Types...> {
typedef _Type type;
};