dbus-cxx
objectproxy.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) 2009,2010 by Rick L. Vinyard, Jr. *
4 * rvinyard@cs.nmsu.edu *
5 * *
6 * This file is part of the dbus-cxx library. *
7 ***************************************************************************/
10#include <dbus-cxx/dbus-cxx-config.h>
12#include <map>
13#include <memory>
14#include <mutex>
15#include <shared_mutex>
16#include <string>
17#include "path.h"
18#include <sigc++/sigc++.h>
19
20#ifndef DBUSCXX_OBJECTPROXY_H
21#define DBUSCXX_OBJECTPROXY_H
22
23namespace DBus {
24
25class Connection;
26class CallMessage;
27class InterfaceProxy;
28class MethodProxyBase;
29class PendingCall;
30class ReturnMessage;
31template <typename signature> class MethodProxy;
32class PeerInterfaceProxy;
33class IntrospectableInterfaceProxy;
34class PropertiesInterfaceProxy;
35class ObjectManagerProxy;
36
46protected:
47
52 ObjectProxy( std::shared_ptr<Connection> conn, const std::string& destination, const std::string& path );
53
54public:
59 static std::shared_ptr<ObjectProxy> create( const std::string& path );
60
66 static std::shared_ptr<ObjectProxy> create( const std::string& destination, const std::string& path );
67
68 static std::shared_ptr<ObjectProxy> create( std::shared_ptr<Connection> conn, const std::string& path );
69
70 static std::shared_ptr<ObjectProxy> create( std::shared_ptr<Connection> conn, const std::string& destination, const std::string& path );
71
72 virtual ~ObjectProxy();
73
74 std::weak_ptr<Connection> connection() const;
75
76 void set_connection( std::shared_ptr<Connection> conn );
77
78 const std::string& destination() const;
79
80 void set_destination( const std::string& destination );
81
82 const Path& path() const;
83
84 void set_path( const std::string& path );
85
86 typedef std::map<std::string, std::shared_ptr<InterfaceProxy>> Interfaces;
87
88 const Interfaces& interfaces() const;
89
91 std::shared_ptr<InterfaceProxy> interface_by_name( const std::string& name ) const;
92
94 bool add_interface( std::shared_ptr<InterfaceProxy> interface_ptr );
95
101 std::shared_ptr<InterfaceProxy> create_interface( const std::string& name );
102
104 void remove_interface( const std::string& name );
105
107 void remove_interface( std::shared_ptr<InterfaceProxy> interface_ptr );
108
109 bool has_interface( const std::string& name ) const;
110
111 bool has_interface( std::shared_ptr<InterfaceProxy> interface_ptr ) const;
112
114 bool add_method( const std::string& interface_name, std::shared_ptr<MethodProxyBase> method );
115
116 std::shared_ptr<CallMessage> create_call_message( const std::string& interface_name, const std::string& method_name ) const;
117
118 std::shared_ptr<CallMessage> create_call_message( const std::string& method_name ) const;
119
127 std::shared_ptr<const ReturnMessage> call( std::shared_ptr<const CallMessage>, int timeout_milliseconds = -1 ) const;
128
132 std::shared_ptr<const ReturnMessage> call_notimeout( std::shared_ptr<const CallMessage> ) const;
133
140 template <class T_type>
141 std::shared_ptr<MethodProxy<T_type>>
142 create_method( const std::string& interface_name, const std::string& method_name ) {
143 std::shared_ptr<InterfaceProxy> interface_ptr = this->interface_by_name( interface_name );
144
145 if( !interface_ptr ) { interface_ptr = this->create_interface( interface_name ); }
146
147 return interface_ptr->create_method<T_type>( method_name );
148 }
149
156 template <class T_type>
157 std::shared_ptr<SignalProxy<T_type> >
158 create_signal( const std::string& interface_name, const std::string& sig_name ) {
159 std::shared_ptr<InterfaceProxy> interface_ptr = this->interface_by_name( interface_name );
160
161 if( !interface_ptr ) { interface_ptr = this->create_interface( interface_name ); }
162
163 return interface_ptr->create_signal<T_type>( sig_name );
164 }
165
166 template <class T_type>
167 std::shared_ptr<PropertyProxy<T_type>>
168 create_property( const std::string& interface_name,
169 const std::string& property_name,
172 std::shared_ptr<InterfaceProxy> interface_ptr = this->interface_by_name( interface_name );
173
174 if( !interface_ptr ) { interface_ptr = this->create_interface( interface_name ); }
175
176 return interface_ptr->create_property<T_type>( property_name, update );
177 }
178
185 sigc::signal<void( std::shared_ptr<InterfaceProxy> )> signal_interface_added();
186
193 sigc::signal<void( std::shared_ptr<InterfaceProxy> )> signal_interface_removed();
194
195 std::shared_ptr<PeerInterfaceProxy> getPeerInterface();
196
197 std::shared_ptr<IntrospectableInterfaceProxy> getIntrospectableInterface();
198
199 std::shared_ptr<PropertiesInterfaceProxy> getPropertiesInterface();
200
201 std::shared_ptr<ObjectManagerProxy> getObjectManagerInterface();
202
203private:
204 class priv_data;
205
206 DBUS_CXX_PROPAGATE_CONST( std::unique_ptr<priv_data> ) m_priv;
207};
208
209}
210
211#endif
Object proxies are local proxies that provide local methods and signals for remote objects with dbus ...
Definition: objectproxy.h:45
void remove_interface(const std::string &name)
Removes the first interface with the given name.
Definition: objectproxy.cpp:162
std::shared_ptr< CallMessage > create_call_message(const std::string &interface_name, const std::string &method_name) const
Definition: objectproxy.cpp:247
std::shared_ptr< ObjectManagerProxy > getObjectManagerInterface()
Definition: objectproxy.cpp:307
std::shared_ptr< PropertiesInterfaceProxy > getPropertiesInterface()
Definition: objectproxy.cpp:303
std::shared_ptr< MethodProxy< T_type > > create_method(const std::string &interface_name, const std::string &method_name)
Creates a proxy method with a signature based on the template parameters and adds it to the named int...
Definition: objectproxy.h:142
std::weak_ptr< Connection > connection() const
Definition: objectproxy.cpp:86
std::shared_ptr< const ReturnMessage > call(std::shared_ptr< const CallMessage >, int timeout_milliseconds=-1) const
Forwards this CallMessage to the Connection that this ObjectProxy is on, and returns a message with t...
Definition: objectproxy.cpp:271
std::shared_ptr< InterfaceProxy > interface_by_name(const std::string &name) const
Returns the first interface with the given name.
Definition: objectproxy.cpp:118
sigc::signal< void(std::shared_ptr< InterfaceProxy >)> signal_interface_removed()
Return a signal that you may connect to when an interface is removed.
Definition: objectproxy.cpp:291
std::shared_ptr< InterfaceProxy > create_interface(const std::string &name)
Creates and adds the named interface to this object.
Definition: objectproxy.cpp:152
void set_connection(std::shared_ptr< Connection > conn)
Definition: objectproxy.cpp:90
DBUS_CXX_PROPAGATE_CONST(std::unique_ptr< priv_data >) m_priv
sigc::signal< void(std::shared_ptr< InterfaceProxy >)> signal_interface_added()
Return a signal that you may connect to when an interface is added.
Definition: objectproxy.cpp:287
std::shared_ptr< IntrospectableInterfaceProxy > getIntrospectableInterface()
Definition: objectproxy.cpp:299
std::map< std::string, std::shared_ptr< InterfaceProxy > > Interfaces
Definition: objectproxy.h:86
ObjectProxy(std::shared_ptr< Connection > conn, const std::string &destination, const std::string &path)
This class has a protected constructor.
Definition: objectproxy.cpp:50
void set_destination(const std::string &destination)
Definition: objectproxy.cpp:98
virtual ~ObjectProxy()
Definition: objectproxy.cpp:74
std::shared_ptr< PropertyProxy< T_type > > create_property(const std::string &interface_name, const std::string &property_name, PropertyAccess access_type=PropertyAccess::ReadWrite, PropertyUpdateType update=PropertyUpdateType::Updates)
Definition: objectproxy.h:168
std::shared_ptr< PeerInterfaceProxy > getPeerInterface()
Definition: objectproxy.cpp:295
std::shared_ptr< const ReturnMessage > call_notimeout(std::shared_ptr< const CallMessage >) const
A timeout-less version of call().
Definition: objectproxy.cpp:279
bool add_method(const std::string &interface_name, std::shared_ptr< MethodProxyBase > method)
Adds the method to the named interface.
Definition: objectproxy.cpp:237
std::shared_ptr< SignalProxy< T_type > > create_signal(const std::string &interface_name, const std::string &sig_name)
Creates a signal proxy with a signature based on the template parameters and adds it to the named int...
Definition: objectproxy.h:158
static std::shared_ptr< ObjectProxy > create(const std::string &path)
Creates an ObjectProxy with a specific path.
Definition: objectproxy.cpp:58
bool has_interface(const std::string &name) const
Definition: objectproxy.cpp:205
void set_path(const std::string &path)
Definition: objectproxy.cpp:106
const std::string & destination() const
Definition: objectproxy.cpp:94
const Interfaces & interfaces() const
Definition: objectproxy.cpp:114
const Path & path() const
Definition: objectproxy.cpp:102
bool add_interface(std::shared_ptr< InterfaceProxy > interface_ptr)
Adds the interface to this object.
Definition: objectproxy.cpp:132
Represents a DBus Path.
Definition: path.h:21
Global DBus namespace, where everything happens.
Definition: callmessage.cpp:18
PropertyAccess
Definition: enums.h:46
PropertyUpdateType
Definition: enums.h:23
@ Updates
When this property changes, the PropertyChanged signal will be emitted with the new value.
static std::shared_ptr< DBus::Connection > conn
Definition: recursive-signal-test-qt.cpp:30