summaryrefslogtreecommitdiff
path: root/include/dbus-c++/message.h
blob: ba326b7db89ad1c47171732d99950185f590f234 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
/*
 *
 *  D-Bus++ - C++ bindings for D-Bus
 *
 *  Copyright (C) 2005-2007  Paolo Durante <shackan@gmail.com>
 *
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#ifndef __DBUSXX_MESSAGE_H
#define __DBUSXX_MESSAGE_H

#include <string>
#include <map>

#include "api.h"
#include "util.h"

namespace DBus {

class Message;
class ErrorMessage;
class SignalMessage;
class ReturnMessage;
class Error;
class Connection;

class DXXAPI MessageIter
{
public:

	MessageIter() {}

	int type();

	bool at_end();

	bool has_next();

	MessageIter &operator ++();

	MessageIter operator ++(int);

	bool append_byte(unsigned char byte);

	unsigned char get_byte();

	bool append_bool(bool b);

	bool get_bool();

	bool append_int16(signed short i);

	signed short get_int16();

	bool append_uint16(unsigned short u);

	unsigned short get_uint16();

	bool append_int32(signed int i);

	signed int get_int32();

	bool append_uint32(unsigned int u);

	unsigned int get_uint32();

	bool append_int64(signed long long i);

	signed long long get_int64();

	bool append_uint64(unsigned long long i);

	unsigned long long get_uint64();

	bool append_double(double d);

	double get_double();
	
	bool append_string(const char *chars);

	const char *get_string();

	bool append_path(const char *chars);

	const char *get_path();

	bool append_signature(const char *chars);

	const char *get_signature();

	char *signature() const; //returned string must be manually free()'d
	
	MessageIter recurse();

	bool append_array(char type, const void *ptr, size_t length);

	int array_type();

	int get_array(void *ptr);

	bool is_array();

	bool is_dict();

	MessageIter new_array(const char *sig);

	MessageIter new_variant(const char *sig);

	MessageIter new_struct();

	MessageIter new_dict_entry();

	void close_container(MessageIter &container);

	void copy_data(MessageIter &to);

	Message &msg() const
	{
		return *_msg;
	}

private:

	DXXAPILOCAL MessageIter(Message &msg) : _msg(&msg) {}

	DXXAPILOCAL bool append_basic(int type_id, void *value);

	DXXAPILOCAL void get_basic(int type_id, void *ptr);

private:

	/* I'm sorry, but don't want to include dbus.h in the public api
	 */
	unsigned char _iter[sizeof(void *)*3+sizeof(int)*11];

	Message *_msg;

friend class Message;
};

class DXXAPI Message
{
public:
	
	struct Private;

	Message(Private *, bool incref = true);

	Message(const Message &m);

	~Message();

	Message &operator = (const Message &m);

	Message copy();

	int type() const;

	int serial() const;

	int reply_serial() const;

	bool reply_serial(int);

	const char *sender() const;

	bool sender(const char *s);

	const char *destination() const;

	bool destination(const char *s);

	bool is_error() const;

	bool is_signal(const char *interface, const char *member) const;

	MessageIter reader() const;

	MessageIter writer();

	bool append(int first_type, ...);

	void terminate();

protected:

	Message();

protected:

	RefPtrI<Private> _pvt;

/*	classes who need to read `_pvt` directly
*/
friend class ErrorMessage;
friend class ReturnMessage;
friend class MessageIter;
friend class Error;
friend class Connection;
};

/*
*/

class DXXAPI ErrorMessage : public Message
{
public:
	
	ErrorMessage();

	ErrorMessage(const Message &, const char *name, const char *message);

	const char *name() const;

	bool name(const char *n);

	bool operator == (const ErrorMessage &) const;
};

/*
*/

class DXXAPI SignalMessage : public Message
{
public:

	SignalMessage(const char *name);

	SignalMessage(const char *path, const char *interface, const char *name);

	const char *interface() const;

	bool interface(const char *i);

	const char *member() const;

	bool member(const char *m);

	const char *path() const;

	char ** path_split() const;

	bool path(const char *p);

	bool operator == (const SignalMessage &) const;
};

/*
*/

class DXXAPI CallMessage : public Message
{
public:
	
	CallMessage();

	CallMessage(const char *dest, const char *path, const char *iface, const char *method);

	const char *interface() const;

	bool interface(const char *i);

	const char *member() const;

	bool member(const char *m);

	const char *path() const;

	char ** path_split() const;

	bool path(const char *p);

	const char *signature() const;

	bool operator == (const CallMessage &) const;
};

/*
*/

class DXXAPI ReturnMessage : public Message
{
public:
	
	ReturnMessage(const CallMessage &callee);

	const char *signature() const;
};

} /* namespace DBus */

#endif//__DBUSXX_MESSAGE_H