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