object.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_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
37namespace DBus
38{
39
41{
42protected:
43
44 Object(Connection &conn, const Path &path, const char *service);
45
46public:
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
60private:
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
66private:
67
70 std::string _service;
72};
73
74/*
75*/
76
78{
79 return _conn;
80}
81
83{
84 return _path;
85}
86
87const std::string &Object::service() const
88{
89 return _service;
90}
91
93{
94 return _default_timeout;
95}
96
97/*
98*/
99
101{
102public:
103
104 virtual ~Tag()
105 {}
106};
107
108/*
109*/
110
111class ObjectAdaptor;
112
113typedef std::list<ObjectAdaptor *> ObjectAdaptorPList;
114typedef std::list<std::string> ObjectPathList;
115
116class DXXAPI ObjectAdaptor : public Object, public virtual AdaptorBase
117{
118public:
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
131
132 inline const ObjectAdaptor *object() const;
133
134protected:
135
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
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
165private:
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;
176
177 friend struct Private;
178};
179
181{
182 return this;
183}
184
186{
187 return const_cast<Tag *>(_tag);
188}
189
191{
192 return _writer;
193}
194
195/*
196*/
197
198class ObjectProxy;
199
200typedef std::list<ObjectProxy *> ObjectProxyPList;
201
202class DXXAPI ObjectProxy : public Object, public virtual ProxyBase
203{
204public:
205
206 ObjectProxy(Connection &conn, const Path &path, const char *service = "");
207
208 ~ObjectProxy();
209
210 inline const ObjectProxy *object() const;
211
212private:
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
223private:
224
226};
227
229{
230 return this;
231}
232
233} /* namespace DBus */
234
235#endif//__DBUSXX_OBJECT_H
#define DXXAPILOCAL
Definition: api.h:32
#define DXXAPI
Definition: api.h:36
bool handle_message(const Message &)
Definition: object.cpp:203
void unregister_obj(bool throw_on_error=true)
Definition: object.cpp:182
ContinuationMap _continuations
Definition: object.h:175
std::map< const Tag *, Continuation * > ContinuationMap
Definition: object.h:174
const ObjectAdaptor * object() const
Definition: object.h:180
const ObjectProxy * object() const
Definition: object.h:228
MessageSlot _filtered
Definition: object.h:225
Connection _conn
Definition: object.h:68
virtual DXXAPILOCAL bool handle_message(const Message &)=0
int _default_timeout
Definition: object.h:71
virtual DXXAPILOCAL void unregister_obj(bool throw_on_error=true)=0
const DBus::Path & path() const
Definition: object.h:82
int get_timeout() const
Definition: object.h:92
const std::string & service() const
Definition: object.h:87
virtual DXXAPILOCAL void register_obj()=0
Connection & conn()
Definition: object.h:77
DBus::Path _path
Definition: object.h:69
std::string _service
Definition: object.h:70
virtual ~Tag()
Definition: object.h:104
std::list< ObjectProxy * > ObjectProxyPList
Definition: object.h:200
std::list< ObjectAdaptor * > ObjectAdaptorPList
Definition: object.h:113
std::list< std::string > ObjectPathList
Definition: object.h:114