xref: /openbmc/boost-dbus/include/dbus/element.hpp (revision 44d24258)
1 // 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 <boost/cstdint.hpp>
11 #include <string>
12 
13 namespace 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
21 typedef boost::uint8_t  byte;
22 
23 typedef boost:: int16_t int16;
24 typedef boost::uint16_t uint16;
25 typedef boost:: int32_t int32;
26 typedef boost::uint32_t uint32;
27 
28 typedef boost:: int64_t int64;
29 typedef boost::uint64_t uint64;
30 // double
31 // unix_fd
32 
33 typedef std::string   string;
34 struct object_path
35 {
36   string value;
37 };
38 struct signature
39 {
40   string value;
41 };
42 
43 /// Traits template for message elements
44 /**
45  * D-Bus Message elements are identified by unique integer type codes.
46  */
47 template<typename InvalidType> struct element
48 {
49   static const int code = DBUS_TYPE_INVALID;
50 };
51 
52 template<> struct element< bool >
53 {
54   static const int code = DBUS_TYPE_BOOLEAN;
55 };
56 
57 template<> struct element< byte >
58 {
59   static const int code = DBUS_TYPE_BYTE;
60 };
61 
62 template<> struct element< int16 >
63 {
64   static const int code = DBUS_TYPE_INT16;
65 };
66 
67 template<> struct element< uint16 >
68 {
69   static const int code = DBUS_TYPE_UINT16;
70 };
71 
72 template<> struct element< int32 >
73 {
74   static const int code = DBUS_TYPE_INT32;
75 };
76 
77 template<> struct element< uint32 >
78 {
79   static const int code = DBUS_TYPE_UINT32;
80 };
81 
82 template<> struct element< int64 >
83 {
84   static const int code = DBUS_TYPE_INT64;
85 };
86 
87 template<> struct element< uint64 >
88 {
89   static const int code = DBUS_TYPE_UINT64;
90 };
91 
92 template<> struct element< double >
93 {
94   static const int code = DBUS_TYPE_DOUBLE;
95 };
96 
97 template<> struct element< string >
98 {
99   static const int code = DBUS_TYPE_STRING;
100 };
101 
102 template<> struct element< object_path >
103 {
104   static const int code = DBUS_TYPE_OBJECT_PATH;
105 };
106 
107 template<> struct element< signature >
108 {
109   static const int code = DBUS_TYPE_SIGNATURE;
110 };
111 
112 
113 
114 template<typename InvalidType> struct is_fixed_type
115 {
116   static const int value = false;
117 };
118 
119 template<> struct is_fixed_type< bool >
120 {
121   static const int value = true;
122 };
123 
124 template<> struct is_fixed_type< byte >
125 {
126   static const int value = true;
127 };
128 
129 template<> struct is_fixed_type< int16 >
130 {
131   static const int value = true;
132 };
133 
134 template<> struct is_fixed_type< uint16 >
135 {
136   static const int value = true;
137 };
138 
139 template<> struct is_fixed_type< int32 >
140 {
141   static const int value = true;
142 };
143 
144 template<> struct is_fixed_type< uint32 >
145 {
146   static const int value = true;
147 };
148 
149 template<> struct is_fixed_type< int64 >
150 {
151   static const int value = true;
152 };
153 
154 template<> struct is_fixed_type< uint64 >
155 {
156   static const int value = true;
157 };
158 
159 template<> struct is_fixed_type< double >
160 {
161   static const int value = true;
162 };
163 
164 
165 
166 template<typename InvalidType> struct is_string_type
167 {
168   static const bool value = false;
169 };
170 
171 template<> struct is_string_type< string >
172 {
173   static const bool value = true;
174 };
175 
176 template<> struct is_string_type< object_path >
177 {
178   static const bool value = true;
179 };
180 
181 template<> struct is_string_type< signature >
182 {
183   static const bool value = true;
184 };
185 
186 
187 } // namespace dbus
188 
189 #endif // DBUS_ELEMENT_HPP
190