dbus-cxx
interfaceproxy.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) 2019 by Robert Middleton *
4 * robert.middleton@rm5248.com *
5 * *
6 * This file is part of the dbus-cxx library. *
7 ***************************************************************************/
10#include <map>
11#include <memory>
12#include <mutex>
13#include <set>
14#include <shared_mutex>
15#include <string>
16#include "path.h"
17#include <sigc++/sigc++.h>
19
20#ifndef DBUSCXX_INTERFACEPROXY_H
21#define DBUSCXX_INTERFACEPROXY_H
22
23namespace DBus {
24
25class CallMessage;
26class Connection;
27class ObjectProxy;
28class PendingCall;
29class ReturnMessage;
30template <typename signature> class MethodProxy;
31
44protected:
45 InterfaceProxy( const std::string& name );
46
47public:
48 typedef std::multimap<std::string, std::shared_ptr<MethodProxyBase>> Methods;
49
50 typedef std::set<std::shared_ptr<SignalProxyBase>> Signals;
51
52 static std::shared_ptr<InterfaceProxy> create( const std::string& name = std::string() );
53
54 virtual ~InterfaceProxy();
55
56 ObjectProxy* object() const;
57
58 Path path() const;
59
60 std::weak_ptr<Connection> connection() const;
61
62 const std::string& name() const;
63
64 const Methods& methods() const;
65
67 std::shared_ptr<MethodProxyBase> method( const std::string& name ) const;
68
69 template <class T_type>
70 std::shared_ptr<MethodProxy<T_type>> create_method( const std::string& name ) {
71 std::shared_ptr< MethodProxy<T_type> > method;
73
74 if( !this->add_method( method ) ) {
75 return std::shared_ptr< MethodProxy<T_type> >();
76 }
77
78 return method;
79 }
80
85 bool add_method( std::shared_ptr<MethodProxyBase> method );
86
88 void remove_method( const std::string& name );
89
91 void remove_method( std::shared_ptr<MethodProxyBase> method );
92
94 bool has_method( const std::string& name ) const;
95
97 bool has_method( std::shared_ptr<MethodProxyBase> method ) const;
98
103 const std::map<std::string,std::shared_ptr<PropertyProxyBase>>& properties() const;
104
105 std::shared_ptr<PropertyProxyBase> property( const std::string& name ) const;
106
108 bool has_property( const std::string& name ) const;
109
111 bool has_property( std::shared_ptr<PropertyProxyBase> property ) const;
112
114 void remove_property( const std::string& name );
115
117 void remove_property( std::shared_ptr<PropertyProxyBase> method );
118
122 template <class T_type>
123 std::shared_ptr<PropertyProxy<T_type>> create_property( const std::string& name,
125 std::shared_ptr< PropertyProxy<T_type> > prop;
126 prop = PropertyProxy<T_type>::create( name, update );
127
128 if( !this->add_property( prop ) ) {
129 return std::shared_ptr< PropertyProxy<T_type> >();
130 }
131
132 return prop;
133 }
134
139 bool add_property( std::shared_ptr<PropertyProxyBase> property );
140
144 void cache_properties();
145
146 std::shared_ptr<CallMessage> create_call_message( const std::string& method_name ) const;
147
148 std::shared_ptr<const ReturnMessage> call( std::shared_ptr<const CallMessage>, int timeout_milliseconds = -1 ) const;
149
150 std::shared_ptr<const ReturnMessage> call_notimeout( std::shared_ptr<const CallMessage> ) const;
151
152 // std::shared_ptr<PendingCall> call_async( std::shared_ptr<const CallMessage>, int timeout_milliseconds=-1 ) const;
153
154 template <class T_arg>
155 std::shared_ptr<SignalProxy<T_arg >> create_signal( const std::string& sig_name ) {
156 std::shared_ptr< SignalProxy<T_arg> > sig;
158 .set_path( this->path() )
159 .set_interface( name() )
160 .set_member( sig_name )
162 sig = SignalProxy<T_arg>::create( match );
163 this->add_signal( sig );
164 return sig;
165 }
166
167 const Signals& signals() const;
168
169 std::shared_ptr<SignalProxyBase> signal( const std::string& signame );
170
171 bool add_signal( std::shared_ptr<SignalProxyBase> sig );
172
173 bool remove_signal( const std::string& signame );
174
175 bool remove_signal( std::shared_ptr<SignalProxyBase> sig );
176
177 bool has_signal( const std::string& signame ) const;
178
179 bool has_signal( std::shared_ptr<SignalProxyBase> sig ) const;
180
181private:
182 void on_object_set_path( const std::string& path );
183
184 void set_object( ObjectProxy* obj );
185
186 void property_updated( std::string,std::map<std::string,DBus::Variant>,std::vector<std::string> );
187
188private:
189 class priv_data;
190
191 DBUS_CXX_PROPAGATE_CONST( std::unique_ptr<priv_data> ) m_priv;
192
193 friend class ObjectProxy;
194};
195
196}
197
198#endif
An InterfaceProxy represents a remote Interface in another application on the DBus.
Definition: interfaceproxy.h:43
void cache_properties()
Ask the remote object for the status of all of its properties.
Definition: interfaceproxy.cpp:408
static std::shared_ptr< InterfaceProxy > create(const std::string &name=std::string())
Definition: interfaceproxy.cpp:46
std::shared_ptr< SignalProxyBase > signal(const std::string &signame)
Definition: interfaceproxy.cpp:243
std::shared_ptr< CallMessage > create_call_message(const std::string &method_name) const
Definition: interfaceproxy.cpp:215
bool has_method(const std::string &name) const
True if the interface has a method with the given name.
Definition: interfaceproxy.cpp:182
std::shared_ptr< const ReturnMessage > call_notimeout(std::shared_ptr< const CallMessage >) const
Definition: interfaceproxy.cpp:227
std::shared_ptr< SignalProxy< T_arg > > create_signal(const std::string &sig_name)
Definition: interfaceproxy.h:155
bool remove_signal(const std::string &signame)
Definition: interfaceproxy.cpp:273
bool has_property(const std::string &name) const
True if the interface has a property with the given name.
Definition: interfaceproxy.cpp:338
void remove_property(const std::string &name)
Removes the property with the given name.
Definition: interfaceproxy.cpp:371
bool add_property(std::shared_ptr< PropertyProxyBase > property)
Adds the given property.
Definition: interfaceproxy.cpp:319
std::shared_ptr< PropertyProxy< T_type > > create_property(const std::string &name, PropertyUpdateType update=PropertyUpdateType::Updates)
Create a property with the given type, and the given name.
Definition: interfaceproxy.h:123
std::multimap< std::string, std::shared_ptr< MethodProxyBase > > Methods
Definition: interfaceproxy.h:48
void remove_method(const std::string &name)
Removes the method with the given name.
Definition: interfaceproxy.cpp:145
std::shared_ptr< const ReturnMessage > call(std::shared_ptr< const CallMessage >, int timeout_milliseconds=-1) const
Definition: interfaceproxy.cpp:221
const std::map< std::string, std::shared_ptr< PropertyProxyBase > > & properties() const
Get the (local) cache of all properties.
Definition: interfaceproxy.cpp:304
const Methods & methods() const
Definition: interfaceproxy.cpp:111
const std::string & name() const
Definition: interfaceproxy.cpp:107
InterfaceProxy(const std::string &name)
Definition: interfaceproxy.cpp:42
bool add_method(std::shared_ptr< MethodProxyBase > method)
Adds the named method.
Definition: interfaceproxy.cpp:126
void property_updated(std::string, std::map< std::string, DBus::Variant >, std::vector< std::string >)
Definition: interfaceproxy.cpp:429
std::weak_ptr< Connection > connection() const
Definition: interfaceproxy.cpp:101
std::set< std::shared_ptr< SignalProxyBase > > Signals
Definition: interfaceproxy.h:50
bool has_signal(const std::string &signame) const
Definition: interfaceproxy.cpp:286
ObjectProxy * object() const
Definition: interfaceproxy.cpp:61
virtual ~InterfaceProxy()
Definition: interfaceproxy.cpp:50
void set_object(ObjectProxy *obj)
Definition: interfaceproxy.cpp:65
bool add_signal(std::shared_ptr< SignalProxyBase > sig)
Definition: interfaceproxy.cpp:251
std::shared_ptr< MethodProxyBase > method(const std::string &name) const
Returns the first method with the given name.
Definition: interfaceproxy.cpp:115
void on_object_set_path(const std::string &path)
Definition: interfaceproxy.cpp:298
const Signals & signals() const
Definition: interfaceproxy.cpp:239
Path path() const
Definition: interfaceproxy.cpp:95
std::shared_ptr< PropertyProxyBase > property(const std::string &name) const
Definition: interfaceproxy.cpp:308
DBUS_CXX_PROPAGATE_CONST(std::unique_ptr< priv_data >) m_priv
std::shared_ptr< MethodProxy< T_type > > create_method(const std::string &name)
Definition: interfaceproxy.h:70
MatchRuleBuilder & set_interface(const std::string &interface_name)
Definition: matchrule.cpp:43
MatchRuleBuilder & set_path(const std::string &path)
Definition: matchrule.cpp:38
SignalMatchRule as_signal_match()
Definition: matchrule.cpp:63
static MatchRuleBuilder create()
Definition: matchrule.cpp:87
MatchRuleBuilder & set_member(const std::string &member)
Definition: matchrule.cpp:48
Definition: interfaceproxy.h:30
Object proxies are local proxies that provide local methods and signals for remote objects with dbus ...
Definition: objectproxy.h:45
Represents a DBus Path.
Definition: path.h:21
static std::shared_ptr< PropertyProxy< T_type > > create(std::string name, PropertyUpdateType update)
Definition: propertyproxy.h:101
A special MatchRule for signals.
Definition: matchrule.h:45
Definition: signalproxy.h:26
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18
PropertyUpdateType
Definition: enums.h:23
@ Updates
When this property changes, the PropertyChanged signal will be emitted with the new value.