WvStreams
include/wvdbusmsg.h
1/* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 2004-2006 Net Integration Technologies, Inc.
4 *
5 * Pathfinder Software:
6 * Copyright (C) 2007, Carillon Information Security Inc.
7 *
8 * This library is licensed under the LGPL, please read LICENSE for details.
9 *
10 * WvDBusMsg is intended to be an easy-to-use abstraction over the low-level
11 * D-Bus DBusMessage structure. It represents a message being passed around on
12 * the bus.
13 */
14#ifndef __WVDBUSMSG_H
15#define __WVDBUSMSG_H
16
17#include "wvstringlist.h"
18#include "wvbuf.h"
19#include <stdint.h>
20
21struct DBusMessageIter;
22struct DBusMessage;
23
24class WvDBusMsg;
25class WvDBusConn;
26
27
28class WvDBusMsg
29{
30public:
36 WvDBusMsg(WvStringParm busname, WvStringParm objectname,
37 WvStringParm ifc, WvStringParm method);
38
43
48 WvDBusMsg(DBusMessage *_msg);
49
50 virtual ~WvDBusMsg();
51
52 operator DBusMessage* () const;
53
61 static WvDBusMsg *demarshal(WvBuf &buf);
62
71 static size_t demarshal_bytes_needed(WvBuf &buf);
72
80 void marshal(WvBuf &buf);
81
82 WvString get_sender() const;
83 WvString get_dest() const;
84 WvString get_path() const;
85 WvString get_interface() const;
86 WvString get_member() const;
87 WvString get_error() const;
88 uint32_t get_serial() const;
89 uint32_t get_replyserial() const;
90 bool is_reply() const;
91 operator WvString() const;
92
93 void get_arglist(WvStringList &list) const;
94 WvString get_argstr() const;
95
100 WvDBusMsg &append(const char *s);
101 WvDBusMsg &append(bool b);
102 WvDBusMsg &append(signed char c);
103 WvDBusMsg &append(unsigned char c);
104 WvDBusMsg &append(int16_t i);
105 WvDBusMsg &append(uint16_t i);
106 WvDBusMsg &append(int32_t i);
107 WvDBusMsg &append(uint32_t i);
108 WvDBusMsg &append(int64_t i);
109 WvDBusMsg &append(uint64_t i);
110 WvDBusMsg &append(double d);
111
116
121
128
133
139
144
154
159
164
168 bool iserror() const;
169
174 void send(WvDBusConn &conn);
175
176 class Iter
177 {
178 public:
179 DBusMessageIter *const first, *const it;
180 mutable WvString s;
181 bool rewound;
182
183 Iter(const WvDBusMsg &_msg);
184 Iter(const WvDBusMsg::Iter &_it);
185 Iter(const DBusMessageIter &_first);
186 ~Iter();
187
192 void rewind();
193
198 int type() const;
199
207 Iter open() const;
208
215 bool next();
216
223 { next(); return *this; }
224
228 bool cur() const;
229
234
240
245
250 int64_t get_int() const;
251 operator int64_t() const { return get_int(); }
252 operator int32_t() const { return get_int(); }
253 operator int16_t() const { return get_int(); }
254 operator int8_t() const { return get_int(); }
255 operator bool() const { return get_int() != 0; }
256
261 uint64_t get_uint() const;
262 operator uint64_t() const { return get_uint(); }
263 operator uint32_t() const { return get_uint(); }
264 operator uint16_t() const { return get_uint(); }
265 operator uint8_t() const { return get_uint(); }
266
271 double get_double() const;
272 operator double() const { return get_double(); }
273 operator float() const { return get_double(); }
274
279 WvString *ptr() const;
280 operator WvString() const { return *ptr(); }
281
282 WvIterStuff(WvString);
283 };
284
285protected:
286 mutable DBusMessage *msg;
288};
289
290
291class WvDBusSignal : public WvDBusMsg
292{
293public:
294 WvDBusSignal(WvStringParm objectname, WvStringParm ifc,
295 WvStringParm name);
296};
297
298
299class WvDBusError : public WvDBusMsg
300{
301 DBusMessage *setup1(WvDBusMsg &in_reply_to,
302 WvStringParm errname, WvStringParm message);
303 void setup2();
304public:
305 WvDBusError(WvDBusMsg &in_reply_to,
306 WvStringParm errname, WvStringParm message)
307 : WvDBusMsg(setup1(in_reply_to, errname, message))
308 {
309 setup2();
310 }
311
312 WvDBusError(WvDBusMsg &in_reply_to,
313 WvStringParm errname, WVSTRING_FORMAT_DECL)
314 : WvDBusMsg(setup1(in_reply_to, errname,
315 WvString(WVSTRING_FORMAT_CALL)))
316 {
317 setup2();
318 }
319};
320
321#endif // __WVDBUSMSG_H
uint64_t get_uint() const
Get the current element as a uint64_t (possible for all integer types)
bool next()
Moves the iterator along the list to point to the next element.
bool cur() const
Returns: true if the current link is valid.
int type() const
Returns the data type of the current element.
void get_all(WvStringList &list)
Fill a WvStringList with a string for each element of the iter.
double get_double() const
Get the current element as a double (possible for all integer and floating point types)
WvString get_all()
Return a WvString representation of all elements in a single string.
Iter & getnext()
Same as next(), but returns *this instead so you can convert the new item to the right value type.
WvString get_str() const
Get the current element as a string (possible for all types).
WvString * ptr() const
Returns a pointer to the WvString at the iterator's current location.
Iter open() const
Returns a sub-iterator for walking through recursive types, such as arrays, structs,...
void rewind()
Rewinds the iterator to make it point to an imaginary element preceeding the first element of the lis...
int64_t get_int() const
Get the current element as an int64_t (possible for all integer types)
WvDBusMsg(WvDBusMsg &_msg)
Constructs a new WvDBus message, copying it out of an old one.
WvDBusMsg reply()
Generate a message that will be a reply to this one.
void send(WvDBusConn &conn)
A shortcut for sending this message on the given connection.
WvDBusMsg & struct_start(WvStringParm element_type)
Start a struct.
WvDBusMsg & append(const char *s)
The following methods are designed to allow appending various arguments to the message.
static WvDBusMsg * demarshal(WvBuf &buf)
Demarshals a new WvDBusMsg from a buffer containing its binary DBus protocol representation.
WvDBusMsg(WvStringParm busname, WvStringParm objectname, WvStringParm ifc, WvStringParm method)
Constructs a new WvDBus message.
WvDBusMsg & varray_start(WvStringParm element_type)
Start a variant-array.
WvDBusMsg & variant_end()
End a variant.
WvDBusMsg & struct_end()
End a struct started with struct_start().
static size_t demarshal_bytes_needed(WvBuf &buf)
Given a buffer containing what might be the header of a DBus message, checks how many bytes need to b...
WvDBusMsg & variant_start(WvStringParm element_type)
Start a variant.
bool iserror() const
Return true if this message is an error response.
void marshal(WvBuf &buf)
Locks this message, encodes it in DBus binary protocol format, and adds it to the given buffer.
WvDBusMsg(DBusMessage *_msg)
Constructs a new WvDBus message from an existing low-level D-Bus message.
WvDBusMsg & array_start(WvStringParm element_type)
Start an array.
WvDBusMsg & varray_end()
End an array started with array_start().
WvDBusMsg & array_end()
End an array started with array_start().
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
This is a WvList of WvStrings, and is a really handy way to parse strings.
WvString is an implementation of a simple and efficient printable-string class.