1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4 #ifndef COMMONAPI_DBUS_DBUS_ATTRIBUTE_H_
5 #define COMMONAPI_DBUS_DBUS_ATTRIBUTE_H_
7 #include "DBusProxyHelper.h"
19 template <typename _AttributeType, typename _DBusProxyType = DBusProxy>
20 class DBusReadonlyAttribute: public _AttributeType {
22 typedef typename _AttributeType::ValueType ValueType;
23 typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
25 DBusReadonlyAttribute(_DBusProxyType& dbusProxy, const char* getMethodName):
26 dbusProxy_(dbusProxy),
27 getMethodName_(getMethodName) {
28 assert(getMethodName);
31 CallStatus getValue(ValueType& value) const {
32 CallStatus callStatus;
33 DBusProxyHelper<DBusSerializableArguments<>,
34 DBusSerializableArguments<ValueType> >::callMethodWithReply(dbusProxy_, getMethodName_, "", callStatus, value);
38 std::future<CallStatus> getValueAsync(AttributeAsyncCallback attributeAsyncCallback) {
39 return DBusProxyHelper<DBusSerializableArguments<>,
40 DBusSerializableArguments<ValueType> >::callMethodAsync(dbusProxy_, getMethodName_, "", std::move(attributeAsyncCallback));
44 _DBusProxyType& dbusProxy_;
45 const char* getMethodName_;
49 template <typename _AttributeType, typename _DBusProxyType = DBusProxy>
50 class DBusAttribute: public DBusReadonlyAttribute<_AttributeType> {
52 typedef typename _AttributeType::ValueType ValueType;
53 typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
55 DBusAttribute(_DBusProxyType& dbusProxy, const char* setMethodName, const char* setMethodSignature, const char* getMethodName):
56 DBusReadonlyAttribute<_AttributeType>(dbusProxy, getMethodName),
57 setMethodName_(setMethodName),
58 setMethodSignature_(setMethodSignature) {
59 assert(setMethodName);
60 assert(setMethodSignature);
63 void setValue(const ValueType& requestValue, CallStatus& callStatus, ValueType& responseValue) {
64 DBusProxyHelper<DBusSerializableArguments<ValueType>,
65 DBusSerializableArguments<ValueType> >::callMethodWithReply(
74 std::future<CallStatus> setValueAsync(const ValueType& requestValue, AttributeAsyncCallback attributeAsyncCallback) {
75 return DBusProxyHelper<DBusSerializableArguments<ValueType>,
76 DBusSerializableArguments<ValueType> >::callMethodAsync(
81 attributeAsyncCallback);
85 const char* setMethodName_;
86 const char* setMethodSignature_;
90 template <typename _AttributeType, typename _DBusProxyType = DBusProxy>
91 class DBusObservableAttribute: public _AttributeType {
93 typedef typename _AttributeType::ValueType ValueType;
94 typedef typename _AttributeType::AttributeAsyncCallback AttributeAsyncCallback;
95 typedef typename _AttributeType::ChangedEvent ChangedEvent;
97 template <typename... _AttributeTypeArguments>
98 DBusObservableAttribute(_DBusProxyType& dbusProxy, const char* changedEventName, _AttributeTypeArguments... arguments):
99 _AttributeType(dbusProxy, arguments...),
100 changedEvent_(dbusProxy, changedEventName, this->setMethodSignature_) {
103 ChangedEvent& getChangedEvent() {
104 return changedEvent_;
108 DBusEvent<ChangedEvent> changedEvent_;
112 } // namespace CommonAPI
114 #endif // COMMONAPI_DBUS_DBUS_ATTRIBUTE_H_