message.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_MESSAGE_H
26 #define __DBUSXX_MESSAGE_H
27 
28 #include <string>
29 #include <map>
30 
31 #include "api.h"
32 #include "util.h"
33 
34 namespace DBus
35 {
36 
37 class Message;
38 class ErrorMessage;
39 class SignalMessage;
40 class ReturnMessage;
41 class Error;
42 class Connection;
43 
45 {
46 public:
47 
49 
50  int type();
51 
52  bool at_end();
53 
54  bool has_next();
55 
56  MessageIter &operator ++();
57 
58  MessageIter operator ++(int);
59 
60  bool append_byte(unsigned char byte);
61 
62  unsigned char get_byte();
63 
64  bool append_bool(bool b);
65 
66  bool get_bool();
67 
68  bool append_int16(signed short i);
69 
70  signed short get_int16();
71 
72  bool append_uint16(unsigned short u);
73 
74  unsigned short get_uint16();
75 
76  bool append_int32(signed int i);
77 
78  signed int get_int32();
79 
80  bool append_uint32(unsigned int u);
81 
82  unsigned int get_uint32();
83 
84  bool append_int64(signed long long i);
85 
86  signed long long get_int64();
87 
88  bool append_uint64(unsigned long long i);
89 
90  unsigned long long get_uint64();
91 
92  bool append_double(double d);
93 
94  double get_double();
95 
96  bool append_string(const char *chars);
97 
98  const char *get_string();
99 
100  bool append_path(const char *chars);
101 
102  const char *get_path();
103 
104  bool append_signature(const char *chars);
105 
106  const char *get_signature();
107 
108  char *signature() const; //returned string must be manually free()'d
109 
110  MessageIter recurse();
111 
112  bool append_array(char type, const void *ptr, size_t length);
113 
114  int array_type();
115 
116  int get_array(void *ptr);
117 
118  bool is_array();
119 
120  bool is_dict();
121 
122  MessageIter new_array(const char *sig);
123 
124  MessageIter new_variant(const char *sig);
125 
126  MessageIter new_struct();
127 
128  MessageIter new_dict_entry();
129 
130  void close_container(MessageIter &container);
131 
132  void copy_data(MessageIter &to);
133 
134  Message &msg() const
135  {
136  return *_msg;
137  }
138 
139 private:
140 
141  DXXAPILOCAL MessageIter(Message &msg) : _msg(&msg) {}
142 
143  DXXAPILOCAL bool append_basic(int type_id, void *value);
144 
145  DXXAPILOCAL void get_basic(int type_id, void *ptr);
146 
147 private:
148 
149  /* I'm sorry, but don't want to include dbus.h in the public api
150  */
151  unsigned char _iter[sizeof(void *) * 3 + sizeof(int) * 11];
152 
154 
155  friend class Message;
156 };
157 
158 class DXXAPI Message
159 {
160 public:
161 
162  struct Private;
163 
164  Message(Private *, bool incref = true);
165 
166  Message(const Message &m);
167 
168  ~Message();
169 
170  Message &operator = (const Message &m);
171 
172  Message copy();
173 
174  int type() const;
175 
176  int serial() const;
177 
178  int reply_serial() const;
179 
180  bool reply_serial(int);
181 
182  const char *sender() const;
183 
184  bool sender(const char *s);
185 
186  const char *destination() const;
187 
188  bool destination(const char *s);
189 
190  bool is_error() const;
191 
192  bool is_signal(const char *interface, const char *member) const;
193 
194  MessageIter reader() const;
195 
196  MessageIter writer();
197 
198  bool append(int first_type, ...);
199 
200  void terminate();
201 
202 protected:
203 
204  Message();
205 
206 protected:
207 
209 
210  /* classes who need to read `_pvt` directly
211  */
212  friend class ErrorMessage;
213  friend class ReturnMessage;
214  friend class MessageIter;
215  friend class Error;
216  friend class Connection;
217 };
218 
219 /*
220 */
221 
223 {
224 public:
225 
226  ErrorMessage();
227 
228  ErrorMessage(const Message &, const char *name, const char *message);
229 
230  const char *name() const;
231 
232  bool name(const char *n);
233 
234  bool operator == (const ErrorMessage &) const;
235 };
236 
237 /*
238 */
239 
241 {
242 public:
243 
244  SignalMessage(const char *name);
245 
246  SignalMessage(const char *path, const char *interface, const char *name);
247 
248  const char *interface() const;
249 
250  bool interface(const char *i);
251 
252  const char *member() const;
253 
254  bool member(const char *m);
255 
256  const char *path() const;
257 
258  char **path_split() const;
259 
260  bool path(const char *p);
261 
262  bool operator == (const SignalMessage &) const;
263 };
264 
265 /*
266 */
267 
268 class DXXAPI CallMessage : public Message
269 {
270 public:
271 
272  CallMessage();
273 
274  CallMessage(const char *dest, const char *path, const char *iface, const char *method);
275 
276  const char *interface() const;
277 
278  bool interface(const char *i);
279 
280  const char *member() const;
281 
282  bool member(const char *m);
283 
284  const char *path() const;
285 
286  char **path_split() const;
287 
288  bool path(const char *p);
289 
290  const char *signature() const;
291 
292  bool operator == (const CallMessage &) const;
293 };
294 
295 /*
296 */
297 
299 {
300 public:
301 
302  ReturnMessage(const CallMessage &callee);
303 
304  const char *signature() const;
305 };
306 
307 } /* namespace DBus */
308 
309 #endif//__DBUSXX_MESSAGE_H
#define DXXAPI
Definition: api.h:36
#define DXXAPILOCAL
Definition: api.h:32
RefPtrI< Private > _pvt
Definition: message.h:208
Message & msg() const
Definition: message.h:134
Message * _msg
Definition: message.h:153
DXXAPILOCAL MessageIter(Message &msg)
Definition: message.h:141