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 
37 namespace DBus
38 {
39 
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 
70  std::string _service;
72 };
73 
74 /*
75 */
76 
78 {
79  return _conn;
80 }
81 
82 const DBus::Path &Object::path() const
83 {
84  return _path;
85 }
86 
87 const std::string &Object::service() const
88 {
89  return _service;
90 }
91 
93 {
94  return _default_timeout;
95 }
96 
97 /*
98 */
99 
100 class DXXAPI Tag
101 {
102 public:
103 
104  virtual ~Tag()
105  {}
106 };
107 
108 /*
109 */
110 
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 
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 
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;
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 
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 
226 };
227 
229 {
230  return this;
231 }
232 
233 } /* namespace DBus */
234 
235 #endif//__DBUSXX_OBJECT_H
Connection _conn
Definition: object.h:68
virtual ~Tag()
Definition: object.h:104
const ObjectProxy * object() const
Definition: object.h:228
std::string _service
Definition: object.h:70
bool handle_message(const Message &)
Definition: object.cpp:203
ContinuationMap _continuations
Definition: object.h:175
Connection & conn()
Definition: object.h:77
#define DXXAPI
Definition: api.h:36
#define DXXAPILOCAL
Definition: api.h:32
int get_timeout() const
Definition: object.h:92
std::map< const Tag *, Continuation * > ContinuationMap
Definition: object.h:174
DBus::Path _path
Definition: object.h:69
MessageSlot _filtered
Definition: object.h:225
const std::string & service() const
Definition: object.h:87
std::list< std::string > ObjectPathList
Definition: object.h:114
const DBus::Path & path() const
Definition: object.h:82
int _default_timeout
Definition: object.h:71
std::list< ObjectProxy * > ObjectProxyPList
Definition: object.h:198
const ObjectAdaptor * object() const
Definition: object.h:180
void unregister_obj(bool throw_on_error=true)
Definition: object.cpp:182
std::list< ObjectAdaptor * > ObjectAdaptorPList
Definition: object.h:111