/** * (C) 2017 KISTLER INSTRUMENTE AG, Winterthur, Switzerland * * @file ConvenienceClasses.h * * Created on: Jan 19, 2017 * Project: sdbus-c++ * Description: High-level D-Bus IPC C++ library based on sd-bus * * This file is part of sdbus-c++. * * sdbus-c++ is free software; you can redistribute it and/or modify it * under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation, either version 2.1 of the License, or * (at your option) any later version. * * sdbus-c++ is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with sdbus-c++. If not, see . */ #ifndef SDBUS_CXX_CONVENIENCECLASSES_H_ #define SDBUS_CXX_CONVENIENCECLASSES_H_ #include #include #include #include // Forward declarations namespace sdbus { class IObject; class IObjectProxy; class Variant; } namespace sdbus { class MethodRegistrator { public: MethodRegistrator(IObject& object, const std::string& methodName); MethodRegistrator& onInterface(const std::string& interfaceName); template std::enable_if_t> implementedAs(_Function&& callback); template std::enable_if_t> implementedAs(_Function&& callback); private: IObject& object_; const std::string& methodName_; std::string interfaceName_; }; class SignalRegistrator { public: SignalRegistrator(IObject& object, const std::string& signalName); SignalRegistrator(SignalRegistrator&& other) = default; SignalRegistrator& operator=(SignalRegistrator&& other) = default; ~SignalRegistrator() noexcept(false); SignalRegistrator& onInterface(std::string interfaceName); template void withParameters(); private: IObject& object_; const std::string& signalName_; std::string interfaceName_; std::string signalSignature_; int exceptions_{}; // Number of active exceptions when SignalRegistrator is constructed }; class PropertyRegistrator { public: PropertyRegistrator(IObject& object, const std::string& propertyName); PropertyRegistrator(PropertyRegistrator&& other) = default; PropertyRegistrator& operator=(PropertyRegistrator&& other) = default; ~PropertyRegistrator() noexcept(false); PropertyRegistrator& onInterface(const std::string& interfaceName); template PropertyRegistrator& withGetter(_Function&& callback); template PropertyRegistrator& withSetter(_Function&& callback); private: IObject& object_; const std::string& propertyName_; std::string interfaceName_; std::string propertySignature_; property_get_callback getter_; property_set_callback setter_; int exceptions_{}; // Number of active exceptions when PropertyRegistrator is constructed }; class SignalEmitter { public: SignalEmitter(IObject& object, const std::string& signalName); SignalEmitter(SignalEmitter&& other) = default; SignalEmitter& operator=(SignalEmitter&& other) = default; ~SignalEmitter() noexcept(false); SignalEmitter& onInterface(const std::string& interfaceName); template void withArguments(_Args&&... args); private: IObject& object_; const std::string& signalName_; Signal signal_; int exceptions_{}; // Number of active exceptions when SignalEmitter is constructed }; class MethodInvoker { public: MethodInvoker(IObjectProxy& objectProxy, const std::string& methodName); MethodInvoker(MethodInvoker&& other) = default; MethodInvoker& operator=(MethodInvoker&& other) = default; ~MethodInvoker() noexcept(false); MethodInvoker& onInterface(const std::string& interfaceName); template MethodInvoker& withArguments(_Args&&... args); template void storeResultsTo(_Args&... args); private: IObjectProxy& objectProxy_; const std::string& methodName_; MethodCall method_; int exceptions_{}; // Number of active exceptions when MethodInvoker is constructed bool methodCalled_{}; }; class SignalSubscriber { public: SignalSubscriber(IObjectProxy& objectProxy, const std::string& signalName); SignalSubscriber& onInterface(const std::string& interfaceName); template void call(_Function&& callback); private: IObjectProxy& objectProxy_; std::string signalName_; std::string interfaceName_; }; class PropertyGetter { public: PropertyGetter(IObjectProxy& objectProxy, const std::string& propertyName); sdbus::Variant onInterface(const std::string& interfaceName); private: IObjectProxy& objectProxy_; std::string propertyName_; }; class PropertySetter { public: PropertySetter(IObjectProxy& objectProxy, const std::string& propertyName); PropertySetter& onInterface(const std::string& interfaceName); template void toValue(const _Value& value); private: IObjectProxy& objectProxy_; const std::string& propertyName_; std::string interfaceName_; }; } #endif /* SDBUS_CXX_CONVENIENCECLASSES_H_ */