summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/CommonAPI/DBus/DBusAddress.hpp34
-rw-r--r--include/CommonAPI/DBus/DBusAddressTranslator.hpp52
-rw-r--r--include/CommonAPI/DBus/DBusAttribute.hpp120
-rw-r--r--include/CommonAPI/DBus/DBusClientId.hpp14
-rw-r--r--include/CommonAPI/DBus/DBusConnection.hpp187
-rw-r--r--include/CommonAPI/DBus/DBusDaemonProxy.hpp44
-rw-r--r--include/CommonAPI/DBus/DBusDeployment.hpp38
-rw-r--r--include/CommonAPI/DBus/DBusError.hpp16
-rw-r--r--include/CommonAPI/DBus/DBusEvent.hpp92
-rw-r--r--include/CommonAPI/DBus/DBusFactory.hpp100
-rw-r--r--include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp491
-rw-r--r--include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp2
-rw-r--r--include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp160
-rw-r--r--include/CommonAPI/DBus/DBusFreedesktopVariant.hpp65
-rw-r--r--include/CommonAPI/DBus/DBusFunctionalHash.hpp16
-rw-r--r--include/CommonAPI/DBus/DBusHelper.hpp32
-rw-r--r--include/CommonAPI/DBus/DBusInputStream.hpp508
-rw-r--r--include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp14
-rw-r--r--include/CommonAPI/DBus/DBusInterfaceHandler.hpp2
-rwxr-xr-xinclude/CommonAPI/DBus/DBusMainLoop.hpp185
-rw-r--r--include/CommonAPI/DBus/DBusMainLoopContext.hpp4
-rw-r--r--include/CommonAPI/DBus/DBusMessage.hpp4
-rw-r--r--include/CommonAPI/DBus/DBusMultiEvent.hpp122
-rw-r--r--include/CommonAPI/DBus/DBusObjectManager.hpp26
-rw-r--r--include/CommonAPI/DBus/DBusObjectManagerStub.hpp40
-rw-r--r--include/CommonAPI/DBus/DBusOutputStream.hpp435
-rw-r--r--include/CommonAPI/DBus/DBusProxy.hpp88
-rw-r--r--include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp95
-rw-r--r--include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp70
-rw-r--r--include/CommonAPI/DBus/DBusProxyBase.hpp40
-rw-r--r--include/CommonAPI/DBus/DBusProxyConnection.hpp14
-rw-r--r--include/CommonAPI/DBus/DBusProxyHelper.hpp223
-rw-r--r--include/CommonAPI/DBus/DBusProxyManager.hpp26
-rw-r--r--include/CommonAPI/DBus/DBusSelectiveEvent.hpp35
-rw-r--r--include/CommonAPI/DBus/DBusSerializableArguments.hpp10
-rw-r--r--include/CommonAPI/DBus/DBusServiceRegistry.hpp86
-rw-r--r--include/CommonAPI/DBus/DBusStubAdapter.hpp28
-rw-r--r--include/CommonAPI/DBus/DBusStubAdapterHelper.hpp433
-rw-r--r--include/CommonAPI/DBus/DBusTypeOutputStream.hpp137
-rw-r--r--include/CommonAPI/DBus/DBusTypes.hpp4
-rw-r--r--include/CommonAPI/DBus/DBusUtils.hpp8
41 files changed, 2212 insertions, 1888 deletions
diff --git a/include/CommonAPI/DBus/DBusAddress.hpp b/include/CommonAPI/DBus/DBusAddress.hpp
index 926b11b..448012c 100644
--- a/include/CommonAPI/DBus/DBusAddress.hpp
+++ b/include/CommonAPI/DBus/DBusAddress.hpp
@@ -20,29 +20,29 @@ namespace DBus {
class DBusAddress {
public:
- COMMONAPI_EXPORT DBusAddress(const std::string &_service = "",
- const std::string &_objectPath = "",
- const std::string &_interface = "");
- COMMONAPI_EXPORT DBusAddress(const DBusAddress &_source);
- COMMONAPI_EXPORT virtual ~DBusAddress();
+ COMMONAPI_EXPORT DBusAddress(const std::string &_service = "",
+ const std::string &_objectPath = "",
+ const std::string &_interface = "");
+ COMMONAPI_EXPORT DBusAddress(const DBusAddress &_source);
+ COMMONAPI_EXPORT virtual ~DBusAddress();
- COMMONAPI_EXPORT bool operator==(const DBusAddress &_other) const;
- COMMONAPI_EXPORT bool operator!=(const DBusAddress &_other) const;
- COMMONAPI_EXPORT bool operator<(const DBusAddress &_other) const;
+ COMMONAPI_EXPORT bool operator==(const DBusAddress &_other) const;
+ COMMONAPI_EXPORT bool operator!=(const DBusAddress &_other) const;
+ COMMONAPI_EXPORT bool operator<(const DBusAddress &_other) const;
- COMMONAPI_EXPORT const std::string &getInterface() const;
- COMMONAPI_EXPORT void setInterface(const std::string &_interface);
+ COMMONAPI_EXPORT const std::string &getInterface() const;
+ COMMONAPI_EXPORT void setInterface(const std::string &_interface);
- COMMONAPI_EXPORT const std::string &getObjectPath() const;
- COMMONAPI_EXPORT void setObjectPath(const std::string &_objectPath);
+ COMMONAPI_EXPORT const std::string &getObjectPath() const;
+ COMMONAPI_EXPORT void setObjectPath(const std::string &_objectPath);
- COMMONAPI_EXPORT const std::string &getService() const;
- COMMONAPI_EXPORT void setService(const std::string &_service);
+ COMMONAPI_EXPORT const std::string &getService() const;
+ COMMONAPI_EXPORT void setService(const std::string &_service);
private:
- std::string service_;
- std::string objectPath_;
- std::string interface_;
+ std::string service_;
+ std::string objectPath_;
+ std::string interface_;
friend std::ostream &operator<<(std::ostream &_out, const DBusAddress &_dbusAddress);
};
diff --git a/include/CommonAPI/DBus/DBusAddressTranslator.hpp b/include/CommonAPI/DBus/DBusAddressTranslator.hpp
index bbe1d75..ef95905 100644
--- a/include/CommonAPI/DBus/DBusAddressTranslator.hpp
+++ b/include/CommonAPI/DBus/DBusAddressTranslator.hpp
@@ -24,49 +24,49 @@ namespace DBus {
class DBusAddressTranslator {
public:
- COMMONAPI_EXPORT static std::shared_ptr<DBusAddressTranslator> get();
+ COMMONAPI_EXPORT static std::shared_ptr<DBusAddressTranslator> get();
- COMMONAPI_EXPORT DBusAddressTranslator();
+ COMMONAPI_EXPORT DBusAddressTranslator();
- COMMONAPI_EXPORT void init();
+ COMMONAPI_EXPORT void init();
- COMMONAPI_EXPORT bool translate(const std::string &_key, DBusAddress &_value);
- COMMONAPI_EXPORT bool translate(const CommonAPI::Address &_key, DBusAddress &_value);
+ COMMONAPI_EXPORT bool translate(const std::string &_key, DBusAddress &_value);
+ COMMONAPI_EXPORT bool translate(const CommonAPI::Address &_key, DBusAddress &_value);
- COMMONAPI_EXPORT bool translate(const DBusAddress &_key, std::string &_value);
- COMMONAPI_EXPORT bool translate(const DBusAddress &_key, CommonAPI::Address &_value);
+ COMMONAPI_EXPORT bool translate(const DBusAddress &_key, std::string &_value);
+ COMMONAPI_EXPORT bool translate(const DBusAddress &_key, CommonAPI::Address &_value);
- COMMONAPI_EXPORT void insert(const std::string &_address,
- const std::string &_service, const std::string &_path, const std::string &_interface, const bool _objPathStartWithDigits = false);
+ COMMONAPI_EXPORT void insert(const std::string &_address,
+ const std::string &_service, const std::string &_path, const std::string &_interface, const bool _objPathStartWithDigits = false);
- COMMONAPI_EXPORT DBusType_t getDBusBusType(const ConnectionId_t &_connectionId) const ;
+ COMMONAPI_EXPORT DBusType_t getDBusBusType(const ConnectionId_t &_connectionId) const ;
- /**
- * @brief Returns whether or not org.freedesktop.DBus.Peer interface is used in a (valid) name mapping.
- * @return true in case any (valid) mapping of org.freedesktop.DBus.Peer is present, otherwise false
- */
- COMMONAPI_EXPORT bool isOrgFreedesktopDBusPeerMapped() const;
+ /**
+ * @brief Returns whether or not org.freedesktop.DBus.Peer interface is used in a (valid) name mapping.
+ * @return true in case any (valid) mapping of org.freedesktop.DBus.Peer is present, otherwise false
+ */
+ COMMONAPI_EXPORT bool isOrgFreedesktopDBusPeerMapped() const;
private:
- COMMONAPI_EXPORT bool readConfiguration();
+ COMMONAPI_EXPORT bool readConfiguration();
- COMMONAPI_EXPORT bool isValid(const std::string &, const char,
- bool = false, bool = false, bool = false) const;
+ COMMONAPI_EXPORT bool isValid(const std::string &, const char,
+ bool = false, bool = false, bool = false) const;
private:
- bool isDefault_;
+ bool isDefault_;
- std::string defaultConfig_;
- std::string defaultDomain_;
+ std::string defaultConfig_;
+ std::string defaultDomain_;
- std::map<CommonAPI::Address, DBusAddress> forwards_;
- std::map<DBusAddress, CommonAPI::Address> backwards_;
+ std::map<CommonAPI::Address, DBusAddress> forwards_;
+ std::map<DBusAddress, CommonAPI::Address> backwards_;
- std::mutex mutex_;
+ std::mutex mutex_;
- std::map<ConnectionId_t, DBusType_t> dbusTypes_;
+ std::map<ConnectionId_t, DBusType_t> dbusTypes_;
- bool orgFreedesktopDBusPeerMapped_;
+ bool orgFreedesktopDBusPeerMapped_;
};
} // namespace DBus
diff --git a/include/CommonAPI/DBus/DBusAttribute.hpp b/include/CommonAPI/DBus/DBusAttribute.hpp
index 50dea3b..ba3ca77 100644
--- a/include/CommonAPI/DBus/DBusAttribute.hpp
+++ b/include/CommonAPI/DBus/DBusAttribute.hpp
@@ -21,67 +21,67 @@
namespace CommonAPI {
namespace DBus {
-template <typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
-class DBusReadonlyAttribute: public _AttributeType {
+template <typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
+class DBusReadonlyAttribute: public AttributeType_ {
public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef _AttributeDepl ValueTypeDepl;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
+ typedef typename AttributeType_::ValueType ValueType;
+ typedef AttributeDepl_ ValueTypeDepl;
+ typedef typename AttributeType_::AttributeAsyncCallback AttributeAsyncCallback;
DBusReadonlyAttribute(DBusProxy &_proxy,
- const char *setMethodSignature, const char *getMethodName,
- _AttributeDepl *_depl = nullptr)
- : proxy_(_proxy),
+ const char *setMethodSignature, const char *getMethodName,
+ AttributeDepl_ *_depl = nullptr)
+ : proxy_(_proxy),
getMethodName_(getMethodName),
setMethodSignature_(setMethodSignature),
- depl_(_depl) {
+ depl_(_depl) {
assert(getMethodName);
}
void getValue(CommonAPI::CallStatus &_status, ValueType &_value, const CommonAPI::CallInfo *_info) const {
- CommonAPI::Deployable<ValueType, _AttributeDepl> deployedValue(depl_);
+ CommonAPI::Deployable<ValueType, AttributeDepl_> deployedValue(depl_);
DBusProxyHelper<
- DBusSerializableArguments<
- >,
DBusSerializableArguments<
- CommonAPI::Deployable<
- ValueType,
- _AttributeDepl
- >
- >
+ >,
+ DBusSerializableArguments<
+ CommonAPI::Deployable<
+ ValueType,
+ AttributeDepl_
+ >
+ >
>::callMethodWithReply(proxy_, getMethodName_, "", (_info ? _info : &defaultCallInfo), _status, deployedValue);
_value = deployedValue.getValue();
}
std::future<CallStatus> getValueAsync(AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<ValueType, _AttributeDepl> deployedValue(depl_);
+ CommonAPI::Deployable<ValueType, AttributeDepl_> deployedValue(depl_);
return DBusProxyHelper<
- DBusSerializableArguments<>,
- DBusSerializableArguments<CommonAPI::Deployable<ValueType, _AttributeDepl>>
- >::callMethodAsync(proxy_, getMethodName_, "", (_info ? _info : &defaultCallInfo),
- [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable<ValueType, _AttributeDepl> _response) {
- _callback(_status, _response.getValue());
- },
- std::make_tuple(deployedValue));
+ DBusSerializableArguments<>,
+ DBusSerializableArguments<CommonAPI::Deployable<ValueType, AttributeDepl_>>
+ >::callMethodAsync(proxy_, getMethodName_, "", (_info ? _info : &defaultCallInfo),
+ [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable<ValueType, AttributeDepl_> _response) {
+ _callback(_status, _response.getValue());
+ },
+ std::make_tuple(deployedValue));
}
protected:
DBusProxy &proxy_;
const char *getMethodName_;
const char *setMethodSignature_;
- _AttributeDepl *depl_;
+ AttributeDepl_ *depl_;
};
-template <typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
-class DBusAttribute: public DBusReadonlyAttribute<_AttributeType, _AttributeDepl> {
+template <typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
+class DBusAttribute: public DBusReadonlyAttribute<AttributeType_, AttributeDepl_> {
public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
+ typedef typename AttributeType_::ValueType ValueType;
+ typedef typename AttributeType_::AttributeAsyncCallback AttributeAsyncCallback;
DBusAttribute(DBusProxy &_proxy,
- const char *_setMethodName, const char *_setMethodSignature, const char *_getMethodName,
- _AttributeDepl *_depl = nullptr)
- : DBusReadonlyAttribute<_AttributeType, _AttributeDepl>(_proxy, _setMethodSignature, _getMethodName, _depl),
+ const char *_setMethodName, const char *_setMethodSignature, const char *_getMethodName,
+ AttributeDepl_ *_depl = nullptr)
+ : DBusReadonlyAttribute<AttributeType_, AttributeDepl_>(_proxy, _setMethodSignature, _getMethodName, _depl),
setMethodName_(_setMethodName),
setMethodSignature_(_setMethodSignature) {
assert(_setMethodName);
@@ -89,34 +89,34 @@ public:
}
void setValue(const ValueType &_request, CommonAPI::CallStatus &_status, ValueType &_response, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<ValueType, _AttributeDepl> deployedRequest(_request, this->depl_);
- CommonAPI::Deployable<ValueType, _AttributeDepl> deployedResponse(this->depl_);
- DBusProxyHelper<DBusSerializableArguments<CommonAPI::Deployable<ValueType, _AttributeDepl>>,
- DBusSerializableArguments<CommonAPI::Deployable<ValueType, _AttributeDepl>> >::callMethodWithReply(
+ CommonAPI::Deployable<ValueType, AttributeDepl_> deployedRequest(_request, this->depl_);
+ CommonAPI::Deployable<ValueType, AttributeDepl_> deployedResponse(this->depl_);
+ DBusProxyHelper<DBusSerializableArguments<CommonAPI::Deployable<ValueType, AttributeDepl_>>,
+ DBusSerializableArguments<CommonAPI::Deployable<ValueType, AttributeDepl_>> >::callMethodWithReply(
this->proxy_,
setMethodName_,
setMethodSignature_,
- (_info ? _info : &defaultCallInfo),
+ (_info ? _info : &defaultCallInfo),
deployedRequest,
- _status,
+ _status,
deployedResponse);
- _response = deployedResponse.getValue();
+ _response = deployedResponse.getValue();
}
std::future<CallStatus> setValueAsync(const ValueType &_request, AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<ValueType, _AttributeDepl> deployedRequest(_request, this->depl_);
- CommonAPI::Deployable<ValueType, _AttributeDepl> deployedResponse(this->depl_);
- return DBusProxyHelper<DBusSerializableArguments<CommonAPI::Deployable<ValueType, _AttributeDepl>>,
- DBusSerializableArguments<CommonAPI::Deployable<ValueType, _AttributeDepl>> >::callMethodAsync(
+ CommonAPI::Deployable<ValueType, AttributeDepl_> deployedRequest(_request, this->depl_);
+ CommonAPI::Deployable<ValueType, AttributeDepl_> deployedResponse(this->depl_);
+ return DBusProxyHelper<DBusSerializableArguments<CommonAPI::Deployable<ValueType, AttributeDepl_>>,
+ DBusSerializableArguments<CommonAPI::Deployable<ValueType, AttributeDepl_>> >::callMethodAsync(
this->proxy_,
setMethodName_,
setMethodSignature_,
- (_info ? _info : &defaultCallInfo),
+ (_info ? _info : &defaultCallInfo),
deployedRequest,
- [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable<ValueType, _AttributeDepl> _response) {
- _callback(_status, _response.getValue());
- },
+ [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable<ValueType, AttributeDepl_> _response) {
+ _callback(_status, _response.getValue());
+ },
std::make_tuple(deployedResponse));
}
@@ -125,21 +125,21 @@ public:
const char* setMethodSignature_;
};
-template <typename _AttributeType>
-class DBusObservableAttribute: public _AttributeType {
+template <typename AttributeType_>
+class DBusObservableAttribute: public AttributeType_ {
public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef typename _AttributeType::ValueTypeDepl ValueTypeDepl;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
- typedef typename _AttributeType::ChangedEvent ChangedEvent;
+ typedef typename AttributeType_::ValueType ValueType;
+ typedef typename AttributeType_::ValueTypeDepl ValueTypeDepl;
+ typedef typename AttributeType_::AttributeAsyncCallback AttributeAsyncCallback;
+ typedef typename AttributeType_::ChangedEvent ChangedEvent;
- template <typename... _AttributeTypeArguments>
+ template <typename... AttributeType_Arguments>
DBusObservableAttribute(DBusProxy &_proxy,
- const char *_changedEventName,
- _AttributeTypeArguments... arguments)
- : _AttributeType(_proxy, arguments...),
- changedEvent_(_proxy, _changedEventName, this->setMethodSignature_, this->getMethodName_,
- std::make_tuple(CommonAPI::Deployable<ValueType, ValueTypeDepl>(this->depl_))) {
+ const char *_changedEventName,
+ AttributeType_Arguments... arguments)
+ : AttributeType_(_proxy, arguments...),
+ changedEvent_(_proxy, _changedEventName, this->setMethodSignature_, this->getMethodName_,
+ std::make_tuple(CommonAPI::Deployable<ValueType, ValueTypeDepl>(this->depl_))) {
}
ChangedEvent &getChangedEvent() {
diff --git a/include/CommonAPI/DBus/DBusClientId.hpp b/include/CommonAPI/DBus/DBusClientId.hpp
index 72dc1c5..02e369f 100644
--- a/include/CommonAPI/DBus/DBusClientId.hpp
+++ b/include/CommonAPI/DBus/DBusClientId.hpp
@@ -25,19 +25,19 @@ class DBusMessage;
* It internally uses a string to identify clients. This string is the unique sender id used by dbus.
*/
class DBusClientId
- : public CommonAPI::ClientId {
+ : public CommonAPI::ClientId {
friend struct std::hash<DBusClientId>;
public:
- COMMONAPI_EXPORT DBusClientId(std::string dbusId);
+ COMMONAPI_EXPORT DBusClientId(std::string dbusId);
- COMMONAPI_EXPORT bool operator==(CommonAPI::ClientId& clientIdToCompare);
- COMMONAPI_EXPORT bool operator==(DBusClientId& clientIdToCompare);
- COMMONAPI_EXPORT size_t hashCode();
+ COMMONAPI_EXPORT bool operator==(CommonAPI::ClientId& clientIdToCompare);
+ COMMONAPI_EXPORT bool operator==(DBusClientId& clientIdToCompare);
+ COMMONAPI_EXPORT size_t hashCode();
- COMMONAPI_EXPORT const char * getDBusId();
+ COMMONAPI_EXPORT const char * getDBusId();
- COMMONAPI_EXPORT DBusMessage createMessage(const std::string objectPath, const std::string interfaceName, const std::string signalName) const;
+ COMMONAPI_EXPORT DBusMessage createMessage(const std::string objectPath, const std::string interfaceName, const std::string signalName) const;
protected:
std::string dbusId_;
};
diff --git a/include/CommonAPI/DBus/DBusConnection.hpp b/include/CommonAPI/DBus/DBusConnection.hpp
index 97cb069..e3608da 100644
--- a/include/CommonAPI/DBus/DBusConnection.hpp
+++ b/include/CommonAPI/DBus/DBusConnection.hpp
@@ -11,11 +11,13 @@
#define COMMONAPI_DBUS_DBUS_CONNECTION_HPP_
#include <atomic>
+#include <mutex>
#include <dbus/dbus.h>
#include <CommonAPI/DBus/DBusConfig.hpp>
#include <CommonAPI/DBus/DBusDaemonProxy.hpp>
+#include <CommonAPI/DBus/DBusMainLoop.hpp>
#include <CommonAPI/DBus/DBusMainLoopContext.hpp>
#include <CommonAPI/DBus/DBusObjectManager.hpp>
#include <CommonAPI/DBus/DBusProxyConnection.hpp>
@@ -24,10 +26,11 @@
namespace CommonAPI {
namespace DBus {
+class DBusMainLoop;
class DBusObjectManager;
class DBusConnectionStatusEvent
- : public DBusProxyConnection::ConnectionStatusEvent {
+ : public DBusProxyConnection::ConnectionStatusEvent {
public:
DBusConnectionStatusEvent(DBusConnection* dbusConnection);
virtual ~DBusConnectionStatusEvent() {}
@@ -51,56 +54,56 @@ struct WatchContext {
};
class DBusConnection
- : public DBusProxyConnection,
- public std::enable_shared_from_this<DBusConnection> {
+ : public DBusProxyConnection,
+ public std::enable_shared_from_this<DBusConnection> {
public:
- COMMONAPI_EXPORT static std::shared_ptr<DBusConnection> getBus(const DBusType_t &_type);
- COMMONAPI_EXPORT static std::shared_ptr<DBusConnection> wrap(::DBusConnection *_connection);
+ COMMONAPI_EXPORT static std::shared_ptr<DBusConnection> getBus(const DBusType_t &_type);
+ COMMONAPI_EXPORT static std::shared_ptr<DBusConnection> wrap(::DBusConnection *_connection);
- COMMONAPI_EXPORT DBusConnection(DBusType_t _type);
- COMMONAPI_EXPORT DBusConnection(const DBusConnection&) = delete;
- COMMONAPI_EXPORT DBusConnection(::DBusConnection* libDbusConnection);
- COMMONAPI_EXPORT virtual ~DBusConnection();
+ COMMONAPI_EXPORT DBusConnection(DBusType_t _type);
+ COMMONAPI_EXPORT DBusConnection(const DBusConnection&) = delete;
+ COMMONAPI_EXPORT DBusConnection(::DBusConnection* libDbusConnection);
+ COMMONAPI_EXPORT virtual ~DBusConnection();
- COMMONAPI_EXPORT DBusConnection& operator=(const DBusConnection&) = delete;
+ COMMONAPI_EXPORT DBusConnection& operator=(const DBusConnection&) = delete;
- COMMONAPI_EXPORT DBusType_t getBusType() const;
+ COMMONAPI_EXPORT DBusType_t getBusType() const;
- COMMONAPI_EXPORT bool connect(bool startDispatchThread = true);
- COMMONAPI_EXPORT bool connect(DBusError& dbusError, bool startDispatchThread = true);
- COMMONAPI_EXPORT void disconnect();
+ COMMONAPI_EXPORT bool connect(bool startDispatchThread = true);
+ COMMONAPI_EXPORT bool connect(DBusError& dbusError, bool startDispatchThread = true);
+ COMMONAPI_EXPORT void disconnect();
- COMMONAPI_EXPORT virtual bool isConnected() const;
+ COMMONAPI_EXPORT virtual bool isConnected() const;
- COMMONAPI_EXPORT virtual ConnectionStatusEvent& getConnectionStatusEvent();
+ COMMONAPI_EXPORT virtual ConnectionStatusEvent& getConnectionStatusEvent();
- COMMONAPI_EXPORT virtual bool requestServiceNameAndBlock(const std::string& serviceName) const;
- COMMONAPI_EXPORT virtual bool releaseServiceName(const std::string& serviceName) const;
+ COMMONAPI_EXPORT virtual bool requestServiceNameAndBlock(const std::string& serviceName) const;
+ COMMONAPI_EXPORT virtual bool releaseServiceName(const std::string& serviceName) const;
- COMMONAPI_EXPORT bool sendDBusMessage(const DBusMessage& dbusMessage/*, uint32_t* allocatedSerial = NULL*/) const;
+ COMMONAPI_EXPORT bool sendDBusMessage(const DBusMessage& dbusMessage/*, uint32_t* allocatedSerial = NULL*/) const;
- COMMONAPI_EXPORT std::future<CallStatus> sendDBusMessageWithReplyAsync(
+ COMMONAPI_EXPORT std::future<CallStatus> sendDBusMessageWithReplyAsync(
const DBusMessage& dbusMessage,
std::unique_ptr<DBusMessageReplyAsyncHandler> dbusMessageReplyAsyncHandler,
- const CommonAPI::CallInfo *_info) const;
+ const CommonAPI::CallInfo *_info) const;
- COMMONAPI_EXPORT DBusMessage sendDBusMessageWithReplyAndBlock(const DBusMessage& dbusMessage,
+ COMMONAPI_EXPORT DBusMessage sendDBusMessageWithReplyAndBlock(const DBusMessage& dbusMessage,
DBusError& dbusError,
- const CommonAPI::CallInfo *_info) const;
+ const CommonAPI::CallInfo *_info) const;
- COMMONAPI_EXPORT virtual bool addObjectManagerSignalMemberHandler(const std::string& dbusBusName,
+ COMMONAPI_EXPORT virtual bool addObjectManagerSignalMemberHandler(const std::string& dbusBusName,
DBusSignalHandler* dbusSignalHandler);
- COMMONAPI_EXPORT virtual bool removeObjectManagerSignalMemberHandler(const std::string& dbusBusName,
+ COMMONAPI_EXPORT virtual bool removeObjectManagerSignalMemberHandler(const std::string& dbusBusName,
DBusSignalHandler* dbusSignalHandler);
- COMMONAPI_EXPORT DBusSignalHandlerToken addSignalMemberHandler(const std::string& objectPath,
+ COMMONAPI_EXPORT DBusSignalHandlerToken addSignalMemberHandler(const std::string& objectPath,
const std::string& interfaceName,
const std::string& interfaceMemberName,
const std::string& inuint32_tterfaceMemberSignature,
DBusSignalHandler* dbusSignalHandler,
const bool justAddFilter = false);
- COMMONAPI_EXPORT DBusProxyConnection::DBusSignalHandlerToken subscribeForSelectiveBroadcast(bool& subscriptionAccepted,
+ COMMONAPI_EXPORT DBusProxyConnection::DBusSignalHandlerToken subscribeForSelectiveBroadcast(bool& subscriptionAccepted,
const std::string& objectPath,
const std::string& interfaceName,
const std::string& interfaceMemberName,
@@ -108,37 +111,41 @@ public:
DBusSignalHandler* dbusSignalHandler,
DBusProxy* callingProxy);
- COMMONAPI_EXPORT void unsubscribeFromSelectiveBroadcast(const std::string& eventName,
+ COMMONAPI_EXPORT void unsubscribeFromSelectiveBroadcast(const std::string& eventName,
DBusProxyConnection::DBusSignalHandlerToken subscription,
DBusProxy* callingProxy,
const DBusSignalHandler* dbusSignalHandler);
- COMMONAPI_EXPORT void registerObjectPath(const std::string& objectPath);
- COMMONAPI_EXPORT void unregisterObjectPath(const std::string& objectPath);
+ COMMONAPI_EXPORT void registerObjectPath(const std::string& objectPath);
+ COMMONAPI_EXPORT void unregisterObjectPath(const std::string& objectPath);
- COMMONAPI_EXPORT bool removeSignalMemberHandler(const DBusSignalHandlerToken& dbusSignalHandlerToken,
+ COMMONAPI_EXPORT bool removeSignalMemberHandler(const DBusSignalHandlerToken& dbusSignalHandlerToken,
const DBusSignalHandler* dbusSignalHandler = NULL);
- COMMONAPI_EXPORT bool readWriteDispatch(int timeoutMilliseconds = -1);
+ COMMONAPI_EXPORT bool readWriteDispatch(int timeoutMilliseconds = -1);
- COMMONAPI_EXPORT virtual const std::shared_ptr<DBusObjectManager> getDBusObjectManager();
+ COMMONAPI_EXPORT virtual const std::shared_ptr<DBusObjectManager> getDBusObjectManager();
- COMMONAPI_EXPORT void setObjectPathMessageHandler(DBusObjectPathMessageHandler);
- COMMONAPI_EXPORT bool isObjectPathMessageHandlerSet();
+ COMMONAPI_EXPORT void setObjectPathMessageHandler(DBusObjectPathMessageHandler);
+ COMMONAPI_EXPORT bool isObjectPathMessageHandlerSet();
- COMMONAPI_EXPORT virtual bool attachMainLoopContext(std::weak_ptr<MainLoopContext>);
+ COMMONAPI_EXPORT virtual bool attachMainLoopContext(std::weak_ptr<MainLoopContext>);
- COMMONAPI_EXPORT bool isDispatchReady();
- COMMONAPI_EXPORT bool singleDispatch();
+ COMMONAPI_EXPORT bool isDispatchReady();
+ COMMONAPI_EXPORT bool singleDispatch();
- COMMONAPI_EXPORT virtual bool hasDispatchThread();
+ COMMONAPI_EXPORT virtual bool hasDispatchThread();
- typedef std::tuple<std::string, std::string, std::string> DBusSignalMatchRuleTuple;
- typedef std::pair<uint32_t, std::string> DBusSignalMatchRuleMapping;
- typedef std::unordered_map<DBusSignalMatchRuleTuple, DBusSignalMatchRuleMapping> DBusSignalMatchRulesMap;
+#ifdef COMMONAPI_DBUS_TEST
+ inline std::weak_ptr<DBusMainloop> getLoop() { return loop_; }
+#endif
+
+ typedef std::tuple<std::string, std::string, std::string> DBusSignalMatchRuleTuple;
+ typedef std::pair<uint32_t, std::string> DBusSignalMatchRuleMapping;
+ typedef std::unordered_map<DBusSignalMatchRuleTuple, DBusSignalMatchRuleMapping> DBusSignalMatchRulesMap;
private:
- COMMONAPI_EXPORT void dispatch();
- COMMONAPI_EXPORT void suspendDispatching() const;
- COMMONAPI_EXPORT void resumeDispatching() const;
+ COMMONAPI_EXPORT void dispatch();
+ COMMONAPI_EXPORT void suspendDispatching() const;
+ COMMONAPI_EXPORT void resumeDispatching() const;
std::thread* dispatchThread_;
bool stopDispatching_;
@@ -151,46 +158,46 @@ public:
mutable bool pauseDispatching_;
mutable std::mutex dispatchSuspendLock_;
- COMMONAPI_EXPORT void addLibdbusSignalMatchRule(const std::string& objectPath,
+ COMMONAPI_EXPORT void addLibdbusSignalMatchRule(const std::string& objectPath,
const std::string& interfaceName,
const std::string& interfaceMemberName,
const bool justAddFilter = false);
- COMMONAPI_EXPORT void removeLibdbusSignalMatchRule(const std::string& objectPath,
+ COMMONAPI_EXPORT void removeLibdbusSignalMatchRule(const std::string& objectPath,
const std::string& interfaceName,
const std::string& interfaceMemberName);
- COMMONAPI_EXPORT void initLibdbusSignalFilterAfterConnect();
+ COMMONAPI_EXPORT void initLibdbusSignalFilterAfterConnect();
::DBusHandlerResult onLibdbusSignalFilter(::DBusMessage* libdbusMessage);
- COMMONAPI_EXPORT void initLibdbusObjectPathHandlerAfterConnect();
+ COMMONAPI_EXPORT void initLibdbusObjectPathHandlerAfterConnect();
::DBusHandlerResult onLibdbusObjectPathMessage(::DBusMessage* libdbusMessage);
COMMONAPI_EXPORT static DBusMessage convertToDBusMessage(::DBusPendingCall* _libdbusPendingCall,
- CallStatus& _callStatus);
- COMMONAPI_EXPORT static void onLibdbusPendingCallNotifyThunk(::DBusPendingCall* libdbusPendingCall, void* userData);
- COMMONAPI_EXPORT static void onLibdbusDataCleanup(void* userData);
+ CallStatus& _callStatus);
+ COMMONAPI_EXPORT static void onLibdbusPendingCallNotifyThunk(::DBusPendingCall* libdbusPendingCall, void* userData);
+ COMMONAPI_EXPORT static void onLibdbusDataCleanup(void* userData);
- COMMONAPI_EXPORT static ::DBusHandlerResult onLibdbusObjectPathMessageThunk(::DBusConnection* libdbusConnection,
+ COMMONAPI_EXPORT static ::DBusHandlerResult onLibdbusObjectPathMessageThunk(::DBusConnection* libdbusConnection,
::DBusMessage* libdbusMessage,
void* userData);
- COMMONAPI_EXPORT static ::DBusHandlerResult onLibdbusSignalFilterThunk(::DBusConnection* libdbusConnection,
+ COMMONAPI_EXPORT static ::DBusHandlerResult onLibdbusSignalFilterThunk(::DBusConnection* libdbusConnection,
::DBusMessage* libdbusMessage,
void* userData);
- COMMONAPI_EXPORT static dbus_bool_t onAddWatch(::DBusWatch* libdbusWatch, void* data);
- COMMONAPI_EXPORT static void onRemoveWatch(::DBusWatch* libdbusWatch, void* data);
- COMMONAPI_EXPORT static void onToggleWatch(::DBusWatch* libdbusWatch, void* data);
+ COMMONAPI_EXPORT static dbus_bool_t onAddWatch(::DBusWatch* libdbusWatch, void* data);
+ COMMONAPI_EXPORT static void onRemoveWatch(::DBusWatch* libdbusWatch, void* data);
+ COMMONAPI_EXPORT static void onToggleWatch(::DBusWatch* libdbusWatch, void* data);
- COMMONAPI_EXPORT static dbus_bool_t onAddTimeout(::DBusTimeout* dbus_timeout, void* data);
- COMMONAPI_EXPORT static void onRemoveTimeout(::DBusTimeout* dbus_timeout, void* data);
- COMMONAPI_EXPORT static void onToggleTimeout(::DBusTimeout* dbus_timeout, void* data);
+ COMMONAPI_EXPORT static dbus_bool_t onAddTimeout(::DBusTimeout* dbus_timeout, void* data);
+ COMMONAPI_EXPORT static void onRemoveTimeout(::DBusTimeout* dbus_timeout, void* data);
+ COMMONAPI_EXPORT static void onToggleTimeout(::DBusTimeout* dbus_timeout, void* data);
- COMMONAPI_EXPORT static void onWakeupMainContext(void* data);
+ COMMONAPI_EXPORT static void onWakeupMainContext(void* data);
- COMMONAPI_EXPORT void enforceAsynchronousTimeouts() const;
- COMMONAPI_EXPORT static const DBusObjectPathVTable* getDBusObjectPathVTable();
+ COMMONAPI_EXPORT void enforceAsynchronousTimeouts() const;
+ COMMONAPI_EXPORT static const DBusObjectPathVTable* getDBusObjectPathVTable();
::DBusConnection* connection_;
mutable std::mutex connectionGuard_;
@@ -213,11 +220,11 @@ public:
std::unordered_multimap<std::string, DBusSignalHandler*> dbusObjectManagerSignalHandlerTable_;
std::mutex dbusObjectManagerSignalGuard_;
- COMMONAPI_EXPORT bool addObjectManagerSignalMatchRule(const std::string& dbusBusName);
- COMMONAPI_EXPORT bool removeObjectManagerSignalMatchRule(const std::string& dbusBusName);
+ COMMONAPI_EXPORT bool addObjectManagerSignalMatchRule(const std::string& dbusBusName);
+ COMMONAPI_EXPORT bool removeObjectManagerSignalMatchRule(const std::string& dbusBusName);
- COMMONAPI_EXPORT bool addLibdbusSignalMatchRule(const std::string& dbusMatchRule);
- COMMONAPI_EXPORT bool removeLibdbusSignalMatchRule(const std::string& dbusMatchRule);
+ COMMONAPI_EXPORT bool addLibdbusSignalMatchRule(const std::string& dbusMatchRule);
+ COMMONAPI_EXPORT bool removeLibdbusSignalMatchRule(const std::string& dbusMatchRule);
std::atomic_size_t libdbusSignalMatchRulesCount_;
@@ -230,29 +237,30 @@ public:
mutable std::unordered_map<std::string, uint16_t> connectionNameCount_;
typedef std::pair<
- DBusPendingCall*,
- std::tuple<
- std::chrono::time_point<std::chrono::high_resolution_clock>,
- DBusMessageReplyAsyncHandler*,
- DBusMessage
- >
- > TimeoutMapElement;
+ DBusPendingCall*,
+ std::tuple<
+ std::chrono::time_point<std::chrono::high_resolution_clock>,
+ DBusMessageReplyAsyncHandler*,
+ DBusMessage
+ >
+ > TimeoutMapElement;
mutable std::map<
- DBusPendingCall*,
- std::tuple<
- std::chrono::time_point<std::chrono::high_resolution_clock>,
- DBusMessageReplyAsyncHandler*,
- DBusMessage
- >
- > timeoutMap_;
+ DBusPendingCall*,
+ std::tuple<
+ std::chrono::time_point<std::chrono::high_resolution_clock>,
+ DBusMessageReplyAsyncHandler*,
+ DBusMessage
+ >
+ > timeoutMap_;
typedef std::tuple<
- DBusMessageReplyAsyncHandler *,
- DBusMessage,
- CommonAPI::CallStatus,
- ::DBusPendingCall*
- > MainloopTimeout_t;
+ DBusMessageReplyAsyncHandler *,
+ DBusMessage,
+ CommonAPI::CallStatus,
+ ::DBusPendingCall*
+ > MainloopTimeout_t;
mutable std::list<MainloopTimeout_t> mainloopTimeouts_;
+ mutable std::mutex mainloopTimeoutsMutex_;
mutable std::mutex enforceTimeoutMutex_;
mutable std::condition_variable enforceTimeoutCondition_;
@@ -260,6 +268,13 @@ public:
mutable std::shared_ptr<std::thread> enforcerThread_;
mutable std::mutex enforcerThreadMutex_;
bool enforcerThreadCancelled_;
+
+ std::shared_ptr<DBusMainLoop> loop_;
+
+ // set contains asyncHandlers with infinite timeout
+ mutable std::set<DBusMessageReplyAsyncHandler*> timeoutInfiniteAsyncHandlers_;
+ mutable std::mutex timeoutInfiniteAsyncHandlersMutex_;
+
};
diff --git a/include/CommonAPI/DBus/DBusDaemonProxy.hpp b/include/CommonAPI/DBus/DBusDaemonProxy.hpp
index 1333548..69541b6 100644
--- a/include/CommonAPI/DBus/DBusDaemonProxy.hpp
+++ b/include/CommonAPI/DBus/DBusDaemonProxy.hpp
@@ -37,40 +37,40 @@ class StaticInterfaceVersionAttribute: public InterfaceVersionAttribute {
class DBusDaemonProxy : public DBusProxyBase {
public:
- typedef Event<std::string, std::string, std::string> NameOwnerChangedEvent;
+ typedef Event<std::string, std::string, std::string> NameOwnerChangedEvent;
- typedef std::unordered_map<std::string, int> PropertyDictStub;
- typedef std::unordered_map<std::string, PropertyDictStub> InterfaceToPropertyDict;
- typedef std::unordered_map<std::string, InterfaceToPropertyDict> DBusObjectToInterfaceDict;
+ typedef std::unordered_map<std::string, int> PropertyDictStub;
+ typedef std::unordered_map<std::string, PropertyDictStub> InterfaceToPropertyDict;
+ typedef std::unordered_map<std::string, InterfaceToPropertyDict> DBusObjectToInterfaceDict;
- typedef std::function<void(const CommonAPI::CallStatus&, std::vector<std::string>)> ListNamesAsyncCallback;
- typedef std::function<void(const CommonAPI::CallStatus&, bool)> NameHasOwnerAsyncCallback;
- typedef std::function<void(const CommonAPI::CallStatus&, DBusObjectToInterfaceDict)> GetManagedObjectsAsyncCallback;
- typedef std::function<void(const CommonAPI::CallStatus&, std::string)> GetNameOwnerAsyncCallback;
+ typedef std::function<void(const CommonAPI::CallStatus&, std::vector<std::string>)> ListNamesAsyncCallback;
+ typedef std::function<void(const CommonAPI::CallStatus&, bool)> NameHasOwnerAsyncCallback;
+ typedef std::function<void(const CommonAPI::CallStatus&, DBusObjectToInterfaceDict)> GetManagedObjectsAsyncCallback;
+ typedef std::function<void(const CommonAPI::CallStatus&, std::string)> GetNameOwnerAsyncCallback;
- COMMONAPI_EXPORT DBusDaemonProxy(const std::shared_ptr<DBusProxyConnection>& dbusConnection);
- COMMONAPI_EXPORT virtual ~DBusDaemonProxy() {}
+ COMMONAPI_EXPORT DBusDaemonProxy(const std::shared_ptr<DBusProxyConnection>& dbusConnection);
+ COMMONAPI_EXPORT virtual ~DBusDaemonProxy() {}
- COMMONAPI_EXPORT virtual bool isAvailable() const;
- COMMONAPI_EXPORT virtual bool isAvailableBlocking() const;
- COMMONAPI_EXPORT virtual ProxyStatusEvent& getProxyStatusEvent();
+ COMMONAPI_EXPORT virtual bool isAvailable() const;
+ COMMONAPI_EXPORT virtual bool isAvailableBlocking() const;
+ COMMONAPI_EXPORT virtual ProxyStatusEvent& getProxyStatusEvent();
- COMMONAPI_EXPORT virtual InterfaceVersionAttribute& getInterfaceVersionAttribute();
+ COMMONAPI_EXPORT virtual InterfaceVersionAttribute& getInterfaceVersionAttribute();
- COMMONAPI_EXPORT void init();
+ COMMONAPI_EXPORT void init();
- COMMONAPI_EXPORT static const char* getInterfaceId();
+ COMMONAPI_EXPORT static const char* getInterfaceId();
- COMMONAPI_EXPORT NameOwnerChangedEvent& getNameOwnerChangedEvent();
+ COMMONAPI_EXPORT NameOwnerChangedEvent& getNameOwnerChangedEvent();
- COMMONAPI_EXPORT void listNames(CommonAPI::CallStatus& callStatus, std::vector<std::string>& busNames) const;
- COMMONAPI_EXPORT std::future<CallStatus> listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const;
+ COMMONAPI_EXPORT void listNames(CommonAPI::CallStatus& callStatus, std::vector<std::string>& busNames) const;
+ COMMONAPI_EXPORT std::future<CallStatus> listNamesAsync(ListNamesAsyncCallback listNamesAsyncCallback) const;
- COMMONAPI_EXPORT void nameHasOwner(const std::string& busName, CommonAPI::CallStatus& callStatus, bool& hasOwner) const;
- COMMONAPI_EXPORT std::future<CallStatus> nameHasOwnerAsync(const std::string& busName,
+ COMMONAPI_EXPORT void nameHasOwner(const std::string& busName, CommonAPI::CallStatus& callStatus, bool& hasOwner) const;
+ COMMONAPI_EXPORT std::future<CallStatus> nameHasOwnerAsync(const std::string& busName,
NameHasOwnerAsyncCallback nameHasOwnerAsyncCallback) const;
- COMMONAPI_EXPORT std::future<CallStatus> getManagedObjectsAsync(const std::string& forDBusServiceName,
+ COMMONAPI_EXPORT std::future<CallStatus> getManagedObjectsAsync(const std::string& forDBusServiceName,
GetManagedObjectsAsyncCallback) const;
/**
diff --git a/include/CommonAPI/DBus/DBusDeployment.hpp b/include/CommonAPI/DBus/DBusDeployment.hpp
index dce9d21..c6ce15c 100644
--- a/include/CommonAPI/DBus/DBusDeployment.hpp
+++ b/include/CommonAPI/DBus/DBusDeployment.hpp
@@ -19,34 +19,32 @@
namespace CommonAPI {
namespace DBus {
-template<typename... _Types>
-struct VariantDeployment : CommonAPI::Deployment<_Types...> {
- VariantDeployment(bool _isDBus, _Types*... _t)
- : CommonAPI::Deployment<_Types...>(_t...),
- isDBus_(_isDBus) {};
-
- bool isDBus_;
+template<typename... Types_>
+struct VariantDeployment : CommonAPI::Deployment<Types_...> {
+ static const size_t size_ = std::tuple_size<std::tuple<Types_...>>::value;
+ VariantDeployment(bool _isDBus, Types_*... _t)
+ : CommonAPI::Deployment<Types_...>(_t...),
+ isDBus_(_isDBus) {};
+ bool isDBus_;
};
-extern COMMONAPI_IMPORT_EXPORT VariantDeployment<> freedesktopVariant;
-
struct StringDeployment : CommonAPI::Deployment<> {
- StringDeployment(bool _isObjectPath)
- : isObjectPath_(_isObjectPath) {};
+ StringDeployment(bool _isObjectPath)
+ : isObjectPath_(_isObjectPath) {};
- bool isObjectPath_;
+ bool isObjectPath_;
};
-template<typename... _Types>
-struct StructDeployment : CommonAPI::Deployment<_Types...> {
- StructDeployment(_Types*... t)
- : CommonAPI::Deployment<_Types...>(t...) {};
+template<typename... Types_>
+struct StructDeployment : CommonAPI::Deployment<Types_...> {
+ StructDeployment(Types_*... t)
+ : CommonAPI::Deployment<Types_...>(t...) {};
};
-template<typename _ElementDepl>
-struct ArrayDeployment : CommonAPI::ArrayDeployment<_ElementDepl> {
- ArrayDeployment(_ElementDepl *_element)
- : CommonAPI::ArrayDeployment<_ElementDepl>(_element) {}
+template<typename ElementDepl_>
+struct ArrayDeployment : CommonAPI::ArrayDeployment<ElementDepl_> {
+ ArrayDeployment(ElementDepl_ *_element)
+ : CommonAPI::ArrayDeployment<ElementDepl_>(_element) {}
};
} // namespace DBus
diff --git a/include/CommonAPI/DBus/DBusError.hpp b/include/CommonAPI/DBus/DBusError.hpp
index 6e8f170..bd3a636 100644
--- a/include/CommonAPI/DBus/DBusError.hpp
+++ b/include/CommonAPI/DBus/DBusError.hpp
@@ -23,20 +23,20 @@ class DBusConnection;
class COMMONAPI_EXPORT DBusError {
public:
- DBusError();
- ~DBusError();
+ DBusError();
+ ~DBusError();
- operator bool() const;
+ operator bool() const;
- void clear();
+ void clear();
- std::string getName() const;
- std::string getMessage() const;
+ std::string getName() const;
+ std::string getMessage() const;
private:
- ::DBusError libdbusError_;
+ ::DBusError libdbusError_;
- friend class DBusConnection;
+ friend class DBusConnection;
};
} // namespace DBus
diff --git a/include/CommonAPI/DBus/DBusEvent.hpp b/include/CommonAPI/DBus/DBusEvent.hpp
index 3ce945c..550f4da 100644
--- a/include/CommonAPI/DBus/DBusEvent.hpp
+++ b/include/CommonAPI/DBus/DBusEvent.hpp
@@ -21,18 +21,18 @@
namespace CommonAPI {
namespace DBus {
-template <typename _Event, typename... _Arguments>
-class DBusEvent: public _Event, public DBusProxyConnection::DBusSignalHandler {
+template <typename Event_, typename... Arguments_>
+class DBusEvent: public Event_, public DBusProxyConnection::DBusSignalHandler {
public:
- typedef typename _Event::Subscription Subscription;
- typedef typename _Event::Listener Listener;
+ typedef typename Event_::Subscription Subscription;
+ typedef typename Event_::Listener Listener;
DBusEvent(DBusProxyBase &_proxy,
- const std::string &_name, const std::string &_signature,
- std::tuple<_Arguments...> _arguments)
- : proxy_(_proxy),
+ const std::string &_name, const std::string &_signature,
+ std::tuple<Arguments_...> _arguments)
+ : proxy_(_proxy),
name_(_name), signature_(_signature),
- getMethodName_(""),
+ getMethodName_(""),
arguments_(_arguments) {
interface_ = proxy_.getDBusAddress().getInterface();
@@ -40,53 +40,55 @@ public:
}
DBusEvent(DBusProxyBase &_proxy,
- const std::string &_name, const std::string &_signature,
- const std::string &_path, const std::string &_interface,
- std::tuple<_Arguments...> _arguments)
- : proxy_(_proxy),
+ const std::string &_name, const std::string &_signature,
+ const std::string &_path, const std::string &_interface,
+ std::tuple<Arguments_...> _arguments)
+ : proxy_(_proxy),
name_(_name), signature_(_signature),
path_(_path), interface_(_interface),
- getMethodName_(""),
+ getMethodName_(""),
arguments_(_arguments) {
}
DBusEvent(DBusProxyBase &_proxy,
- const std::string &_name,
- const std::string &_signature,
- const std::string &_getMethodName,
- std::tuple<_Arguments...> _arguments)
- : proxy_(_proxy),
- name_(_name),
- signature_(_signature),
- getMethodName_(_getMethodName),
- arguments_(_arguments) {
-
- interface_ = proxy_.getDBusAddress().getInterface();
- path_ = proxy_.getDBusAddress().getObjectPath();
- }
+ const std::string &_name,
+ const std::string &_signature,
+ const std::string &_getMethodName,
+ std::tuple<Arguments_...> _arguments)
+ : proxy_(_proxy),
+ name_(_name),
+ signature_(_signature),
+ getMethodName_(_getMethodName),
+ arguments_(_arguments) {
+
+ interface_ = proxy_.getDBusAddress().getInterface();
+ path_ = proxy_.getDBusAddress().getObjectPath();
+ }
virtual ~DBusEvent() {
proxy_.removeSignalMemberHandler(subscription_, this);
}
virtual void onSignalDBusMessage(const DBusMessage &_message) {
- handleSignalDBusMessage(_message, typename make_sequence<sizeof...(_Arguments)>::type());
+ handleSignalDBusMessage(_message, typename make_sequence<sizeof...(Arguments_)>::type());
}
virtual void onInitialValueSignalDBusMessage(const DBusMessage&_message, const uint32_t tag) {
- handleSignalDBusMessage(tag, _message, typename make_sequence<sizeof...(_Arguments)>::type());
+ handleSignalDBusMessage(tag, _message, typename make_sequence<sizeof...(Arguments_)>::type());
}
protected:
- virtual void onFirstListenerAdded(const Listener& listener) {
- subscription_ = proxy_.addSignalMemberHandler(
+ virtual void onFirstListenerAdded(const Listener &_listener) {
+ (void)_listener;
+ subscription_ = proxy_.addSignalMemberHandler(
path_, interface_, name_, signature_, getMethodName_, this, false);
}
- virtual void onListenerAdded(const Listener& listener, const Subscription subscription) {
- if ("" != getMethodName_) {
- proxy_.getCurrentValueForSignalListener(getMethodName_, this, subscription);
- }
+ virtual void onListenerAdded(const Listener &_listener, const Subscription subscription) {
+ (void)_listener;
+ if ("" != getMethodName_) {
+ proxy_.getCurrentValueForSignalListener(getMethodName_, this, subscription);
+ }
}
virtual void onLastListenerRemoved(const Listener&) {
@@ -97,23 +99,23 @@ public:
std::get<3>(subscription_) = "";
}
- template<int ... _Indices>
- inline void handleSignalDBusMessage(const DBusMessage &_message, index_sequence<_Indices...>) {
+ template<int ... Indices_>
+ inline void handleSignalDBusMessage(const DBusMessage &_message, index_sequence<Indices_...>) {
DBusInputStream input(_message);
if (DBusSerializableArguments<
- _Arguments...
- >::deserialize(input, std::get<_Indices>(arguments_)...)) {
- this->notifyListeners(std::get<_Indices>(arguments_)...);
+ Arguments_...
+ >::deserialize(input, std::get<Indices_>(arguments_)...)) {
+ this->notifyListeners(std::get<Indices_>(arguments_)...);
}
}
- template<int ... _Indices>
- inline void handleSignalDBusMessage(const uint32_t tag, const DBusMessage &_message, index_sequence<_Indices...>) {
+ template<int ... Indices_>
+ inline void handleSignalDBusMessage(const uint32_t tag, const DBusMessage &_message, index_sequence<Indices_...>) {
DBusInputStream input(_message);
if (DBusSerializableArguments<
- _Arguments...
- >::deserialize(input, std::get<_Indices>(arguments_)...)) {
- this->notifySpecificListener(tag, std::get<_Indices>(arguments_)...);
+ Arguments_...
+ >::deserialize(input, std::get<Indices_>(arguments_)...)) {
+ this->notifySpecificListener(tag, std::get<Indices_>(arguments_)...);
}
}
@@ -126,7 +128,7 @@ public:
std::string getMethodName_;
DBusProxyConnection::DBusSignalHandlerToken subscription_;
- std::tuple<_Arguments...> arguments_;
+ std::tuple<Arguments_...> arguments_;
};
} // namespace DBus
diff --git a/include/CommonAPI/DBus/DBusFactory.hpp b/include/CommonAPI/DBus/DBusFactory.hpp
index 644e035..fda0129 100644
--- a/include/CommonAPI/DBus/DBusFactory.hpp
+++ b/include/CommonAPI/DBus/DBusFactory.hpp
@@ -26,79 +26,79 @@ class DBusStubAdapter;
typedef std::shared_ptr<DBusProxy>
(*ProxyCreateFunction)(const DBusAddress &_address,
- const std::shared_ptr<DBusProxyConnection> &_connection);
+ const std::shared_ptr<DBusProxyConnection> &_connection);
typedef std::shared_ptr<DBusStubAdapter>
(*StubAdapterCreateFunction) (const DBusAddress &_address,
- const std::shared_ptr<DBusProxyConnection> &_connection,
- const std::shared_ptr<StubBase> &_stub);
+ const std::shared_ptr<DBusProxyConnection> &_connection,
+ const std::shared_ptr<StubBase> &_stub);
class Factory : public CommonAPI::Factory {
public:
- COMMONAPI_EXPORT static std::shared_ptr<Factory> get();
+ COMMONAPI_EXPORT static std::shared_ptr<Factory> get();
- COMMONAPI_EXPORT Factory();
- COMMONAPI_EXPORT virtual ~Factory();
+ COMMONAPI_EXPORT Factory();
+ COMMONAPI_EXPORT virtual ~Factory();
- COMMONAPI_EXPORT void registerProxyCreateMethod(const std::string &_address,
- ProxyCreateFunction _function);
+ COMMONAPI_EXPORT void registerProxyCreateMethod(const std::string &_address,
+ ProxyCreateFunction _function);
- COMMONAPI_EXPORT void registerStubAdapterCreateMethod(const std::string &_address,
- StubAdapterCreateFunction _function);
+ COMMONAPI_EXPORT void registerStubAdapterCreateMethod(const std::string &_address,
+ StubAdapterCreateFunction _function);
- COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &_domain,
- const std::string &_interface,
- const std::string &_instance,
- const ConnectionId_t &_connectionId);
+ COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &_domain,
+ const std::string &_interface,
+ const std::string &_instance,
+ const ConnectionId_t &_connectionId);
- COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &_domain,
- const std::string &_interface,
- const std::string &_instance,
- std::shared_ptr<MainLoopContext> _context);
+ COMMONAPI_EXPORT std::shared_ptr<Proxy> createProxy(const std::string &_domain,
+ const std::string &_interface,
+ const std::string &_instance,
+ std::shared_ptr<MainLoopContext> _context);
- COMMONAPI_EXPORT bool registerStub(const std::string &_domain,
- const std::string &_interface,
- const std::string &_instance,
- std::shared_ptr<StubBase> _stub,
- const ConnectionId_t &_connectionId);
+ COMMONAPI_EXPORT bool registerStub(const std::string &_domain,
+ const std::string &_interface,
+ const std::string &_instance,
+ std::shared_ptr<StubBase> _stub,
+ const ConnectionId_t &_connectionId);
- COMMONAPI_EXPORT bool registerStub(const std::string &_domain,
- const std::string &_interface,
- const std::string &_instance,
- std::shared_ptr<StubBase> _stub,
- std::shared_ptr<MainLoopContext> _context);
+ COMMONAPI_EXPORT bool registerStub(const std::string &_domain,
+ const std::string &_interface,
+ const std::string &_instance,
+ std::shared_ptr<StubBase> _stub,
+ std::shared_ptr<MainLoopContext> _context);
- COMMONAPI_EXPORT bool unregisterStub(const std::string &_domain,
- const std::string &_interface,
- const std::string &_instance);
+ COMMONAPI_EXPORT bool unregisterStub(const std::string &_domain,
+ const std::string &_interface,
+ const std::string &_instance);
- // Services
- COMMONAPI_EXPORT std::shared_ptr<DBusStubAdapter> getRegisteredService(const std::string &_address);
+ // Services
+ COMMONAPI_EXPORT std::shared_ptr<DBusStubAdapter> getRegisteredService(const std::string &_address);
- // Managed services
- COMMONAPI_EXPORT std::shared_ptr<DBusStubAdapter> createDBusStubAdapter(const std::shared_ptr<StubBase> &_stub,
- const std::string &_interface,
- const DBusAddress &_address,
- const std::shared_ptr<DBusProxyConnection> &_connection);
- COMMONAPI_EXPORT bool registerManagedService(const std::shared_ptr<DBusStubAdapter> &_adapter);
- COMMONAPI_EXPORT bool unregisterManagedService(const std::string &_address);
+ // Managed services
+ COMMONAPI_EXPORT std::shared_ptr<DBusStubAdapter> createDBusStubAdapter(const std::shared_ptr<StubBase> &_stub,
+ const std::string &_interface,
+ const DBusAddress &_address,
+ const std::shared_ptr<DBusProxyConnection> &_connection);
+ COMMONAPI_EXPORT bool registerManagedService(const std::shared_ptr<DBusStubAdapter> &_adapter);
+ COMMONAPI_EXPORT bool unregisterManagedService(const std::string &_address);
private:
- COMMONAPI_EXPORT std::shared_ptr<DBusConnection> getConnection(const ConnectionId_t &);
- COMMONAPI_EXPORT std::shared_ptr<DBusConnection> getConnection(std::shared_ptr<MainLoopContext>);
- COMMONAPI_EXPORT bool registerStubAdapter(std::shared_ptr<DBusStubAdapter>);
- COMMONAPI_EXPORT bool unregisterStubAdapter(std::shared_ptr<DBusStubAdapter>);
+ COMMONAPI_EXPORT std::shared_ptr<DBusConnection> getConnection(const ConnectionId_t &);
+ COMMONAPI_EXPORT std::shared_ptr<DBusConnection> getConnection(std::shared_ptr<MainLoopContext>);
+ COMMONAPI_EXPORT bool registerStubAdapter(std::shared_ptr<DBusStubAdapter>);
+ COMMONAPI_EXPORT bool unregisterStubAdapter(std::shared_ptr<DBusStubAdapter>);
- // Managed services
- typedef std::unordered_map<std::string, std::shared_ptr<DBusStubAdapter>> ServicesMap;
- COMMONAPI_EXPORT bool unregisterManagedService(const ServicesMap::iterator &);
+ // Managed services
+ typedef std::unordered_map<std::string, std::shared_ptr<DBusStubAdapter>> ServicesMap;
+ COMMONAPI_EXPORT bool unregisterManagedService(const ServicesMap::iterator &);
private:
- static std::shared_ptr<Factory> theFactory;
+ static std::shared_ptr<Factory> theFactory;
- std::map<ConnectionId_t, std::shared_ptr<DBusConnection>> connections_;
- std::map<MainLoopContext *, std::shared_ptr<DBusConnection>> contextConnections_;
+ std::map<ConnectionId_t, std::shared_ptr<DBusConnection>> connections_;
+ std::map<MainLoopContext *, std::shared_ptr<DBusConnection>> contextConnections_;
std::map<std::string, ProxyCreateFunction> proxyCreateFunctions_;
std::map<std::string, StubAdapterCreateFunction> stubAdapterCreateFunctions_;
diff --git a/include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp b/include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp
index fd9237e..4f78f5c 100644
--- a/include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp
+++ b/include/CommonAPI/DBus/DBusFreedesktopAttribute.hpp
@@ -15,37 +15,38 @@
namespace CommonAPI {
namespace DBus {
-template <typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
-class DBusFreedesktopReadonlyAttribute: public _AttributeType {
+template <typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
+class DBusFreedesktopReadonlyAttribute: public AttributeType_ {
public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef _AttributeDepl ValueTypeDepl;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
+ typedef typename AttributeType_::ValueType ValueType;
+ typedef AttributeDepl_ ValueTypeDepl;
+ typedef typename AttributeType_::AttributeAsyncCallback AttributeAsyncCallback;
DBusFreedesktopReadonlyAttribute(DBusProxy &_proxy, const std::string &_interfaceName, const std::string &_propertyName,
- _AttributeDepl *_depl = nullptr)
- : proxy_(_proxy),
+ AttributeDepl_ *_depl = nullptr)
+ : proxy_(_proxy),
interfaceName_(_interfaceName),
propertyName_(_propertyName),
depl_(_depl) {
}
void getValue(CommonAPI::CallStatus &_status, ValueType &_value, const CommonAPI::CallInfo *_info) const {
- CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>> deployedValue(&freedesktopVariant);
+ VariantDeployment<AttributeDepl_> actualDepl(true, depl_);
+ CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>> deployedValue(&actualDepl);
DBusProxyHelper<
- DBusSerializableArguments<
- std::string, std::string
- >,
DBusSerializableArguments<
- CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>>
- >
+ std::string, std::string
+ >,
+ DBusSerializableArguments<
+ CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>>
+ >
>::callMethodWithReply(
- proxy_,
+ proxy_,
"org.freedesktop.DBus.Properties",
"Get",
"ss",
- (_info ? _info : &defaultCallInfo),
- interfaceName_,
+ (_info ? _info : &defaultCallInfo),
+ interfaceName_,
propertyName_,
_status,
deployedValue);
@@ -54,259 +55,173 @@ public:
}
std::future<CallStatus> getValueAsync(AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>> deployedValue(&freedesktopVariant);
+ VariantDeployment<AttributeDepl_> actualDepl(true, depl_);
+ CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>> deployedValue(&actualDepl);
return DBusProxyHelper<
- DBusSerializableArguments<
- std::string, std::string
- >,
DBusSerializableArguments<
- CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>>
- >
- >::callMethodAsync(
- proxy_,
- "org.freedesktop.DBus.Properties",
- "Get",
- "ss",
- (_info ? _info : &defaultCallInfo),
- interfaceName_,
- propertyName_,
- [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>> _value) {
- _callback(_status, _value.getValue().template get<ValueType>());
- },
- std::make_tuple(deployedValue)
- );
- }
-
-protected:
- DBusProxy &proxy_;
- std::string interfaceName_;
- std::string propertyName_;
- _AttributeDepl *depl_;
-};
-
-template <typename _AttributeType>
-class DBusFreedesktopUnionReadonlyAttribute: public _AttributeType {
-public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
-
- DBusFreedesktopUnionReadonlyAttribute(DBusProxy &_proxy, const std::string &_interfaceName, const std::string &_propertyName)
- : proxy_(_proxy),
- interfaceName_(_interfaceName),
- propertyName_(_propertyName) {
- }
-
- void getValue(CommonAPI::CallStatus &_status, ValueType &_value, const CommonAPI::CallInfo *_info) const {
- CommonAPI::Deployable<ValueType, VariantDeployment<>> deployedValue(&freedesktopVariant);
- DBusProxyHelper<
- DBusSerializableArguments<
- std::string, std::string
- >,
- DBusSerializableArguments<
- CommonAPI::Deployable<ValueType, VariantDeployment<>>
- >
- >::callMethodWithReply(
- proxy_,
- "org.freedesktop.DBus.Properties",
- "Get",
- "ss",
- (_info ? _info : &defaultCallInfo),
- interfaceName_,
- propertyName_,
- _status,
- deployedValue);
-
- _value = deployedValue.getValue().template get<ValueType>();
- }
-
- std::future<CommonAPI::CallStatus> getValueAsync(AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<ValueType, VariantDeployment<>> deployedValue(&freedesktopVariant);
- return DBusProxyHelper<
- DBusSerializableArguments<
- std::string, std::string
- >,
+ std::string, std::string
+ >,
DBusSerializableArguments<
- CommonAPI::Deployable<ValueType, VariantDeployment<>>
- >
- >::callMethodAsync(
+ CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>>
+ >
+ >::callMethodAsync(
proxy_,
- "org.freedesktop.DBus.Properties",
+ "org.freedesktop.DBus.Properties",
"Get",
"ss",
- (_info ? _info : &defaultCallInfo),
+ (_info ? _info : &defaultCallInfo),
interfaceName_,
propertyName_,
- [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable<ValueType, VariantDeployment<>> _value) {
- _callback(_status, _value.getValue().template get<ValueType>());
- },
- std::make_tuple(deployedValue)
- );
+ [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>> _value) {
+ _callback(_status, _value.getValue().template get<ValueType>());
+ },
+ std::make_tuple(deployedValue)
+ );
+ }
+ AttributeDepl_ *getDepl(void) {
+ return depl_;
}
-
protected:
DBusProxy &proxy_;
std::string interfaceName_;
std::string propertyName_;
+ AttributeDepl_ *depl_;
};
-template <typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
+template <typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
class DBusFreedesktopAttribute
- : public DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl> {
+ : public DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_> {
public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
+ typedef typename AttributeType_::ValueType ValueType;
+ typedef typename AttributeType_::AttributeAsyncCallback AttributeAsyncCallback;
- DBusFreedesktopAttribute(DBusProxy &_proxy, const std::string &_interfaceName, const std::string &_propertyName, _AttributeDepl *_depl = nullptr)
- : DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl>(_proxy, _interfaceName, _propertyName, _depl) {
+ DBusFreedesktopAttribute(DBusProxy &_proxy, const std::string &_interfaceName, const std::string &_propertyName, AttributeDepl_ *_depl = nullptr)
+ : DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>(_proxy, _interfaceName, _propertyName, _depl) {
}
void setValue(const ValueType &_request, CommonAPI::CallStatus &_status, ValueType &_response, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>> deployedVariant(_request, &freedesktopVariant);
+ VariantDeployment<AttributeDepl_> actualDepl(true, DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>::depl_);
+ Variant<ValueType> reqVariant(_request);
+ CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>> deployedVariant(reqVariant, &actualDepl);
DBusProxyHelper<
- DBusSerializableArguments<
- std::string, std::string, CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>>
- >,
DBusSerializableArguments<
- >
+ std::string, std::string, CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>>
+ >,
+ DBusSerializableArguments<
+ >
>::callMethodWithReply(
- DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl>::proxy_,
- "org.freedesktop.DBus.Properties",
- "Set",
- "ssv",
- (_info ? _info : &defaultCallInfo),
- DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl>::interfaceName_,
- DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl>::propertyName_,
- deployedVariant,
- _status);
+ DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>::proxy_,
+ "org.freedesktop.DBus.Properties",
+ "Set",
+ "ssv",
+ (_info ? _info : &defaultCallInfo),
+ DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>::interfaceName_,
+ DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>::propertyName_,
+ deployedVariant,
+ _status);
_response = _request;
}
std::future<CommonAPI::CallStatus> setValueAsync(const ValueType &_request, AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>> deployedVariant(_request, &freedesktopVariant);
+ VariantDeployment<AttributeDepl_> actualDepl(true, DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>::depl_);
+ Variant<ValueType> reqVariant(_request);
+ CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>> deployedVariant(reqVariant, &actualDepl);
return DBusProxyHelper<
- DBusSerializableArguments<
- std::string, std::string, CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<>>
- >,
DBusSerializableArguments<
- >
- >::callMethodAsync(
- DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl>::proxy_,
- "org.freedesktop.DBus.Properties",
- "Set",
- "ssv",
- (_info ? _info : &defaultCallInfo),
- DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl>::interfaceName_,
- DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl>::propertyName_,
- deployedVariant,
- [_callback, deployedVariant](CommonAPI::CallStatus _status) {
- _callback(_status, deployedVariant.getValue().template get<ValueType>());
- },
- std::tuple<>());
- }
-};
-
-template <typename _AttributeType>
-class DBusFreedesktopUnionAttribute
- : public DBusFreedesktopReadonlyAttribute<_AttributeType> {
- public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
-
- DBusFreedesktopUnionAttribute(DBusProxy &_proxy, const std::string &_interfaceName, const std::string &_propertyName)
- : DBusFreedesktopUnionReadonlyAttribute<_AttributeType>(_proxy, _interfaceName, _propertyName) {
- }
-
- void setValue(const ValueType &_request, CommonAPI::CallStatus &_status, ValueType &_response, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<ValueType, VariantDeployment<>> deployedVariant(_request, &freedesktopVariant);
- DBusProxyHelper<
- DBusSerializableArguments<
- std::string, std::string, CommonAPI::Deployable<ValueType, VariantDeployment<>>
- >,
- DBusSerializableArguments<
- >
- >::callMethodWithReply(
- DBusFreedesktopReadonlyAttribute<_AttributeType>::proxy_,
- "org.freedesktop.DBus.Properties",
- "Set",
- "ssv",
- (_info ? _info : &defaultCallInfo),
- DBusFreedesktopReadonlyAttribute<_AttributeType>::interfaceName_,
- DBusFreedesktopReadonlyAttribute<_AttributeType>::propertyName_,
- deployedVariant,
- _status);
- _response = _request;
- }
-
- std::future<CallStatus> setValueAsync(const ValueType &_request, AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) {
- CommonAPI::Deployable<ValueType, VariantDeployment<>> deployedVariant(_request, &freedesktopVariant);
- return DBusProxyHelper<
- DBusSerializableArguments<
- std::string, std::string, CommonAPI::Deployable<ValueType, VariantDeployment<>>
- >,
+ std::string, std::string, CommonAPI::Deployable<Variant<ValueType>, VariantDeployment<AttributeDepl_>>
+ >,
DBusSerializableArguments<
- >
- >::callMethodAsync(
- DBusFreedesktopReadonlyAttribute<_AttributeType>::proxy_,
- "org.freedesktop.DBus.Properties",
- "Set",
- "ssv",
- (_info ? _info : &defaultCallInfo),
- DBusFreedesktopReadonlyAttribute<_AttributeType>::interfaceName_,
- DBusFreedesktopReadonlyAttribute<_AttributeType>::propertyName_,
- deployedVariant,
- [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable<ValueType, VariantDeployment<>> _value) {
- _callback(_status, _value.getValue().template get<ValueType>());
- },
- std::make_tuple(deployedVariant));
+ >
+ >::callMethodAsync(
+ DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>::proxy_,
+ "org.freedesktop.DBus.Properties",
+ "Set",
+ "ssv",
+ (_info ? _info : &defaultCallInfo),
+ DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>::interfaceName_,
+ DBusFreedesktopReadonlyAttribute<AttributeType_, AttributeDepl_>::propertyName_,
+ deployedVariant,
+ [_callback, deployedVariant](CommonAPI::CallStatus _status) {
+ _callback(_status, deployedVariant.getValue().template get<ValueType>());
+ },
+ std::tuple<>());
}
};
-template<class, class>
+template<class, class, class>
class LegacyEvent;
-
-template <template <class...> class _Type, class _Types, class _Variant>
-class LegacyEvent<_Type<_Types>, _Variant>: public _Type<_Types> {
+template <template <class...> class Type_, class Types_, class DataType_, class DataDeplType_>
+class LegacyEvent<Type_<Types_>, DataType_, DataDeplType_>: public Type_<Types_>,
+ public DBusProxyConnection::DBusSignalHandler {
public:
- typedef _Types ValueType;
- typedef typename _Type<ValueType>::Listener Listener;
- typedef std::unordered_map<std::string, _Variant> PropertyMap;
- typedef MapDeployment<EmptyDeployment, VariantDeployment<>> PropertyMapDeployment;
+ typedef Types_ ValueType;
+ typedef typename Type_<ValueType>::Listener Listener;
+ typedef std::unordered_map<std::string, Variant<DataType_>> PropertyMap;
+ typedef MapDeployment<EmptyDeployment, VariantDeployment<DataDeplType_>> PropertyMapDeployment;
typedef Deployable<PropertyMap, PropertyMapDeployment> DeployedPropertyMap;
typedef std::vector<std::string> InvalidArray;
typedef Event<std::string, DeployedPropertyMap, InvalidArray> SignalEvent;
+ typedef typename Type_<ValueType>::Subscription Subscription;
- LegacyEvent(DBusProxy &_proxy, const std::string &_interfaceName, const std::string &_propertyName)
- : interfaceName_(_interfaceName),
- propertyName_(_propertyName),
- isSubcriptionSet_(false),
- internalEvent_(_proxy,
- "PropertiesChanged",
- "sa{sv}as",
- _proxy.getDBusAddress().getObjectPath(),
- "org.freedesktop.DBus.Properties",
- std::make_tuple("", getDeployedMap(), InvalidArray())) {
+ LegacyEvent(DBusProxy &_proxy, const std::string &_interfaceName, const std::string &_propertyName, DataDeplType_ *_depl)
+ : interfaceName_(_interfaceName),
+ propertyName_(_propertyName),
+ variantDepl_(true, _depl),
+ mapDepl_(nullptr, &variantDepl_),
+ deployedMap_(&mapDepl_),
+ proxy_(_proxy),
+ isSubcriptionSet_(false),
+ internalEvent_(_proxy,
+ "PropertiesChanged",
+ "sa{sv}as",
+ _proxy.getDBusAddress().getObjectPath(),
+ "org.freedesktop.DBus.Properties",
+ std::make_tuple("", deployedMap_, InvalidArray())) {
}
protected:
void onFirstListenerAdded(const Listener &) {
- if (!isSubcriptionSet_) {
- subscription_ = internalEvent_.subscribe(
- [this](const std::string &_interfaceName,
- const PropertyMap &_properties,
- const InvalidArray &_invalid) {
- if (interfaceName_ == _interfaceName) {
- auto iter = _properties.find(propertyName_);
- if (iter != _properties.end()) {
- const ValueType &value = iter->second.template get<ValueType>();
- this->notifyListeners(value);
- }
- }
- });
+ if (!isSubcriptionSet_) {
+ subscription_ = internalEvent_.subscribe(
+ [this](const std::string &_interfaceName,
+ const PropertyMap &_properties,
+ const InvalidArray &_invalid) {
+ (void)_invalid;
+ if (interfaceName_ == _interfaceName) {
+ auto iter = _properties.find(propertyName_);
+ if (iter != _properties.end()) {
+ const ValueType &value = iter->second.template get<ValueType>();
+ this->notifyListeners(value);
+ }
+ }
+ });
+
+ isSubcriptionSet_ = true;
+ }
+ }
- isSubcriptionSet_ = true;
- }
+ virtual void onListenerAdded(const Listener& listener, const Subscription subscription) {
+ (void)listener;
+ proxy_.freeDesktopGetCurrentValueForSignalListener(this, subscription, interfaceName_, propertyName_);
}
+ virtual void onInitialValueSignalDBusMessage(const DBusMessage&_message, const uint32_t tag) {
+ CommonAPI::Deployable<Variant<DataType_>, VariantDeployment<DataDeplType_>> deployedValue(&variantDepl_);
+ DBusInputStream input(_message);
+ if (DBusSerializableArguments<
+ CommonAPI::Deployable<
+ Variant<DataType_>,
+ VariantDeployment<DataDeplType_>
+ >
+ >::deserialize(input, deployedValue)) {
+ Variant<DataType_> v = deployedValue.getValue();
+ const DataType_ &value = v.template get<DataType_>();
+ this->notifySpecificListener(tag, value);
+ }
+ }
+ virtual void onSignalDBusMessage(const DBusMessage&) {
+ // ignore
+ }
void onLastListenerRemoved(const Listener &) {
if (isSubcriptionSet_) {
internalEvent_.unsubscribe(subscription_);
@@ -316,36 +231,33 @@ protected:
std::string interfaceName_;
std::string propertyName_;
+ VariantDeployment<DataDeplType_> variantDepl_;
+ PropertyMapDeployment mapDepl_;
+ DeployedPropertyMap deployedMap_;
+ DBusProxy &proxy_;
typename DBusEvent<SignalEvent, std::string, DeployedPropertyMap, InvalidArray>::Subscription subscription_;
bool isSubcriptionSet_;
DBusEvent<SignalEvent, std::string, DeployedPropertyMap, InvalidArray> internalEvent_;
-
-private:
- static DeployedPropertyMap &getDeployedMap() {
- static PropertyMapDeployment itsDeployment(nullptr, &freedesktopVariant);
- static DeployedPropertyMap itsDeployedMap(&itsDeployment);
- return itsDeployedMap;
- }
};
-template <typename _AttributeType, typename _Variant>
-class DBusFreedesktopObservableAttribute: public _AttributeType {
+template <typename AttributeType_>
+class DBusFreedesktopObservableAttribute: public AttributeType_ {
public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
- typedef typename _AttributeType::ChangedEvent ChangedEvent;
-
- template <typename... _AttributeTypeArguments>
+ typedef typename AttributeType_::ValueType ValueType;
+ typedef typename AttributeType_::AttributeAsyncCallback AttributeAsyncCallback;
+ typedef typename AttributeType_::ChangedEvent ChangedEvent;
+ typedef typename AttributeType_::ValueTypeDepl ValueTypeDepl;
+ template <typename... AttributeType_Arguments>
DBusFreedesktopObservableAttribute(DBusProxy &_proxy,
- const std::string &_interfaceName,
- const std::string &_propertyName,
- _AttributeTypeArguments... _arguments)
- : _AttributeType(_proxy, _interfaceName, _propertyName, _arguments...),
- interfaceName_(_interfaceName),
- propertyName_(_propertyName),
- externalChangedEvent_(_proxy, _interfaceName, _propertyName) {
+ const std::string &_interfaceName,
+ const std::string &_propertyName,
+ AttributeType_Arguments... _arguments)
+ : AttributeType_(_proxy, _interfaceName, _propertyName, _arguments...),
+ interfaceName_(_interfaceName),
+ propertyName_(_propertyName),
+ externalChangedEvent_(_proxy, _interfaceName, _propertyName, AttributeType_::getDepl()) {
}
ChangedEvent &getChangedEvent() {
@@ -355,98 +267,7 @@ class DBusFreedesktopObservableAttribute: public _AttributeType {
protected:
std::string interfaceName_;
std::string propertyName_;
- LegacyEvent<ChangedEvent, _Variant> externalChangedEvent_;
-};
-
-template<class, class>
-class LegacyUnionEvent;
-
-template <template <class...> class _Type, class _Types, class _Variant>
-class LegacyUnionEvent<_Type<_Types>, _Variant>: public _Type<_Types> {
-public:
- typedef _Types ValueType;
- typedef typename _Type<ValueType>::Listener Listener;
- typedef std::unordered_map<std::string, _Variant> PropertyMap;
- typedef MapDeployment<EmptyDeployment, VariantDeployment<>> PropertyMapDeployment;
- typedef CommonAPI::Deployable<PropertyMap, PropertyMapDeployment> DeployedPropertyMap;
- typedef std::vector<std::string> InvalidArray;
- typedef Event<std::string, DeployedPropertyMap, InvalidArray> SignalEvent;
-
- LegacyUnionEvent(DBusProxy &_proxy, const std::string &_interfaceName, const std::string &_propertyName)
- : interfaceName_(_interfaceName),
- propertyName_(_propertyName),
- isSubcriptionSet_(false),
- internalEvent_(_proxy,
- "PropertiesChanged",
- "sa{sv}as",
- _proxy.getDBusAddress().getObjectPath(),
- "org.freedesktop.DBus.Properties",
- std::make_tuple("", getDeployedMap(), InvalidArray())) {
- }
-
-protected:
- void onFirstListenerAdded(const Listener &) {
- if (isSubcriptionSet_) {
- subscription_ = internalEvent_.subscribe(
- [this](const std::string &_interfaceName,
- const PropertyMap &_properties,
- const std::vector<std::string> &_invalid) {
- if (interfaceName_ == _interfaceName) {
- auto iter = _properties.find(propertyName_);
- if (iter != _properties.end()) {
- this->notifyListeners(iter->second.template get<ValueType>());
- }
- }
- });
- isSubcriptionSet_ = true;
- }
- }
-
- void onLastListenerRemoved(const Listener &) {
- if (isSubcriptionSet_) {
- internalEvent_.unsubscribe(subscription_);
- isSubcriptionSet_ = false;
- }
- }
-
- DBusEvent<SignalEvent, ValueType> internalEvent_;
- std::string interfaceName_;
- std::string propertyName_;
-
- typename DBusEvent<SignalEvent>::Subscription subscription_;
- bool isSubcriptionSet_;
-
-private:
- static DeployedPropertyMap &getDeployedMap() {
- static PropertyMapDeployment itsDeployment(nullptr, &freedesktopVariant);
- static DeployedPropertyMap itsDeployedMap(&itsDeployment);
- return itsDeployedMap;
- }
-};
-
-template <typename _AttributeType, typename _Variant>
-class DBusFreedesktopUnionObservableAttribute: public _AttributeType {
- public:
- typedef typename _AttributeType::ValueType ValueType;
- typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
- typedef typename _AttributeType::ChangedEvent ChangedEvent;
-
- template <typename... _AttributeTypeArguments>
- DBusFreedesktopUnionObservableAttribute(DBusProxy &_proxy,
- const std::string &_interfaceName,
- const std::string &_propertyName,
- _AttributeTypeArguments... _arguments)
- : _AttributeType(_proxy, _interfaceName, _propertyName, _arguments...),
- externalChangedEvent_(_proxy, _interfaceName, _propertyName) {
- }
-
- ChangedEvent &getChangedEvent() {
- return externalChangedEvent_;
- }
-
- protected:
- LegacyUnionEvent<ChangedEvent, _Variant> externalChangedEvent_;
-};
+ LegacyEvent<ChangedEvent, ValueType, ValueTypeDepl> externalChangedEvent_;};
} // namespace DBus
} // namespace CommonAPI
diff --git a/include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp b/include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp
index f7e2cdf..1c01da9 100644
--- a/include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp
+++ b/include/CommonAPI/DBus/DBusFreedesktopPropertiesStub.hpp
@@ -40,7 +40,7 @@ public:
virtual const char* getMethodsDBusIntrospectionXmlData() const;
virtual bool onInterfaceDBusMessage(const DBusMessage &_message);
- virtual const bool hasFreedesktopProperties();
+ virtual bool hasFreedesktopProperties();
private:
std::string path_;
diff --git a/include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp b/include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp
index bfe2493..4593400 100644
--- a/include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp
+++ b/include/CommonAPI/DBus/DBusFreedesktopStubAdapterHelper.hpp
@@ -16,48 +16,50 @@
namespace CommonAPI {
namespace DBus {
-template <typename _StubClass>
+template <typename StubClass_>
class DBusGetFreedesktopAttributeStubDispatcherBase {
public:
virtual ~DBusGetFreedesktopAttributeStubDispatcherBase() {}
virtual void dispatchDBusMessageAndAppendReply(const DBusMessage &_message,
- const std::shared_ptr<_StubClass> &_stub,
- DBusOutputStream &_output,
- const std::shared_ptr<DBusClientId> &_clientId) = 0;
+ const std::shared_ptr<StubClass_> &_stub,
+ DBusOutputStream &_output,
+ const std::shared_ptr<DBusClientId> &_clientId) = 0;
};
-template <typename _StubClass, typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
+template <typename StubClass_, typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
class DBusGetFreedesktopAttributeStubDispatcher
- : public virtual DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>,
- public virtual DBusGetFreedesktopAttributeStubDispatcherBase<_StubClass> {
+ : public virtual DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>,
+ public virtual DBusGetFreedesktopAttributeStubDispatcherBase<StubClass_> {
public:
- typedef DBusStubAdapterHelper<_StubClass> DBusStubAdapterHelperType;
- typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::GetStubFunctor GetStubFunctor;
+ typedef DBusStubAdapterHelper<StubClass_> DBusStubAdapterHelperType;
+ typedef typename DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::GetStubFunctor GetStubFunctor;
- DBusGetFreedesktopAttributeStubDispatcher(GetStubFunctor _getStubFunctor, _AttributeDepl *_depl = nullptr)
- : DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, "v", _depl) {
+ DBusGetFreedesktopAttributeStubDispatcher(GetStubFunctor _getStubFunctor, AttributeDepl_ *_depl = nullptr)
+ : DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, "v", _depl) {
}
virtual ~DBusGetFreedesktopAttributeStubDispatcher() {};
void dispatchDBusMessageAndAppendReply(const DBusMessage &_message,
- const std::shared_ptr<_StubClass> &_stub,
- DBusOutputStream &_output,
- const std::shared_ptr<DBusClientId> &_clientId) {
- CommonAPI::Deployable<CommonAPI::Variant<_AttributeType>, VariantDeployment<>> deployedVariant(
- (_stub.get()->*(DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::getStubFunctor_))(_clientId), &freedesktopVariant);
+ const std::shared_ptr<StubClass_> &_stub,
+ DBusOutputStream &_output,
+ const std::shared_ptr<DBusClientId> &_clientId) {
+ (void)_message;
+ VariantDeployment<AttributeDepl_> actualDepl(true, DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::depl_);
+ CommonAPI::Deployable<CommonAPI::Variant<AttributeType_>, VariantDeployment<AttributeDepl_>> deployedVariant(
+ (_stub.get()->*(DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::getStubFunctor_))(_clientId), &actualDepl);
_output << deployedVariant;
}
protected:
- virtual bool sendAttributeValueReply(const DBusMessage &_message, const std::shared_ptr<_StubClass> &_stub, DBusStubAdapterHelperType &_helper) {
- DBusMessage reply = _message.createMethodReturn(DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::signature_);
+ virtual bool sendAttributeValueReply(const DBusMessage &_message, const std::shared_ptr<StubClass_> &_stub, DBusStubAdapterHelperType &_helper) {
+ DBusMessage reply = _message.createMethodReturn(DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::signature_);
- VariantDeployment<_AttributeDepl> actualDepl(true, DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::depl_);
+ VariantDeployment<AttributeDepl_> actualDepl(true, DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::depl_);
std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(_message.getSender()));
- CommonAPI::Deployable<CommonAPI::Variant<_AttributeType>, VariantDeployment<_AttributeDepl>> deployedVariant(
- (_stub.get()->*(DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::getStubFunctor_))(clientId), &actualDepl);
+ CommonAPI::Deployable<CommonAPI::Variant<AttributeType_>, VariantDeployment<AttributeDepl_>> deployedVariant(
+ (_stub.get()->*(DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::getStubFunctor_))(clientId), &actualDepl);
DBusOutputStream output(reply);
output << deployedVariant;
@@ -67,120 +69,120 @@ protected:
}
};
-template <typename _StubClass, typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
+template <typename StubClass_, typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
class DBusSetFreedesktopAttributeStubDispatcher
- : public virtual DBusGetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>,
- public virtual DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl> {
+ : public virtual DBusGetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>,
+ public virtual DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_> {
public:
- typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::GetStubFunctor GetStubFunctor;
- typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::DBusStubAdapterHelperType DBusStubAdapterHelperType;
+ typedef typename DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::GetStubFunctor GetStubFunctor;
+ typedef typename DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::DBusStubAdapterHelperType DBusStubAdapterHelperType;
typedef typename DBusStubAdapterHelperType::RemoteEventHandlerType RemoteEventHandlerType;
- typedef bool (RemoteEventHandlerType::*OnRemoteSetFunctor)(std::shared_ptr<CommonAPI::ClientId>, _AttributeType);
+ typedef bool (RemoteEventHandlerType::*OnRemoteSetFunctor)(std::shared_ptr<CommonAPI::ClientId>, AttributeType_);
typedef void (RemoteEventHandlerType::*OnRemoteChangedFunctor)();
DBusSetFreedesktopAttributeStubDispatcher(
- GetStubFunctor _getStubFunctor,
- OnRemoteSetFunctor _onRemoteSetFunctor,
+ GetStubFunctor _getStubFunctor,
+ OnRemoteSetFunctor _onRemoteSetFunctor,
OnRemoteChangedFunctor _onRemoteChangedFunctor,
- _AttributeDepl * _depl = nullptr)
- : DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, "v", _depl),
- DBusGetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, _depl),
- DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _depl) {
+ AttributeDepl_ * _depl = nullptr)
+ : DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, "v", _depl),
+ DBusGetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, _depl),
+ DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _depl) {
}
virtual ~DBusSetFreedesktopAttributeStubDispatcher() {};
protected:
- virtual _AttributeType retrieveAttributeValue(const DBusMessage &_message, bool &_error) {
+ virtual AttributeType_ retrieveAttributeValue(const DBusMessage &_message, bool &_error) {
std::string interfaceName, attributeName;
DBusInputStream input(_message);
- CommonAPI::Deployable<CommonAPI::Variant<_AttributeType>, VariantDeployment<>> deployedVariant(&freedesktopVariant);
+ VariantDeployment<AttributeDepl_> actualDepl(true, DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::depl_);
+ CommonAPI::Deployable<CommonAPI::Variant<AttributeType_>, VariantDeployment<AttributeDepl_>> deployedVariant(&actualDepl);
input >> interfaceName; // skip over interface and attribute name
input >> attributeName;
input >> deployedVariant;
_error = input.hasError();
- _AttributeType attributeValue = deployedVariant.getValue().template get<_AttributeType>() ;
+ AttributeType_ attributeValue = deployedVariant.getValue().template get<AttributeType_>() ;
return attributeValue;
}
};
-template <typename _StubClass, typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
+template <typename StubClass_, typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
class DBusSetFreedesktopObservableAttributeStubDispatcher
- : public virtual DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>,
- public virtual DBusSetObservableAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl> {
+ : public virtual DBusSetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>,
+ public virtual DBusSetObservableAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_> {
public:
- typedef typename DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::DBusStubAdapterHelperType DBusStubAdapterHelperType;
+ typedef typename DBusSetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::DBusStubAdapterHelperType DBusStubAdapterHelperType;
typedef typename DBusStubAdapterHelperType::StubAdapterType StubAdapterType;
- typedef typename DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::GetStubFunctor GetStubFunctor;
- typedef typename DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::OnRemoteSetFunctor OnRemoteSetFunctor;
- typedef typename DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::OnRemoteChangedFunctor OnRemoteChangedFunctor;
- typedef void (StubAdapterType::*FireChangedFunctor)(const _AttributeType&);
+ typedef typename DBusSetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::GetStubFunctor GetStubFunctor;
+ typedef typename DBusSetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::OnRemoteSetFunctor OnRemoteSetFunctor;
+ typedef typename DBusSetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::OnRemoteChangedFunctor OnRemoteChangedFunctor;
+ typedef void (StubAdapterType::*FireChangedFunctor)(const AttributeType_&);
DBusSetFreedesktopObservableAttributeStubDispatcher(
- GetStubFunctor _getStubFunctor,
+ GetStubFunctor _getStubFunctor,
OnRemoteSetFunctor _onRemoteSetFunctor,
OnRemoteChangedFunctor _onRemoteChangedFunctor,
FireChangedFunctor _fireChangedFunctor,
- _AttributeDepl *_depl = nullptr)
- : DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, "v", _depl),
- DBusGetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, _depl),
- DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _depl),
- DBusSetFreedesktopAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _depl),
- DBusSetObservableAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(_getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _fireChangedFunctor, "v", _depl) {
+ AttributeDepl_ *_depl = nullptr)
+ : DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, "v", _depl),
+ DBusGetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, _depl),
+ DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, "v", _depl),
+ DBusSetFreedesktopAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _depl),
+ DBusSetObservableAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(_getStubFunctor, _onRemoteSetFunctor, _onRemoteChangedFunctor, _fireChangedFunctor, "v", _depl) {
}
};
-template<class>
+template<typename, typename>
struct DBusStubFreedesktopPropertiesSignalHelper;
-template<template<class ...> class _In, class _InArg>
-struct DBusStubFreedesktopPropertiesSignalHelper<_In<DBusInputStream, DBusOutputStream, _InArg>> {
+template<typename DataType_, typename DeplType_>
+struct DBusStubFreedesktopPropertiesSignalHelper {
- template <typename _ValueType>
+ template <typename ValueType_>
struct DBusPropertiesEntry
- : public CommonAPI::Struct<std::string, CommonAPI::Variant<_ValueType>> {
+ : public CommonAPI::Struct<std::string, CommonAPI::Variant<ValueType_>> {
- DBusPropertiesEntry() = default;
+ DBusPropertiesEntry() = default;
DBusPropertiesEntry(const std::string &_propertyName,
- const _ValueType &_propertyValue) {
- std::get<0>(this->values_) = _propertyName;
- std::get<1>(this->values_) = _propertyValue;
+ const ValueType_ &_propertyValue) {
+ std::get<0>(this->values_) = _propertyName;
+ std::get<1>(this->values_) = _propertyValue;
};
const std::string &getPropertyName() const { return std::get<0>(this->values_); }
void setPropertyName(const std::string &_value) { std::get<0>(this->values_) = _value; }
- const _ValueType getPropertyValue() const { return std::get<1>(this->values_); }
- void setPropertyValue(const _ValueType &_value) { std::get<1>(this->values_) = _value; }
+ const ValueType_ getPropertyValue() const { return std::get<1>(this->values_); }
+ void setPropertyValue(const ValueType_ &_value) { std::get<1>(this->values_) = _value; }
};
- typedef std::vector<DBusPropertiesEntry<_InArg>> PropertiesArray;
- typedef CommonAPI::Deployment<CommonAPI::EmptyDeployment, VariantDeployment<>> PropertyDeployment;
- typedef CommonAPI::ArrayDeployment<PropertyDeployment> PropertiesDeployment;
- typedef CommonAPI::Deployable<PropertiesArray, PropertiesDeployment> DeployedPropertiesArray;
+ typedef std::vector<DBusPropertiesEntry<DataType_>> PropertiesArray;
+ typedef CommonAPI::Deployment<CommonAPI::EmptyDeployment, VariantDeployment<DeplType_>> PropertyDeployment;
+ typedef CommonAPI::ArrayDeployment<PropertyDeployment> PropertiesDeployment;
+ typedef CommonAPI::Deployable<PropertiesArray, PropertiesDeployment> DeployedPropertiesArray;
- template <typename _StubClass>
- static bool sendPropertiesChangedSignal(const _StubClass &_stub, const std::string &_propertyName, const _InArg &_inArg) {
+ template <typename StubClass_>
+ static bool sendPropertiesChangedSignal(const StubClass_ &_stub, const std::string &_propertyName, const DataType_ &_inArg, DeplType_ *_depl) {
const std::vector<std::string> invalidatedProperties;
PropertiesArray changedProperties;
- DBusPropertiesEntry<_InArg> entry(_propertyName, _inArg);
+ DBusPropertiesEntry<DataType_> entry(_propertyName, _inArg);
changedProperties.push_back(entry);
- PropertyDeployment propertyDeployment(nullptr, &freedesktopVariant);
+ VariantDeployment<DeplType_> actualDepl(true, _depl);
+ PropertyDeployment propertyDeployment(nullptr, &actualDepl);
PropertiesDeployment changedPropertiesDeployment(&propertyDeployment);
DeployedPropertiesArray deployedChangedProperties(changedProperties, &changedPropertiesDeployment);
return DBusStubSignalHelper<
- _In<
- DBusInputStream,
- DBusOutputStream,
- const std::string,
- DeployedPropertiesArray,
- std::vector<std::string>
- >
- >::sendSignal(
- _stub.getDBusAddress().getObjectPath().c_str(),
+ DBusSerializableArguments<
+ const std::string,
+ DeployedPropertiesArray,
+ std::vector<std::string>
+ >
+ >::sendSignal(
+ _stub.getDBusAddress().getObjectPath().c_str(),
"org.freedesktop.DBus.Properties",
"PropertiesChanged",
"sa{sv}as",
diff --git a/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp b/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp
index 31490d2..243604e 100644
--- a/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp
+++ b/include/CommonAPI/DBus/DBusFreedesktopVariant.hpp
@@ -14,58 +14,65 @@
namespace CommonAPI {
namespace DBus {
-
-template<class Visitor, class Variant, typename ... _Types>
+template<class Visitor_, class Variant_, class Deployment_, typename ... Types_>
struct ApplyTypeCompareVisitor;
-template<class Visitor, class Variant>
-struct ApplyTypeCompareVisitor<Visitor, Variant> {
+template<class Visitor_, class Variant_, class Deployment_>
+struct ApplyTypeCompareVisitor<Visitor_, Variant_, Deployment_> {
static const uint8_t index = 0;
- static uint8_t visit(Visitor&, const Variant&) {
- // won't be called if the variant contains the requested type
- assert(false);
- return 0;
+ static bool visit(Visitor_&, const Variant_&, const Deployment_ *_depl, uint8_t &typeindex) {
+ (void)_depl;
+ // will be called only if the variant does not contain the requested type
+ typeindex = index;
+ return false;
}
};
-template<class Visitor, class Variant, typename _Type, typename ... _Types>
-struct ApplyTypeCompareVisitor<Visitor, Variant, _Type, _Types...> {
+template<class Visitor_, class Variant_, class Deployment_, typename Type_, typename ... Types_>
+struct ApplyTypeCompareVisitor<Visitor_, Variant_, Deployment_, Type_, Types_...> {
static const uint8_t index
- = ApplyTypeCompareVisitor<Visitor, Variant, _Types...>::index + 1;
+ = ApplyTypeCompareVisitor<Visitor_, Variant_, Deployment_, Types_...>::index + 1;
- static uint8_t visit(Visitor &_visitor, const Variant &_variant) {
+ static bool visit(Visitor_ &_visitor, const Variant_ &_variant, const Deployment_ *_depl, uint8_t &typeindex) {
DBusTypeOutputStream output;
- _Type current;
- output.writeType(current);
+ Type_ current;
+
+ if ((0 < Deployment_::size_) && (_depl)) {
+ output.writeType(current, std::get<Deployment_::size_-index>(_depl->values_));
+ }
+ else {
+ output.writeType(current, static_cast<CommonAPI::EmptyDeployment*>(nullptr));
+ }
+
#ifdef WIN32
- if (_visitor.operator()<_Type>(output.getSignature())) {
+ if (_visitor.operator()<Type_>(output.getSignature())) {
#else
- if (_visitor.template operator()<_Type>(output.getSignature())) {
+ if (_visitor.template operator()<Type_>(output.getSignature())) {
#endif
- return index;
+ typeindex = index;
+ return true;
} else {
return ApplyTypeCompareVisitor<
- Visitor, Variant, _Types...
- >::visit(_visitor, _variant);
+ Visitor_, Variant_, Deployment_, Types_...
+ >::visit(_visitor, _variant, _depl, typeindex);
}
}
};
-
-template<typename ... _Types>
+template<typename ... Types_>
struct TypeCompareVisitor {
public:
- TypeCompareVisitor(const std::string &_type)
- : type_(_type) {
- }
+ TypeCompareVisitor(const std::string &_type)
+ : type_(_type) {
+ }
- template<typename _Type>
- bool operator()(const std::string &_type) const {
- return (_type == type_);
- }
+ template<typename Type_>
+ bool operator()(const std::string &_type) const {
+ return (_type == type_);
+ }
private:
- const std::string type_;
+ const std::string type_;
};
} // namespace DBus
diff --git a/include/CommonAPI/DBus/DBusFunctionalHash.hpp b/include/CommonAPI/DBus/DBusFunctionalHash.hpp
index 78848c7..4903c21 100644
--- a/include/CommonAPI/DBus/DBusFunctionalHash.hpp
+++ b/include/CommonAPI/DBus/DBusFunctionalHash.hpp
@@ -20,56 +20,56 @@ namespace std {
template<>
struct COMMONAPI_EXPORT hash<pair<const char*, const char*> >
- : public unary_function<pair<const char*, const char*>, size_t> {
+ : public unary_function<pair<const char*, const char*>, size_t> {
size_t operator()(const pair<const char*, const char*>& t) const;
};
template<>
struct COMMONAPI_EXPORT hash<const char*>
- : public unary_function<const char*, size_t> {
+ : public unary_function<const char*, size_t> {
size_t operator()(const char* const t) const;
};
template<>
struct COMMONAPI_EXPORT hash<pair<string, string> >
- : public unary_function<pair<string, string>, size_t> {
+ : public unary_function<pair<string, string>, size_t> {
size_t operator()(const pair<string, string>& t) const;
};
template<>
struct COMMONAPI_EXPORT hash<tuple<string, string, string> >
- : public unary_function<tuple<string, string, string>, size_t> {
+ : public unary_function<tuple<string, string, string>, size_t> {
size_t operator()(const tuple<string, string, string>& t) const;
};
template<>
struct COMMONAPI_EXPORT hash<tuple<string, string, string, bool> >
- : public unary_function<tuple<string, string, string, bool>, size_t> {
+ : public unary_function<tuple<string, string, string, bool>, size_t> {
size_t operator()(const tuple<string, string, string, bool>& t) const;
};
template<>
struct COMMONAPI_EXPORT hash<tuple<string, string, string, int> >
- : public unary_function<tuple<string, string, string, int>, size_t> {
+ : public unary_function<tuple<string, string, string, int>, size_t> {
size_t operator()(const tuple<string, string, string, int>& t) const;
};
template<>
struct COMMONAPI_EXPORT hash<tuple<string, string, string, string> >
- : public std::unary_function<tuple<string, string, string, string>, size_t> {
+ : public std::unary_function<tuple<string, string, string, string>, size_t> {
size_t operator()(const tuple<string, string, string, string>& t) const;
};
template<>
struct COMMONAPI_EXPORT equal_to<pair<const char*, const char*> >
- : public binary_function<pair<const char*, const char*>,
+ : public binary_function<pair<const char*, const char*>,
pair<const char*, const char*>,
bool> {
diff --git a/include/CommonAPI/DBus/DBusHelper.hpp b/include/CommonAPI/DBus/DBusHelper.hpp
index 53a5625..889cf53 100644
--- a/include/CommonAPI/DBus/DBusHelper.hpp
+++ b/include/CommonAPI/DBus/DBusHelper.hpp
@@ -20,34 +20,34 @@ template <int ...>
struct index_sequence {};
-template <int N, int ...S>
-struct make_sequence : make_sequence<N-1, N-1, S...> {};
+template <int N_, int ...S_>
+struct make_sequence : make_sequence<N_-1, N_-1, S_...> {};
-template <int ...S>
-struct make_sequence<0, S...> {
- typedef index_sequence<S...> type;
+template <int ...S_>
+struct make_sequence<0, S_...> {
+ typedef index_sequence<S_...> type;
};
-template <int N, int _Offset, int ...S>
-struct make_sequence_range : make_sequence_range<N-1, _Offset, N-1+_Offset, S...> {};
+template <int N_, int Offset_, int ...S_>
+struct make_sequence_range : make_sequence_range<N_-1, Offset_, N_-1+Offset_, S_...> {};
-template <int _Offset, int ...S>
-struct make_sequence_range<0, _Offset, S...> {
- typedef index_sequence<S...> type;
+template <int Offset_, int ...S_>
+struct make_sequence_range<0, Offset_, S_...> {
+ typedef index_sequence<S_...> type;
};
-template<typename _Type>
+template<typename Type>
struct is_std_vector { static const bool value = false; };
-template<typename _Type>
-struct is_std_vector<std::vector<_Type> > { static const bool value = true; };
+template<typename Type_>
+struct is_std_vector<std::vector<Type_> > { static const bool value = true; };
-template<typename _Type>
+template<typename Type_>
struct is_std_unordered_map { static const bool value = false; };
-template<typename _Key, typename _Value, typename _Hash>
-struct is_std_unordered_map<std::unordered_map<_Key, _Value, _Hash>> { static const bool value = true; };
+template<typename KeyType_, typename ValueType_, typename HasherType_>
+struct is_std_unordered_map<std::unordered_map<KeyType_, ValueType_, HasherType_>> { static const bool value = true; };
} // namespace DBus
} // namespace CommonAPI
diff --git a/include/CommonAPI/DBus/DBusInputStream.hpp b/include/CommonAPI/DBus/DBusInputStream.hpp
index 4f00cec..b4c81d1 100644
--- a/include/CommonAPI/DBus/DBusInputStream.hpp
+++ b/include/CommonAPI/DBus/DBusInputStream.hpp
@@ -42,272 +42,282 @@ typedef uint32_t position_t;
* (this operator is predefined for all basic data types and for vectors).
*/
class DBusInputStream
- : public InputStream<DBusInputStream> {
+ : public InputStream<DBusInputStream> {
public:
- COMMONAPI_EXPORT bool hasError() const {
+ COMMONAPI_EXPORT bool hasError() const {
return isErrorSet();
}
- COMMONAPI_EXPORT InputStream &readValue(bool &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(bool &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(int8_t &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(int16_t &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(int32_t &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(int64_t &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(int8_t &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(int16_t &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(int32_t &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(int64_t &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(uint8_t &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(uint16_t &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(uint32_t &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(uint64_t &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(uint8_t &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(uint16_t &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(uint32_t &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(uint64_t &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(float &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(double &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(float &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(double &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(std::string &_value, const EmptyDeployment *_depl);
+ COMMONAPI_EXPORT InputStream &readValue(std::string &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(std::string &_value, const CommonAPI::DBus::StringDeployment* _depl) {
- return readValue(_value, static_cast<EmptyDeployment *>(nullptr));
- }
+ COMMONAPI_EXPORT InputStream &readValue(std::string &_value, const CommonAPI::DBus::StringDeployment* _depl) {
+ (void)_depl;
+ return readValue(_value, static_cast<EmptyDeployment *>(nullptr));
+ }
+
+ COMMONAPI_EXPORT InputStream &readValue(Version &_value, const EmptyDeployment *_depl);
- COMMONAPI_EXPORT InputStream &readValue(Version &_value, const EmptyDeployment *_depl);
-
- COMMONAPI_EXPORT void beginReadMapOfSerializableStructs() {
- uint32_t itsSize;
- _readValue(itsSize);
- pushSize(itsSize);
- align(8); /* correct alignment for first DICT_ENTRY */
- pushPosition();
- }
-
- COMMONAPI_EXPORT bool readMapCompleted() {
- return (sizes_.top() <= (current_ - positions_.top()));
- }
-
- COMMONAPI_EXPORT void endReadMapOfSerializableStructs() {
- (void)popSize();
- (void)popPosition();
- }
-
- COMMONAPI_EXPORT InputStream &skipMap() {
- uint32_t itsSize;
- _readValue(itsSize);
- align(8); /* skip padding (if any) */
- assert(itsSize <= (sizes_.top() + positions_.top() - current_));
- _readRaw(itsSize);
- return (*this);
- }
-
- template<class _Deployment, typename _Base>
- COMMONAPI_EXPORT InputStream &readValue(Enumeration<_Base> &_value, const _Deployment *_depl) {
- _Base tmpValue;
- readValue(tmpValue, _depl);
- _value = tmpValue;
- return (*this);
+ COMMONAPI_EXPORT void beginReadMapOfSerializableStructs() {
+ uint32_t itsSize;
+ _readValue(itsSize);
+ pushSize(itsSize);
+ align(8); /* correct alignment for first DICT_ENTRY */
+ pushPosition();
}
- template<class _Deployment, typename... _Types>
- COMMONAPI_EXPORT InputStream &readValue(Struct<_Types...> &_value, const _Deployment *_depl) {
- align(8);
- const auto itsSize(std::tuple_size<std::tuple<_Types...>>::value);
- StructReader<itsSize-1, DBusInputStream, Struct<_Types...>, _Deployment>{}(
- (*this), _value, _depl);
- return (*this);
+ COMMONAPI_EXPORT bool readMapCompleted() {
+ return (sizes_.top() <= (current_ - positions_.top()));
}
- template<class _Deployment, class _PolymorphicStruct>
- COMMONAPI_EXPORT InputStream &readValue(std::shared_ptr<_PolymorphicStruct> &_value,
- const _Deployment *_depl) {
- uint32_t serial;
- align(8);
- _readValue(serial);
- skipSignature();
- align(8);
- if (!hasError()) {
- _value = _PolymorphicStruct::create(serial);
- _value->template readValue<>(*this, _depl);
- }
-
- return (*this);
+ COMMONAPI_EXPORT void endReadMapOfSerializableStructs() {
+ (void)popSize();
+ (void)popPosition();
}
- template<typename... _Types>
- COMMONAPI_EXPORT InputStream &readValue(Variant<_Types...> &_value, const CommonAPI::EmptyDeployment *_depl = nullptr) {
- if(_value.hasValue()) {
- DeleteVisitor<_value.maxSize> visitor(_value.valueStorage_);
- ApplyVoidVisitor<DeleteVisitor<_value.maxSize>,
- Variant<_Types...>, _Types... >::visit(visitor, _value);
- }
+ COMMONAPI_EXPORT InputStream &skipMap() {
+ uint32_t itsSize;
+ _readValue(itsSize);
+ align(8); /* skip padding (if any) */
+ assert(itsSize <= (sizes_.top() + positions_.top() - current_));
+ _readRaw(itsSize);
+ return (*this);
+ }
- align(8);
- readValue(_value.valueType_, static_cast<EmptyDeployment *>(nullptr));
- skipSignature();
+ template<class Deployment_, typename Base_>
+ COMMONAPI_EXPORT InputStream &readValue(Enumeration<Base_> &_value, const Deployment_ *_depl) {
+ Base_ tmpValue;
+ readValue(tmpValue, _depl);
+ _value = tmpValue;
+ return (*this);
+ }
- InputStreamReadVisitor<DBusInputStream, _Types...> visitor((*this), _value);
- ApplyVoidVisitor<InputStreamReadVisitor<DBusInputStream, _Types... >,
- Variant<_Types...>, _Types...>::visit(visitor, _value);
+ template<class Deployment_, typename... Types_>
+ COMMONAPI_EXPORT InputStream &readValue(Struct<Types_...> &_value, const Deployment_ *_depl) {
+ align(8);
+ const auto itsSize(std::tuple_size<std::tuple<Types_...>>::value);
+ StructReader<itsSize-1, DBusInputStream, Struct<Types_...>, Deployment_>{}(
+ (*this), _value, _depl);
+ return (*this);
+ }
- return (*this);
+ template<class Deployment_, class PolymorphicStruct_>
+ COMMONAPI_EXPORT InputStream &readValue(std::shared_ptr<PolymorphicStruct_> &_value,
+ const Deployment_ *_depl) {
+ uint32_t serial;
+ align(8);
+ _readValue(serial);
+ skipSignature();
+ align(8);
+ if (!hasError()) {
+ _value = PolymorphicStruct_::create(serial);
+ _value->template readValue<>(*this, _depl);
+ }
+
+ return (*this);
+ }
+
+ template<typename... Types_>
+ COMMONAPI_EXPORT InputStream &readValue(Variant<Types_...> &_value, const CommonAPI::EmptyDeployment *_depl = nullptr) {
+ (void)_depl;
+ if(_value.hasValue()) {
+ DeleteVisitor<_value.maxSize> visitor(_value.valueStorage_);
+ ApplyVoidVisitor<DeleteVisitor<_value.maxSize>,
+ Variant<Types_...>, Types_... >::visit(visitor, _value);
+ }
+
+ align(8);
+ readValue(_value.valueType_, static_cast<EmptyDeployment *>(nullptr));
+ skipSignature();
+
+ InputStreamReadVisitor<DBusInputStream, Types_...> visitor((*this), _value);
+ ApplyVoidVisitor<InputStreamReadVisitor<DBusInputStream, Types_... >,
+ Variant<Types_...>, Types_...>::visit(visitor, _value);
+
+ return (*this);
}
- template<typename _Deployment, typename... _Types>
- COMMONAPI_EXPORT InputStream &readValue(Variant<_Types...> &_value, const _Deployment *_depl) {
- if(_value.hasValue()) {
- DeleteVisitor<_value.maxSize> visitor(_value.valueStorage_);
- ApplyVoidVisitor<DeleteVisitor<_value.maxSize>,
- Variant<_Types...>, _Types... >::visit(visitor, _value);
- }
-
- if (_depl != nullptr && _depl->isDBus_) {
- // Read signature
- uint8_t signatureLength;
- readValue(signatureLength, static_cast<EmptyDeployment *>(nullptr));
- std::string signature(_readRaw(signatureLength+1), signatureLength);
-
- // Determine index (value type) from signature
- TypeCompareVisitor<_Types...> visitor(signature);
- _value.valueType_ = ApplyTypeCompareVisitor<
- TypeCompareVisitor<_Types...>,
- Variant<_Types...>,
- _Types...
- >::visit(visitor, _value);
- } else {
- align(8);
- readValue(_value.valueType_, static_cast<EmptyDeployment *>(nullptr));
- skipSignature();
- }
-
-
- InputStreamReadVisitor<DBusInputStream, _Types...> visitor((*this), _value);
- ApplyVoidVisitor<InputStreamReadVisitor<DBusInputStream, _Types... >,
- Variant<_Types...>, _Types...>::visit(visitor, _value);
-
- return (*this);
+ template<typename Deployment_, typename... Types_>
+ COMMONAPI_EXPORT InputStream &readValue(Variant<Types_...> &_value, const Deployment_ *_depl) {
+ if(_value.hasValue()) {
+ DeleteVisitor<_value.maxSize> visitor(_value.valueStorage_);
+ ApplyVoidVisitor<DeleteVisitor<_value.maxSize>,
+ Variant<Types_...>, Types_... >::visit(visitor, _value);
+ }
+
+ if (_depl != nullptr && _depl->isDBus_) {
+ // Read signature
+ uint8_t signatureLength;
+ readValue(signatureLength, static_cast<EmptyDeployment *>(nullptr));
+ std::string signature(_readRaw(signatureLength+1), signatureLength);
+
+ // Determine index (value type) from signature
+ TypeCompareVisitor<Types_...> visitor(signature);
+ bool success = ApplyTypeCompareVisitor<
+ TypeCompareVisitor<Types_...>,
+ Variant<Types_...>,
+ Deployment_,
+ Types_...
+ >::visit(visitor, _value, _depl, _value.valueType_);
+ if (!success) {
+ _value.valueType_ = _value.maxSize + 1;
+ setError();
+ return (*this);
+ }
+ } else {
+ align(8);
+ readValue(_value.valueType_, static_cast<EmptyDeployment *>(nullptr));
+ skipSignature();
+ }
+
+
+ InputStreamReadVisitor<DBusInputStream, Types_...> visitor((*this), _value);
+ ApplyStreamVisitor<InputStreamReadVisitor<DBusInputStream, Types_... >,
+ Variant<Types_...>, Deployment_, Types_...>::visit(visitor, _value, _depl);
+
+ return (*this);
}
- template<typename _ElementType>
- COMMONAPI_EXPORT InputStream &readValue(std::vector<_ElementType> &_value, const EmptyDeployment *_depl) {
- uint32_t itsSize;
- _readValue(itsSize);
- pushSize(itsSize);
+ template<typename ElementType_>
+ COMMONAPI_EXPORT InputStream &readValue(std::vector<ElementType_> &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
- alignVector<_ElementType>();
+ uint32_t itsSize;
+ _readValue(itsSize);
+ pushSize(itsSize);
- pushPosition();
+ alignVector<ElementType_>();
- _value.clear();
- while (sizes_.top() > current_ - positions_.top()) {
- _ElementType itsElement;
- readValue(itsElement, static_cast<EmptyDeployment *>(nullptr));
+ pushPosition();
- if (hasError()) {
- break;
- }
+ _value.clear();
+ while (sizes_.top() > current_ - positions_.top()) {
+ ElementType_ itsElement;
+ readValue(itsElement, static_cast<EmptyDeployment *>(nullptr));
- _value.push_back(std::move(itsElement));
- }
+ if (hasError()) {
+ break;
+ }
- popSize();
- popPosition();
+ _value.push_back(std::move(itsElement));
+ }
- return (*this);
+ popSize();
+ popPosition();
+
+ return (*this);
}
- template<class _Deployment, typename _ElementType>
- COMMONAPI_EXPORT InputStream &readValue(std::vector<_ElementType> &_value, const _Deployment *_depl) {
- uint32_t itsSize;
- _readValue(itsSize);
- pushSize(itsSize);
+ template<class Deployment_, typename ElementType_>
+ COMMONAPI_EXPORT InputStream &readValue(std::vector<ElementType_> &_value, const Deployment_ *_depl) {
+ uint32_t itsSize;
+ _readValue(itsSize);
+ pushSize(itsSize);
- alignVector<_ElementType>();
+ alignVector<ElementType_>();
- pushPosition();
+ pushPosition();
- _value.clear();
- while (sizes_.top() > current_ - positions_.top()) {
- _ElementType itsElement;
- readValue(itsElement, (_depl ? _depl->elementDepl_ : nullptr));
+ _value.clear();
+ while (sizes_.top() > current_ - positions_.top()) {
+ ElementType_ itsElement;
+ readValue(itsElement, (_depl ? _depl->elementDepl_ : nullptr));
- if (hasError()) {
- break;
- }
+ if (hasError()) {
+ break;
+ }
- _value.push_back(std::move(itsElement));
- }
+ _value.push_back(std::move(itsElement));
+ }
- popSize();
- popPosition();
+ popSize();
+ popPosition();
- return (*this);
+ return (*this);
}
- template<typename _KeyType, typename _ValueType, typename _HasherType>
- COMMONAPI_EXPORT InputStream &readValue(std::unordered_map<_KeyType, _ValueType, _HasherType> &_value,
- const EmptyDeployment *_depl) {
+ template<typename KeyType_, typename ValueType_, typename HasherType_>
+ COMMONAPI_EXPORT InputStream &readValue(std::unordered_map<KeyType_, ValueType_, HasherType_> &_value,
+ const EmptyDeployment *_depl) {
- typedef typename std::unordered_map<_KeyType, _ValueType, _HasherType>::value_type MapElement;
+ typedef typename std::unordered_map<KeyType_, ValueType_, HasherType_>::value_type MapElement;
- uint32_t itsSize;
- _readValue(itsSize);
- pushSize(itsSize);
+ uint32_t itsSize;
+ _readValue(itsSize);
+ pushSize(itsSize);
- align(8);
- pushPosition();
+ align(8);
+ pushPosition();
- _value.clear();
- while (sizes_.top() > current_ - positions_.top()) {
- _KeyType itsKey;
- _ValueType itsValue;
+ _value.clear();
+ while (sizes_.top() > current_ - positions_.top()) {
+ KeyType_ itsKey;
+ ValueType_ itsValue;
- align(8);
- readValue(itsKey, _depl);
- readValue(itsValue, _depl);
+ align(8);
+ readValue(itsKey, _depl);
+ readValue(itsValue, _depl);
- if (hasError()) {
- break;
- }
+ if (hasError()) {
+ break;
+ }
- _value.insert(MapElement(std::move(itsKey), std::move(itsValue)));
- }
+ _value.insert(MapElement(std::move(itsKey), std::move(itsValue)));
+ }
- (void)popSize();
- (void)popPosition();
+ (void)popSize();
+ (void)popPosition();
- return (*this);
+ return (*this);
}
- template<class _Deployment, typename _KeyType, typename _ValueType, typename _HasherType>
- COMMONAPI_EXPORT InputStream &readValue(std::unordered_map<_KeyType, _ValueType, _HasherType> &_value,
- const _Deployment *_depl) {
+ template<class Deployment_, typename KeyType_, typename ValueType_, typename HasherType_>
+ COMMONAPI_EXPORT InputStream &readValue(std::unordered_map<KeyType_, ValueType_, HasherType_> &_value,
+ const Deployment_ *_depl) {
- typedef typename std::unordered_map<_KeyType, _ValueType, _HasherType>::value_type MapElement;
+ typedef typename std::unordered_map<KeyType_, ValueType_, HasherType_>::value_type MapElement;
- uint32_t itsSize;
- _readValue(itsSize);
- pushSize(itsSize);
+ uint32_t itsSize;
+ _readValue(itsSize);
+ pushSize(itsSize);
- align(8);
- pushPosition();
+ align(8);
+ pushPosition();
- _value.clear();
- while (sizes_.top() > current_ - positions_.top()) {
- _KeyType itsKey;
- _ValueType itsValue;
+ _value.clear();
+ while (sizes_.top() > current_ - positions_.top()) {
+ KeyType_ itsKey;
+ ValueType_ itsValue;
- align(8);
- readValue(itsKey, (_depl ? _depl->key_ : nullptr));
- readValue(itsValue, (_depl ? _depl->value_ : nullptr));
+ align(8);
+ readValue(itsKey, (_depl ? _depl->key_ : nullptr));
+ readValue(itsValue, (_depl ? _depl->value_ : nullptr));
- if (hasError()) {
- break;
- }
+ if (hasError()) {
+ break;
+ }
- _value.insert(MapElement(std::move(itsKey), std::move(itsValue)));
- }
+ _value.insert(MapElement(std::move(itsKey), std::move(itsValue)));
+ }
- (void)popSize();
- (void)popPosition();
+ (void)popSize();
+ (void)popPosition();
- return (*this);
+ return (*this);
}
/**
@@ -316,31 +326,31 @@ public:
*
* @param message the #DBusMessage from which data should be read.
*/
- COMMONAPI_EXPORT DBusInputStream(const CommonAPI::DBus::DBusMessage &_message);
- COMMONAPI_EXPORT DBusInputStream(const DBusInputStream &_stream) = delete;
+ COMMONAPI_EXPORT DBusInputStream(const CommonAPI::DBus::DBusMessage &_message);
+ COMMONAPI_EXPORT DBusInputStream(const DBusInputStream &_stream) = delete;
/**
* Destructor; does not call the destructor of the referred #DBusMessage. Make sure to maintain a reference to the
* #DBusMessage outside of the stream if you intend to make further use of the message.
*/
- COMMONAPI_EXPORT ~DBusInputStream();
+ COMMONAPI_EXPORT ~DBusInputStream();
// Marks the stream as erroneous.
- COMMONAPI_EXPORT void setError();
+ COMMONAPI_EXPORT void setError();
/**
* @return An instance of #DBusError if this stream is in an erroneous state, NULL otherwise
*/
- COMMONAPI_EXPORT const DBusError &getError() const;
+ COMMONAPI_EXPORT const DBusError &getError() const;
/**
* @return true if this stream is in an erroneous state, false otherwise.
*/
- COMMONAPI_EXPORT bool isErrorSet() const;
+ COMMONAPI_EXPORT bool isErrorSet() const;
// Marks the state of the stream as cleared from all errors. Further reading is possible afterwards.
// The stream will have maintained the last valid position from before its state became erroneous.
- COMMONAPI_EXPORT void clearError();
+ COMMONAPI_EXPORT void clearError();
/**
* Aligns the stream to the given byte boundary, i.e. the stream skips as many bytes as are necessary to execute the next read
@@ -348,7 +358,7 @@ public:
*
* @param _boundary the byte boundary to which the stream needs to be aligned.
*/
- COMMONAPI_EXPORT void align(const size_t _boundary);
+ COMMONAPI_EXPORT void align(const size_t _boundary);
/**
* Reads the given number of bytes and returns them as an array of characters.
@@ -368,7 +378,7 @@ public:
* ...
* @endcode
*/
- COMMONAPI_EXPORT char *_readRaw(const size_t _size);
+ COMMONAPI_EXPORT char *_readRaw(const size_t _size);
/**
* Handles all reading of basic types from a given #DBusInputMessageStream.
@@ -376,33 +386,33 @@ public:
* Any types not listed here (especially all complex types, e.g. structs, unions etc.) need to provide a
* specialized implementation of this operator.
*
- * @tparam _Type The type of the value that is to be read from the given stream.
+ * @tparam Type_ The type of the value that is to be read from the given stream.
* @param _value The variable in which the retrieved value is to be stored
* @return The given inputMessageStream to allow for successive reading
*/
- template<typename _Type>
- COMMONAPI_EXPORT DBusInputStream &_readValue(_Type &_value) {
+ template<typename Type_>
+ COMMONAPI_EXPORT DBusInputStream &_readValue(Type_ &_value) {
if (sizeof(_value) > 1)
- align(sizeof(_Type));
+ align(sizeof(Type_));
- _value = *(reinterpret_cast<_Type *>(_readRaw(sizeof(_Type))));
+ _value = *(reinterpret_cast<Type_ *>(_readRaw(sizeof(Type_))));
return (*this);
}
- COMMONAPI_EXPORT DBusInputStream &_readValue(float &_value) {
- align(sizeof(double));
+ COMMONAPI_EXPORT DBusInputStream &_readValue(float &_value) {
+ align(sizeof(double));
_value = (float) (*(reinterpret_cast<double*>(_readRaw(sizeof(double)))));
return (*this);
}
private:
- COMMONAPI_EXPORT void pushPosition();
- COMMONAPI_EXPORT size_t popPosition();
+ COMMONAPI_EXPORT void pushPosition();
+ COMMONAPI_EXPORT size_t popPosition();
- COMMONAPI_EXPORT void pushSize(size_t _size);
- COMMONAPI_EXPORT size_t popSize();
+ COMMONAPI_EXPORT void pushSize(size_t _size);
+ COMMONAPI_EXPORT size_t popSize();
inline void skipSignature() {
uint8_t length;
@@ -410,34 +420,40 @@ private:
_readRaw(length + 1);
}
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_class<_Type>::value>::type * = nullptr,
- typename std::enable_if<!is_std_vector<_Type>::value>::type * = nullptr,
- typename std::enable_if<!is_std_unordered_map<_Type>::value>::type * = nullptr) {
- if (4 < sizeof(_Type)) align(8);
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_class<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!is_std_vector<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!is_std_unordered_map<Type_>::value>::type * = nullptr) {
+ if (4 < sizeof(Type_)) align(8);
+ }
+
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_same<Type_, std::string>::value>::type * = nullptr,
+ typename std::enable_if<std::is_class<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!is_std_vector<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!is_std_unordered_map<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!std::is_base_of<Enumeration<int32_t>, Type_>::value>::type * = nullptr) {
+ align(8);
}
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_same<_Type, std::string>::value>::type * = nullptr,
- typename std::enable_if<std::is_class<_Type>::value>::type * = nullptr,
- typename std::enable_if<!is_std_vector<_Type>::value>::type * = nullptr,
- typename std::enable_if<!is_std_unordered_map<_Type>::value>::type * = nullptr) {
- align(8);
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_same<Type_, std::string>::value>::type * = nullptr) {
+ // Intentionally do nothing
}
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_same<_Type, std::string>::value>::type * = nullptr) {
- // Intentionally do nothing
- }
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_vector<Type_>::value>::type * = nullptr) {
+ // Intentionally do nothing
+ }
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_vector<_Type>::value>::type * = nullptr) {
- // Intentionally do nothing
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_unordered_map<Type_>::value>::type * = nullptr) {
+ align(4);
}
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_unordered_map<_Type>::value>::type * = nullptr) {
- align(4);
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_base_of<Enumeration<int32_t>, Type_>::value>::type * = nullptr) {
+ align(4);
}
char *begin_;
diff --git a/include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp b/include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp
index 0f3dd24..6c6c9e1 100644
--- a/include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp
+++ b/include/CommonAPI/DBus/DBusInstanceAvailabilityStatusChangedEvent.hpp
@@ -36,8 +36,8 @@ class DBusInstanceAvailabilityStatusChangedEvent:
}
virtual ~DBusInstanceAvailabilityStatusChangedEvent() {
- proxy_.removeSignalMemberHandler(interfacesAddedSubscription_);
- proxy_.removeSignalMemberHandler(interfacesRemovedSubscription_);
+ proxy_.removeSignalMemberHandler(interfacesAddedSubscription_, this);
+ proxy_.removeSignalMemberHandler(interfacesRemovedSubscription_, this);
}
virtual void onSignalDBusMessage(const DBusMessage& dbusMessage) {
@@ -59,7 +59,7 @@ class DBusInstanceAvailabilityStatusChangedEvent:
false);
interfacesRemovedSubscription_ = proxy_.addSignalMemberHandler(
- proxy_.getDBusAddress().getObjectPath(),
+ proxy_.getDBusAddress().getObjectPath(),
DBusObjectManagerStub::getInterfaceName(),
"InterfacesRemoved",
"oas",
@@ -68,8 +68,8 @@ class DBusInstanceAvailabilityStatusChangedEvent:
}
virtual void onLastListenerRemoved(const Listener&) {
- proxy_.removeSignalMemberHandler(interfacesAddedSubscription_);
- proxy_.removeSignalMemberHandler(interfacesRemovedSubscription_);
+ proxy_.removeSignalMemberHandler(interfacesAddedSubscription_, this);
+ proxy_.removeSignalMemberHandler(interfacesRemovedSubscription_, this);
}
private:
@@ -118,8 +118,8 @@ class DBusInstanceAvailabilityStatusChangedEvent:
const AvailabilityStatus &_availability) {
CommonAPI::Address itsAddress;
DBusAddress itsDBusAddress(proxy_.getDBusAddress().getService(),
- _objectPath,
- _interfaceName);
+ _objectPath,
+ _interfaceName);
DBusAddressTranslator::get()->translate(itsDBusAddress, itsAddress);
diff --git a/include/CommonAPI/DBus/DBusInterfaceHandler.hpp b/include/CommonAPI/DBus/DBusInterfaceHandler.hpp
index c570975..fa6c0bb 100644
--- a/include/CommonAPI/DBus/DBusInterfaceHandler.hpp
+++ b/include/CommonAPI/DBus/DBusInterfaceHandler.hpp
@@ -22,7 +22,7 @@ class DBusInterfaceHandler {
virtual bool onInterfaceDBusMessage(const DBusMessage& dbusMessage) = 0;
- virtual const bool hasFreedesktopProperties() = 0;
+ virtual bool hasFreedesktopProperties() = 0;
};
} // namespace dbus
diff --git a/include/CommonAPI/DBus/DBusMainLoop.hpp b/include/CommonAPI/DBus/DBusMainLoop.hpp
new file mode 100755
index 0000000..2fff847
--- /dev/null
+++ b/include/CommonAPI/DBus/DBusMainLoop.hpp
@@ -0,0 +1,185 @@
+// Copyright (C) 2013-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
+// 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_DBUS_MAIN_LOOP_HPP_
+#define COMMONAPI_DBUS_MAIN_LOOP_HPP_
+
+#if !defined (COMMONAPI_INTERNAL_COMPILATION)
+#define COMMONAPI_INTERNAL_COMPILATION
+#endif
+
+#include <CommonAPI/MainLoopContext.hpp>
+
+#include <condition_variable>
+#include <map>
+#include <memory>
+#include <mutex>
+#include <set>
+#include <vector>
+
+namespace CommonAPI {
+namespace DBus {
+
+typedef pollfd DBusMainLoopPollFd;
+
+class DBusMainLoop {
+ public:
+ DBusMainLoop() = delete;
+ DBusMainLoop(const DBusMainLoop&) = delete;
+ DBusMainLoop& operator=(const DBusMainLoop&) = delete;
+ DBusMainLoop(DBusMainLoop&&) = delete;
+ DBusMainLoop& operator=(DBusMainLoop&&) = delete;
+
+ COMMONAPI_EXPORT explicit DBusMainLoop(std::shared_ptr<MainLoopContext> context);
+ COMMONAPI_EXPORT ~DBusMainLoop();
+
+ /**
+ * \brief Runs the mainloop indefinitely until stop() is called.
+ *
+ * Runs the mainloop indefinitely until stop() is called. The given timeout (milliseconds)
+ * will be overridden if a timeout-event is present that defines an earlier ready time.
+ */
+ COMMONAPI_EXPORT void run(const int64_t& timeoutInterval = TIMEOUT_INFINITE);
+ COMMONAPI_EXPORT void stop();
+
+ /**
+ * \brief Executes a single cycle of the mainloop.
+ *
+ * Subsequently calls prepare(), poll(), check() and, if necessary, dispatch().
+ * The given timeout (milliseconds) represents the maximum time
+ * this iteration will remain in the poll state. All other steps
+ * are handled in a non-blocking way. Note however that a source
+ * might claim to have infinite amounts of data to dispatch.
+ * This demo-implementation of a Mainloop will dispatch a source
+ * until it no longer claims to have data to dispatch.
+ * Dispatch will not be called if no sources, watches and timeouts
+ * claim to be ready during the check()-phase.
+ *
+ * @param timeout The maximum poll-timeout for this iteration.
+ */
+ COMMONAPI_EXPORT void doSingleIteration(const int64_t& timeout = TIMEOUT_INFINITE);
+
+ /*
+ * The given timeout is a maximum timeout in ms, measured from the current time in the future
+ * (a value of 0 means "no timeout"). It will be overridden if a timeout-event is present
+ * that defines an earlier ready time.
+ */
+ COMMONAPI_EXPORT bool prepare(const int64_t& timeout = TIMEOUT_INFINITE);
+ COMMONAPI_EXPORT void poll();
+ COMMONAPI_EXPORT bool check();
+ COMMONAPI_EXPORT void dispatch();
+
+ private:
+ COMMONAPI_EXPORT void wakeup();
+ COMMONAPI_EXPORT void wakeupAck();
+
+ COMMONAPI_EXPORT void registerFileDescriptor(const DBusMainLoopPollFd& fileDescriptor);
+ COMMONAPI_EXPORT void unregisterFileDescriptor(const DBusMainLoopPollFd& fileDescriptor);
+
+ COMMONAPI_EXPORT void registerDispatchSource(DispatchSource* dispatchSource, const DispatchPriority dispatchPriority);
+ COMMONAPI_EXPORT void unregisterDispatchSource(DispatchSource* dispatchSource);
+
+ COMMONAPI_EXPORT void registerWatch(Watch* watch, const DispatchPriority dispatchPriority);
+ COMMONAPI_EXPORT void unregisterWatch(Watch* watch);
+
+ COMMONAPI_EXPORT void registerTimeout(Timeout* timeout, const DispatchPriority dispatchPriority);
+ COMMONAPI_EXPORT void unregisterTimeout(Timeout* timeout);
+
+
+ std::shared_ptr<MainLoopContext> context_;
+
+ std::vector<DBusMainLoopPollFd> managedFileDescriptors_;
+ std::mutex fileDescriptorsMutex_;
+
+ struct DispatchSourceToDispatchStruct {
+ DispatchSource* dispatchSource_;
+ std::mutex* mutex_;
+ bool isExecuted_; /* execution flag: indicates, whether the dispatchSource is dispatched currently */
+ bool deleteObject_; /* delete flag: indicates, whether the dispatchSource can be deleted*/
+
+ DispatchSourceToDispatchStruct(DispatchSource* _dispatchSource,
+ std::mutex* _mutex,
+ bool _isExecuted,
+ bool _deleteObject) {
+ dispatchSource_ = _dispatchSource;
+ mutex_ = _mutex;
+ isExecuted_ = _isExecuted;
+ deleteObject_ = _deleteObject;
+ }
+ };
+
+ struct TimeoutToDispatchStruct {
+ Timeout* timeout_;
+ std::mutex* mutex_;
+ bool isExecuted_; /* execution flag: indicates, whether the timeout is dispatched currently */
+ bool deleteObject_; /* delete flag: indicates, whether the timeout can be deleted*/
+ bool timeoutElapsed_; /* timeout elapsed flag: indicates, whether the timeout is elapsed*/
+
+ TimeoutToDispatchStruct(Timeout* _timeout,
+ std::mutex* _mutex,
+ bool _isExecuted,
+ bool _deleteObject,
+ bool _timeoutElapsed) {
+ timeout_ = _timeout;
+ mutex_ = _mutex;
+ isExecuted_ = _isExecuted;
+ deleteObject_ = _deleteObject;
+ timeoutElapsed_ = _timeoutElapsed;
+ }
+ };
+
+ struct WatchToDispatchStruct {
+ int fd_;
+ Watch* watch_;
+ std::mutex* mutex_;
+ bool isExecuted_; /* execution flag: indicates, whether the watch is dispatched currently */
+ bool deleteObject_; /* delete flag: indicates, whether the watch can be deleted*/
+
+ WatchToDispatchStruct(int _fd,
+ Watch* _watch,
+ std::mutex* _mutex,
+ bool _isExecuted,
+ bool _deleteObject) {
+ fd_ = _fd;
+ watch_ = _watch;
+ mutex_ = _mutex;
+ isExecuted_ = _isExecuted;
+ deleteObject_ = _deleteObject;
+ }
+ };
+
+ std::multimap<DispatchPriority, DispatchSourceToDispatchStruct*> registeredDispatchSources_;
+ std::multimap<DispatchPriority, WatchToDispatchStruct*> registeredWatches_;
+ std::multimap<DispatchPriority, TimeoutToDispatchStruct*> registeredTimeouts_;
+
+ std::mutex dispatchSourcesMutex_;
+ std::mutex watchesMutex_;
+ std::mutex timeoutsMutex_;
+
+ std::set<DispatchSourceToDispatchStruct*> sourcesToDispatch_;
+ std::set<WatchToDispatchStruct*> watchesToDispatch_;
+ std::set<TimeoutToDispatchStruct*> timeoutsToDispatch_;
+
+ DispatchSourceListenerSubscription dispatchSourceListenerSubscription_;
+ WatchListenerSubscription watchListenerSubscription_;
+ TimeoutSourceListenerSubscription timeoutSourceListenerSubscription_;
+ WakeupListenerSubscription wakeupListenerSubscription_;
+
+ int64_t currentMinimalTimeoutInterval_;
+
+ DBusMainLoopPollFd wakeFd_;
+
+#ifdef WIN32
+ DBusMainLoopPollFd sendFd_;
+#endif
+
+ bool hasToStop_;
+ bool isBroken_;
+};
+
+} // namespace DBus
+} // namespace CommonAPI
+
+#endif // COMMONAPI_DEMO_MAIN_LOOP_HPP_
diff --git a/include/CommonAPI/DBus/DBusMainLoopContext.hpp b/include/CommonAPI/DBus/DBusMainLoopContext.hpp
index 27428db..8cf9cf2 100644
--- a/include/CommonAPI/DBus/DBusMainLoopContext.hpp
+++ b/include/CommonAPI/DBus/DBusMainLoopContext.hpp
@@ -48,7 +48,7 @@ class DBusWatch: public Watch {
const pollfd& getAssociatedFileDescriptor();
#ifdef WIN32
- const HANDLE& getAssociatedEvent();
+ const HANDLE& getAssociatedEvent();
#endif
const std::vector<DispatchSource*>& getDependentDispatchSources();
@@ -63,7 +63,7 @@ class DBusWatch: public Watch {
std::weak_ptr<MainLoopContext> mainLoopContext_;
#ifdef WIN32
- HANDLE wsaEvent_;
+ HANDLE wsaEvent_;
#endif
};
diff --git a/include/CommonAPI/DBus/DBusMessage.hpp b/include/CommonAPI/DBus/DBusMessage.hpp
index 97c521d..0519e9d 100644
--- a/include/CommonAPI/DBus/DBusMessage.hpp
+++ b/include/CommonAPI/DBus/DBusMessage.hpp
@@ -70,7 +70,7 @@ public:
const char* getSignature() const;
const char* getError() const;
const char* getDestination() const;
- const uint32_t getSerial() const;
+ uint32_t getSerial() const;
bool hasObjectPath(const std::string& objectPath) const;
@@ -79,7 +79,7 @@ public:
bool hasMemberName(const char* memberName) const;
bool hasSignature(const char* signature) const;
- const Type getType() const;
+ Type getType() const;
bool isInvalidType() const;
bool isMethodCallType() const;
bool isMethodReturnType() const;
diff --git a/include/CommonAPI/DBus/DBusMultiEvent.hpp b/include/CommonAPI/DBus/DBusMultiEvent.hpp
index 8215d4f..db0c1e5 100644
--- a/include/CommonAPI/DBus/DBusMultiEvent.hpp
+++ b/include/CommonAPI/DBus/DBusMultiEvent.hpp
@@ -18,98 +18,98 @@
namespace CommonAPI {
namespace DBus {
-template <typename... _Arguments>
+template <typename... Arguments_>
class DBusMultiEvent {
public:
- typedef std::function<SubscriptionStatus(const std::string&, const _Arguments&...)> Listener;
- typedef std::unordered_multimap<std::string, Listener> ListenersMap;
- typedef typename ListenersMap::iterator Subscription;
+ typedef std::function<SubscriptionStatus(const std::string&, const Arguments_&...)> Listener;
+ typedef std::unordered_multimap<std::string, Listener> ListenersMap;
+ typedef typename ListenersMap::iterator Subscription;
- virtual ~DBusMultiEvent() {}
+ virtual ~DBusMultiEvent() {}
- Subscription subscribeAll(const Listener& listener);
- Subscription subscribe(const std::string& eventName, const Listener& listener);
+ Subscription subscribeAll(const Listener& listener);
+ Subscription subscribe(const std::string& eventName, const Listener& listener);
- void unsubscribe(Subscription listenerSubscription);
+ void unsubscribe(Subscription listenerSubscription);
protected:
- SubscriptionStatus notifyListeners(const std::string& name, const _Arguments&... eventArguments);
+ SubscriptionStatus notifyListeners(const std::string& name, const Arguments_&... eventArguments);
- virtual void onFirstListenerAdded(const std::string& name, const Listener& listener) { }
- virtual void onListenerAdded(const std::string& name, const Listener& listener) { }
+ virtual void onFirstListenerAdded(const std::string& name, const Listener& listener) { }
+ virtual void onListenerAdded(const std::string& name, const Listener& listener) { }
- virtual void onListenerRemoved(const std::string& name, const Listener& listener) { }
- virtual void onLastListenerRemoved(const std::string& name, const Listener& listener) { }
+ virtual void onListenerRemoved(const std::string& name, const Listener& listener) { }
+ virtual void onLastListenerRemoved(const std::string& name, const Listener& listener) { }
private:
- typedef std::pair<typename ListenersMap::iterator, typename ListenersMap::iterator> IteratorRange;
- SubscriptionStatus notifyListenersRange(const std::string& name, IteratorRange listenersRange, const _Arguments&... eventArguments);
+ typedef std::pair<typename ListenersMap::iterator, typename ListenersMap::iterator> IteratorRange;
+ SubscriptionStatus notifyListenersRange(const std::string& name, IteratorRange listenersRange, const Arguments_&... eventArguments);
- ListenersMap listenersMap_;
+ ListenersMap listenersMap_;
};
-template <typename... _Arguments>
-typename DBusMultiEvent<_Arguments...>::Subscription
-DBusMultiEvent<_Arguments...>::subscribeAll(const Listener& listener) {
- return subscribe(std::string(), listener);
+template <typename... Arguments_>
+typename DBusMultiEvent<Arguments_...>::Subscription
+DBusMultiEvent<Arguments_...>::subscribeAll(const Listener& listener) {
+ return subscribe(std::string(), listener);
}
-template <typename... _Arguments>
-typename DBusMultiEvent<_Arguments...>::Subscription
-DBusMultiEvent<_Arguments...>::subscribe(const std::string& eventName, const Listener& listener) {
- const bool firstListenerAdded = listenersMap_.empty();
+template <typename... Arguments_>
+typename DBusMultiEvent<Arguments_...>::Subscription
+DBusMultiEvent<Arguments_...>::subscribe(const std::string& eventName, const Listener& listener) {
+ const bool firstListenerAdded = listenersMap_.empty();
- auto listenerSubscription = listenersMap_.insert({eventName, listener});
+ auto listenerSubscription = listenersMap_.insert({eventName, listener});
- if (firstListenerAdded) {
- onFirstListenerAdded(eventName, listener);
- }
+ if (firstListenerAdded) {
+ onFirstListenerAdded(eventName, listener);
+ }
- onListenerAdded(eventName, listener);
+ onListenerAdded(eventName, listener);
- return listenerSubscription;
+ return listenerSubscription;
}
-template <typename... _Arguments>
-void DBusMultiEvent<_Arguments...>::unsubscribe(Subscription listenerSubscription) {
- const std::string name = listenerSubscription->first;
- const Listener listener = listenerSubscription->second;
+template <typename... Arguments_>
+void DBusMultiEvent<Arguments_...>::unsubscribe(Subscription listenerSubscription) {
+ const std::string name = listenerSubscription->first;
+ const Listener listener = listenerSubscription->second;
- listenersMap_.erase(listenerSubscription);
+ listenersMap_.erase(listenerSubscription);
- onListenerRemoved(name, listener);
+ onListenerRemoved(name, listener);
- const bool lastListenerRemoved = listenersMap_.empty();
- if (lastListenerRemoved)
- onLastListenerRemoved(name, listener);
+ const bool lastListenerRemoved = listenersMap_.empty();
+ if (lastListenerRemoved)
+ onLastListenerRemoved(name, listener);
}
-template <typename... _Arguments>
-SubscriptionStatus DBusMultiEvent<_Arguments...>::notifyListeners(const std::string& name, const _Arguments&... eventArguments) {
- const SubscriptionStatus subscriptionStatus = notifyListenersRange(name, listenersMap_.equal_range(name), eventArguments...);
+template <typename... Arguments_>
+SubscriptionStatus DBusMultiEvent<Arguments_...>::notifyListeners(const std::string& name, const Arguments_&... eventArguments) {
+ const SubscriptionStatus subscriptionStatus = notifyListenersRange(name, listenersMap_.equal_range(name), eventArguments...);
- if (subscriptionStatus == SubscriptionStatus::CANCEL)
- return SubscriptionStatus::CANCEL;
+ if (subscriptionStatus == SubscriptionStatus::CANCEL)
+ return SubscriptionStatus::CANCEL;
- return notifyListenersRange(name, listenersMap_.equal_range(std::string()), eventArguments...);
+ return notifyListenersRange(name, listenersMap_.equal_range(std::string()), eventArguments...);
}
-template <typename... _Arguments>
-SubscriptionStatus DBusMultiEvent<_Arguments...>::notifyListenersRange(
- const std::string& name,
- IteratorRange listenersRange,
- const _Arguments&... eventArguments) {
- for (auto iterator = listenersRange.first; iterator != listenersRange.second; iterator++) {
- const Listener& listener = iterator->second;
- const SubscriptionStatus listenerSubcriptionStatus = listener(name, eventArguments...);
-
- if (listenerSubcriptionStatus == SubscriptionStatus::CANCEL) {
- auto listenerIterator = iterator;
- listenersMap_.erase(listenerIterator);
- }
- }
-
- return listenersMap_.empty() ? SubscriptionStatus::CANCEL : SubscriptionStatus::RETAIN;
+template <typename... Arguments_>
+SubscriptionStatus DBusMultiEvent<Arguments_...>::notifyListenersRange(
+ const std::string& name,
+ IteratorRange listenersRange,
+ const Arguments_&... eventArguments) {
+ for (auto iterator = listenersRange.first; iterator != listenersRange.second; iterator++) {
+ const Listener& listener = iterator->second;
+ const SubscriptionStatus listenerSubcriptionStatus = listener(name, eventArguments...);
+
+ if (listenerSubcriptionStatus == SubscriptionStatus::CANCEL) {
+ auto listenerIterator = iterator;
+ listenersMap_.erase(listenerIterator);
+ }
+ }
+
+ return listenersMap_.empty() ? SubscriptionStatus::CANCEL : SubscriptionStatus::RETAIN;
}
} // namespace DBus
diff --git a/include/CommonAPI/DBus/DBusObjectManager.hpp b/include/CommonAPI/DBus/DBusObjectManager.hpp
index 8c7225b..e2ec2c5 100644
--- a/include/CommonAPI/DBus/DBusObjectManager.hpp
+++ b/include/CommonAPI/DBus/DBusObjectManager.hpp
@@ -22,32 +22,32 @@ class DBusInterfaceHandler;
class DBusObjectManager {
public:
- COMMONAPI_EXPORT DBusObjectManager(const std::shared_ptr<DBusProxyConnection>&);
- COMMONAPI_EXPORT ~DBusObjectManager();
+ COMMONAPI_EXPORT DBusObjectManager(const std::shared_ptr<DBusProxyConnection>&);
+ COMMONAPI_EXPORT ~DBusObjectManager();
- COMMONAPI_EXPORT bool registerDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
- COMMONAPI_EXPORT bool unregisterDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool registerDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool unregisterDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
//Zusammenfassbar mit "registerDBusStubAdapter"?
- COMMONAPI_EXPORT bool exportManagedDBusStubAdapter(const std::string& parentObjectPath, std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
- COMMONAPI_EXPORT bool unexportManagedDBusStubAdapter(const std::string& parentObjectPath, std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool exportManagedDBusStubAdapter(const std::string& parentObjectPath, std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool unexportManagedDBusStubAdapter(const std::string& parentObjectPath, std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
- COMMONAPI_EXPORT bool handleMessage(const DBusMessage&);
+ COMMONAPI_EXPORT bool handleMessage(const DBusMessage&);
- COMMONAPI_EXPORT std::shared_ptr<DBusObjectManagerStub> getRootDBusObjectManagerStub();
+ COMMONAPI_EXPORT std::shared_ptr<DBusObjectManagerStub> getRootDBusObjectManagerStub();
private:
// objectPath, interfaceName
- typedef std::pair<std::string, std::string> DBusInterfaceHandlerPath;
+ typedef std::pair<std::string, std::string> DBusInterfaceHandlerPath;
- COMMONAPI_EXPORT bool addDBusInterfaceHandler(const DBusInterfaceHandlerPath& dbusInterfaceHandlerPath,
+ COMMONAPI_EXPORT bool addDBusInterfaceHandler(const DBusInterfaceHandlerPath& dbusInterfaceHandlerPath,
std::shared_ptr<DBusInterfaceHandler> dbusInterfaceHandler);
- COMMONAPI_EXPORT bool removeDBusInterfaceHandler(const DBusInterfaceHandlerPath& dbusInterfaceHandlerPath,
+ COMMONAPI_EXPORT bool removeDBusInterfaceHandler(const DBusInterfaceHandlerPath& dbusInterfaceHandlerPath,
std::shared_ptr<DBusInterfaceHandler> dbusInterfaceHandler);
- COMMONAPI_EXPORT bool onIntrospectableInterfaceDBusMessage(const DBusMessage& callMessage);
- COMMONAPI_EXPORT bool onFreedesktopPropertiesDBusMessage(const DBusMessage& callMessage);
+ COMMONAPI_EXPORT bool onIntrospectableInterfaceDBusMessage(const DBusMessage& callMessage);
+ COMMONAPI_EXPORT bool onFreedesktopPropertiesDBusMessage(const DBusMessage& callMessage);
typedef std::unordered_map<DBusInterfaceHandlerPath, std::shared_ptr<DBusInterfaceHandler>> DBusRegisteredObjectsTable;
diff --git a/include/CommonAPI/DBus/DBusObjectManagerStub.hpp b/include/CommonAPI/DBus/DBusObjectManagerStub.hpp
index a16578b..6d88951 100644
--- a/include/CommonAPI/DBus/DBusObjectManagerStub.hpp
+++ b/include/CommonAPI/DBus/DBusObjectManagerStub.hpp
@@ -42,17 +42,17 @@ class DBusStubAdapter;
class DBusObjectManagerStub : public DBusInterfaceHandler {
public:
// serialization trick: use bool instead of variant since we never serialize it
- typedef std::unordered_map<std::string, bool> DBusPropertiesChangedDict;
- typedef std::unordered_map<std::string, DBusPropertiesChangedDict> DBusInterfacesAndPropertiesDict;
- typedef std::unordered_map<std::string, DBusInterfacesAndPropertiesDict> DBusObjectPathAndInterfacesDict;
+ typedef std::unordered_map<std::string, bool> DBusPropertiesChangedDict;
+ typedef std::unordered_map<std::string, DBusPropertiesChangedDict> DBusInterfacesAndPropertiesDict;
+ typedef std::unordered_map<std::string, DBusInterfacesAndPropertiesDict> DBusObjectPathAndInterfacesDict;
public:
- COMMONAPI_EXPORT DBusObjectManagerStub(const std::string& dbusObjectPath, const std::shared_ptr<DBusProxyConnection>&);
+ COMMONAPI_EXPORT DBusObjectManagerStub(const std::string& dbusObjectPath, const std::shared_ptr<DBusProxyConnection>&);
- /**
- * Unregisters all currently registered DBusStubAdapter instances from the DBusServicePublisher
- */
- COMMONAPI_EXPORT virtual ~DBusObjectManagerStub();
+ /**
+ * Unregisters all currently registered DBusStubAdapter instances from the DBusServicePublisher
+ */
+ COMMONAPI_EXPORT virtual ~DBusObjectManagerStub();
/**
* Export DBusStubAdapter instance with the current DBusObjectManagerStub instance.
@@ -72,7 +72,7 @@ public:
* @see CommonAPI::ServicePublisher
* @see DBusObjectManager
*/
- COMMONAPI_EXPORT bool exportManagedDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool exportManagedDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
/**
* Unexport DBusStubAdapter instance from this DBusObjectManagerStub instance.
@@ -88,25 +88,25 @@ public:
*
* @see exportDBusStubAdapter()
*/
- COMMONAPI_EXPORT bool unexportManagedDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool unexportManagedDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
- COMMONAPI_EXPORT bool isDBusStubAdapterExported(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool isDBusStubAdapterExported(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
- COMMONAPI_EXPORT const std::string& getDBusObjectPath() const;
- COMMONAPI_EXPORT static const char* getInterfaceName();
+ COMMONAPI_EXPORT const std::string& getDBusObjectPath() const;
+ COMMONAPI_EXPORT static const char* getInterfaceName();
- COMMONAPI_EXPORT virtual const char* getMethodsDBusIntrospectionXmlData() const;
- COMMONAPI_EXPORT virtual bool onInterfaceDBusMessage(const DBusMessage& dbusMessage);
- COMMONAPI_EXPORT virtual const bool hasFreedesktopProperties();
+ COMMONAPI_EXPORT virtual const char* getMethodsDBusIntrospectionXmlData() const;
+ COMMONAPI_EXPORT virtual bool onInterfaceDBusMessage(const DBusMessage& dbusMessage);
+ COMMONAPI_EXPORT virtual bool hasFreedesktopProperties();
private:
- COMMONAPI_EXPORT bool registerDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
- COMMONAPI_EXPORT bool unregisterDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool registerDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
+ COMMONAPI_EXPORT bool unregisterDBusStubAdapter(std::shared_ptr<DBusStubAdapter> dbusStubAdapter);
- COMMONAPI_EXPORT bool emitInterfacesAddedSignal(std::shared_ptr<DBusStubAdapter> dbusStubAdapter,
+ COMMONAPI_EXPORT bool emitInterfacesAddedSignal(std::shared_ptr<DBusStubAdapter> dbusStubAdapter,
const std::shared_ptr<DBusProxyConnection>& dbusConnection) const;
- COMMONAPI_EXPORT bool emitInterfacesRemovedSignal(std::shared_ptr<DBusStubAdapter> dbusStubAdapter,
+ COMMONAPI_EXPORT bool emitInterfacesRemovedSignal(std::shared_ptr<DBusStubAdapter> dbusStubAdapter,
const std::shared_ptr<DBusProxyConnection>& dbusConnection) const;
std::string dbusObjectPath_;
diff --git a/include/CommonAPI/DBus/DBusOutputStream.hpp b/include/CommonAPI/DBus/DBusOutputStream.hpp
index 93afca2..b99c9c8 100644
--- a/include/CommonAPI/DBus/DBusOutputStream.hpp
+++ b/include/CommonAPI/DBus/DBusOutputStream.hpp
@@ -45,251 +45,268 @@ public:
*
* @param dbusMessage The #DBusMessage any data pushed into this stream should be written to.
*/
- COMMONAPI_EXPORT DBusOutputStream(DBusMessage dbusMessage);
+ COMMONAPI_EXPORT DBusOutputStream(DBusMessage dbusMessage);
- COMMONAPI_EXPORT void beginWriteVectorOfSerializableStructs() {
- align(sizeof(uint32_t));
- pushPosition();
- _writeValue(static_cast<uint32_t>(0)); // Placeholder
+ COMMONAPI_EXPORT void beginWriteVectorOfSerializableStructs() {
+ align(sizeof(uint32_t));
+ pushPosition();
+ _writeValue(static_cast<uint32_t>(0)); // Placeholder
- align(8);
- pushPosition(); // Start of map data
- }
+ align(8);
+ pushPosition(); // Start of map data
+ }
- COMMONAPI_EXPORT void endWriteVector() {
- // Write number of written bytes to placeholder position
- const uint32_t length = getPosition() - popPosition();
- _writeValueAt(popPosition(), length);
- }
+ COMMONAPI_EXPORT void endWriteVector() {
+ // Write number of written bytes to placeholder position
+ const uint32_t length = uint32_t(getPosition() - popPosition());
+ _writeValueAt(popPosition(), length);
+ }
- COMMONAPI_EXPORT OutputStream &writeValue(const bool &_value, const EmptyDeployment *_depl) {
- uint32_t tmp = (_value ? 1 : 0);
+ COMMONAPI_EXPORT OutputStream &writeValue(const bool &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
+ uint32_t tmp = (_value ? 1 : 0);
return _writeValue(tmp);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const int8_t &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const int8_t &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const int16_t &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const int16_t &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const int32_t &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const int32_t &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const int64_t &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const int64_t &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const uint8_t &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const uint8_t &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const uint16_t &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const uint16_t &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const uint32_t &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const uint32_t &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const uint64_t &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const uint64_t &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const float &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const float &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(static_cast<double>(_value));
}
- COMMONAPI_EXPORT OutputStream &writeValue(const double &_value, const EmptyDeployment *_depl) {
+ COMMONAPI_EXPORT OutputStream &writeValue(const double &_value, const EmptyDeployment *_depl) {
+ (void)_depl;
return _writeValue(_value);
}
- COMMONAPI_EXPORT OutputStream &writeValue(const std::string &_value, const EmptyDeployment * = nullptr) {
- return writeString(_value.c_str(), _value.length());
+ COMMONAPI_EXPORT OutputStream &writeValue(const std::string &_value, const EmptyDeployment *_depl = nullptr) {
+ (void)_depl;
+ return writeString(_value.c_str(), uint32_t(_value.length()));
}
- COMMONAPI_EXPORT OutputStream &writeValue(const std::string &_value, const CommonAPI::DBus::StringDeployment* _depl) {
- return writeString(_value.c_str(), _value.length());
+ COMMONAPI_EXPORT OutputStream &writeValue(const std::string &_value, const CommonAPI::DBus::StringDeployment* _depl) {
+ (void)_depl;
+ return writeString(_value.c_str(), uint32_t(_value.length()));
}
- COMMONAPI_EXPORT OutputStream &writeValue(const Version &_value, const EmptyDeployment *_depl = nullptr) {
- align(8);
- writeValue(_value.Major, _depl);
- writeValue(_value.Minor, _depl);
- return (*this);
+ COMMONAPI_EXPORT OutputStream &writeValue(const Version &_value, const EmptyDeployment *_depl = nullptr) {
+ align(8);
+ writeValue(_value.Major, _depl);
+ writeValue(_value.Minor, _depl);
+ return (*this);
}
- template<class _Deployment, typename _Base>
- COMMONAPI_EXPORT OutputStream &writeValue(const Enumeration<_Base> &_value, const _Deployment *_depl = nullptr) {
- return writeValue(static_cast<_Base>(_value), _depl);
+ template<class Deployment_, typename Base_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const Enumeration<Base_> &_value, const Deployment_ *_depl = nullptr) {
+ return writeValue(static_cast<Base_>(_value), _depl);
}
- template<class _Deployment, typename... _Types>
- COMMONAPI_EXPORT OutputStream &writeValue(const Struct<_Types...> &_value, const _Deployment *_depl = nullptr) {
- align(8);
+ template<class Deployment_, typename... Types_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const Struct<Types_...> &_value, const Deployment_ *_depl = nullptr) {
+ align(8);
- const auto itsSize(std::tuple_size<std::tuple<_Types...>>::value);
- StructWriter<itsSize-1, DBusOutputStream, Struct<_Types...>, _Deployment>{}((*this), _value, _depl);
+ const auto itsSize(std::tuple_size<std::tuple<Types_...>>::value);
+ StructWriter<itsSize-1, DBusOutputStream, Struct<Types_...>, Deployment_>{}((*this), _value, _depl);
- return (*this);
+ return (*this);
}
- template<class _Deployment, class _PolymorphicStruct>
- COMMONAPI_EXPORT OutputStream &writeValue(const std::shared_ptr<_PolymorphicStruct> &_value, const _Deployment *_depl = nullptr) {
- align(8);
- _writeValue(_value->getSerial());
+ template<class Deployment_, class PolymorphicStruct_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const std::shared_ptr<PolymorphicStruct_> &_value, const Deployment_ *_depl = nullptr) {
+ align(8);
+ _writeValue(_value->getSerial());
- DBusTypeOutputStream typeOutput;
- typeOutput.writeType(_value);
- writeSignature(typeOutput.getSignature());
+ DBusTypeOutputStream typeOutput;
+ typeOutput.writeType(_value, _depl);
+ writeSignature(typeOutput.getSignature());
- align(8);
- _value->template writeValue<>((*this), _depl);
+ align(8);
+ _value->template writeValue<>((*this), _depl);
- return (*this);
+ return (*this);
}
- template<typename... _Types>
- COMMONAPI_EXPORT OutputStream &writeValue(const Variant<_Types...> &_value, const CommonAPI::EmptyDeployment *_depl = nullptr) {
- align(8);
- writeValue(_value.getValueType(), static_cast<EmptyDeployment *>(nullptr));
+ template<typename... Types_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const Variant<Types_...> &_value, const CommonAPI::EmptyDeployment *_depl = nullptr) {
+ (void)_depl;
- DBusTypeOutputStream typeOutput;
- TypeOutputStreamWriteVisitor<DBusTypeOutputStream> typeVisitor(typeOutput);
- ApplyVoidVisitor<TypeOutputStreamWriteVisitor<DBusTypeOutputStream>,
- Variant<_Types...>, _Types...>::visit(typeVisitor, _value);
- writeSignature(typeOutput.getSignature());
+ align(8);
+ writeValue(_value.getValueType(), static_cast<EmptyDeployment *>(nullptr));
- OutputStreamWriteVisitor<DBusOutputStream> valueVisitor(*this);
- ApplyVoidVisitor<OutputStreamWriteVisitor<DBusOutputStream>,
- Variant<_Types...>, _Types...>::visit(valueVisitor, _value);
+ DBusTypeOutputStream typeOutput;
+ TypeOutputStreamWriteVisitor<DBusTypeOutputStream> typeVisitor(typeOutput);
+ ApplyVoidVisitor<TypeOutputStreamWriteVisitor<DBusTypeOutputStream>,
+ Variant<Types_...>, Types_...>::visit(typeVisitor, _value);
+ writeSignature(typeOutput.getSignature());
- return (*this);
- }
+ OutputStreamWriteVisitor<DBusOutputStream> valueVisitor(*this);
+ ApplyVoidVisitor<OutputStreamWriteVisitor<DBusOutputStream>,
+ Variant<Types_...>, Types_...>::visit(valueVisitor, _value);
- template<typename _Deployment, typename... _Types>
- COMMONAPI_EXPORT OutputStream &writeValue(const Variant<_Types...> &_value, const _Deployment *_depl = nullptr) {
- if (_depl != nullptr && _depl->isDBus_) {
- align(1);
- } else {
- align(8);
- writeValue(_value.getValueType(), static_cast<EmptyDeployment *>(nullptr));
- }
-
- DBusTypeOutputStream typeOutput;
- TypeOutputStreamWriteVisitor<DBusTypeOutputStream> typeVisitor(typeOutput);
- ApplyVoidVisitor<TypeOutputStreamWriteVisitor<DBusTypeOutputStream>,
- Variant<_Types...>, _Types...>::visit(typeVisitor, _value);
- writeSignature(typeOutput.getSignature());
+ return (*this);
+ }
- OutputStreamWriteVisitor<DBusOutputStream> valueVisitor(*this);
- ApplyVoidVisitor<OutputStreamWriteVisitor<DBusOutputStream>,
- Variant<_Types...>, _Types...>::visit(valueVisitor, _value);
+ template<typename Deployment_, typename... Types_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const Variant<Types_...> &_value, const Deployment_ *_depl = nullptr) {
+ if (_depl != nullptr && _depl->isDBus_) {
+ align(1);
+ } else {
+ align(8);
+ writeValue(_value.getValueType(), static_cast<EmptyDeployment *>(nullptr));
+ }
+
+ DBusTypeOutputStream typeOutput;
+ TypeOutputStreamWriteVisitor<DBusTypeOutputStream> typeVisitor(typeOutput);
+ ApplyStreamVisitor<TypeOutputStreamWriteVisitor<DBusTypeOutputStream>,
+ Variant<Types_...>, Deployment_, Types_...>::visit(typeVisitor, _value, _depl);
+ writeSignature(typeOutput.getSignature());
+
+ OutputStreamWriteVisitor<DBusOutputStream> valueVisitor(*this);
+ ApplyStreamVisitor<OutputStreamWriteVisitor<DBusOutputStream>,
+ Variant<Types_...>, Deployment_, Types_...>::visit(valueVisitor, _value, _depl);
- return (*this);
+ return (*this);
}
- template<typename _ElementType>
- COMMONAPI_EXPORT OutputStream &writeValue(const std::vector<_ElementType> &_value,
- const EmptyDeployment *_depl) {
- align(sizeof(uint32_t));
- pushPosition();
- _writeValue(static_cast<uint32_t>(0)); // Placeholder
+ template<typename ElementType_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const std::vector<ElementType_> &_value,
+ const EmptyDeployment *_depl) {
+ align(sizeof(uint32_t));
+ pushPosition();
+ _writeValue(static_cast<uint32_t>(0)); // Placeholder
- alignVector<_ElementType>();
- pushPosition(); // Start of vector data
+ alignVector<ElementType_>();
+ pushPosition(); // Start of vector data
- for (auto i : _value) {
- writeValue(i, _depl);
- if (hasError()) {
- break;
- }
- }
+ for (auto i : _value) {
+ writeValue(i, _depl);
+ if (hasError()) {
+ break;
+ }
+ }
- // Write number of written bytes to placeholder position
- uint32_t length = getPosition() - popPosition();
- _writeValueAt(popPosition(), length);
+ // Write number of written bytes to placeholder position
+ uint32_t length = uint32_t(getPosition() - popPosition());
+ _writeValueAt(popPosition(), length);
- return (*this);
+ return (*this);
}
- template<class _Deployment, typename _ElementType>
- COMMONAPI_EXPORT OutputStream &writeValue(const std::vector<_ElementType> &_value,
- const _Deployment *_depl) {
- align(sizeof(uint32_t));
- pushPosition();
- _writeValue(static_cast<uint32_t>(0)); // Placeholder
+ template<class Deployment_, typename ElementType_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const std::vector<ElementType_> &_value,
+ const Deployment_ *_depl) {
+ align(sizeof(uint32_t));
+ pushPosition();
+ _writeValue(static_cast<uint32_t>(0)); // Placeholder
- alignVector<_ElementType>();
- pushPosition(); // Start of vector data
+ alignVector<ElementType_>();
+ pushPosition(); // Start of vector data
- for (auto i : _value) {
- writeValue(i, (_depl ? _depl->elementDepl_ : nullptr));
- if (hasError()) {
- break;
- }
- }
+ for (auto i : _value) {
+ writeValue(i, (_depl ? _depl->elementDepl_ : nullptr));
+ if (hasError()) {
+ break;
+ }
+ }
- // Write number of written bytes to placeholder position
- uint32_t length = getPosition() - popPosition();
- _writeValueAt(popPosition(), length);
+ // Write number of written bytes to placeholder position
+ uint32_t length = uint32_t(getPosition() - popPosition());
+ _writeValueAt(popPosition(), length);
- return (*this);
+ return (*this);
}
- template<typename _KeyType, typename _ValueType, typename _HasherType>
- COMMONAPI_EXPORT OutputStream &writeValue(const std::unordered_map<_KeyType, _ValueType, _HasherType> &_value,
- const EmptyDeployment *_depl) {
- align(sizeof(uint32_t));
- pushPosition();
- _writeValue(static_cast<uint32_t>(0)); // Placeholder
+ template<typename KeyType_, typename ValueType_, typename HasherType_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const std::unordered_map<KeyType_, ValueType_, HasherType_> &_value,
+ const EmptyDeployment *_depl) {
+ (void)_depl;
- align(8);
- pushPosition(); // Start of map data
+ align(sizeof(uint32_t));
+ pushPosition();
+ _writeValue(static_cast<uint32_t>(0)); // Placeholder
- for (auto v : _value) {
- align(8);
- writeValue(v.first, static_cast<EmptyDeployment *>(nullptr));
- writeValue(v.second, static_cast<EmptyDeployment *>(nullptr));
+ align(8);
+ pushPosition(); // Start of map data
+
+ for (auto v : _value) {
+ align(8);
+ writeValue(v.first, static_cast<EmptyDeployment *>(nullptr));
+ writeValue(v.second, static_cast<EmptyDeployment *>(nullptr));
- if (hasError()) {
- return (*this);
- }
- }
+ if (hasError()) {
+ return (*this);
+ }
+ }
- // Write number of written bytes to placeholder position
- uint32_t length = getPosition() - popPosition();
- _writeValueAt(popPosition(), length);
- return (*this);
+ // Write number of written bytes to placeholder position
+ uint32_t length = uint32_t(getPosition() - popPosition());
+ _writeValueAt(popPosition(), length);
+ return (*this);
}
- template<class _Deployment, typename _KeyType, typename _ValueType, typename _HasherType>
- COMMONAPI_EXPORT OutputStream &writeValue(const std::unordered_map<_KeyType, _ValueType, _HasherType> &_value,
- const _Deployment *_depl) {
- align(sizeof(uint32_t));
- pushPosition();
- _writeValue(static_cast<uint32_t>(0)); // Placeholder
-
- align(8);
- pushPosition(); // Start of map data
+ template<class Deployment_, typename KeyType_, typename ValueType_, typename HasherType_>
+ COMMONAPI_EXPORT OutputStream &writeValue(const std::unordered_map<KeyType_, ValueType_, HasherType_> &_value,
+ const Deployment_ *_depl) {
+ align(sizeof(uint32_t));
+ pushPosition();
+ _writeValue(static_cast<uint32_t>(0)); // Placeholder
+
+ align(8);
+ pushPosition(); // Start of map data
- for (auto v : _value) {
- align(8);
- writeValue(v.first, (_depl ? _depl->key_ : nullptr));
- writeValue(v.second, (_depl ? _depl->value_ : nullptr));
+ for (auto v : _value) {
+ align(8);
+ writeValue(v.first, (_depl ? _depl->key_ : nullptr));
+ writeValue(v.second, (_depl ? _depl->value_ : nullptr));
- if (hasError()) {
- return (*this);
- }
- }
+ if (hasError()) {
+ return (*this);
+ }
+ }
- // Write number of written bytes to placeholder position
- uint32_t length = getPosition() - popPosition();
- _writeValueAt(popPosition(), length);
- return (*this);
+ // Write number of written bytes to placeholder position
+ uint32_t length = uint32_t(getPosition() - popPosition());
+ _writeValueAt(popPosition(), length);
+ return (*this);
}
/**
@@ -306,11 +323,11 @@ public:
* will completely override the data that currently is contained in the #DBusMessage. The data that is buffered in this #DBusOutputMessageStream is
* not deleted by calling flush().
*/
- COMMONAPI_EXPORT void flush();
+ COMMONAPI_EXPORT void flush();
- COMMONAPI_EXPORT bool hasError() const;
+ COMMONAPI_EXPORT bool hasError() const;
- // Helper for serializing Freedesktop properties
+ // Helper for serializing Freedesktop properties
COMMONAPI_EXPORT void beginWriteMap() {
align(sizeof(uint32_t));
pushPosition();
@@ -322,46 +339,52 @@ public:
COMMONAPI_EXPORT void endWriteMap() {
// Write number of written bytes to placeholder position
- const uint32_t length = getPosition() - popPosition();
+ const uint32_t length = uint32_t(getPosition() - popPosition());
_writeValueAt(popPosition(), length);
}
private:
- COMMONAPI_EXPORT size_t getPosition();
- COMMONAPI_EXPORT void pushPosition();
- COMMONAPI_EXPORT size_t popPosition();
+ COMMONAPI_EXPORT size_t getPosition();
+ COMMONAPI_EXPORT void pushPosition();
+ COMMONAPI_EXPORT size_t popPosition();
+
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_class<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!is_std_vector<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!is_std_unordered_map<Type_>::value>::type * = nullptr) {
+ if (4 < sizeof(Type_)) align(8);
+ }
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_class<_Type>::value>::type * = nullptr,
- typename std::enable_if<!is_std_vector<_Type>::value>::type * = nullptr,
- typename std::enable_if<!is_std_unordered_map<_Type>::value>::type * = nullptr) {
- if (4 < sizeof(_Type)) align(8);
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_same<Type_, std::string>::value>::type * = nullptr,
+ typename std::enable_if<std::is_class<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!is_std_vector<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!is_std_unordered_map<Type_>::value>::type * = nullptr,
+ typename std::enable_if<!std::is_base_of<Enumeration<int32_t>, Type_>::value>::type * = nullptr) {
+ align(8);
}
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<!std::is_same<_Type, std::string>::value>::type * = nullptr,
- typename std::enable_if<std::is_class<_Type>::value>::type * = nullptr,
- typename std::enable_if<!is_std_vector<_Type>::value>::type * = nullptr,
- typename std::enable_if<!is_std_unordered_map<_Type>::value>::type * = nullptr) {
- align(8);
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_same<Type_, std::string>::value>::type * = nullptr) {
+ // Intentionally do nothing
}
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_same<_Type, std::string>::value>::type * = nullptr) {
- // Intentionally do nothing
- }
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_vector<Type_>::value>::type * = nullptr) {
+ // Intentionally do nothing
+ }
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_vector<_Type>::value>::type * = nullptr) {
- // Intentionally do nothing
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_unordered_map<Type_>::value>::type * = nullptr) {
+ align(4);
}
- template<typename _Type>
- COMMONAPI_EXPORT void alignVector(typename std::enable_if<is_std_unordered_map<_Type>::value>::type * = nullptr) {
- align(4);
+ template<typename Type_>
+ COMMONAPI_EXPORT void alignVector(typename std::enable_if<std::is_base_of<Enumeration<int32_t>, Type_>::value>::type * = nullptr) {
+ align(4);
}
- COMMONAPI_EXPORT void setError();
+ COMMONAPI_EXPORT void setError();
/**
* Reserves the given number of bytes for writing, thereby negating the need to dynamically allocate memory while writing.
@@ -369,25 +392,25 @@ private:
*
* @param numOfBytes The number of bytes that should be reserved for writing.
*/
- COMMONAPI_EXPORT void reserveMemory(size_t numOfBytes);
+ COMMONAPI_EXPORT void reserveMemory(size_t numOfBytes);
- template<typename _Type>
- COMMONAPI_EXPORT DBusOutputStream &_writeValue(const _Type &_value) {
- if (sizeof(_Type) > 1)
- align(sizeof(_Type));
+ template<typename Type_>
+ COMMONAPI_EXPORT DBusOutputStream &_writeValue(const Type_ &_value) {
+ if (sizeof(Type_) > 1)
+ align(sizeof(Type_));
- _writeRaw(reinterpret_cast<const char*>(&_value), sizeof(_Type));
+ _writeRaw(reinterpret_cast<const char*>(&_value), sizeof(Type_));
return (*this);
}
- template<typename _Type>
- COMMONAPI_EXPORT void _writeValueAt(size_t _position, const _Type &_value) {
- assert(_position + sizeof(_Type) <= payload_.size());
+ template<typename Type_>
+ COMMONAPI_EXPORT void _writeValueAt(size_t _position, const Type_ &_value) {
+ assert(_position + sizeof(Type_) <= payload_.size());
_writeRawAt(reinterpret_cast<const char *>(&_value),
- sizeof(_Type), _position);
+ sizeof(Type_), _position);
}
- COMMONAPI_EXPORT DBusOutputStream &writeString(const char *_data, const uint32_t &_length);
+ COMMONAPI_EXPORT DBusOutputStream &writeString(const char *_data, const uint32_t &_length);
/**
* Takes sizeInByte characters, starting from the character which val points to, and stores them for later writing.
@@ -410,16 +433,16 @@ private:
* @see DBusOutputMessageStream()
* @see flush()
*/
- COMMONAPI_EXPORT void _writeRaw(const char *_data, const size_t _size);
- COMMONAPI_EXPORT void _writeRawAt(const char *_data, const size_t _size, size_t _position);
+ COMMONAPI_EXPORT void _writeRaw(const char *_data, const size_t _size);
+ COMMONAPI_EXPORT void _writeRawAt(const char *_data, const size_t _size, size_t _position);
protected:
std::string payload_;
private:
- COMMONAPI_EXPORT void writeSignature(const std::string& signature);
+ COMMONAPI_EXPORT void writeSignature(const std::string& signature);
- COMMONAPI_EXPORT size_t getCurrentStreamPosition();
+ COMMONAPI_EXPORT size_t getCurrentStreamPosition();
DBusError dbusError_;
DBusMessage dbusMessage_;
diff --git a/include/CommonAPI/DBus/DBusProxy.hpp b/include/CommonAPI/DBus/DBusProxy.hpp
index 2f8a89c..ad5439e 100644
--- a/include/CommonAPI/DBus/DBusProxy.hpp
+++ b/include/CommonAPI/DBus/DBusProxy.hpp
@@ -22,7 +22,7 @@ namespace CommonAPI {
namespace DBus {
class DBusProxyStatusEvent
- : public ProxyStatusEvent {
+ : public ProxyStatusEvent {
friend class DBusProxy;
public:
@@ -37,32 +37,32 @@ class DBusProxyStatusEvent
class DBusProxy
- : public DBusProxyBase {
+ : public DBusProxyBase {
public:
- COMMONAPI_EXPORT DBusProxy(const DBusAddress &_address,
+ COMMONAPI_EXPORT DBusProxy(const DBusAddress &_address,
const std::shared_ptr<DBusProxyConnection> &_connection);
- COMMONAPI_EXPORT virtual ~DBusProxy();
+ COMMONAPI_EXPORT virtual ~DBusProxy();
- COMMONAPI_EXPORT virtual ProxyStatusEvent& getProxyStatusEvent();
- COMMONAPI_EXPORT virtual InterfaceVersionAttribute& getInterfaceVersionAttribute();
+ COMMONAPI_EXPORT virtual ProxyStatusEvent& getProxyStatusEvent();
+ COMMONAPI_EXPORT virtual InterfaceVersionAttribute& getInterfaceVersionAttribute();
- COMMONAPI_EXPORT virtual bool isAvailable() const;
- COMMONAPI_EXPORT virtual bool isAvailableBlocking() const;
+ COMMONAPI_EXPORT virtual bool isAvailable() const;
+ COMMONAPI_EXPORT virtual bool isAvailableBlocking() const;
- COMMONAPI_EXPORT DBusProxyConnection::DBusSignalHandlerToken subscribeForSelectiveBroadcastOnConnection(
+ COMMONAPI_EXPORT DBusProxyConnection::DBusSignalHandlerToken subscribeForSelectiveBroadcastOnConnection(
bool& subscriptionAccepted,
const std::string& objectPath,
const std::string& interfaceName,
const std::string& interfaceMemberName,
const std::string& interfaceMemberSignature,
DBusProxyConnection::DBusSignalHandler* dbusSignalHandler);
- COMMONAPI_EXPORT void unsubscribeFromSelectiveBroadcast(const std::string& eventName,
+ COMMONAPI_EXPORT void unsubscribeFromSelectiveBroadcast(const std::string& eventName,
DBusProxyConnection::DBusSignalHandlerToken subscription,
const DBusProxyConnection::DBusSignalHandler* dbusSignalHandler);
- COMMONAPI_EXPORT void init();
+ COMMONAPI_EXPORT void init();
- COMMONAPI_EXPORT virtual DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
+ COMMONAPI_EXPORT virtual DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
const std::string &objectPath,
const std::string &interfaceName,
const std::string &signalName,
@@ -70,48 +70,54 @@ public:
DBusProxyConnection::DBusSignalHandler *dbusSignalHandler,
const bool justAddFilter);
- COMMONAPI_EXPORT virtual DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
+ COMMONAPI_EXPORT virtual DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
const std::string &objectPath,
const std::string &interfaceName,
const std::string &signalName,
const std::string &signalSignature,
- const std::string &getMethodName,
+ const std::string &getMethodName,
DBusProxyConnection::DBusSignalHandler *dbusSignalHandler,
const bool justAddFilter);
- COMMONAPI_EXPORT virtual bool removeSignalMemberHandler(
- const DBusProxyConnection::DBusSignalHandlerToken &_dbusSignalHandlerToken,
- const DBusProxyConnection::DBusSignalHandler *_dbusSignalHandler = NULL);
+ COMMONAPI_EXPORT virtual bool removeSignalMemberHandler(
+ const DBusProxyConnection::DBusSignalHandlerToken &_dbusSignalHandlerToken,
+ const DBusProxyConnection::DBusSignalHandler *_dbusSignalHandler = NULL);
- COMMONAPI_EXPORT virtual void getCurrentValueForSignalListener(
+ COMMONAPI_EXPORT virtual void getCurrentValueForSignalListener(
const std::string &getMethodName,
DBusProxyConnection::DBusSignalHandler *dbusSignalHandler,
- const uint32_t subscription);
+ const uint32_t subscription);
+
+ COMMONAPI_EXPORT virtual void freeDesktopGetCurrentValueForSignalListener(
+ DBusProxyConnection::DBusSignalHandler *dbusSignalHandler,
+ const uint32_t subscription,
+ const std::string &interfaceName,
+ const std::string &propertyName);
private:
typedef std::tuple<
- const std::string,
- const std::string,
- const std::string,
- const std::string,
- const std::string,
- DBusProxyConnection::DBusSignalHandler*,
- const bool,
- bool
- > SignalMemberHandlerTuple;
-
- COMMONAPI_EXPORT DBusProxy(const DBusProxy &) = delete;
-
- COMMONAPI_EXPORT void onDBusServiceInstanceStatus(const AvailabilityStatus& availabilityStatus);
- COMMONAPI_EXPORT void signalMemberCallback(const CallStatus dbusMessageCallStatus,
- const DBusMessage& dbusMessage,
- DBusProxyConnection::DBusSignalHandler* dbusSignalHandlers,
- const uint32_t tag);
- COMMONAPI_EXPORT void signalInitialValueCallback(const CallStatus dbusMessageCallStatus,
- const DBusMessage& dbusMessage,
- DBusProxyConnection::DBusSignalHandler* dbusSignalHandlers,
- const uint32_t tag);
- COMMONAPI_EXPORT void addSignalMemberHandlerToQueue(SignalMemberHandlerTuple& _signalMemberHandler);
+ const std::string,
+ const std::string,
+ const std::string,
+ const std::string,
+ const std::string,
+ DBusProxyConnection::DBusSignalHandler*,
+ const bool,
+ bool
+ > SignalMemberHandlerTuple;
+
+ COMMONAPI_EXPORT DBusProxy(const DBusProxy &) = delete;
+
+ COMMONAPI_EXPORT void onDBusServiceInstanceStatus(const AvailabilityStatus& availabilityStatus);
+ COMMONAPI_EXPORT void signalMemberCallback(const CallStatus dbusMessageCallStatus,
+ const DBusMessage& dbusMessage,
+ DBusProxyConnection::DBusSignalHandler* dbusSignalHandlers,
+ const uint32_t tag);
+ COMMONAPI_EXPORT void signalInitialValueCallback(const CallStatus dbusMessageCallStatus,
+ const DBusMessage& dbusMessage,
+ DBusProxyConnection::DBusSignalHandler* dbusSignalHandlers,
+ const uint32_t tag);
+ COMMONAPI_EXPORT void addSignalMemberHandlerToQueue(SignalMemberHandlerTuple& _signalMemberHandler);
DBusProxyStatusEvent dbusProxyStatusEvent_;
DBusServiceRegistry::DBusServiceSubscription dbusServiceRegistrySubscription_;
diff --git a/include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp b/include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp
index eac96d2..0a0ee56 100644
--- a/include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp
+++ b/include/CommonAPI/DBus/DBusProxyAsyncCallbackHandler.hpp
@@ -22,20 +22,26 @@
namespace CommonAPI {
namespace DBus {
-template<typename ... _ArgTypes>
-class DBusProxyAsyncCallbackHandler: public DBusProxyConnection::DBusMessageReplyAsyncHandler {
+template<typename ... ArgTypes_>
+class DBusProxyAsyncCallbackHandler:
+ public DBusProxyConnection::DBusMessageReplyAsyncHandler {
public:
- typedef std::function<void(CallStatus, _ArgTypes...)> FunctionType;
+ typedef std::function<void(CallStatus, ArgTypes_...)> FunctionType;
static std::unique_ptr<DBusProxyConnection::DBusMessageReplyAsyncHandler> create(
- FunctionType&& callback, std::tuple<_ArgTypes...> args) {
+ FunctionType&& callback, std::tuple<ArgTypes_...> args) {
return std::unique_ptr<DBusProxyConnection::DBusMessageReplyAsyncHandler>(
new DBusProxyAsyncCallbackHandler(std::move(callback), args));
}
DBusProxyAsyncCallbackHandler() = delete;
- DBusProxyAsyncCallbackHandler(FunctionType&& callback, std::tuple<_ArgTypes...> args):
- callback_(std::move(callback)), args_(args) {
+ DBusProxyAsyncCallbackHandler(FunctionType&& callback, std::tuple<ArgTypes_...> args)
+ : callback_(std::move(callback)),
+ args_(args),
+ executionStarted_(false),
+ executionFinished_(false),
+ timeoutOccurred_(false),
+ hasToBeDeleted_(false) {
}
virtual ~DBusProxyAsyncCallbackHandler() {}
@@ -43,19 +49,74 @@ class DBusProxyAsyncCallbackHandler: public DBusProxyConnection::DBusMessageRepl
return promise_.get_future();
}
- virtual void onDBusMessageReply(const CallStatus& dbusMessageCallStatus, const DBusMessage& dbusMessage) {
- promise_.set_value(handleDBusMessageReply(dbusMessageCallStatus, dbusMessage, typename make_sequence<sizeof...(_ArgTypes)>::type(), args_));
+ virtual void onDBusMessageReply(const CallStatus& dbusMessageCallStatus,
+ const DBusMessage& dbusMessage) {
+ promise_.set_value(handleDBusMessageReply(dbusMessageCallStatus,
+ dbusMessage,
+ typename make_sequence<sizeof...(ArgTypes_)>::type(), args_));
+ }
+
+ virtual void setExecutionStarted() {
+ executionStarted_ = true;
+ }
+
+ virtual bool getExecutionStarted() {
+ return executionStarted_;
+ }
+
+ virtual void setExecutionFinished() {
+ executionFinished_ = true;
+ // free assigned std::function<> immediately
+ callback_ = [](CallStatus, ArgTypes_...) {};
+ }
+
+ virtual bool getExecutionFinished() {
+ return executionFinished_;
+ }
+
+ virtual void setTimeoutOccurred() {
+ timeoutOccurred_ = true;
+ }
+
+ virtual bool getTimeoutOccurred() {
+ return timeoutOccurred_;
+ }
+
+ virtual void setHasToBeDeleted() {
+ hasToBeDeleted_ = true;
+ }
+
+ virtual bool hasToBeDeleted() {
+ return hasToBeDeleted_;
+ }
+
+ virtual void lock() {
+ asyncHandlerMutex_.lock();
+ }
+
+ virtual void unlock() {
+ asyncHandlerMutex_.unlock();
}
private:
- template <int... _ArgIndices>
- inline CallStatus handleDBusMessageReply(const CallStatus dbusMessageCallStatus, const DBusMessage& dbusMessage, index_sequence<_ArgIndices...>, std::tuple<_ArgTypes...> argTuple) const {
+ template <int... ArgIndices_>
+ inline CallStatus handleDBusMessageReply(
+ const CallStatus dbusMessageCallStatus,
+ const DBusMessage& dbusMessage,
+ index_sequence<ArgIndices_...>,
+ std::tuple<ArgTypes_...> argTuple) const {
+ (void)argTuple; // this suppresses warning "set but not used" in case of empty _ArgTypes
+ // Looks like: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57560 - Bug 57650
+
CallStatus callStatus = dbusMessageCallStatus;
if (dbusMessageCallStatus == CallStatus::SUCCESS) {
if (!dbusMessage.isErrorType()) {
DBusInputStream dbusInputStream(dbusMessage);
- const bool success = DBusSerializableArguments<_ArgTypes...>::deserialize(dbusInputStream, std::get<_ArgIndices>(argTuple)...);
+ const bool success
+ = DBusSerializableArguments<ArgTypes_...>::deserialize(
+ dbusInputStream,
+ std::get<ArgIndices_>(argTuple)...);
if (!success)
callStatus = CallStatus::REMOTE_ERROR;
} else {
@@ -63,13 +124,19 @@ class DBusProxyAsyncCallbackHandler: public DBusProxyConnection::DBusMessageRepl
}
}
- callback_(callStatus, std::move(std::get<_ArgIndices>(argTuple))...);
+ callback_(callStatus, std::move(std::get<ArgIndices_>(argTuple))...);
return callStatus;
}
std::promise<CallStatus> promise_;
- const FunctionType callback_;
- std::tuple<_ArgTypes...> args_;
+ FunctionType callback_;
+ std::tuple<ArgTypes_...> args_;
+ bool executionStarted_;
+ bool executionFinished_;
+ bool timeoutOccurred_;
+ bool hasToBeDeleted_;
+
+ std::mutex asyncHandlerMutex_;
};
} // namespace DBus
diff --git a/include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp b/include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp
index 9c706ca..f6d7791 100644
--- a/include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp
+++ b/include/CommonAPI/DBus/DBusProxyAsyncSignalMemberCallbackHandler.hpp
@@ -23,21 +23,23 @@ namespace DBus {
class DBusProxyAsyncSignalMemberCallbackHandler: public DBusProxyConnection::DBusMessageReplyAsyncHandler {
public:
- typedef std::function<void(CallStatus, DBusMessage, DBusProxyConnection::DBusSignalHandler*, int)> FunctionType;
+ typedef std::function<void(CallStatus, DBusMessage, DBusProxyConnection::DBusSignalHandler*, int)> FunctionType;
static std::unique_ptr<DBusProxyConnection::DBusMessageReplyAsyncHandler> create(
- FunctionType& callback, DBusProxyConnection::DBusSignalHandler* dbusSignalHandler,
- const int tag) {
- return std::unique_ptr<DBusProxyConnection::DBusMessageReplyAsyncHandler>(
- new DBusProxyAsyncSignalMemberCallbackHandler(std::move(callback), dbusSignalHandler, tag));
- }
+ FunctionType& callback, DBusProxyConnection::DBusSignalHandler* dbusSignalHandler,
+ const int tag) {
+ return std::unique_ptr<DBusProxyConnection::DBusMessageReplyAsyncHandler>(
+ new DBusProxyAsyncSignalMemberCallbackHandler(std::move(callback), dbusSignalHandler, tag));
+ }
DBusProxyAsyncSignalMemberCallbackHandler() = delete;
DBusProxyAsyncSignalMemberCallbackHandler(FunctionType&& callback,
- DBusProxyConnection::DBusSignalHandler* dbusSignalHandler,
- const int tag):
- callback_(std::move(callback)), dbusSignalHandler_(dbusSignalHandler), tag_(tag) {
- }
+ DBusProxyConnection::DBusSignalHandler* dbusSignalHandler,
+ const int tag):
+ callback_(std::move(callback)), dbusSignalHandler_(dbusSignalHandler), tag_(tag),
+ executionStarted_(false), executionFinished_(false),
+ timeoutOccurred_(false), hasToBeDeleted_(false) {
+ }
virtual ~DBusProxyAsyncSignalMemberCallbackHandler() {}
virtual std::future<CallStatus> getFuture() {
@@ -45,7 +47,47 @@ class DBusProxyAsyncSignalMemberCallbackHandler: public DBusProxyConnection::DBu
}
virtual void onDBusMessageReply(const CallStatus& dbusMessageCallStatus, const DBusMessage& dbusMessage) {
- promise_.set_value(handleDBusMessageReply(dbusMessageCallStatus, dbusMessage));
+ promise_.set_value(handleDBusMessageReply(dbusMessageCallStatus, dbusMessage));
+ }
+
+ virtual void setExecutionStarted() {
+ executionStarted_ = true;
+ }
+
+ virtual bool getExecutionStarted() {
+ return executionStarted_;
+ }
+
+ virtual void setExecutionFinished() {
+ executionFinished_ = true;
+ }
+
+ virtual bool getExecutionFinished() {
+ return executionFinished_;
+ }
+
+ virtual void setTimeoutOccurred() {
+ timeoutOccurred_ = true;
+ }
+
+ virtual bool getTimeoutOccurred() {
+ return timeoutOccurred_;
+ }
+
+ virtual void setHasToBeDeleted() {
+ hasToBeDeleted_ = true;
+ }
+
+ virtual bool hasToBeDeleted() {
+ return hasToBeDeleted_;
+ }
+
+ virtual void lock() {
+ asyncHandlerMutex_.lock();
+ }
+
+ virtual void unlock() {
+ asyncHandlerMutex_.unlock();
}
private:
@@ -60,6 +102,12 @@ class DBusProxyAsyncSignalMemberCallbackHandler: public DBusProxyConnection::DBu
const FunctionType callback_;
DBusProxyConnection::DBusSignalHandler* dbusSignalHandler_;
const int tag_;
+ bool executionStarted_;
+ bool executionFinished_;
+ bool timeoutOccurred_;
+ bool hasToBeDeleted_;
+
+ std::mutex asyncHandlerMutex_;
};
} // namespace DBus
diff --git a/include/CommonAPI/DBus/DBusProxyBase.hpp b/include/CommonAPI/DBus/DBusProxyBase.hpp
index 970035f..4657bbf 100644
--- a/include/CommonAPI/DBus/DBusProxyBase.hpp
+++ b/include/CommonAPI/DBus/DBusProxyBase.hpp
@@ -27,19 +27,19 @@ namespace DBus {
class DBusAddress;
class DBusProxyBase
- : public virtual CommonAPI::Proxy {
+ : public virtual CommonAPI::Proxy {
public:
- COMMONAPI_EXPORT DBusProxyBase(const DBusAddress &_address,
- const std::shared_ptr<DBusProxyConnection> &_connection);
- COMMONAPI_EXPORT virtual ~DBusProxyBase() {}
+ COMMONAPI_EXPORT DBusProxyBase(const DBusAddress &_address,
+ const std::shared_ptr<DBusProxyConnection> &_connection);
+ COMMONAPI_EXPORT virtual ~DBusProxyBase() {}
- COMMONAPI_EXPORT const DBusAddress &getDBusAddress() const;
- COMMONAPI_EXPORT const std::shared_ptr<DBusProxyConnection> &getDBusConnection() const;
+ COMMONAPI_EXPORT const DBusAddress &getDBusAddress() const;
+ COMMONAPI_EXPORT const std::shared_ptr<DBusProxyConnection> &getDBusConnection() const;
- COMMONAPI_EXPORT DBusMessage createMethodCall(const std::string &_method,
+ COMMONAPI_EXPORT DBusMessage createMethodCall(const std::string &_method,
const std::string &_signature = "") const;
- COMMONAPI_EXPORT virtual DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
+ COMMONAPI_EXPORT virtual DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
const std::string &objectPath,
const std::string &interfaceName,
const std::string &signalName,
@@ -47,7 +47,7 @@ public:
DBusProxyConnection::DBusSignalHandler *dbusSignalHandler,
const bool justAddFilter);
- COMMONAPI_EXPORT virtual DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
+ COMMONAPI_EXPORT virtual DBusProxyConnection::DBusSignalHandlerToken addSignalMemberHandler(
const std::string &objectPath,
const std::string &interfaceName,
const std::string &signalName,
@@ -56,19 +56,23 @@ public:
DBusProxyConnection::DBusSignalHandler *dbusSignalHandler,
const bool justAddFilter);
- COMMONAPI_EXPORT virtual bool removeSignalMemberHandler(
- const DBusProxyConnection::DBusSignalHandlerToken &_dbusSignalHandlerToken,
- const DBusProxyConnection::DBusSignalHandler *_dbusSignalHandler = NULL);
+ COMMONAPI_EXPORT virtual bool removeSignalMemberHandler(
+ const DBusProxyConnection::DBusSignalHandlerToken &_dbusSignalHandlerToken,
+ const DBusProxyConnection::DBusSignalHandler *_dbusSignalHandler = NULL);
- COMMONAPI_EXPORT virtual void getCurrentValueForSignalListener(
- const std::string &getMethodName,
- DBusProxyConnection::DBusSignalHandler *dbusSignalHandler,
- const uint32_t subscription) {}
+ COMMONAPI_EXPORT virtual void getCurrentValueForSignalListener(
+ const std::string &_getMethodName,
+ DBusProxyConnection::DBusSignalHandler *_handler,
+ const uint32_t _subscription) {
+ (void)_getMethodName;
+ (void)_handler;
+ (void)_subscription;
+ }
- COMMONAPI_EXPORT virtual void init() = 0;
+ COMMONAPI_EXPORT virtual void init() = 0;
protected:
- COMMONAPI_EXPORT DBusProxyBase(const DBusProxyBase &) = delete;
+ COMMONAPI_EXPORT DBusProxyBase(const DBusProxyBase &) = delete;
DBusAddress dbusAddress_;
std::shared_ptr<DBusProxyConnection> connection_;
diff --git a/include/CommonAPI/DBus/DBusProxyConnection.hpp b/include/CommonAPI/DBus/DBusProxyConnection.hpp
index 10c2ea4..0dc7cf2 100644
--- a/include/CommonAPI/DBus/DBusProxyConnection.hpp
+++ b/include/CommonAPI/DBus/DBusProxyConnection.hpp
@@ -45,6 +45,16 @@ class DBusProxyConnection {
virtual ~DBusMessageReplyAsyncHandler() {}
virtual std::future<CallStatus> getFuture() = 0;
virtual void onDBusMessageReply(const CallStatus&, const DBusMessage&) = 0;
+ virtual void setExecutionStarted() = 0;
+ virtual bool getExecutionStarted() = 0;
+ virtual void setExecutionFinished() = 0;
+ virtual bool getExecutionFinished() = 0;
+ virtual void setTimeoutOccurred() = 0;
+ virtual bool getTimeoutOccurred() = 0;
+ virtual void setHasToBeDeleted() = 0;
+ virtual bool hasToBeDeleted() = 0;
+ virtual void lock() = 0;
+ virtual void unlock() = 0;
};
class DBusSignalHandler {
@@ -72,12 +82,12 @@ class DBusProxyConnection {
virtual std::future<CallStatus> sendDBusMessageWithReplyAsync(
const DBusMessage& dbusMessage,
std::unique_ptr<DBusMessageReplyAsyncHandler> dbusMessageReplyAsyncHandler,
- const CommonAPI::CallInfo *_info) const = 0;
+ const CommonAPI::CallInfo *_info) const = 0;
virtual DBusMessage sendDBusMessageWithReplyAndBlock(
const DBusMessage& dbusMessage,
DBusError& dbusError,
- const CommonAPI::CallInfo *_info) const = 0;
+ const CommonAPI::CallInfo *_info) const = 0;
virtual DBusSignalHandlerToken addSignalMemberHandler(
const std::string& objectPath,
diff --git a/include/CommonAPI/DBus/DBusProxyHelper.hpp b/include/CommonAPI/DBus/DBusProxyHelper.hpp
index 4a2748b..ef468ee 100644
--- a/include/CommonAPI/DBus/DBusProxyHelper.hpp
+++ b/include/CommonAPI/DBus/DBusProxyHelper.hpp
@@ -30,29 +30,41 @@ class DBusProxy;
template< class, class >
struct DBusProxyHelper;
+#ifdef WIN32
+// Visual Studio 2013 does not support 'magic statics' yet.
+// Change back when switched to Visual Studio 2015 or higher.
+static std::mutex callMethod_mutex_;
+static std::mutex callMethodWithReply_mutex_;
+static std::mutex callMethodAsync_mutex_;
+#endif
+
template<
- template<class ...> class _In, class... _InArgs,
- template <class...> class _Out, class... _OutArgs>
-struct DBusProxyHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>,
- _Out<DBusInputStream, DBusOutputStream, _OutArgs...>> {
-
- template <typename _DBusProxy = DBusProxy>
- static void callMethod(const _DBusProxy &_proxy,
- const std::string &_method,
- const std::string &_signature,
- const _InArgs&... _in,
- CommonAPI::CallStatus &_status) {
-
- if (_proxy.isAvailable()) {
- DBusMessage message = _proxy.createMethodCall(_method, _signature);
- if (sizeof...(_InArgs) > 0) {
- DBusOutputStream output(message);
- if (!DBusSerializableArguments<_InArgs...>::serialize(output, _in...)) {
- _status = CallStatus::OUT_OF_MEMORY;
- return;
- }
- output.flush();
- }
+ template<class ...> class In_, class... InArgs_,
+ template <class...> class Out_, class... OutArgs_>
+struct DBusProxyHelper<In_<DBusInputStream, DBusOutputStream, InArgs_...>,
+ Out_<DBusInputStream, DBusOutputStream, OutArgs_...>> {
+
+ template <typename DBusProxy_ = DBusProxy>
+ static void callMethod(const DBusProxy_ &_proxy,
+ const std::string &_method,
+ const std::string &_signature,
+ const InArgs_&... _in,
+ CommonAPI::CallStatus &_status) {
+#ifndef WIN32
+ static std::mutex callMethod_mutex_;
+#endif
+ std::lock_guard<std::mutex> lock(callMethod_mutex_);
+
+ if (_proxy.isAvailable()) {
+ DBusMessage message = _proxy.createMethodCall(_method, _signature);
+ if (sizeof...(InArgs_) > 0) {
+ DBusOutputStream output(message);
+ if (!DBusSerializableArguments<InArgs_...>::serialize(output, _in...)) {
+ _status = CallStatus::OUT_OF_MEMORY;
+ return;
+ }
+ output.flush();
+ }
const bool isSent = _proxy.getDBusConnection()->sendDBusMessage(message);
_status = (isSent ? CallStatus::SUCCESS : CallStatus::OUT_OF_MEMORY);
@@ -61,18 +73,18 @@ struct DBusProxyHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>,
}
}
- template <typename _DBusProxy = DBusProxy>
+ template <typename DBusProxy_ = DBusProxy>
static void callMethodWithReply(
- const _DBusProxy &_proxy,
+ const DBusProxy_ &_proxy,
DBusMessage &_message,
- const CommonAPI::CallInfo *_info,
- const _InArgs&... _in,
+ const CommonAPI::CallInfo *_info,
+ const InArgs_&... _in,
CommonAPI::CallStatus &_status,
- _OutArgs&... _out) {
+ OutArgs_&... _out) {
- if (sizeof...(_InArgs) > 0) {
+ if (sizeof...(InArgs_) > 0) {
DBusOutputStream output(_message);
- if (!DBusSerializableArguments<_InArgs...>::serialize(output, _in...)) {
+ if (!DBusSerializableArguments<InArgs_...>::serialize(output, _in...)) {
_status = CallStatus::OUT_OF_MEMORY;
return;
}
@@ -86,9 +98,9 @@ struct DBusProxyHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>,
return;
}
- if (sizeof...(_OutArgs) > 0) {
+ if (sizeof...(OutArgs_) > 0) {
DBusInputStream input(reply);
- if (!DBusSerializableArguments<_OutArgs...>::deserialize(input, _out...)) {
+ if (!DBusSerializableArguments<OutArgs_...>::deserialize(input, _out...)) {
_status = CallStatus::REMOTE_ERROR;
return;
}
@@ -96,16 +108,21 @@ struct DBusProxyHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>,
_status = CallStatus::SUCCESS;
}
- template <typename _DBusProxy = DBusProxy>
+ template <typename DBusProxy_ = DBusProxy>
static void callMethodWithReply(
- const _DBusProxy &_proxy,
+ const DBusProxy_ &_proxy,
const DBusAddress &_address,
const char *_method,
const char *_signature,
- const CommonAPI::CallInfo *_info,
- const _InArgs&... _in,
+ const CommonAPI::CallInfo *_info,
+ const InArgs_&... _in,
CommonAPI::CallStatus &_status,
- _OutArgs&... _out) {
+ OutArgs_&... _out) {
+#ifndef WIN32
+ static std::mutex callMethodWithReply_mutex_;
+#endif
+ std::lock_guard<std::mutex> lock(callMethodWithReply_mutex_);
+
if (_proxy.isAvailable()) {
DBusMessage message = DBusMessage::createMethodCall(_address, _method, _signature);
callMethodWithReply(_proxy, message, _info, _in..., _status, _out...);
@@ -114,34 +131,39 @@ struct DBusProxyHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>,
}
}
- template <typename _DBusProxy = DBusProxy>
+ template <typename DBusProxy_ = DBusProxy>
static void callMethodWithReply(
- const _DBusProxy &_proxy,
+ const DBusProxy_ &_proxy,
const std::string &_interface,
const std::string &_method,
const std::string &_signature,
- const CommonAPI::CallInfo *_info,
- const _InArgs&... _in,
+ const CommonAPI::CallInfo *_info,
+ const InArgs_&... _in,
CommonAPI::CallStatus &_status,
- _OutArgs&... _out) {
- DBusAddress itsAddress(_proxy.getDBusAddress());
- itsAddress.setInterface(_interface);
+ OutArgs_&... _out) {
+ DBusAddress itsAddress(_proxy.getDBusAddress());
+ itsAddress.setInterface(_interface);
callMethodWithReply(
- _proxy, itsAddress,
- _method.c_str(), _signature.c_str(),
- _info,
- _in..., _status, _out...);
+ _proxy, itsAddress,
+ _method.c_str(), _signature.c_str(),
+ _info,
+ _in..., _status, _out...);
}
- template <typename _DBusProxy = DBusProxy>
+ template <typename DBusProxy_ = DBusProxy>
static void callMethodWithReply(
- const _DBusProxy &_proxy,
+ const DBusProxy_ &_proxy,
const std::string &_method,
const std::string &_signature,
- const CommonAPI::CallInfo *_info,
- const _InArgs&... _in,
+ const CommonAPI::CallInfo *_info,
+ const InArgs_&... _in,
CommonAPI::CallStatus &_status,
- _OutArgs&... _out) {
+ OutArgs_&... _out) {
+#ifndef WIN32
+ static std::mutex callMethodWithReply_mutex_;
+#endif
+ std::lock_guard<std::mutex> lock(callMethodWithReply_mutex_);
+
if (_proxy.isAvailable()) {
DBusMessage message = _proxy.createMethodCall(_method, _signature);
callMethodWithReply(_proxy, message, _info, _in..., _status, _out...);
@@ -150,19 +172,19 @@ struct DBusProxyHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>,
}
}
- template <typename _DBusProxy = DBusProxy, typename _AsyncCallback>
+ template <typename DBusProxy_ = DBusProxy, typename AsyncCallback_>
static std::future<CallStatus> callMethodAsync(
- const _DBusProxy &_proxy,
+ const DBusProxy_ &_proxy,
DBusMessage &_message,
- const CommonAPI::CallInfo *_info,
- const _InArgs&... _in,
- _AsyncCallback _callback,
- std::tuple<_OutArgs...> _out) {
- if (sizeof...(_InArgs) > 0) {
+ const CommonAPI::CallInfo *_info,
+ const InArgs_&... _in,
+ AsyncCallback_ _callback,
+ std::tuple<OutArgs_...> _out) {
+ if (sizeof...(InArgs_) > 0) {
DBusOutputStream output(_message);
const bool success = DBusSerializableArguments<
- _InArgs...
- >::serialize(output, _in...);
+ InArgs_...
+ >::serialize(output, _in...);
if (!success) {
std::promise<CallStatus> promise;
promise.set_value(CallStatus::OUT_OF_MEMORY);
@@ -174,27 +196,32 @@ struct DBusProxyHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>,
return _proxy.getDBusConnection()->sendDBusMessageWithReplyAsync(
_message,
DBusProxyAsyncCallbackHandler<
- _OutArgs...
+ OutArgs_...
>::create(std::move(_callback), _out),
- _info);
+ _info);
}
- template <typename _DBusProxy = DBusProxy, typename _AsyncCallback>
+ template <typename DBusProxy_ = DBusProxy, typename AsyncCallback_>
static std::future<CallStatus> callMethodAsync(
- const _DBusProxy &_proxy,
+ const DBusProxy_ &_proxy,
const DBusAddress &_address,
const std::string &_method,
const std::string &_signature,
- const CommonAPI::CallInfo *_info,
- const _InArgs&... _in,
- _AsyncCallback _callback,
- std::tuple<_OutArgs...> _out) {
+ const CommonAPI::CallInfo *_info,
+ const InArgs_&... _in,
+ AsyncCallback_ _callback,
+ std::tuple<OutArgs_...> _out) {
+#ifndef WIN32
+ static std::mutex callMethodAsync_mutex_;
+#endif
+ std::lock_guard<std::mutex> lock(callMethodAsync_mutex_);
+
if (_proxy.isAvailable()) {
DBusMessage message = DBusMessage::createMethodCall(_address, _method, _signature);
return callMethodAsync(_proxy, message, _info, _in..., _callback, _out);
} else {
CallStatus status = CallStatus::NOT_AVAILABLE;
- callCallbackOnNotAvailable(_callback, typename make_sequence<sizeof...(_OutArgs)>::type(), _out);
+ callCallbackOnNotAvailable(_callback, typename make_sequence<sizeof...(OutArgs_)>::type(), _out);
std::promise<CallStatus> promise;
promise.set_value(status);
@@ -202,53 +229,59 @@ struct DBusProxyHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>,
}
}
- template <typename _DBusProxy = DBusProxy, typename _AsyncCallback>
+ template <typename DBusProxy_ = DBusProxy, typename AsyncCallback_>
static std::future<CallStatus> callMethodAsync(
- const _DBusProxy &_proxy,
+ const DBusProxy_ &_proxy,
const std::string &_interface,
const std::string &_method,
const std::string &_signature,
- const CommonAPI::CallInfo *_info,
- const _InArgs&... _in,
- _AsyncCallback _callback,
- std::tuple<_OutArgs...> _out) {
- DBusAddress itsAddress(_proxy.getDBusAddress());
- itsAddress.setInterface(_interface);
- return callMethodAsync(
- _proxy, itsAddress,
- _method, _signature,
- _info,
- _in..., _callback, _out);
+ const CommonAPI::CallInfo *_info,
+ const InArgs_&... _in,
+ AsyncCallback_ _callback,
+ std::tuple<OutArgs_...> _out) {
+ DBusAddress itsAddress(_proxy.getDBusAddress());
+ itsAddress.setInterface(_interface);
+ return callMethodAsync(
+ _proxy, itsAddress,
+ _method, _signature,
+ _info,
+ _in..., _callback, _out);
}
- template <typename _DBusProxy = DBusProxy, typename _AsyncCallback>
+ template <typename DBusProxy_ = DBusProxy, typename AsyncCallback_>
static std::future<CallStatus> callMethodAsync(
- const _DBusProxy &_proxy,
+ const DBusProxy_ &_proxy,
const std::string &_method,
const std::string &_signature,
- const CommonAPI::CallInfo *_info,
- const _InArgs&... _in,
- _AsyncCallback _callback,
- std::tuple<_OutArgs...> _out) {
+ const CommonAPI::CallInfo *_info,
+ const InArgs_&... _in,
+ AsyncCallback_ _callback,
+ std::tuple<OutArgs_...> _out) {
+#ifndef WIN32
+ static std::mutex callMethodAsync_mutex_;
+#endif
+ std::lock_guard<std::mutex> lock(callMethodAsync_mutex_);
+
if (_proxy.isAvailable()) {
DBusMessage message = _proxy.createMethodCall(_method, _signature);
return callMethodAsync(_proxy, message, _info, _in..., _callback, _out);
} else {
callCallbackOnNotAvailable(
- _callback, typename make_sequence<sizeof...(_OutArgs)>::type(), _out);
+ _callback, typename make_sequence<sizeof...(OutArgs_)>::type(), _out);
CallStatus status = CallStatus::NOT_AVAILABLE;
std::promise<CallStatus> promise;
promise.set_value(status);
return promise.get_future();
- }
+ }
}
- template <int... _ArgIndices>
- static void callCallbackOnNotAvailable(std::function<void(CallStatus, _OutArgs&...)> _callback,
- index_sequence<_ArgIndices...>, std::tuple<_OutArgs...> _out) {
+ template <int... ArgIndices_>
+ static void callCallbackOnNotAvailable(std::function<void(CallStatus, OutArgs_&...)> _callback,
+ index_sequence<ArgIndices_...>, std::tuple<OutArgs_...> _out) {
const CallStatus status(CallStatus::NOT_AVAILABLE);
- _callback(status, std::get<_ArgIndices>(_out)...);
+ _callback(status, std::get<ArgIndices_>(_out)...);
+ (void)_out;
}
};
diff --git a/include/CommonAPI/DBus/DBusProxyManager.hpp b/include/CommonAPI/DBus/DBusProxyManager.hpp
index a28527a..15ed474 100644
--- a/include/CommonAPI/DBus/DBusProxyManager.hpp
+++ b/include/CommonAPI/DBus/DBusProxyManager.hpp
@@ -30,33 +30,33 @@ public:
COMMONAPI_EXPORT DBusProxyManager(DBusProxy &_proxy,
const std::string &_interfaceName);
- COMMONAPI_EXPORT const std::string &getDomain() const;
- COMMONAPI_EXPORT const std::string &getInterface() const;
- COMMONAPI_EXPORT const ConnectionId_t &getConnectionId() const;
+ COMMONAPI_EXPORT const std::string &getDomain() const;
+ COMMONAPI_EXPORT const std::string &getInterface() const;
+ COMMONAPI_EXPORT const ConnectionId_t &getConnectionId() const;
- COMMONAPI_EXPORT virtual void getAvailableInstances(CommonAPI::CallStatus &, std::vector<std::string> &_instances);
- COMMONAPI_EXPORT virtual std::future<CallStatus> getAvailableInstancesAsync(GetAvailableInstancesCallback _callback);
+ COMMONAPI_EXPORT virtual void getAvailableInstances(CommonAPI::CallStatus &, std::vector<std::string> &_instances);
+ COMMONAPI_EXPORT virtual std::future<CallStatus> getAvailableInstancesAsync(GetAvailableInstancesCallback _callback);
- COMMONAPI_EXPORT virtual void getInstanceAvailabilityStatus(const std::string &_address,
+ COMMONAPI_EXPORT virtual void getInstanceAvailabilityStatus(const std::string &_address,
CallStatus &_callStatus,
AvailabilityStatus &_availabilityStatus);
- COMMONAPI_EXPORT virtual std::future<CallStatus> getInstanceAvailabilityStatusAsync(
- const std::string&,
+ COMMONAPI_EXPORT virtual std::future<CallStatus> getInstanceAvailabilityStatusAsync(
+ const std::string&,
GetInstanceAvailabilityStatusCallback callback);
- COMMONAPI_EXPORT virtual InstanceAvailabilityStatusChangedEvent& getInstanceAvailabilityStatusChangedEvent();
+ COMMONAPI_EXPORT virtual InstanceAvailabilityStatusChangedEvent& getInstanceAvailabilityStatusChangedEvent();
private:
- COMMONAPI_EXPORT void instancesAsyncCallback(const CommonAPI::CallStatus& status,
+ COMMONAPI_EXPORT void instancesAsyncCallback(const CommonAPI::CallStatus& status,
const DBusObjectManagerStub::DBusObjectPathAndInterfacesDict& dict,
GetAvailableInstancesCallback& call);
- COMMONAPI_EXPORT void instanceAliveAsyncCallback(const AvailabilityStatus &_alive,
+ COMMONAPI_EXPORT void instanceAliveAsyncCallback(const AvailabilityStatus &_alive,
GetInstanceAvailabilityStatusCallback &_call,
- std::shared_ptr<std::promise<CallStatus>> &_status);
+ std::shared_ptr<std::promise<CallStatus>> &_status);
- COMMONAPI_EXPORT void translateCommonApiAddresses(const DBusObjectManagerStub::DBusObjectPathAndInterfacesDict &_dict,
+ COMMONAPI_EXPORT void translateCommonApiAddresses(const DBusObjectManagerStub::DBusObjectPathAndInterfacesDict &_dict,
std::vector<std::string> &_instances);
DBusProxy &proxy_;
diff --git a/include/CommonAPI/DBus/DBusSelectiveEvent.hpp b/include/CommonAPI/DBus/DBusSelectiveEvent.hpp
index 65c61f9..05f2f5f 100644
--- a/include/CommonAPI/DBus/DBusSelectiveEvent.hpp
+++ b/include/CommonAPI/DBus/DBusSelectiveEvent.hpp
@@ -15,37 +15,42 @@
namespace CommonAPI {
namespace DBus {
-template<typename _EventType, typename... _Arguments>
-class DBusSelectiveEvent: public DBusEvent<_EventType, _Arguments...> {
+template<typename EventType_, typename... Arguments_>
+class DBusSelectiveEvent: public DBusEvent<EventType_, Arguments_...> {
public:
- typedef typename DBusEvent<_EventType, _Arguments...>::Listener Listener;
- typedef DBusEvent<_EventType, _Arguments...> DBusEventBase;
+ typedef typename DBusEvent<EventType_, Arguments_...>::Listener Listener;
+ typedef DBusEvent<EventType_, Arguments_...> DBusEventBase;
DBusSelectiveEvent(DBusProxy &_proxy,
- const char *_name, const char *_signature,
- std::tuple<_Arguments...> _arguments)
- : DBusEventBase(_proxy, _name, _signature, _arguments) {
+ const char *_name, const char *_signature,
+ std::tuple<Arguments_...> _arguments)
+ : DBusEventBase(_proxy, _name, _signature, _arguments) {
}
DBusSelectiveEvent(DBusProxy &_proxy,
- const char *_name, const char *_signature,
+ const char *_name, const char *_signature,
const char *_path, const char *_interface,
- std::tuple<_Arguments...> _arguments)
- : DBusEventBase(_proxy, _name, _signature, _path, _interface, _arguments) {
+ std::tuple<Arguments_...> _arguments)
+ : DBusEventBase(_proxy, _name, _signature, _path, _interface, _arguments) {
}
virtual ~DBusSelectiveEvent() {}
protected:
void onFirstListenerAdded(const Listener &) {
- bool success;
- this->subscription_
- = static_cast<DBusProxy&>(this->proxy_).subscribeForSelectiveBroadcastOnConnection(
- success, this->path_, this->interface_, this->name_, this->signature_, this);
+ bool success;
+ this->subscription_
+ = static_cast<DBusProxy&>(this->proxy_).subscribeForSelectiveBroadcastOnConnection(
+ success, this->path_, this->interface_, this->name_, this->signature_, this);
+
+ if (success == false) {
+ // Call error listener with an error code
+ this->notifyError(CommonAPI::CallStatus::SUBSCRIPTION_REFUSED);
+ }
}
void onLastListenerRemoved(const Listener &) {
- static_cast<DBusProxy&>(this->proxy_).unsubscribeFromSelectiveBroadcast(
+ static_cast<DBusProxy&>(this->proxy_).unsubscribeFromSelectiveBroadcast(
this->name_, this->subscription_, this);
}
};
diff --git a/include/CommonAPI/DBus/DBusSerializableArguments.hpp b/include/CommonAPI/DBus/DBusSerializableArguments.hpp
index f763ce5..6b48eff 100644
--- a/include/CommonAPI/DBus/DBusSerializableArguments.hpp
+++ b/include/CommonAPI/DBus/DBusSerializableArguments.hpp
@@ -17,12 +17,12 @@
namespace CommonAPI {
namespace DBus {
-template<typename... _Arguments>
+template<typename... Arguments_>
using DBusSerializableArguments = CommonAPI::SerializableArguments<
- DBusInputStream,
- DBusOutputStream,
- _Arguments...
- >;
+ DBusInputStream,
+ DBusOutputStream,
+ Arguments_...
+ >;
} // namespace DBus
} // namespace CommonAPI
diff --git a/include/CommonAPI/DBus/DBusServiceRegistry.hpp b/include/CommonAPI/DBus/DBusServiceRegistry.hpp
index 3dbcf1b..584c47a 100644
--- a/include/CommonAPI/DBus/DBusServiceRegistry.hpp
+++ b/include/CommonAPI/DBus/DBusServiceRegistry.hpp
@@ -31,6 +31,7 @@
#include <CommonAPI/Types.hpp>
#include <CommonAPI/DBus/DBusProxyConnection.hpp>
#include <CommonAPI/DBus/DBusFactory.hpp>
+#include <CommonAPI/DBus/DBusObjectManagerStub.hpp>
namespace CommonAPI {
namespace DBus {
@@ -98,15 +99,17 @@ class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegist
virtual void onSignalDBusMessage(const DBusMessage&);
+ void setDBusServicePredefined(const std::string& _serviceName);
+
private:
struct DBusInterfaceNameListenersRecord {
DBusInterfaceNameListenersRecord()
- : state(DBusRecordState::UNKNOWN) {
+ : state(DBusRecordState::UNKNOWN) {
}
DBusInterfaceNameListenersRecord(DBusInterfaceNameListenersRecord &&_other)
- : state(_other.state),
- listenerList(std::move(_other.listenerList)) {
+ : state(_other.state),
+ listenerList(std::move(_other.listenerList)) {
}
DBusRecordState state;
@@ -117,23 +120,23 @@ class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegist
struct DBusServiceListenersRecord {
DBusServiceListenersRecord()
- : uniqueBusNameState(DBusRecordState::UNKNOWN),
- mutexOnResolve() {
+ : uniqueBusNameState(DBusRecordState::UNKNOWN),
+ mutexOnResolve() {
}
DBusServiceListenersRecord(DBusServiceListenersRecord&& other)
- : uniqueBusNameState(other.uniqueBusNameState),
- uniqueBusName(std::move(other.uniqueBusName)),
- promiseOnResolve(std::move(other.promiseOnResolve)),
- futureOnResolve(std::move(other.futureOnResolve)),
- mutexOnResolve(std::move(other.mutexOnResolve)),
- dbusObjectPathListenersMap(std::move(other.dbusObjectPathListenersMap)) {
+ : uniqueBusNameState(other.uniqueBusNameState),
+ uniqueBusName(std::move(other.uniqueBusName)),
+ promiseOnResolve(std::move(other.promiseOnResolve)),
+ futureOnResolve(std::move(other.futureOnResolve)),
+ mutexOnResolve(std::move(other.mutexOnResolve)),
+ dbusObjectPathListenersMap(std::move(other.dbusObjectPathListenersMap)) {
}
~DBusServiceListenersRecord() {};
DBusRecordState uniqueBusNameState;
- std::string uniqueBusName;
+ std::string uniqueBusName;
std::promise<DBusRecordState> promiseOnResolve;
std::shared_future<DBusRecordState> futureOnResolve;
@@ -147,15 +150,16 @@ class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegist
struct DBusObjectPathCache {
DBusObjectPathCache()
- : referenceCount(0),
- state(DBusRecordState::UNKNOWN) {
+ : referenceCount(0),
+ state(DBusRecordState::UNKNOWN){
}
DBusObjectPathCache(DBusObjectPathCache&& other)
- : referenceCount(other.referenceCount),
- state(other.state),
- promiseOnResolve(std::move(other.promiseOnResolve)),
- dbusInterfaceNamesCache(std::move(other.dbusInterfaceNamesCache)) {
+ : referenceCount(other.referenceCount),
+ state(other.state),
+ promiseOnResolve(std::move(other.promiseOnResolve)),
+ serviceName(std::move(other.serviceName)),
+ dbusInterfaceNamesCache(std::move(other.dbusInterfaceNamesCache)){
}
~DBusObjectPathCache() {}
@@ -163,20 +167,21 @@ class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegist
size_t referenceCount;
DBusRecordState state;
std::promise<DBusRecordState> promiseOnResolve;
+ std::string serviceName;
std::unordered_set<std::string> dbusInterfaceNamesCache;
};
struct DBusUniqueNameRecord {
DBusUniqueNameRecord()
- : objectPathsState(DBusRecordState::UNKNOWN) {
+ : objectPathsState(DBusRecordState::UNKNOWN) {
}
DBusUniqueNameRecord(DBusUniqueNameRecord&& other)
- : uniqueName(std::move(other.uniqueName)),
- objectPathsState(other.objectPathsState),
- ownedBusNames(std::move(other.ownedBusNames)),
- dbusObjectPathsCache(std::move(other.dbusObjectPathsCache)) {
+ : uniqueName(std::move(other.uniqueName)),
+ objectPathsState(other.objectPathsState),
+ ownedBusNames(std::move(other.ownedBusNames)),
+ dbusObjectPathsCache(std::move(other.dbusObjectPathsCache)) {
}
std::string uniqueName;
@@ -198,8 +203,8 @@ class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegist
DBusServiceListenersRecord& dbusServiceListenersRecord);
void onGetNameOwnerCallback(const CallStatus& status,
- std::string dbusServiceUniqueName,
- const std::string& dbusServiceName);
+ std::string dbusServiceUniqueName,
+ const std::string& dbusServiceName);
DBusRecordState resolveDBusInterfaceNameState(const DBusAddress &_address,
@@ -207,12 +212,37 @@ class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegist
DBusObjectPathCache& getDBusObjectPathCacheReference(const std::string& dbusObjectPath,
+ const std::string& dbusServiceName,
const std::string& dbusServiceUniqueName,
DBusUniqueNameRecord& dbusUniqueNameRecord);
void releaseDBusObjectPathCacheReference(const std::string& dbusObjectPath,
const DBusServiceListenersRecord& dbusServiceListenersRecord);
+ typedef std::function<void(const CallStatus&,
+ const DBusObjectManagerStub::DBusObjectPathAndInterfacesDict,
+ const std::string&,
+ const std::string&)> GetManagedObjectsCallback;
+
+ bool resolveObjectPathWithObjectManager(const std::string& dbusServiceUniqueName, const std::string& dbusObjectPath);
+
+ bool getManagedObjects(const std::string& dbusServiceUniqueName,
+ const std::string& dbusObjectPath,
+ GetManagedObjectsCallback callback);
+
+ void onGetManagedObjectsCallbackResolve(const CallStatus& callStatus,
+ const DBusObjectManagerStub::DBusObjectPathAndInterfacesDict dbusObjectPathAndInterfacesDict,
+ const std::string& dbusServiceUniqueName,
+ const std::string& dbusObjectPath);
+
+ void onGetManagedObjectsCallbackResolveFurther(const CallStatus& callStatus,
+ const DBusObjectManagerStub::DBusObjectPathAndInterfacesDict dbusObjectPathAndInterfacesDict,
+ const std::string& dbusServiceUniqueName,
+ const std::string& dbusObjectPath);
+
+ void processManagedObject(const std::string& dbusObjectPath,
+ const std::string& dbusServiceUniqueName,
+ const std::string& interfaceName);
bool introspectDBusObjectPath(const std::string& dbusServiceUniqueName, const std::string& dbusObjectPath);
@@ -290,17 +320,19 @@ class DBusServiceRegistry: public std::enable_shared_from_this<DBusServiceRegist
void fetchAllServiceNames();
- inline const bool isDBusServiceName(const std::string &_name) {
+ inline bool isDBusServiceName(const std::string &_name) {
return (_name.length() > 0 && _name[0] != ':');
};
- inline const bool isOrgFreedesktopDBusInterface(const std::string& dbusInterfaceName) {
+ inline bool isOrgFreedesktopDBusInterface(const std::string& dbusInterfaceName) {
return dbusInterfaceName.find("org.freedesktop.DBus.") == 0;
}
std::thread::id notificationThread_;
+ std::unordered_set<std::string> dbusPredefinedServices_;
+
private:
typedef std::map<std::shared_ptr<DBusProxyConnection>, std::shared_ptr<DBusServiceRegistry>> RegistryMap_t;
static RegistryMap_t registries_;
diff --git a/include/CommonAPI/DBus/DBusStubAdapter.hpp b/include/CommonAPI/DBus/DBusStubAdapter.hpp
index 5d1657b..b2bea37 100644
--- a/include/CommonAPI/DBus/DBusStubAdapter.hpp
+++ b/include/CommonAPI/DBus/DBusStubAdapter.hpp
@@ -23,29 +23,29 @@ namespace DBus {
class DBusProxyConnection;
class DBusStubAdapter
- : virtual public CommonAPI::StubAdapter,
- public DBusInterfaceHandler {
+ : virtual public CommonAPI::StubAdapter,
+ public DBusInterfaceHandler {
public:
- COMMONAPI_EXPORT DBusStubAdapter(const DBusAddress &_dbusAddress,
+ COMMONAPI_EXPORT DBusStubAdapter(const DBusAddress &_dbusAddress,
const std::shared_ptr<DBusProxyConnection> &_connection,
const bool isManagingInterface);
- COMMONAPI_EXPORT virtual ~DBusStubAdapter();
+ COMMONAPI_EXPORT virtual ~DBusStubAdapter();
- COMMONAPI_EXPORT virtual void init(std::shared_ptr<DBusStubAdapter> _instance);
- COMMONAPI_EXPORT virtual void deinit();
+ COMMONAPI_EXPORT virtual void init(std::shared_ptr<DBusStubAdapter> _instance);
+ COMMONAPI_EXPORT virtual void deinit();
- COMMONAPI_EXPORT const DBusAddress &getDBusAddress() const;
- COMMONAPI_EXPORT const std::shared_ptr<DBusProxyConnection> &getDBusConnection() const;
+ COMMONAPI_EXPORT const DBusAddress &getDBusAddress() const;
+ COMMONAPI_EXPORT const std::shared_ptr<DBusProxyConnection> &getDBusConnection() const;
- COMMONAPI_EXPORT const bool isManaging() const;
+ COMMONAPI_EXPORT bool isManaging() const;
- COMMONAPI_EXPORT virtual const char* getMethodsDBusIntrospectionXmlData() const = 0;
- COMMONAPI_EXPORT virtual bool onInterfaceDBusMessage(const DBusMessage &_message) = 0;
+ COMMONAPI_EXPORT virtual const char* getMethodsDBusIntrospectionXmlData() const = 0;
+ COMMONAPI_EXPORT virtual bool onInterfaceDBusMessage(const DBusMessage &_message) = 0;
- COMMONAPI_EXPORT virtual void deactivateManagedInstances() = 0;
- COMMONAPI_EXPORT virtual const bool hasFreedesktopProperties();
- COMMONAPI_EXPORT virtual bool onInterfaceDBusFreedesktopPropertiesMessage(const DBusMessage &_message) = 0;
+ COMMONAPI_EXPORT virtual void deactivateManagedInstances() = 0;
+ COMMONAPI_EXPORT virtual bool hasFreedesktopProperties();
+ COMMONAPI_EXPORT virtual bool onInterfaceDBusFreedesktopPropertiesMessage(const DBusMessage &_message) = 0;
protected:
DBusAddress dbusAddress_;
diff --git a/include/CommonAPI/DBus/DBusStubAdapterHelper.hpp b/include/CommonAPI/DBus/DBusStubAdapterHelper.hpp
index 90efba5..b533a2e 100644
--- a/include/CommonAPI/DBus/DBusStubAdapterHelper.hpp
+++ b/include/CommonAPI/DBus/DBusStubAdapterHelper.hpp
@@ -47,22 +47,27 @@ struct DBusAttributeDispatcherStruct {
typedef std::unordered_map<std::string, DBusAttributeDispatcherStruct> StubAttributeTable;
-template <typename _StubClass>
+template <typename StubClass_>
class DBusStubAdapterHelper: public virtual DBusStubAdapter {
public:
- typedef typename _StubClass::StubAdapterType StubAdapterType;
- typedef typename _StubClass::RemoteEventHandlerType RemoteEventHandlerType;
+ typedef typename StubClass_::StubAdapterType StubAdapterType;
+ typedef typename StubClass_::RemoteEventHandlerType RemoteEventHandlerType;
class StubDispatcher: public StubDispatcherBase {
public:
- virtual ~StubDispatcher() {}
- virtual bool dispatchDBusMessage(const DBusMessage& dbusMessage,
- const std::shared_ptr<_StubClass>& stub,
- DBusStubAdapterHelper<_StubClass>& dbusStubAdapterHelper) = 0;
- virtual void appendGetAllReply(const DBusMessage& dbusMessage,
- const std::shared_ptr<_StubClass>& stub,
- DBusStubAdapterHelper<_StubClass>& dbusStubAdapterHelper,
- DBusOutputStream &_output) {}
+ virtual ~StubDispatcher() {}
+ virtual bool dispatchDBusMessage(const DBusMessage &_message,
+ const std::shared_ptr<StubClass_> &_stub,
+ DBusStubAdapterHelper<StubClass_> &_helper) = 0;
+ virtual void appendGetAllReply(const DBusMessage &_message,
+ const std::shared_ptr<StubClass_> &_stub,
+ DBusStubAdapterHelper<StubClass_> &_helper,
+ DBusOutputStream &_output) {
+ (void)_message;
+ (void)_stub;
+ (void)_helper;
+ (void)_output;
+ }
};
// interfaceMemberName, interfaceMemberSignature
typedef std::pair<const char*, const char*> DBusInterfaceMemberPath;
@@ -70,7 +75,7 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter {
DBusStubAdapterHelper(const DBusAddress &_address,
const std::shared_ptr<DBusProxyConnection> &_connection,
- const std::shared_ptr<_StubClass> &_stub,
+ const std::shared_ptr<StubClass_> &_stub,
const bool _isManaging):
DBusStubAdapter(_address, _connection, _isManaging),
stub_(_stub),
@@ -135,7 +140,7 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter {
virtual const StubDispatcherTable& getStubDispatcherTable() = 0;
virtual const StubAttributeTable& getStubAttributeTable() = 0;
- std::shared_ptr<_StubClass> stub_;
+ std::shared_ptr<StubClass_> stub_;
RemoteEventHandlerType* remoteEventHandler_;
private:
@@ -154,9 +159,9 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter {
return false;
}
- StubDispatcher* getterDispatcher = static_cast<StubDispatcher*>(attributeDispatcherIterator->second.getter);
- assert(getterDispatcher != NULL); // all attributes have at least a getter
- return (getterDispatcher->dispatchDBusMessage(_message, stub_, *this));
+ StubDispatcher* getterDispatcher = static_cast<StubDispatcher*>(attributeDispatcherIterator->second.getter);
+ assert(getterDispatcher != NULL); // all attributes have at least a getter
+ return (getterDispatcher->dispatchDBusMessage(_message, stub_, *this));
}
bool handleFreedesktopSet(const DBusMessage& dbusMessage, DBusInputStream& dbusInputStream) {
@@ -174,12 +179,12 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter {
return false;
}
- StubDispatcher *setterDispatcher = static_cast<StubDispatcher*>(attributeDispatcherIterator->second.setter);
- if (setterDispatcher == NULL) { // readonly attributes do not have a setter
- return false;
- }
+ StubDispatcher *setterDispatcher = static_cast<StubDispatcher*>(attributeDispatcherIterator->second.setter);
+ if (setterDispatcher == NULL) { // readonly attributes do not have a setter
+ return false;
+ }
- return setterDispatcher->dispatchDBusMessage(dbusMessage, stub_, *this);
+ return setterDispatcher->dispatchDBusMessage(dbusMessage, stub_, *this);
}
bool handleFreedesktopGetAll(const DBusMessage& dbusMessage, DBusInputStream& dbusInputStream) {
@@ -218,24 +223,24 @@ class DBusStubAdapterHelper: public virtual DBusStubAdapter {
template< class >
struct DBusStubSignalHelper;
-template<template<class ...> class _In, class... _InArgs>
-struct DBusStubSignalHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>> {
+template<template<class ...> class In_, class... InArgs_>
+struct DBusStubSignalHelper<In_<DBusInputStream, DBusOutputStream, InArgs_...>> {
static inline bool sendSignal(const char* objectPath,
const char* interfaceName,
const char* signalName,
const char* signalSignature,
const std::shared_ptr<DBusProxyConnection>& dbusConnection,
- const _InArgs&... inArgs) {
+ const InArgs_&... inArgs) {
DBusMessage dbusMessage = DBusMessage::createSignal(
objectPath,
interfaceName,
signalName,
signalSignature);
- if (sizeof...(_InArgs) > 0) {
+ if (sizeof...(InArgs_) > 0) {
DBusOutputStream outputStream(dbusMessage);
- const bool success = DBusSerializableArguments<_InArgs...>::serialize(outputStream, inArgs...);
+ const bool success = DBusSerializableArguments<InArgs_...>::serialize(outputStream, inArgs...);
if (!success) {
return false;
}
@@ -246,11 +251,11 @@ struct DBusStubSignalHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>>
return dbusMessageSent;
}
- template <typename _DBusStub = DBusStubAdapter>
- static bool sendSignal(const _DBusStub &_stub,
+ template <typename DBusStub_ = DBusStubAdapter>
+ static bool sendSignal(const DBusStub_ &_stub,
const char *_name,
const char *_signature,
- const _InArgs&... inArgs) {
+ const InArgs_&... inArgs) {
return(sendSignal(_stub.getDBusAddress().getObjectPath().c_str(),
_stub.getDBusAddress().getInterface().c_str(),
_name,
@@ -260,24 +265,24 @@ struct DBusStubSignalHelper<_In<DBusInputStream, DBusOutputStream, _InArgs...>>
}
- template <typename _DBusStub = DBusStubAdapter>
+ template <typename DBusStub_ = DBusStubAdapter>
static bool sendSignal(const char *_target,
- const _DBusStub &_stub,
- const char *_name,
- const char *_signature,
- const _InArgs&... inArgs) {
+ const DBusStub_ &_stub,
+ const char *_name,
+ const char *_signature,
+ const InArgs_&... inArgs) {
DBusMessage dbusMessage
- = DBusMessage::createSignal(
- _stub.getDBusAddress().getObjectPath().c_str(),
- _stub.getDBusAddress().getInterface().c_str(),
- _name,
- _signature);
+ = DBusMessage::createSignal(
+ _stub.getDBusAddress().getObjectPath().c_str(),
+ _stub.getDBusAddress().getInterface().c_str(),
+ _name,
+ _signature);
dbusMessage.setDestination(_target);
- if (sizeof...(_InArgs) > 0) {
+ if (sizeof...(InArgs_) > 0) {
DBusOutputStream outputStream(dbusMessage);
- const bool success = DBusSerializableArguments<_InArgs...>::serialize(outputStream, inArgs...);
+ const bool success = DBusSerializableArguments<InArgs_...>::serialize(outputStream, inArgs...);
if (!success) {
return false;
}
@@ -292,52 +297,54 @@ template< class, class, class >
class DBusMethodStubDispatcher;
template <
- typename _StubClass,
- template <class...> class _In, class... _InArgs,
- template <class...> class _DeplIn, class... _DeplInArgs>
+ typename StubClass_,
+ template <class...> class In_, class... InArgs_,
+ template <class...> class DeplIn_, class... DeplIn_Args>
-class DBusMethodStubDispatcher<_StubClass, _In<_InArgs...>, _DeplIn<_DeplInArgs...> >: public DBusStubAdapterHelper<_StubClass>::StubDispatcher {
+class DBusMethodStubDispatcher<StubClass_, In_<InArgs_...>, DeplIn_<DeplIn_Args...> >: public DBusStubAdapterHelper<StubClass_>::StubDispatcher {
public:
- typedef DBusStubAdapterHelper<_StubClass> DBusStubAdapterHelperType;
- typedef void (_StubClass::*_StubFunctor)(std::shared_ptr<CommonAPI::ClientId>, _InArgs...);
+ typedef DBusStubAdapterHelper<StubClass_> DBusStubAdapterHelperType;
+ typedef void (StubClass_::*StubFunctor_)(std::shared_ptr<CommonAPI::ClientId>, InArgs_...);
- DBusMethodStubDispatcher(_StubFunctor stubFunctor, std::tuple<_DeplInArgs*...> _in):
+ DBusMethodStubDispatcher(StubFunctor_ stubFunctor, std::tuple<DeplIn_Args*...> _in):
stubFunctor_(stubFunctor) {
- initialize(typename make_sequence_range<sizeof...(_DeplInArgs), 0>::type(), _in);
+ initialize(typename make_sequence_range<sizeof...(DeplIn_Args), 0>::type(), _in);
}
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
- return handleDBusMessage(dbusMessage, stub, dbusStubAdapterHelper, typename make_sequence_range<sizeof...(_InArgs), 0>::type());
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ return handleDBusMessage(dbusMessage, stub, dbusStubAdapterHelper, typename make_sequence_range<sizeof...(InArgs_), 0>::type());
}
private:
- template <int... _DeplInArgIndices>
- inline void initialize(index_sequence<_DeplInArgIndices...>, std::tuple<_DeplInArgs*...> &_in) {
- in_ = std::make_tuple(std::get<_DeplInArgIndices>(_in)...);
+ template <int... DeplIn_ArgIndices>
+ inline void initialize(index_sequence<DeplIn_ArgIndices...>, std::tuple<DeplIn_Args*...> &_in) {
+ in_ = std::make_tuple(std::get<DeplIn_ArgIndices>(_in)...);
}
- template <int... _InArgIndices>
+ template <int... InArgIndices_>
inline bool handleDBusMessage(const DBusMessage& dbusMessage,
- const std::shared_ptr<_StubClass>& stub,
+ const std::shared_ptr<StubClass_>& stub,
DBusStubAdapterHelperType& dbusStubAdapterHelper,
- index_sequence<_InArgIndices...>) {
+ index_sequence<InArgIndices_...>) {
+ (void)dbusStubAdapterHelper;
+ std::tuple<InArgs_...> argTuple;
- if (sizeof...(_InArgs) > 0) {
+ if (sizeof...(InArgs_) > 0) {
DBusInputStream dbusInputStream(dbusMessage);
- const bool success = DBusSerializableArguments<CommonAPI::Deployable<_InArgs, _DeplInArgs>...>::deserialize(dbusInputStream, std::get<_InArgIndices>(in_)...);
+ const bool success = DBusSerializableArguments<CommonAPI::Deployable<InArgs_, DeplIn_Args>...>::deserialize(dbusInputStream, std::get<InArgIndices_>(in_)...);
if (!success)
return false;
}
std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender()));
- (stub.get()->*stubFunctor_)(clientId, std::move(std::get<_InArgIndices>(in_).getValue())...);
+ (stub.get()->*stubFunctor_)(clientId, std::move(std::get<InArgIndices_>(in_).getValue())...);
return true;
}
- _StubFunctor stubFunctor_;
- std::tuple<CommonAPI::Deployable<_InArgs, _DeplInArgs>...> in_;
+ StubFunctor_ stubFunctor_;
+ std::tuple<CommonAPI::Deployable<InArgs_, DeplIn_Args>...> in_;
};
@@ -345,189 +352,192 @@ template< class, class, class, class, class>
class DBusMethodWithReplyStubDispatcher;
template <
- typename _StubClass,
- template <class...> class _In, class... _InArgs,
- template <class...> class _Out, class... _OutArgs,
- template <class...> class _DeplIn, class... _DeplInArgs,
- template <class...> class _DeplOut, class... _DeplOutArgs>
+ typename StubClass_,
+ template <class...> class In_, class... InArgs_,
+ template <class...> class Out_, class... OutArgs_,
+ template <class...> class DeplIn_, class... DeplIn_Args,
+ template <class...> class DeplOut_, class... DeplOutArgs_>
class DBusMethodWithReplyStubDispatcher<
- _StubClass,
- _In<_InArgs...>,
- _Out<_OutArgs...>,
- _DeplIn<_DeplInArgs...>,
- _DeplOut<_DeplOutArgs...> >:
- public DBusStubAdapterHelper<_StubClass>::StubDispatcher {
+ StubClass_,
+ In_<InArgs_...>,
+ Out_<OutArgs_...>,
+ DeplIn_<DeplIn_Args...>,
+ DeplOut_<DeplOutArgs_...> >:
+ public DBusStubAdapterHelper<StubClass_>::StubDispatcher {
public:
- typedef DBusStubAdapterHelper<_StubClass> DBusStubAdapterHelperType;
- typedef std::function<void (_OutArgs...)> ReplyType_t;
- typedef void (_StubClass::*_StubFunctor)(
- std::shared_ptr<CommonAPI::ClientId>, _InArgs..., ReplyType_t);
+ typedef DBusStubAdapterHelper<StubClass_> DBusStubAdapterHelperType;
+ typedef std::function<void (OutArgs_...)> ReplyType_t;
+ typedef void (StubClass_::*StubFunctor_)(
+ std::shared_ptr<CommonAPI::ClientId>, InArgs_..., ReplyType_t);
- DBusMethodWithReplyStubDispatcher(_StubFunctor stubFunctor,
+ DBusMethodWithReplyStubDispatcher(StubFunctor_ stubFunctor,
const char* dbusReplySignature,
- std::tuple<_DeplInArgs*...> _inDepArgs,
- std::tuple<_DeplOutArgs*...> _outDepArgs):
+ std::tuple<DeplIn_Args*...> _inDepArgs,
+ std::tuple<DeplOutArgs_*...> _outDepArgs):
stubFunctor_(stubFunctor),
dbusReplySignature_(dbusReplySignature),
out_(_outDepArgs),
currentCall_(0) {
- initialize(typename make_sequence_range<sizeof...(_DeplInArgs), 0>::type(), _inDepArgs);
+ initialize(typename make_sequence_range<sizeof...(DeplIn_Args), 0>::type(), _inDepArgs);
}
bool dispatchDBusMessage(const DBusMessage& dbusMessage,
- const std::shared_ptr<_StubClass>& stub,
+ const std::shared_ptr<StubClass_>& stub,
DBusStubAdapterHelperType& dbusStubAdapterHelper) {
- connection_ = dbusStubAdapterHelper.getDBusConnection();
+ connection_ = dbusStubAdapterHelper.getDBusConnection();
return handleDBusMessage(
dbusMessage,
stub,
dbusStubAdapterHelper,
- typename make_sequence_range<sizeof...(_InArgs), 0>::type(),
- typename make_sequence_range<sizeof...(_OutArgs), 0>::type());
+ typename make_sequence_range<sizeof...(InArgs_), 0>::type(),
+ typename make_sequence_range<sizeof...(OutArgs_), 0>::type());
}
- bool sendReply(CommonAPI::CallId_t _call,
- std::tuple<CommonAPI::Deployable<_OutArgs, _DeplOutArgs>...> args = std::make_tuple()) {
- return sendReplyInternal(_call, typename make_sequence_range<sizeof...(_OutArgs), 0>::type(), args);
- }
+ bool sendReply(CommonAPI::CallId_t _call,
+ std::tuple<CommonAPI::Deployable<OutArgs_, DeplOutArgs_>...> args = std::make_tuple()) {
+ return sendReplyInternal(_call, typename make_sequence_range<sizeof...(OutArgs_), 0>::type(), args);
+ }
private:
- template <int... _DeplInArgIndices>
- inline void initialize(index_sequence<_DeplInArgIndices...>, std::tuple<_DeplInArgs*...> &_in) {
- in_ = std::make_tuple(std::get<_DeplInArgIndices>(_in)...);
- }
+ template <int... DeplIn_ArgIndices>
+ inline void initialize(index_sequence<DeplIn_ArgIndices...>, std::tuple<DeplIn_Args*...> &_in) {
+ in_ = std::make_tuple(std::get<DeplIn_ArgIndices>(_in)...);
+ }
- template <int... _InArgIndices, int... _OutArgIndices>
+ template <int... InArgIndices_, int... OutArgIndices_>
inline bool handleDBusMessage(const DBusMessage& dbusMessage,
- const std::shared_ptr<_StubClass>& stub,
+ const std::shared_ptr<StubClass_>& stub,
DBusStubAdapterHelperType& dbusStubAdapterHelper,
- index_sequence<_InArgIndices...>,
- index_sequence<_OutArgIndices...>) {
- if (sizeof...(_DeplInArgs) > 0) {
+ index_sequence<InArgIndices_...>,
+ index_sequence<OutArgIndices_...>) {
+ (void)dbusStubAdapterHelper;
+ if (sizeof...(DeplIn_Args) > 0) {
DBusInputStream dbusInputStream(dbusMessage);
- const bool success = DBusSerializableArguments<CommonAPI::Deployable<_InArgs, _DeplInArgs>...>::deserialize(dbusInputStream, std::get<_InArgIndices>(in_)...);
+ const bool success = DBusSerializableArguments<CommonAPI::Deployable<InArgs_, DeplIn_Args>...>::deserialize(dbusInputStream, std::get<InArgIndices_>(in_)...);
if (!success)
return false;
}
std::shared_ptr<DBusClientId> clientId
- = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender()));
+ = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender()));
DBusMessage reply = dbusMessage.createMethodReturn(dbusReplySignature_);
CommonAPI::CallId_t call;
{
- std::lock_guard<std::mutex> lock(mutex_);
- call = currentCall_++;
- pending_[call] = reply;
+ std::lock_guard<std::mutex> lock(mutex_);
+ call = currentCall_++;
+ pending_[call] = reply;
}
(stub.get()->*stubFunctor_)(
- clientId,
- std::move(std::get<_InArgIndices>(in_).getValue())...,
- [call, this](_OutArgs... _args){
- this->sendReply(call, std::make_tuple(CommonAPI::Deployable<_OutArgs, _DeplOutArgs>(
- _args, std::get<_OutArgIndices>(out_)
- )...));
- }
+ clientId,
+ std::move(std::get<InArgIndices_>(in_).getValue())...,
+ [call, this](OutArgs_... _args){
+ this->sendReply(call, std::make_tuple(CommonAPI::Deployable<OutArgs_, DeplOutArgs_>(
+ _args, std::get<OutArgIndices_>(out_)
+ )...));
+ }
);
- return true;
- }
+ return true;
+ }
- template<int... _OutArgIndices>
+ template<int... OutArgIndices_>
bool sendReplyInternal(CommonAPI::CallId_t _call,
- index_sequence<_OutArgIndices...>,
- std::tuple<CommonAPI::Deployable<_OutArgs, _DeplOutArgs>...> args) {
- std::lock_guard<std::mutex> lock(mutex_);
- auto reply = pending_.find(_call);
- if (reply != pending_.end()) {
- if (sizeof...(_DeplOutArgs) > 0) {
- DBusOutputStream output(reply->second);
- if (!DBusSerializableArguments<CommonAPI::Deployable<_OutArgs, _DeplOutArgs>...>::serialize(
- output, std::get<_OutArgIndices>(args)...)) {
- pending_.erase(_call);
- return false;
- }
- output.flush();
- }
- bool isSuccessful = connection_->sendDBusMessage(reply->second);
- pending_.erase(_call);
- return isSuccessful;
- }
- return false;
- }
-
- _StubFunctor stubFunctor_;
+ index_sequence<OutArgIndices_...>,
+ std::tuple<CommonAPI::Deployable<OutArgs_, DeplOutArgs_>...> args) {
+ std::lock_guard<std::mutex> lock(mutex_);
+ auto reply = pending_.find(_call);
+ if (reply != pending_.end()) {
+ if (sizeof...(DeplOutArgs_) > 0) {
+ DBusOutputStream output(reply->second);
+ if (!DBusSerializableArguments<CommonAPI::Deployable<OutArgs_, DeplOutArgs_>...>::serialize(
+ output, std::get<OutArgIndices_>(args)...)) {
+ (void)args;
+ pending_.erase(_call);
+ return false;
+ }
+ output.flush();
+ }
+ bool isSuccessful = connection_->sendDBusMessage(reply->second);
+ pending_.erase(_call);
+ return isSuccessful;
+ }
+ return false;
+ }
+
+ StubFunctor_ stubFunctor_;
const char* dbusReplySignature_;
- std::tuple<CommonAPI::Deployable<_InArgs, _DeplInArgs>...> in_;
- std::tuple<_DeplOutArgs*...> out_;
- CommonAPI::CallId_t currentCall_;
- std::map<CommonAPI::CallId_t, DBusMessage> pending_;
- std::mutex mutex_; // protects pending_
+ std::tuple<CommonAPI::Deployable<InArgs_, DeplIn_Args>...> in_;
+ std::tuple<DeplOutArgs_*...> out_;
+ CommonAPI::CallId_t currentCall_;
+ std::map<CommonAPI::CallId_t, DBusMessage> pending_;
+ std::mutex mutex_; // protects pending_
- std::shared_ptr<DBusProxyConnection> connection_;
+ std::shared_ptr<DBusProxyConnection> connection_;
};
template< class, class, class, class >
class DBusMethodWithReplyAdapterDispatcher;
template <
- typename _StubClass,
- typename _StubAdapterClass,
- template <class...> class _In, class... _InArgs,
- template <class...> class _Out, class... _OutArgs>
-class DBusMethodWithReplyAdapterDispatcher<_StubClass, _StubAdapterClass, _In<_InArgs...>, _Out<_OutArgs...> >:
- public DBusStubAdapterHelper<_StubClass>::StubDispatcher {
+ typename StubClass_,
+ typename StubAdapterClass_,
+ template <class...> class In_, class... InArgs_,
+ template <class...> class Out_, class... OutArgs_>
+class DBusMethodWithReplyAdapterDispatcher<StubClass_, StubAdapterClass_, In_<InArgs_...>, Out_<OutArgs_...> >:
+ public DBusStubAdapterHelper<StubClass_>::StubDispatcher {
public:
- typedef DBusStubAdapterHelper<_StubClass> DBusStubAdapterHelperType;
- typedef void (_StubAdapterClass::*_StubFunctor)(std::shared_ptr<CommonAPI::ClientId>, _InArgs..., _OutArgs&...);
- typedef typename CommonAPI::Stub<typename DBusStubAdapterHelperType::StubAdapterType, typename _StubClass::RemoteEventType> StubType;
+ typedef DBusStubAdapterHelper<StubClass_> DBusStubAdapterHelperType;
+ typedef void (StubAdapterClass_::*StubFunctor_)(std::shared_ptr<CommonAPI::ClientId>, InArgs_..., OutArgs_&...);
+ typedef typename CommonAPI::Stub<typename DBusStubAdapterHelperType::StubAdapterType, typename StubClass_::RemoteEventType> StubType;
- DBusMethodWithReplyAdapterDispatcher(_StubFunctor stubFunctor, const char* dbusReplySignature):
+ DBusMethodWithReplyAdapterDispatcher(StubFunctor_ stubFunctor, const char* dbusReplySignature):
stubFunctor_(stubFunctor),
dbusReplySignature_(dbusReplySignature) {
}
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
- std::tuple<_InArgs..., _OutArgs...> argTuple;
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ std::tuple<InArgs_..., OutArgs_...> argTuple;
return handleDBusMessage(
dbusMessage,
stub,
dbusStubAdapterHelper,
- typename make_sequence_range<sizeof...(_InArgs), 0>::type(),
- typename make_sequence_range<sizeof...(_OutArgs), sizeof...(_InArgs)>::type(),argTuple);
+ typename make_sequence_range<sizeof...(InArgs_), 0>::type(),
+ typename make_sequence_range<sizeof...(OutArgs_), sizeof...(InArgs_)>::type(),argTuple);
}
private:
- template <int... _InArgIndices, int... _OutArgIndices>
+ template <int... InArgIndices_, int... OutArgIndices_>
inline bool handleDBusMessage(const DBusMessage& dbusMessage,
- const std::shared_ptr<_StubClass>& stub,
+ const std::shared_ptr<StubClass_>& stub,
DBusStubAdapterHelperType& dbusStubAdapterHelper,
- index_sequence<_InArgIndices...>,
- index_sequence<_OutArgIndices...>,
- std::tuple<_InArgs..., _OutArgs...> argTuple) const {
+ index_sequence<InArgIndices_...>,
+ index_sequence<OutArgIndices_...>,
+ std::tuple<InArgs_..., OutArgs_...> argTuple) const {
+ (void)argTuple;
- if (sizeof...(_InArgs) > 0) {
+ if (sizeof...(InArgs_) > 0) {
DBusInputStream dbusInputStream(dbusMessage);
- const bool success = DBusSerializableArguments<_InArgs...>::deserialize(dbusInputStream, std::get<_InArgIndices>(argTuple)...);
+ const bool success = DBusSerializableArguments<InArgs_...>::deserialize(dbusInputStream, std::get<InArgIndices_>(argTuple)...);
if (!success)
return false;
}
std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender()));
- (stub->StubType::getStubAdapter().get()->*stubFunctor_)(clientId, std::move(std::get<_InArgIndices>(argTuple))..., std::get<_OutArgIndices>(argTuple)...);
+ (stub->StubType::getStubAdapter().get()->*stubFunctor_)(clientId, std::move(std::get<InArgIndices_>(argTuple))..., std::get<OutArgIndices_>(argTuple)...);
DBusMessage dbusMessageReply = dbusMessage.createMethodReturn(dbusReplySignature_);
- if (sizeof...(_OutArgs) > 0) {
+ if (sizeof...(OutArgs_) > 0) {
DBusOutputStream dbusOutputStream(dbusMessageReply);
- const bool success = DBusSerializableArguments<_OutArgs...>::serialize(dbusOutputStream, std::get<_OutArgIndices>(argTuple)...);
+ const bool success = DBusSerializableArguments<OutArgs_...>::serialize(dbusOutputStream, std::get<OutArgIndices_>(argTuple)...);
if (!success)
return false;
@@ -537,18 +547,18 @@ class DBusMethodWithReplyAdapterDispatcher<_StubClass, _StubAdapterClass, _In<_I
return dbusStubAdapterHelper.getDBusConnection()->sendDBusMessage(dbusMessageReply);
}
- _StubFunctor stubFunctor_;
+ StubFunctor_ stubFunctor_;
const char* dbusReplySignature_;
};
-template <typename _StubClass, typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
-class DBusGetAttributeStubDispatcher: public virtual DBusStubAdapterHelper<_StubClass>::StubDispatcher {
+template <typename StubClass_, typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
+class DBusGetAttributeStubDispatcher: public virtual DBusStubAdapterHelper<StubClass_>::StubDispatcher {
public:
- typedef DBusStubAdapterHelper<_StubClass> DBusStubAdapterHelperType;
- typedef const _AttributeType& (_StubClass::*GetStubFunctor)(std::shared_ptr<CommonAPI::ClientId>);
+ typedef DBusStubAdapterHelper<StubClass_> DBusStubAdapterHelperType;
+ typedef const AttributeType_& (StubClass_::*GetStubFunctor)(std::shared_ptr<CommonAPI::ClientId>);
- DBusGetAttributeStubDispatcher(GetStubFunctor _getStubFunctor, const char *_signature, _AttributeDepl *_depl = nullptr):
+ DBusGetAttributeStubDispatcher(GetStubFunctor _getStubFunctor, const char *_signature, AttributeDepl_ *_depl = nullptr):
getStubFunctor_(_getStubFunctor),
signature_(_signature),
depl_(_depl) {
@@ -556,25 +566,27 @@ class DBusGetAttributeStubDispatcher: public virtual DBusStubAdapterHelper<_Stub
virtual ~DBusGetAttributeStubDispatcher() {};
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
return sendAttributeValueReply(dbusMessage, stub, dbusStubAdapterHelper);
}
- void appendGetAllReply(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper, DBusOutputStream &_output) {
+ void appendGetAllReply(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper, DBusOutputStream &_output) {
+ (void)dbusStubAdapterHelper;
+
std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender()));
- auto varDepl = CommonAPI::DBus::VariantDeployment<_AttributeDepl>(true, depl_); // presuming FreeDesktop variant deployment, as support for "legacy" service only
- _output << CommonAPI::Deployable<CommonAPI::Variant<_AttributeType>, CommonAPI::DBus::VariantDeployment<_AttributeDepl>>((stub.get()->*getStubFunctor_)(clientId), &varDepl);
+ auto varDepl = CommonAPI::DBus::VariantDeployment<AttributeDepl_>(true, depl_); // presuming FreeDesktop variant deployment, as support for "legacy" service only
+ _output << CommonAPI::Deployable<CommonAPI::Variant<AttributeType_>, CommonAPI::DBus::VariantDeployment<AttributeDepl_>>((stub.get()->*getStubFunctor_)(clientId), &varDepl);
_output.flush();
}
protected:
- virtual bool sendAttributeValueReply(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ virtual bool sendAttributeValueReply(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
DBusMessage dbusMessageReply = dbusMessage.createMethodReturn(signature_);
DBusOutputStream dbusOutputStream(dbusMessageReply);
std::shared_ptr<DBusClientId> clientId = std::make_shared<DBusClientId>(std::string(dbusMessage.getSender()));
- dbusOutputStream << CommonAPI::Deployable<_AttributeType, _AttributeDepl>((stub.get()->*getStubFunctor_)(clientId), depl_);
+ dbusOutputStream << CommonAPI::Deployable<AttributeType_, AttributeDepl_>((stub.get()->*getStubFunctor_)(clientId), depl_);
dbusOutputStream.flush();
return dbusStubAdapterHelper.getDBusConnection()->sendDBusMessage(dbusMessageReply);
@@ -583,32 +595,32 @@ class DBusGetAttributeStubDispatcher: public virtual DBusStubAdapterHelper<_Stub
GetStubFunctor getStubFunctor_;
const char* signature_;
- _AttributeDepl *depl_;
+ AttributeDepl_ *depl_;
};
-template <typename _StubClass, typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
-class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl> {
+template <typename StubClass_, typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
+class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_> {
public:
- typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::DBusStubAdapterHelperType DBusStubAdapterHelperType;
+ typedef typename DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::DBusStubAdapterHelperType DBusStubAdapterHelperType;
typedef typename DBusStubAdapterHelperType::RemoteEventHandlerType RemoteEventHandlerType;
- typedef typename DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::GetStubFunctor GetStubFunctor;
- typedef bool (RemoteEventHandlerType::*OnRemoteSetFunctor)(std::shared_ptr<CommonAPI::ClientId>, _AttributeType);
+ typedef typename DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::GetStubFunctor GetStubFunctor;
+ typedef bool (RemoteEventHandlerType::*OnRemoteSetFunctor)(std::shared_ptr<CommonAPI::ClientId>, AttributeType_);
typedef void (RemoteEventHandlerType::*OnRemoteChangedFunctor)();
DBusSetAttributeStubDispatcher(GetStubFunctor getStubFunctor,
OnRemoteSetFunctor onRemoteSetFunctor,
OnRemoteChangedFunctor onRemoteChangedFunctor,
const char* dbusSignature,
- _AttributeDepl *_depl = nullptr) :
- DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(getStubFunctor, dbusSignature, _depl),
+ AttributeDepl_ *_depl = nullptr) :
+ DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(getStubFunctor, dbusSignature, _depl),
onRemoteSetFunctor_(onRemoteSetFunctor),
onRemoteChangedFunctor_(onRemoteChangedFunctor) {
}
virtual ~DBusSetAttributeStubDispatcher() {};
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
bool attributeValueChanged;
if (!setAttributeValue(dbusMessage, stub, dbusStubAdapterHelper, attributeValueChanged))
@@ -621,11 +633,11 @@ class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatc
}
protected:
- virtual _AttributeType retrieveAttributeValue(const DBusMessage& dbusMessage, bool& errorOccured) {
+ virtual AttributeType_ retrieveAttributeValue(const DBusMessage& dbusMessage, bool& errorOccured) {
errorOccured = false;
DBusInputStream dbusInputStream(dbusMessage);
- CommonAPI::Deployable<_AttributeType, _AttributeDepl> attributeValue(this->depl_);
+ CommonAPI::Deployable<AttributeType_, AttributeDepl_> attributeValue(this->depl_);
dbusInputStream >> attributeValue;
if (dbusInputStream.hasError()) {
@@ -636,12 +648,12 @@ class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatc
}
inline bool setAttributeValue(const DBusMessage& dbusMessage,
- const std::shared_ptr<_StubClass>& stub,
+ const std::shared_ptr<StubClass_>& stub,
DBusStubAdapterHelperType& dbusStubAdapterHelper,
bool& attributeValueChanged) {
bool errorOccured;
- CommonAPI::Deployable<_AttributeType, _AttributeDepl> attributeValue(
- retrieveAttributeValue(dbusMessage, errorOccured), this->depl_);
+ CommonAPI::Deployable<AttributeType_, AttributeDepl_> attributeValue(
+ retrieveAttributeValue(dbusMessage, errorOccured), this->depl_);
if(errorOccured) {
return false;
@@ -658,7 +670,7 @@ class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatc
(dbusStubAdapterHelper.getRemoteEventHandler()->*onRemoteChangedFunctor_)();
}
- inline const _AttributeType& getAttributeValue(std::shared_ptr<CommonAPI::ClientId> clientId, const std::shared_ptr<_StubClass>& stub) {
+ inline const AttributeType_& getAttributeValue(std::shared_ptr<CommonAPI::ClientId> clientId, const std::shared_ptr<StubClass_>& stub) {
return (stub.get()->*(this->getStubFunctor_))(clientId);
}
@@ -666,33 +678,33 @@ class DBusSetAttributeStubDispatcher: public virtual DBusGetAttributeStubDispatc
const OnRemoteChangedFunctor onRemoteChangedFunctor_;
};
-template <typename _StubClass, typename _AttributeType, typename _AttributeDepl = EmptyDeployment>
-class DBusSetObservableAttributeStubDispatcher: public virtual DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl> {
+template <typename StubClass_, typename AttributeType_, typename AttributeDepl_ = EmptyDeployment>
+class DBusSetObservableAttributeStubDispatcher: public virtual DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_> {
public:
- typedef typename DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::DBusStubAdapterHelperType DBusStubAdapterHelperType;
+ typedef typename DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::DBusStubAdapterHelperType DBusStubAdapterHelperType;
typedef typename DBusStubAdapterHelperType::StubAdapterType StubAdapterType;
- typedef typename DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::GetStubFunctor GetStubFunctor;
- typedef typename DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::OnRemoteSetFunctor OnRemoteSetFunctor;
- typedef typename DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>::OnRemoteChangedFunctor OnRemoteChangedFunctor;
- typedef typename CommonAPI::Stub<StubAdapterType, typename _StubClass::RemoteEventType> StubType;
- typedef void (StubAdapterType::*FireChangedFunctor)(const _AttributeType&);
+ typedef typename DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::GetStubFunctor GetStubFunctor;
+ typedef typename DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::OnRemoteSetFunctor OnRemoteSetFunctor;
+ typedef typename DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>::OnRemoteChangedFunctor OnRemoteChangedFunctor;
+ typedef typename CommonAPI::Stub<StubAdapterType, typename StubClass_::RemoteEventType> StubType;
+ typedef void (StubAdapterType::*FireChangedFunctor)(const AttributeType_&);
DBusSetObservableAttributeStubDispatcher(GetStubFunctor getStubFunctor,
OnRemoteSetFunctor onRemoteSetFunctor,
OnRemoteChangedFunctor onRemoteChangedFunctor,
FireChangedFunctor fireChangedFunctor,
const char* dbusSignature,
- _AttributeDepl *_depl = nullptr)
- : DBusGetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(
- getStubFunctor, dbusSignature, _depl),
- DBusSetAttributeStubDispatcher<_StubClass, _AttributeType, _AttributeDepl>(
- getStubFunctor, onRemoteSetFunctor, onRemoteChangedFunctor, dbusSignature, _depl),
+ AttributeDepl_ *_depl = nullptr)
+ : DBusGetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(
+ getStubFunctor, dbusSignature, _depl),
+ DBusSetAttributeStubDispatcher<StubClass_, AttributeType_, AttributeDepl_>(
+ getStubFunctor, onRemoteSetFunctor, onRemoteChangedFunctor, dbusSignature, _depl),
fireChangedFunctor_(fireChangedFunctor) {
}
virtual ~DBusSetObservableAttributeStubDispatcher() {};
- bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<_StubClass>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
+ bool dispatchDBusMessage(const DBusMessage& dbusMessage, const std::shared_ptr<StubClass_>& stub, DBusStubAdapterHelperType& dbusStubAdapterHelper) {
bool attributeValueChanged;
if (!this->setAttributeValue(dbusMessage, stub, dbusStubAdapterHelper, attributeValueChanged))
return false;
@@ -705,10 +717,11 @@ class DBusSetObservableAttributeStubDispatcher: public virtual DBusSetAttributeS
return true;
}
protected:
- virtual void fireAttributeValueChanged(std::shared_ptr<CommonAPI::ClientId> clientId,
- DBusStubAdapterHelperType& dbusStubAdapterHelper,
- const std::shared_ptr<_StubClass> stub) {
- (stub->StubType::getStubAdapter().get()->*fireChangedFunctor_)(this->getAttributeValue(clientId, stub));
+ virtual void fireAttributeValueChanged(std::shared_ptr<CommonAPI::ClientId> _client,
+ DBusStubAdapterHelperType &_helper,
+ const std::shared_ptr<StubClass_> _stub) {
+ (void)_helper;
+ (_stub->StubType::getStubAdapter().get()->*fireChangedFunctor_)(this->getAttributeValue(_client, _stub));
}
const FireChangedFunctor fireChangedFunctor_;
diff --git a/include/CommonAPI/DBus/DBusTypeOutputStream.hpp b/include/CommonAPI/DBus/DBusTypeOutputStream.hpp
index 074d76a..a2e96e5 100644
--- a/include/CommonAPI/DBus/DBusTypeOutputStream.hpp
+++ b/include/CommonAPI/DBus/DBusTypeOutputStream.hpp
@@ -15,62 +15,71 @@ class DBusTypeOutputStream: public TypeOutputStream<DBusTypeOutputStream> {
public:
DBusTypeOutputStream() : signature_("") {}
- TypeOutputStream &writeType(const bool &_type) {
+ TypeOutputStream &writeType(const bool &, const EmptyDeployment *) {
signature_.append("b");
return (*this);
}
- TypeOutputStream &writeType(const int8_t &) {
+ TypeOutputStream &writeType(const int8_t &, const EmptyDeployment *) {
signature_.append("y");
return (*this);
}
- TypeOutputStream &writeType(const int16_t &) {
+ TypeOutputStream &writeType(const int16_t &, const EmptyDeployment *) {
signature_.append("n");
return (*this);
}
- TypeOutputStream &writeType(const int32_t &) {
+ TypeOutputStream &writeType(const int32_t &, const EmptyDeployment *) {
signature_.append("i");
return (*this);
}
- TypeOutputStream &writeType(const int64_t &) {
+ TypeOutputStream &writeType(const int64_t &, const EmptyDeployment *) {
signature_.append("x");
return (*this);
}
- TypeOutputStream &writeType(const uint8_t &) {
+ TypeOutputStream &writeType(const uint8_t &, const EmptyDeployment *) {
signature_.append("y");
return (*this);
}
- TypeOutputStream &writeType(const uint16_t &) {
+ TypeOutputStream &writeType(const uint16_t &, const EmptyDeployment *) {
signature_.append("q");
return (*this);
}
- TypeOutputStream &writeType(const uint32_t &) {
+ TypeOutputStream &writeType(const uint32_t &, const EmptyDeployment *) {
signature_.append("u");
return (*this);
}
- TypeOutputStream &writeType(const uint64_t &) {
+ TypeOutputStream &writeType(const uint64_t &, const EmptyDeployment *) {
signature_.append("t");
return (*this);
}
- TypeOutputStream &writeType(const float &) {
+ TypeOutputStream &writeType(const float &, const EmptyDeployment *) {
signature_.append("d");
return (*this);
}
- TypeOutputStream &writeType(const double &) {
+ TypeOutputStream &writeType(const double &, const EmptyDeployment *) {
signature_.append("d");
return (*this);
}
- TypeOutputStream &writeType(const std::string &) {
+ TypeOutputStream &writeType(const std::string &, const StringDeployment *_depl) {
+ if ((_depl != nullptr) && _depl->isObjectPath_) {
+ signature_.append("o");
+ } else {
+ signature_.append("s");
+ }
+ return (*this);
+ }
+
+ TypeOutputStream &writeType(const std::string &, const CommonAPI::EmptyDeployment * = nullptr) {
signature_.append("s");
return (*this);
}
@@ -80,7 +89,7 @@ public:
return (*this);
}
- TypeOutputStream &writeType(const Version &) {
+ TypeOutputStream &writeType(const Version &, const EmptyDeployment *) {
signature_.append("(uu)");
return (*this);
}
@@ -90,61 +99,88 @@ public:
return (*this);
}
- template<typename... _Types>
- TypeOutputStream &writeType(const Struct<_Types...> &_value) {
+ template<typename Deployment_, typename... Types_>
+ TypeOutputStream &writeType(const Struct<Types_...> &_value, const Deployment_ * _depl = nullptr) {
+ (void)_value;
signature_.append("(");
- const auto itsSize(std::tuple_size<std::tuple<_Types...>>::value);
- StructTypeWriter<itsSize-1, DBusTypeOutputStream, Struct<_Types...>>{}
- (*this, _value);
+ const auto itsSize(std::tuple_size<std::tuple<Types_...>>::value);
+ StructTypeWriter<Deployment_, itsSize-1, DBusTypeOutputStream, Struct<Types_...>>{}
+ (*this, _value, _depl);
+
signature_.append(")");
return (*this);
}
- template<class _PolymorphicStruct>
- TypeOutputStream &writeType(const std::shared_ptr<_PolymorphicStruct> &_value) {
+ template<typename Deployment_, class PolymorphicStruct_>
+ TypeOutputStream &writeType(const std::shared_ptr<PolymorphicStruct_> &_value, const Deployment_ * _depl = nullptr) {
+ (void)_value;
signature_.append("(");
- _value->template writeType<>((*this));
+ _value->template writeType<>((*this), _depl);
signature_.append(")");
return (*this);
}
- template<typename... _Types>
- TypeOutputStream &writeType(const Variant<_Types...> &_value) {
+ template<typename... Types_>
+ TypeOutputStream &writeType(const Variant<Types_...> &_value, const EmptyDeployment *_depl) {
+ (void)_value;
+ (void)_depl;
signature_.append("(yv)");
return (*this);
}
- template<typename _Deployment, typename... _Types>
- TypeOutputStream &writeType(const Variant<_Types...> &_value, const _Deployment *_depl) {
- if (_depl != nullptr && _depl->isDBus_) {
- signature_.append("v");
- } else {
- signature_.append("(yv)");
- }
- TypeOutputStreamWriteVisitor<DBusTypeOutputStream> typeVisitor(*this);
- ApplyVoidVisitor<TypeOutputStreamWriteVisitor<DBusTypeOutputStream>,
- Variant<_Types...>, _Types...>::visit(typeVisitor, _value);
+ template<typename Deployment_, typename... Types_>
+ TypeOutputStream &writeType(const Variant<Types_...> &_value, const Deployment_ *_depl) {
+ (void)_value;
+ if (_depl != nullptr && _depl->isDBus_) {
+ signature_.append("v");
+ } else {
+ signature_.append("(yv)");
+ }
+
+ return (*this);
+ }
+
+ template<typename ElementType_>
+ TypeOutputStream &writeType(const std::vector<ElementType_> &_value, const EmptyDeployment * _depl = nullptr) {
+ (void)_value;
+ signature_.append("a");
+ ElementType_ dummyElement;
+ writeType(dummyElement, _depl);
return (*this);
}
- template<typename _ElementType>
- TypeOutputStream &writeType(const std::vector<_ElementType> &_value) {
- signature_.append("a");
- _ElementType dummyElement;
- writeType(dummyElement);
- return (*this);
- }
+ template<typename Deployment_, typename ElementType_>
+ TypeOutputStream &writeType(const std::vector<ElementType_> &_value, const Deployment_ * _depl = nullptr) {
+ (void)_value;
+ signature_.append("a");
+ ElementType_ dummyElement;
+ writeType(dummyElement, (_depl ? _depl->elementDepl_ : nullptr));
+ return (*this);
+ }
+
+ template<typename KeyType_, typename ValueType_, typename HasherType_>
+ TypeOutputStream &writeType(const std::unordered_map<KeyType_, ValueType_, HasherType_> &_value, const EmptyDeployment *_depl = nullptr) {
+ (void)_value;
+ signature_.append("a{");
+ KeyType_ dummyKey;
+ writeType(dummyKey, _depl);
+ ValueType_ dummyValue;
+ writeType(dummyValue, _depl);
+ signature_.append("}");
+ return (*this);
+ }
- template<typename _KeyType, typename _ValueType, typename _HasherType>
- TypeOutputStream &writeType(const std::unordered_map<_KeyType, _ValueType, _HasherType> &_value) {
- signature_.append("a{");
- _KeyType dummyKey;
- writeType(dummyKey);
- _ValueType dummyValue;
- writeType(dummyValue);
- signature_.append("}");
- return (*this);
- }
+ template<typename Deployment_, typename KeyType_, typename ValueType_, typename HasherType_>
+ TypeOutputStream &writeType(const std::unordered_map<KeyType_, ValueType_, HasherType_> &_value, const Deployment_ *_depl = nullptr) {
+ (void)_value;
+ signature_.append("a{");
+ KeyType_ dummyKey;
+ writeType(dummyKey, (_depl ? _depl->key_ : nullptr));
+ ValueType_ dummyValue;
+ writeType(dummyValue, (_depl ? _depl->value_ : nullptr));
+ signature_.append("}");
+ return (*this);
+ }
inline std::string getSignature() {
return std::move(signature_);
@@ -158,3 +194,4 @@ private:
} // namespace CommonAPI
#endif // COMMONAPI_DBUS_DBUSTYPEOUTPUTSTREAM_HPP_
+
diff --git a/include/CommonAPI/DBus/DBusTypes.hpp b/include/CommonAPI/DBus/DBusTypes.hpp
index 4c723c4..86bed2d 100644
--- a/include/CommonAPI/DBus/DBusTypes.hpp
+++ b/include/CommonAPI/DBus/DBusTypes.hpp
@@ -20,9 +20,9 @@ namespace DBus {
typedef std::unordered_map<std::string, bool> DBusPropertiesChangedDict;
typedef std::unordered_map<std::string,
- DBusPropertiesChangedDict> DBusInterfacesAndPropertiesDict;
+ DBusPropertiesChangedDict> DBusInterfacesAndPropertiesDict;
typedef std::unordered_map<std::string,
- DBusInterfacesAndPropertiesDict> DBusObjectPathAndInterfacesDict;
+ DBusInterfacesAndPropertiesDict> DBusObjectPathAndInterfacesDict;
enum class DBusType_t {
SESSION = DBUS_BUS_SESSION,
diff --git a/include/CommonAPI/DBus/DBusUtils.hpp b/include/CommonAPI/DBus/DBusUtils.hpp
index ba8826d..d12e024 100644
--- a/include/CommonAPI/DBus/DBusUtils.hpp
+++ b/include/CommonAPI/DBus/DBusUtils.hpp
@@ -18,17 +18,17 @@ namespace DBus {
//In gcc 4.4.1, the enumeration "std::future_status" is defined, but the return values of some functions
//are bool where the same functions in gcc 4.6. return a value from this enum. This template is a way
//to ensure compatibility for this issue.
-template<typename _FutureWaitType>
-inline bool checkReady(_FutureWaitType&);
+template<typename FutureWaitType_>
+inline bool checkReady(FutureWaitType_&);
template<>
inline bool checkReady<bool>(bool& returnedValue) {
- return returnedValue;
+ return returnedValue;
}
template<>
inline bool checkReady<std::future_status>(std::future_status& returnedValue) {
- return returnedValue == std::future_status::ready;
+ return returnedValue == std::future_status::ready;
}
} // namespace DBus