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_OBJECT_H
26 #define __DBUSXX_OBJECT_H
27
28 #include <string>
29 #include <list>
30
31 #include "api.h"
32 #include "interface.h"
33 #include "connection.h"
34 #include "message.h"
35 #include "types.h"
36
37 namespace DBus
38 {
39
40 class DXXAPI Object
41 {
42 protected:
43
44 Object(Connection &conn, const Path &path, const char *service);
45
46 public:
47
48 virtual ~Object();
49
50 inline const DBus::Path &path() const;
51
52 inline const std::string &service() const;
53
54 inline Connection &conn();
55
56 void set_timeout(int new_timeout = -1);
57
58 inline int get_timeout() const;
59
60 private:
61
62 DXXAPILOCAL virtual bool handle_message(const Message &) = 0;
63 DXXAPILOCAL virtual void register_obj() = 0;
64 DXXAPILOCAL virtual void unregister_obj(bool throw_on_error = true) = 0;
65
66 private:
67
68 Connection _conn;
69 DBus::Path _path;
70 std::string _service;
71 int _default_timeout;
72 };
73
74 /*
75 */
76
conn()77 Connection &Object::conn()
78 {
79 return _conn;
80 }
81
path()82 const DBus::Path &Object::path() const
83 {
84 return _path;
85 }
86
service()87 const std::string &Object::service() const
88 {
89 return _service;
90 }
91
get_timeout()92 int Object::get_timeout() const
93 {
94 return _default_timeout;
95 }
96
97 /*
98 */
99
100 class DXXAPI Tag
101 {
102 public:
103
~Tag()104 virtual ~Tag()
105 {}
106 };
107
108 /*
109 */
110
111 class ObjectAdaptor;
112
113 typedef std::list<ObjectAdaptor *> ObjectAdaptorPList;
114 typedef std::list<std::string> ObjectPathList;
115
116 class DXXAPI ObjectAdaptor : public Object, public virtual AdaptorBase
117 {
118 public:
119
120 static ObjectAdaptor *from_path(const Path &path);
121
122 static ObjectAdaptorPList from_path_prefix(const std::string &prefix);
123
124 static ObjectPathList child_nodes_from_prefix(const std::string &prefix);
125
126 struct Private;
127
128 ObjectAdaptor(Connection &conn, const Path &path);
129
130 ~ObjectAdaptor();
131
132 inline const ObjectAdaptor *object() const;
133
134 protected:
135
136 class DXXAPI Continuation
137 {
138 public:
139
140 inline MessageIter &writer();
141
142 inline Tag *tag();
143
144 private:
145
146 Continuation(Connection &conn, const CallMessage &call, const Tag *tag);
147
148 Connection _conn;
149 CallMessage _call;
150 MessageIter _writer;
151 ReturnMessage _return;
152 const Tag *_tag;
153
154 friend class ObjectAdaptor;
155 };
156
157 void return_later(const Tag *tag);
158
159 void return_now(Continuation *ret);
160
161 void return_error(Continuation *ret, const Error error);
162
163 Continuation *find_continuation(const Tag *tag);
164
165 private:
166
167 void _emit_signal(SignalMessage &);
168
169 bool handle_message(const Message &);
170
171 void register_obj();
172 void unregister_obj(bool throw_on_error = true);
173
174 typedef std::map<const Tag *, Continuation *> ContinuationMap;
175 ContinuationMap _continuations;
176
177 friend struct Private;
178 };
179
object()180 const ObjectAdaptor *ObjectAdaptor::object() const
181 {
182 return this;
183 }
184
tag()185 Tag *ObjectAdaptor::Continuation::tag()
186 {
187 return const_cast<Tag *>(_tag);
188 }
189
writer()190 MessageIter &ObjectAdaptor::Continuation::writer()
191 {
192 return _writer;
193 }
194
195 /*
196 */
197
198 class ObjectProxy;
199
200 typedef std::list<ObjectProxy *> ObjectProxyPList;
201
202 class DXXAPI ObjectProxy : public Object, public virtual ProxyBase
203 {
204 public:
205
206 ObjectProxy(Connection &conn, const Path &path, const char *service = "");
207
208 ~ObjectProxy();
209
210 inline const ObjectProxy *object() const;
211
212 private:
213
214 Message _invoke_method(CallMessage &);
215
216 bool _invoke_method_noreply(CallMessage &call);
217
218 bool handle_message(const Message &);
219
220 void register_obj();
221 void unregister_obj(bool throw_on_error = true);
222
223 private:
224
225 MessageSlot _filtered;
226 };
227
object()228 const ObjectProxy *ObjectProxy::object() const
229 {
230 return this;
231 }
232
233 } /* namespace DBus */
234
235 #endif//__DBUSXX_OBJECT_H
236