dbus-cxx
propertyproxy.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-3.0-or-later OR BSD-3-Clause
2/***************************************************************************
3 * Copyright (C) 2020 by Robert Middleton *
4 * robert.middleton@rm5248.com *
5 * *
6 * This file is part of the dbus-cxx library. *
7 ***************************************************************************/
8#include <dbus-cxx/enums.h>
9#include <dbus-cxx/dbus-cxx-config.h>
10#include <dbus-cxx/variant.h>
11#include <sigc++/sigc++.h>
12#include <memory>
13
14#ifndef DBUSCXX_PROPERTYPROXY_H
15#define DBUSCXX_PROPERTYPROXY_H
16namespace DBus {
17
18class InterfaceProxy;
19
24protected:
25 PropertyProxyBase( std::string name, PropertyUpdateType update );
26
28
29public:
30
35 std::string name() const;
36
46
48
53 sigc::signal<void(Variant)> signal_generic_property_changed();
54
69 void set_value( Variant value );
70
72
73private:
74 void set_interface( InterfaceProxy* proxy );
76 void invalidate();
77
78private:
79 class priv_data;
80
81 DBUS_CXX_PROPAGATE_CONST( std::unique_ptr<priv_data> ) m_priv;
82
83 // Declare InterfaceProxy as a friend so that it can set the interface
84 friend class InterfaceProxy;
85};
86
92template <typename T_type>
94private:
95 PropertyProxy( std::string name, PropertyUpdateType update ) :
96 PropertyProxyBase( name, update ) {
97 signal_generic_property_changed().connect( sigc::mem_fun( *this, &PropertyProxy::parentUpdated ) );
98 }
99
100public:
101 static std::shared_ptr<PropertyProxy<T_type>> create( std::string name, PropertyUpdateType update ) {
102 return std::shared_ptr<PropertyProxy<T_type>>( new PropertyProxy<T_type>( name, update ) );
103 }
104
105 sigc::signal<void(T_type)> signal_property_changed() {
106 return m_signal_changed;
107 }
108
109 void set_value( T_type t ) {
111 }
112
113 T_type value() {
115 T_type t = v;
116 return t;
117 }
118
119private:
121 T_type t = v;
122 m_signal_changed.emit( t );
123 }
124
125private:
126 sigc::signal<void(T_type)> m_signal_changed;
127};
128
129} /* namespace DBus */
130
131#endif /* DBUSCXX_PROPERTY_H */
An InterfaceProxy represents a remote Interface in another application on the DBus.
Definition: interfaceproxy.h:43
Base type of PropertyProxy to allow for storage in e.g.
Definition: propertyproxy.h:23
void set_interface(InterfaceProxy *proxy)
Definition: propertyproxy.cpp:96
PropertyProxyBase(std::string name, PropertyUpdateType update)
Definition: propertyproxy.cpp:33
PropertyUpdateType update_type() const
Definition: propertyproxy.cpp:66
~PropertyProxyBase()
Definition: propertyproxy.cpp:38
DBUS_CXX_PROPAGATE_CONST(std::unique_ptr< priv_data >) m_priv
void set_value(Variant value)
Set the value of this property.
Definition: propertyproxy.cpp:74
Variant variant_value()
Get the value of this property as a Variant.
Definition: propertyproxy.cpp:44
InterfaceProxy * interface_name() const
Definition: propertyproxy.cpp:100
void invalidate()
Definition: propertyproxy.cpp:111
sigc::signal< void(Variant)> signal_generic_property_changed()
This signal is emitted whenever the property changes.
Definition: propertyproxy.cpp:70
void updated_value(Variant value)
Definition: propertyproxy.cpp:104
std::string name() const
Get the name of this propery.
Definition: propertyproxy.cpp:40
Represents a remote DBus property.
Definition: propertyproxy.h:93
void set_value(T_type t)
Definition: propertyproxy.h:109
static std::shared_ptr< PropertyProxy< T_type > > create(std::string name, PropertyUpdateType update)
Definition: propertyproxy.h:101
sigc::signal< void(T_type)> signal_property_changed()
Definition: propertyproxy.h:105
T_type value()
Definition: propertyproxy.h:113
void parentUpdated(Variant v)
Definition: propertyproxy.h:120
PropertyProxy(std::string name, PropertyUpdateType update)
Definition: propertyproxy.h:95
sigc::signal< void(T_type)> m_signal_changed
Definition: propertyproxy.h:126
A Variant is a type-safe union for DBus operations.
Definition: variant.h:42
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18
PropertyUpdateType
Definition: enums.h:23
int value
Definition: uv-caller.cpp:11