# DBus-C++

## Desktop Communication Bus System

libdbus-c-- Documentation 0.9.0

- Files
- Data Structures
- Globals
- Main Page

interface.h
Go to the documentation of this file.
1/*
2 *
3 * D-Bus++ - C++ bindings for D-Bus
4 *
5 * Copyright (C) 2005-2007 Paolo Durante <shackan@gmail.com>
6 *
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
23
24
25#ifndef __DBUSXX_INTERFACE_H
26#define __DBUSXX_INTERFACE_H
27
28#include <string>
29#include <map>
30#include "api.h"
31#include "util.h"
32#include "types.h"
33
34#include "message.h"
35
36 namespace DBus
37{
38
39//todo: this should belong to to properties.h
40 struct DXXAPI PropertyData
41{
42 bool read;
43 bool write;
44 std::string sig;
45 Variant value;
46};
47
48 typedef std::map<std::string, PropertyData> PropertyTable;
49
50 class IntrospectedInterface;
51
52 class ObjectAdaptor;
53 class InterfaceAdaptor;
54 class SignalMessage;
55
56 typedef std::map<std::string, InterfaceAdaptor *> InterfaceAdaptorTable;
57
58 class DXXAPI AdaptorBase
59{
60 public:
61
62 virtual const ObjectAdaptor *object() const = 0 ;
63
64 protected:
65
66 InterfaceAdaptor *find_interface(const std::string &name);
67
68 virtual ~AdaptorBase()
69 {}
70
71 virtual void _emit_signal(SignalMessage &) = 0;
72
73 InterfaceAdaptorTable _interfaces;
74};
75
76/*
77*/
78
79 class ObjectProxy;
80 class InterfaceProxy;
81 class CallMessage;
82
83 typedef std::map<std::string, InterfaceProxy *> InterfaceProxyTable;
84
85 class DXXAPI ProxyBase
86{
87 public:
88
89 virtual const ObjectProxy *object() const = 0 ;
90
91 protected:
92
93 InterfaceProxy *find_interface(const std::string &name);
94
95 virtual ~ProxyBase()
96 {}
97
98 virtual Message _invoke_method(CallMessage &) = 0;
99
100 virtual bool _invoke_method_noreply(CallMessage &call) = 0;
101
102 InterfaceProxyTable _interfaces;
103};
104
105 class DXXAPI Interface
106{
107 public:
108
109 Interface(const std::string &name);
110
111 virtual ~Interface();
112
113 inline const std::string &name() const;
114
115 private:
116
117 std::string _name;
118};
119
120/*
121*/
122
123 const std::string &Interface::name() const
124{
125 return _name;
126}
127
128/*
129*/
130
131 typedef std::map< std::string, Slot<Message, const CallMessage &> > MethodTable;
132
133 class DXXAPI InterfaceAdaptor : public Interface, public virtual AdaptorBase
134{
135 public:
136
137 InterfaceAdaptor(const std::string &name);
138
139 Message dispatch_method(const CallMessage &);
140
141 void emit_signal(const SignalMessage &);
142
143 Variant *get_property(const std::string &name);
144
145 void set_property(const std::string &name, Variant &value);
146
147 virtual IntrospectedInterface *introspect() const
148 {
149 return NULL;
150 }
151
152 protected:
153
154 MethodTable _methods;
155 PropertyTable _properties;
156};
157
158/*
159*/
160
161 typedef std::map< std::string, Slot<void, const SignalMessage &> > SignalTable;
162
163 class DXXAPI InterfaceProxy : public Interface, public virtual ProxyBase
164{
165 public:
166
167 InterfaceProxy(const std::string &name);
168
169 Message invoke_method(const CallMessage &);
170
171 bool invoke_method_noreply(const CallMessage &call);
172
173 bool dispatch_signal(const SignalMessage &);
174
175 protected:
176
177 SignalTable _signals;
178};
179
180# define register_method(interface, method, callback) \
181 InterfaceAdaptor::_methods[ #method ] = \
182 new ::DBus::Callback< interface, ::DBus::Message, const ::DBus::CallMessage &>(this, & interface :: callback);
183
184# define bind_property(variable, type, can_read, can_write) \
185 InterfaceAdaptor::_properties[ #variable ].read = can_read; \
186 InterfaceAdaptor::_properties[ #variable ].write = can_write; \
187 InterfaceAdaptor::_properties[ #variable ].sig = type; \
188 variable.bind(InterfaceAdaptor::_properties[ #variable ]);
189
190# define connect_signal(interface, signal, callback) \
191 InterfaceProxy::_signals[ #signal ] = \
192 new ::DBus::Callback< interface, void, const ::DBus::SignalMessage &>(this, & interface :: callback);
193
194} /* namespace DBus */
195
196#endif//__DBUSXX_INTERFACE_H
api.h
DXXAPI
#define DXXAPI
Definition api.h:36
DBus::AdaptorBase
Definition interface.h:59
DBus::AdaptorBase::object
virtual const ObjectAdaptor * object() const =0
DBus::AdaptorBase::_emit_signal
virtual void _emit_signal(SignalMessage &)=0
DBus::AdaptorBase::find_interface
InterfaceAdaptor * find_interface(const std::string &name)
Definition interface.cpp:42
DBus::AdaptorBase::_interfaces
InterfaceAdaptorTable _interfaces
Definition interface.h:73
DBus::AdaptorBase::~AdaptorBase
virtual ~AdaptorBase()
Definition interface.h:68
DBus::CallMessage
Definition message.h:269
DBus::InterfaceAdaptor
Definition interface.h:134
DBus::InterfaceAdaptor::_properties
PropertyTable _properties
Definition interface.h:155
DBus::InterfaceAdaptor::set_property
void set_property(const std::string &name, Variant &value)
Definition interface.cpp:96
DBus::InterfaceAdaptor::get_property
Variant * get_property(const std::string &name)
Definition interface.cpp:82
DBus::InterfaceAdaptor::InterfaceAdaptor
InterfaceAdaptor(const std::string &name)
Definition interface.cpp:49
DBus::InterfaceAdaptor::introspect
virtual IntrospectedInterface * introspect() const
Definition interface.h:147
DBus::InterfaceAdaptor::emit_signal
void emit_signal(const SignalMessage &)
Definition interface.cpp:72
DBus::InterfaceAdaptor::_methods
MethodTable _methods
Definition interface.h:154
DBus::InterfaceAdaptor::dispatch_method
Message dispatch_method(const CallMessage &)
Definition interface.cpp:57
DBus::InterfaceProxy
Definition interface.h:164
DBus::InterfaceProxy::invoke_method_noreply
bool invoke_method_noreply(const CallMessage &call)
Definition interface.cpp:161
DBus::InterfaceProxy::_signals
SignalTable _signals
Definition interface.h:177
DBus::InterfaceProxy::invoke_method
Message invoke_method(const CallMessage &)
Definition interface.cpp:151
DBus::InterfaceProxy::dispatch_signal
bool dispatch_signal(const SignalMessage &)
Definition interface.cpp:131
DBus::InterfaceProxy::InterfaceProxy
InterfaceProxy(const std::string &name)
Definition interface.cpp:123
DBus::Interface::_name
std::string _name
Definition interface.h:117
DBus::Interface::name
const std::string & name() const
Definition interface.h:123
DBus::Interface::Interface
Interface(const std::string &name)
Definition interface.cpp:35
DBus::Message
Definition message.h:159
DBus::ObjectAdaptor
Definition object.h:117
DBus::ObjectProxy
Definition object.h:203
DBus::ProxyBase
Definition interface.h:86
DBus::ProxyBase::_invoke_method_noreply
virtual bool _invoke_method_noreply(CallMessage &call)=0
DBus::ProxyBase::~ProxyBase
virtual ~ProxyBase()
Definition interface.h:95
DBus::ProxyBase::_invoke_method
virtual Message _invoke_method(CallMessage &)=0
DBus::ProxyBase::find_interface
InterfaceProxy * find_interface(const std::string &name)
Definition interface.cpp:116
DBus::ProxyBase::_interfaces
InterfaceProxyTable _interfaces
Definition interface.h:102
DBus::ProxyBase::object
virtual const ObjectProxy * object() const =0
DBus::SignalMessage
Definition message.h:241
DBus::Variant
Definition types.h:68
message.h
DBus
Definition connection_p.h:42
DBus::PropertyTable
std::map< std::string, PropertyData > PropertyTable
Definition interface.h:48
DBus::MethodTable
std::map< std::string, Slot< Message, const CallMessage & > > MethodTable
Definition interface.h:131
DBus::SignalTable
std::map< std::string, Slot< void, const SignalMessage & > > SignalTable
Definition interface.h:161
DBus::InterfaceAdaptorTable
std::map< std::string, InterfaceAdaptor * > InterfaceAdaptorTable
Definition interface.h:56
DBus::InterfaceProxyTable
std::map< std::string, InterfaceProxy * > InterfaceProxyTable
Definition interface.h:83
DBus::IntrospectedInterface
Definition introspection.h:56
DBus::PropertyData
Definition interface.h:41
DBus::PropertyData::sig
std::string sig
Definition interface.h:44
DBus::PropertyData::write
bool write
Definition interface.h:43
DBus::PropertyData::value
Variant value
Definition interface.h:45
DBus::PropertyData::read
bool read
Definition interface.h:42
types.h
util.h