Ed Tanous | c9b5521 | 2017-06-12 13:25:51 -0700 | [diff] [blame] | 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 <string> |
| 11 | #include <boost/cstdint.hpp> |
| 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 | string value; |
| 36 | }; |
| 37 | struct 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 | */ |
| 45 | template <typename InvalidType> |
| 46 | struct element { |
| 47 | static const int code = DBUS_TYPE_INVALID; |
| 48 | }; |
| 49 | |
| 50 | template <> |
| 51 | struct element<bool> { |
| 52 | static const int code = DBUS_TYPE_BOOLEAN; |
| 53 | }; |
| 54 | |
| 55 | template <> |
| 56 | struct element<byte> { |
| 57 | static const int code = DBUS_TYPE_BYTE; |
| 58 | }; |
| 59 | |
| 60 | template <> |
| 61 | struct element<int16> { |
| 62 | static const int code = DBUS_TYPE_INT16; |
| 63 | }; |
| 64 | |
| 65 | template <> |
| 66 | struct element<uint16> { |
| 67 | static const int code = DBUS_TYPE_UINT16; |
| 68 | }; |
| 69 | |
| 70 | template <> |
| 71 | struct element<int32> { |
| 72 | static const int code = DBUS_TYPE_INT32; |
| 73 | }; |
| 74 | |
| 75 | template <> |
| 76 | struct element<uint32> { |
| 77 | static const int code = DBUS_TYPE_UINT32; |
| 78 | }; |
| 79 | |
| 80 | template <> |
| 81 | struct element<int64> { |
| 82 | static const int code = DBUS_TYPE_INT64; |
| 83 | }; |
| 84 | |
| 85 | template <> |
| 86 | struct element<uint64> { |
| 87 | static const int code = DBUS_TYPE_UINT64; |
| 88 | }; |
| 89 | |
| 90 | template <> |
| 91 | struct element<double> { |
| 92 | static const int code = DBUS_TYPE_DOUBLE; |
| 93 | }; |
| 94 | |
| 95 | template <> |
| 96 | struct element<string> { |
| 97 | static const int code = DBUS_TYPE_STRING; |
| 98 | }; |
| 99 | |
| 100 | template <> |
| 101 | struct element<object_path> { |
| 102 | static const int code = DBUS_TYPE_OBJECT_PATH; |
| 103 | }; |
| 104 | |
| 105 | template <> |
| 106 | struct element<signature> { |
| 107 | static const int code = DBUS_TYPE_SIGNATURE; |
| 108 | }; |
| 109 | |
| 110 | template <typename InvalidType> |
| 111 | struct is_fixed_type { |
| 112 | static const int value = false; |
| 113 | }; |
| 114 | |
| 115 | template <> |
| 116 | struct is_fixed_type<bool> { |
| 117 | static const int value = true; |
| 118 | }; |
| 119 | |
| 120 | template <> |
| 121 | struct is_fixed_type<byte> { |
| 122 | static const int value = true; |
| 123 | }; |
| 124 | |
| 125 | template <> |
| 126 | struct is_fixed_type<int16> { |
| 127 | static const int value = true; |
| 128 | }; |
| 129 | |
| 130 | template <> |
| 131 | struct is_fixed_type<uint16> { |
| 132 | static const int value = true; |
| 133 | }; |
| 134 | |
| 135 | template <> |
| 136 | struct is_fixed_type<int32> { |
| 137 | static const int value = true; |
| 138 | }; |
| 139 | |
| 140 | template <> |
| 141 | struct is_fixed_type<uint32> { |
| 142 | static const int value = true; |
| 143 | }; |
| 144 | |
| 145 | template <> |
| 146 | struct is_fixed_type<int64> { |
| 147 | static const int value = true; |
| 148 | }; |
| 149 | |
| 150 | template <> |
| 151 | struct is_fixed_type<uint64> { |
| 152 | static const int value = true; |
| 153 | }; |
| 154 | |
| 155 | template <> |
| 156 | struct is_fixed_type<double> { |
| 157 | static const int value = true; |
| 158 | }; |
| 159 | |
| 160 | template <typename InvalidType> |
| 161 | struct is_string_type { |
| 162 | static const bool value = false; |
| 163 | }; |
| 164 | |
| 165 | template <> |
| 166 | struct is_string_type<string> { |
| 167 | static const bool value = true; |
| 168 | }; |
| 169 | |
| 170 | template <> |
| 171 | struct is_string_type<object_path> { |
| 172 | static const bool value = true; |
| 173 | }; |
| 174 | |
| 175 | template <> |
| 176 | struct is_string_type<signature> { |
| 177 | static const bool value = true; |
| 178 | }; |
| 179 | |
| 180 | } // namespace dbus |
| 181 | |
| 182 | #endif // DBUS_ELEMENT_HPP |