// Copyright (C) 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_FREEDESKTOPATTRIBUTE_HPP_ #define COMMONAPI_DBUS_DBUS_FREEDESKTOPATTRIBUTE_HPP_ #include namespace CommonAPI { namespace DBus { template class DBusFreedesktopReadonlyAttribute: public _AttributeType { public: 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), interfaceName_(_interfaceName), propertyName_(_propertyName), depl_(_depl) { } void getValue(CommonAPI::CallStatus &_status, ValueType &_value, const CommonAPI::CallInfo *_info) const { CommonAPI::Deployable, VariantDeployment<>> deployedValue(&freedesktopVariant); DBusProxyHelper< DBusSerializableArguments< std::string, std::string >, DBusSerializableArguments< CommonAPI::Deployable, VariantDeployment<>> > >::callMethodWithReply( proxy_, "org.freedesktop.DBus.Properties", "Get", "ss", (_info ? _info : &defaultCallInfo), interfaceName_, propertyName_, _status, deployedValue); _value = deployedValue.getValue().template get(); } std::future getValueAsync(AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) { CommonAPI::Deployable, VariantDeployment<>> deployedValue(&freedesktopVariant); return DBusProxyHelper< DBusSerializableArguments< std::string, std::string >, DBusSerializableArguments< CommonAPI::Deployable, VariantDeployment<>> > >::callMethodAsync( proxy_, "org.freedesktop.DBus.Properties", "Get", "ss", (_info ? _info : &defaultCallInfo), interfaceName_, propertyName_, [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable, VariantDeployment<>> _value) { _callback(_status, _value.getValue().template get()); }, std::make_tuple(deployedValue) ); } protected: DBusProxy &proxy_; std::string interfaceName_; std::string propertyName_; _AttributeDepl *depl_; }; template 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> deployedValue(&freedesktopVariant); DBusProxyHelper< DBusSerializableArguments< std::string, std::string >, DBusSerializableArguments< CommonAPI::Deployable> > >::callMethodWithReply( proxy_, "org.freedesktop.DBus.Properties", "Get", "ss", (_info ? _info : &defaultCallInfo), interfaceName_, propertyName_, _status, deployedValue); _value = deployedValue.getValue().template get(); } std::future getValueAsync(AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) { CommonAPI::Deployable> deployedValue(&freedesktopVariant); return DBusProxyHelper< DBusSerializableArguments< std::string, std::string >, DBusSerializableArguments< CommonAPI::Deployable> > >::callMethodAsync( proxy_, "org.freedesktop.DBus.Properties", "Get", "ss", (_info ? _info : &defaultCallInfo), interfaceName_, propertyName_, [_callback](CommonAPI::CallStatus _status, CommonAPI::Deployable> _value) { _callback(_status, _value.getValue().template get()); }, std::make_tuple(deployedValue) ); } protected: DBusProxy &proxy_; std::string interfaceName_; std::string propertyName_; }; template class DBusFreedesktopAttribute : public DBusFreedesktopReadonlyAttribute<_AttributeType, _AttributeDepl> { public: 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) { } void setValue(const ValueType &_request, CommonAPI::CallStatus &_status, ValueType &_response, const CommonAPI::CallInfo *_info) { CommonAPI::Deployable, VariantDeployment<>> deployedVariant(_request, &freedesktopVariant); DBusProxyHelper< DBusSerializableArguments< std::string, std::string, CommonAPI::Deployable, VariantDeployment<>> >, 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); _response = _request; } std::future setValueAsync(const ValueType &_request, AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) { CommonAPI::Deployable, VariantDeployment<>> deployedVariant(_request, &freedesktopVariant); return DBusProxyHelper< DBusSerializableArguments< std::string, std::string, CommonAPI::Deployable, 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()); }, std::tuple<>()); } }; template 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> deployedVariant(_request, &freedesktopVariant); DBusProxyHelper< DBusSerializableArguments< std::string, std::string, CommonAPI::Deployable> >, 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 setValueAsync(const ValueType &_request, AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) { CommonAPI::Deployable> deployedVariant(_request, &freedesktopVariant); return DBusProxyHelper< DBusSerializableArguments< std::string, std::string, CommonAPI::Deployable> >, 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> _value) { _callback(_status, _value.getValue().template get()); }, std::make_tuple(deployedVariant)); } }; template class LegacyEvent; template