2
* Copyright © 2012 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3,
6
* as published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Thomas Voß <thomas.voss@canonical.com>
18
#ifndef DBUS_ORG_FREEDESKTOP_DBUS_TYPES_STRUCT_H_
19
#define DBUS_ORG_FREEDESKTOP_DBUS_TYPES_STRUCT_H_
21
#include "org/freedesktop/dbus/codec.h"
40
struct TypeMapper<org::freedesktop::dbus::types::Struct<T>>
42
constexpr static ArgumentType type_value()
44
return ArgumentType::structure;
47
constexpr static bool is_basic_type()
52
constexpr static bool requires_signature()
57
static std::string signature()
59
static const std::string s =
60
DBUS_STRUCT_BEGIN_CHAR_AS_STRING +
61
TypeMapper<T>::signature() +
62
DBUS_STRUCT_END_CHAR_AS_STRING;
69
struct Codec<types::Struct<T>>
71
static void encode_argument(DBusMessageIter* out, const types::Struct<T>& arg)
74
if (!dbus_message_iter_open_container(
79
throw std::runtime_error("Problem opening container");
81
Codec<T>::encode_argument(std::addressof(sub), arg.value);
83
if (!dbus_message_iter_close_container(out, std::addressof(sub)))
84
throw std::runtime_error("Problem closing container");
87
static void decode_argument(DBusMessageIter* in, types::Struct<T>& out)
90
dbus_message_iter_recurse(in, std::addressof(sub));
91
Codec<T>::decode_argument(std::addressof(sub), out.value);
97
#endif // DBUS_ORG_FREEDESKTOP_DBUS_TYPES_STRUCT_H_