# DBus-C++

## Desktop Communication Bus System

libdbus-c-- Documentation 0.9.0

- Files
- Data Structures
- Globals
- Main Page

types.cpp
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#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28#include <dbus-c++/types.h>
29#include <dbus-c++/object.h>
30#include <dbus/dbus.h>
31#include <cstdlib>
32#include <stdarg.h>
33
34#include "message_p.h"
35#include "internalerror.h"
36
37 namespace DBus {
38
39 Variant::Variant()
40 : _msg(CallMessage()) // dummy message used as temporary storage for variant data
41{
42}
43
44 Variant::Variant(MessageIter &it)
45 : _msg(CallMessage())
46{
47 MessageIter vi = it.recurse();
48 MessageIter mi = _msg.writer();
49 vi.copy_data(mi);
50}
51
52 Variant &Variant::operator = (const Variant &v)
53{
54 if (&v != this)
55 {
56 _msg = v._msg;
57 }
58 return *this;
59}
60
61 void Variant::clear()
62{
63 CallMessage empty;
64 _msg = empty;
65}
66
67 const Signature Variant::signature() const
68{
69 char *sigbuf = reader().signature();
70
71 Signature signature = sigbuf;
72
73 free(sigbuf);
74
75 return signature;
76}
77
78 MessageIter &operator << (MessageIter &iter, const Variant &val)
79{
80 const Signature sig = val.signature();
81
82 MessageIter rit = val.reader();
83 MessageIter wit = iter.new_variant(sig.c_str());
84
85 rit.copy_data(wit);
86
87 iter.close_container(wit);
88
89 return iter;
90}
91
92 MessageIter &operator >> (MessageIter &iter, Variant &val)
93{
94 if (iter.type() != DBUS_TYPE_VARIANT)
95 throw ErrorInvalidArgs("variant type expected");
96
97 val.clear();
98
99 MessageIter vit = iter.recurse();
100 MessageIter mit = val.writer();
101
102 vit.copy_data(mit);
103
104 return ++iter;
105}
106
107} /* namespace DBus */
DBus::CallMessage
Definition message.h:269
DBus::MessageIter
Definition message.h:45
DBus::MessageIter::copy_data
void copy_data(MessageIter &to)
Definition message.cpp:329
DBus::MessageIter::type
int type()
Definition message.cpp:41
DBus::MessageIter::signature
char * signature() const
Definition message.cpp:234
DBus::MessageIter::close_container
void close_container(MessageIter &container)
Definition message.cpp:302
DBus::MessageIter::recurse
MessageIter recurse()
Definition message.cpp:227
DBus::MessageIter::new_variant
MessageIter new_variant(const char *sig)
Definition message.cpp:275
DBus::Variant
Definition types.h:68
DBus::Variant::Variant
Variant()
Definition types.cpp:39
DBus::Variant::operator=
Variant & operator=(const Variant &v)
Definition types.cpp:52
DBus::Variant::reader
MessageIter reader() const
Definition types.h:81
DBus::Variant::clear
void clear()
Definition types.cpp:61
DBus::Variant::_msg
Message _msg
Definition types.h:96
DBus::Variant::writer
MessageIter writer()
Definition types.h:86
DBus::Variant::signature
const Signature signature() const
Definition types.cpp:67
internalerror.h
message_p.h
DBus
Definition connection_p.h:42
DBus::operator<<
MessageIter & operator<<(MessageIter &iter, const Variant &val)
Definition types.cpp:78
DBus::operator>>
MessageIter & operator>>(MessageIter &iter, Variant &val)
Definition types.cpp:92
object.h
DBus::ErrorInvalidArgs
Definition error.h:187
DBus::Signature
Definition types.h:54
types.h