blob: 276b593d54091fe7cf3aabf48f9d7e39d1a5e5bb [file] [log] [blame]
Ed Tanousc9b55212017-06-12 13:25:51 -07001// Copyright (c) Benjamin Kietzman (github.com/bkietz)
2//
3// Distributed under the Boost Software License, Version 1.0. (See accompanying
4// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5
6#ifndef DBUS_ELEMENT_HPP
7#define DBUS_ELEMENT_HPP
8
9#include <dbus/dbus.h>
10#include <string>
11#include <boost/cstdint.hpp>
12
13namespace dbus {
14
15/// Message elements
16/**
17 * D-Bus Messages are composed of simple elements of one of these types
18 */
19// bool // is this simply valid? It might pack wrong...
20// http://maemo.org/api_refs/5.0/5.0-final/dbus/api/group__DBusTypes.html
21typedef boost::uint8_t byte;
22
23typedef boost::int16_t int16;
24typedef boost::uint16_t uint16;
25typedef boost::int32_t int32;
26typedef boost::uint32_t uint32;
27
28typedef boost::int64_t int64;
29typedef boost::uint64_t uint64;
30// double
31// unix_fd
32
33typedef std::string string;
34struct object_path {
35 string value;
36};
37struct signature {
38 string value;
39};
40
41/// Traits template for message elements
42/**
43 * D-Bus Message elements are identified by unique integer type codes.
44 */
45template <typename InvalidType>
46struct element {
47 static const int code = DBUS_TYPE_INVALID;
48};
49
50template <>
51struct element<bool> {
52 static const int code = DBUS_TYPE_BOOLEAN;
53};
54
55template <>
56struct element<byte> {
57 static const int code = DBUS_TYPE_BYTE;
58};
59
60template <>
61struct element<int16> {
62 static const int code = DBUS_TYPE_INT16;
63};
64
65template <>
66struct element<uint16> {
67 static const int code = DBUS_TYPE_UINT16;
68};
69
70template <>
71struct element<int32> {
72 static const int code = DBUS_TYPE_INT32;
73};
74
75template <>
76struct element<uint32> {
77 static const int code = DBUS_TYPE_UINT32;
78};
79
80template <>
81struct element<int64> {
82 static const int code = DBUS_TYPE_INT64;
83};
84
85template <>
86struct element<uint64> {
87 static const int code = DBUS_TYPE_UINT64;
88};
89
90template <>
91struct element<double> {
92 static const int code = DBUS_TYPE_DOUBLE;
93};
94
95template <>
96struct element<string> {
97 static const int code = DBUS_TYPE_STRING;
98};
99
100template <>
101struct element<object_path> {
102 static const int code = DBUS_TYPE_OBJECT_PATH;
103};
104
105template <>
106struct element<signature> {
107 static const int code = DBUS_TYPE_SIGNATURE;
108};
109
110template <typename InvalidType>
111struct is_fixed_type {
112 static const int value = false;
113};
114
115template <>
116struct is_fixed_type<bool> {
117 static const int value = true;
118};
119
120template <>
121struct is_fixed_type<byte> {
122 static const int value = true;
123};
124
125template <>
126struct is_fixed_type<int16> {
127 static const int value = true;
128};
129
130template <>
131struct is_fixed_type<uint16> {
132 static const int value = true;
133};
134
135template <>
136struct is_fixed_type<int32> {
137 static const int value = true;
138};
139
140template <>
141struct is_fixed_type<uint32> {
142 static const int value = true;
143};
144
145template <>
146struct is_fixed_type<int64> {
147 static const int value = true;
148};
149
150template <>
151struct is_fixed_type<uint64> {
152 static const int value = true;
153};
154
155template <>
156struct is_fixed_type<double> {
157 static const int value = true;
158};
159
160template <typename InvalidType>
161struct is_string_type {
162 static const bool value = false;
163};
164
165template <>
166struct is_string_type<string> {
167 static const bool value = true;
168};
169
170template <>
171struct is_string_type<object_path> {
172 static const bool value = true;
173};
174
175template <>
176struct is_string_type<signature> {
177 static const bool value = true;
178};
179
180} // namespace dbus
181
182#endif // DBUS_ELEMENT_HPP