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
36namespace DBus
37{
38
39//todo: this should belong to to properties.h
41{
42 bool read;
43 bool write;
44 std::string sig;
46};
47
48typedef std::map<std::string, PropertyData> PropertyTable;
49
51
52class ObjectAdaptor;
54class SignalMessage;
55
56typedef std::map<std::string, InterfaceAdaptor *> InterfaceAdaptorTable;
57
59{
60public:
61
62 virtual const ObjectAdaptor *object() const = 0 ;
63
64protected:
65
66 InterfaceAdaptor *find_interface(const std::string &name);
67
68 virtual ~AdaptorBase()
69 {}
70
71 virtual void _emit_signal(SignalMessage &) = 0;
72
74};
75
76/*
77*/
78
79class ObjectProxy;
80class InterfaceProxy;
81class CallMessage;
82
83typedef std::map<std::string, InterfaceProxy *> InterfaceProxyTable;
84
86{
87public:
88
89 virtual const ObjectProxy *object() const = 0 ;
90
91protected:
92
93 InterfaceProxy *find_interface(const std::string &name);
94
95 virtual ~ProxyBase()
96 {}
97
99
100 virtual bool _invoke_method_noreply(CallMessage &call) = 0;
101
103};
104
106{
107public:
108
109 Interface(const std::string &name);
110
111 virtual ~Interface();
112
113 inline const std::string &name() const;
114
115private:
116
117 std::string _name;
118};
119
120/*
121*/
122
123const std::string &Interface::name() const
124{
125 return _name;
126}
127
128/*
129*/
130
131typedef std::map< std::string, Slot<Message, const CallMessage &> > MethodTable;
132
133class DXXAPI InterfaceAdaptor : public Interface, public virtual AdaptorBase
134{
135public:
136
137 InterfaceAdaptor(const std::string &name);
138
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
148 {
149 return NULL;
150 }
151
152protected:
153
156};
157
158/*
159*/
160
161typedef std::map< std::string, Slot<void, const SignalMessage &> > SignalTable;
162
163class DXXAPI InterfaceProxy : public Interface, public virtual ProxyBase
164{
165public:
166
167 InterfaceProxy(const std::string &name);
168
170
171 bool invoke_method_noreply(const CallMessage &call);
172
173 bool dispatch_signal(const SignalMessage &);
174
175protected:
176
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
#define DXXAPI
Definition api.h:36
virtual const ObjectAdaptor * object() const =0
virtual void _emit_signal(SignalMessage &)=0
InterfaceAdaptor * find_interface(const std::string &name)
Definition interface.cpp:42
InterfaceAdaptorTable _interfaces
Definition interface.h:73
virtual ~AdaptorBase()
Definition interface.h:68
PropertyTable _properties
Definition interface.h:155
void set_property(const std::string &name, Variant &value)
Definition interface.cpp:96
Variant * get_property(const std::string &name)
Definition interface.cpp:82
InterfaceAdaptor(const std::string &name)
Definition interface.cpp:49
virtual IntrospectedInterface * introspect() const
Definition interface.h:147
void emit_signal(const SignalMessage &)
Definition interface.cpp:72
Message dispatch_method(const CallMessage &)
Definition interface.cpp:57
bool invoke_method_noreply(const CallMessage &call)
SignalTable _signals
Definition interface.h:177
Message invoke_method(const CallMessage &)
bool dispatch_signal(const SignalMessage &)
InterfaceProxy(const std::string &name)
std::string _name
Definition interface.h:117
const std::string & name() const
Definition interface.h:123
Interface(const std::string &name)
Definition interface.cpp:35
virtual bool _invoke_method_noreply(CallMessage &call)=0
virtual ~ProxyBase()
Definition interface.h:95
virtual Message _invoke_method(CallMessage &)=0
InterfaceProxy * find_interface(const std::string &name)
InterfaceProxyTable _interfaces
Definition interface.h:102
virtual const ObjectProxy * object() const =0
std::map< std::string, PropertyData > PropertyTable
Definition interface.h:48
std::map< std::string, Slot< Message, const CallMessage & > > MethodTable
Definition interface.h:131
std::map< std::string, Slot< void, const SignalMessage & > > SignalTable
Definition interface.h:161
std::map< std::string, InterfaceAdaptor * > InterfaceAdaptorTable
Definition interface.h:56
std::map< std::string, InterfaceProxy * > InterfaceProxyTable
Definition interface.h:83
std::string sig
Definition interface.h:44