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 using namespace DBus;
38 
40  : _msg(CallMessage()) // dummy message used as temporary storage for variant data
41 {
42 }
43 
45  : _msg(CallMessage())
46 {
47  MessageIter vi = it.recurse();
48  MessageIter mi = _msg.writer();
49  vi.copy_data(mi);
50 }
51 
53 {
54  if (&v != this)
55  {
56  _msg = v._msg;
57  }
58  return *this;
59 }
60 
62 {
63  CallMessage empty;
64  _msg = empty;
65 }
66 
68 {
69  char *sigbuf = reader().signature();
70 
71  Signature signature = sigbuf;
72 
73  free(sigbuf);
74 
75  return signature;
76 }
77 
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 
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 
Message _msg
Definition: types.h:102
void clear()
Definition: types.cpp:61
char * signature() const
Definition: message.cpp:234
Variant & operator=(const Variant &v)
Definition: types.cpp:52
MessageIter reader() const
Definition: types.h:81
MessageIter & operator>>(MessageIter &iter, Variant &val)
Definition: types.cpp:92
MessageIter writer()
Definition: types.h:86
void copy_data(MessageIter &to)
Definition: message.cpp:329
MessageIter & operator<<(MessageIter &iter, const Variant &val)
Definition: types.cpp:78
MessageIter recurse()
Definition: message.cpp:227
void close_container(MessageIter &container)
Definition: message.cpp:302
const Signature signature() const
Definition: types.cpp:67
MessageIter writer()
Definition: message.cpp:472
MessageIter new_variant(const char *sig)
Definition: message.cpp:275