// 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 { VariantDeployment actualDepl(true, depl_); CommonAPI::Deployable, VariantDeployment> deployedValue(&actualDepl); 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) { VariantDeployment actualDepl(true, depl_); CommonAPI::Deployable, VariantDeployment> deployedValue(&actualDepl); 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) ); } AttributeDepl_ *getDepl(void) { return depl_; } protected: DBusProxy &proxy_; std::string interfaceName_; std::string propertyName_; AttributeDepl_ *depl_; }; template class DBusFreedesktopAttribute : public DBusFreedesktopReadonlyAttribute { 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(_proxy, _interfaceName, _propertyName, _depl) { } void setValue(const ValueType &_request, CommonAPI::CallStatus &_status, ValueType &_response, const CommonAPI::CallInfo *_info) { VariantDeployment actualDepl(true, DBusFreedesktopReadonlyAttribute::depl_); Variant reqVariant(_request); CommonAPI::Deployable, VariantDeployment> deployedVariant(reqVariant, &actualDepl); DBusProxyHelper< DBusSerializableArguments< std::string, std::string, CommonAPI::Deployable, VariantDeployment> >, DBusSerializableArguments< > >::callMethodWithReply( DBusFreedesktopReadonlyAttribute::proxy_, "org.freedesktop.DBus.Properties", "Set", "ssv", (_info ? _info : &defaultCallInfo), DBusFreedesktopReadonlyAttribute::interfaceName_, DBusFreedesktopReadonlyAttribute::propertyName_, deployedVariant, _status); _response = _request; } std::future setValueAsync(const ValueType &_request, AttributeAsyncCallback _callback, const CommonAPI::CallInfo *_info) { VariantDeployment actualDepl(true, DBusFreedesktopReadonlyAttribute::depl_); Variant reqVariant(_request); CommonAPI::Deployable, VariantDeployment> deployedVariant(reqVariant, &actualDepl); return DBusProxyHelper< DBusSerializableArguments< std::string, std::string, CommonAPI::Deployable, VariantDeployment> >, DBusSerializableArguments< > >::callMethodAsync( DBusFreedesktopReadonlyAttribute::proxy_, "org.freedesktop.DBus.Properties", "Set", "ssv", (_info ? _info : &defaultCallInfo), DBusFreedesktopReadonlyAttribute::interfaceName_, DBusFreedesktopReadonlyAttribute::propertyName_, deployedVariant, [_callback, deployedVariant](CommonAPI::CallStatus _status) { _callback(_status, deployedVariant.getValue().template get()); }, std::tuple<>()); } }; template class LegacyEvent; template