// 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/. #if !defined (COMMONAPI_INTERNAL_COMPILATION) #error "Only can be included directly, this file may disappear or change contents." #endif #ifndef COMMONAPI_DBUS_DBUS_ATTRIBUTE_HPP_ #define COMMONAPI_DBUS_DBUS_ATTRIBUTE_HPP_ #include #include #include #include #include #include namespace CommonAPI { namespace DBus { template class DBusReadonlyAttribute: public _AttributeType { public: 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), getMethodName_(getMethodName), setMethodSignature_(setMethodSignature), depl_(_depl) { assert(getMethodName); } void getValue(CommonAPI::CallStatus &_status, ValueType &_value, const CommonAPI::CallInfo *_info) const { CommonAPI::Deployable deployedValue(depl_); DBusProxyHelper< DBusSerializableArguments< >, DBusSerializableArguments< CommonAPI::Deployable< ValueType, _AttributeDepl > > >::callMethodWithReply(proxy_, getMethodName_, "", (_info ? _info : &defaultCallInfo), _status, deployedValue); _value = deployedValue.getValue(); } std::future getValueAsync(AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) { CommonAPI::Deployable deployedValue(depl_); return DBusProxyHelper< DBusSerializableArguments<>, DBusSerializableArguments> >::callMethodAsync(proxy_, getMethodName_, "", (_info ? _info : &defaultCallInfo), [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable _response) { _callback(_status, _response.getValue()); }, std::make_tuple(deployedValue)); } protected: DBusProxy &proxy_; const char *getMethodName_; const char *setMethodSignature_; _AttributeDepl *depl_; }; template class DBusAttribute: public DBusReadonlyAttribute<_AttributeType, _AttributeDepl> { public: 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), setMethodName_(_setMethodName), setMethodSignature_(_setMethodSignature) { assert(_setMethodName); assert(_setMethodSignature); } void setValue(const ValueType &_request, CommonAPI::CallStatus &_status, ValueType &_response, const CommonAPI::CallInfo *_info) { CommonAPI::Deployable deployedRequest(_request, this->depl_); CommonAPI::Deployable deployedResponse(this->depl_); DBusProxyHelper>, DBusSerializableArguments> >::callMethodWithReply( this->proxy_, setMethodName_, setMethodSignature_, (_info ? _info : &defaultCallInfo), deployedRequest, _status, deployedResponse); _response = deployedResponse.getValue(); } std::future setValueAsync(const ValueType &_request, AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) { CommonAPI::Deployable deployedRequest(_request, this->depl_); CommonAPI::Deployable deployedResponse(this->depl_); return DBusProxyHelper>, DBusSerializableArguments> >::callMethodAsync( this->proxy_, setMethodName_, setMethodSignature_, (_info ? _info : &defaultCallInfo), deployedRequest, [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable _response) { _callback(_status, _response.getValue()); }, std::make_tuple(deployedResponse)); } protected: const char* setMethodName_; const char* setMethodSignature_; }; template 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; template DBusObservableAttribute(DBusProxy &_proxy, const char *_changedEventName, _AttributeTypeArguments... arguments) : _AttributeType(_proxy, arguments...), changedEvent_(_proxy, _changedEventName, this->setMethodSignature_, this->getMethodName_, std::make_tuple(CommonAPI::Deployable(this->depl_))) { } ChangedEvent &getChangedEvent() { return changedEvent_; } protected: DBusEvent > changedEvent_; }; } // namespace DBus } // namespace CommonAPI #endif // COMMONAPI_DBUS_DBUS_ATTRIBUTE_HPP_