2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 * @file dbus_deserialization.h
18 * @author Tomasz Swierczek (t.swierczek@samsung.com)
20 * @brief Header file for DBus data signatures
23 #ifndef DPL_DBUS_SIGNATURE_H
24 #define DPL_DBUS_SIGNATURE_H
26 #include <dbus/dbus.h>
38 static inline const char* value()
40 static const char signature[] =
41 { (char) SimpleType<T>::value, 0 };
46 // signed integer types
48 struct __SignedIntegerType;
51 struct __SignedIntegerType<1>
53 static const int value = DBUS_TYPE_INT16;
57 struct __SignedIntegerType<2>
59 static const int value = DBUS_TYPE_INT16;
63 struct __SignedIntegerType<4>
65 static const int value = DBUS_TYPE_INT32;
69 struct __SignedIntegerType<8>
71 static const int value = DBUS_TYPE_INT64;
74 // unsigned integer types
76 struct __UnsignedIntegerType;
79 struct __UnsignedIntegerType<1>
81 static const int value = DBUS_TYPE_BYTE;
84 struct __UnsignedIntegerType<2>
86 static const int value = DBUS_TYPE_UINT16;
89 struct __UnsignedIntegerType<4>
91 static const int value = DBUS_TYPE_UINT32;
94 struct __UnsignedIntegerType<8>
96 static const int value = DBUS_TYPE_UINT64;
101 struct SimpleType<bool>
103 static const int value = DBUS_TYPE_BOOLEAN;
107 struct SimpleType<char>
109 static const int value = __UnsignedIntegerType<sizeof(char)>::value;
113 struct SimpleType<signed char>
115 static const int value = __SignedIntegerType<sizeof(signed char)>::value;
119 struct SimpleType<unsigned char>
121 static const int value =
122 __UnsignedIntegerType<sizeof(unsigned char)>::value;
126 struct SimpleType<short>
128 static const int value = __SignedIntegerType<sizeof(short)>::value;
132 struct SimpleType<unsigned short>
134 static const int value =
135 __UnsignedIntegerType<sizeof(unsigned short)>::value;
139 struct SimpleType<int>
141 static const int value = __SignedIntegerType<sizeof(int)>::value;
145 struct SimpleType<unsigned int>
147 static const int value =
148 __UnsignedIntegerType<sizeof(unsigned int)>::value;
152 struct SimpleType<long>
154 static const int value = __SignedIntegerType<sizeof(long)>::value;
158 struct SimpleType<unsigned long>
160 static const int value =
161 __UnsignedIntegerType<sizeof(unsigned long)>::value;
165 struct SimpleType<long long>
167 static const int value = __SignedIntegerType<sizeof(long long)>::value;
171 struct SimpleType<unsigned long long>
173 static const int value = __UnsignedIntegerType<
174 sizeof(unsigned long long)>::value;
178 struct SimpleType<float>
180 static const int value = DBUS_TYPE_DOUBLE;
184 struct SimpleType<double>
186 static const int value = DBUS_TYPE_DOUBLE;
190 struct SimpleType<const char *>
192 static const int value = DBUS_TYPE_STRING;
196 struct SimpleType<char *>
198 static const int value = DBUS_TYPE_STRING;
202 struct SimpleType<std::string>
204 static const int value = DBUS_TYPE_STRING;
207 // STL containers signatures
211 struct ArraySignature
213 static inline const char* value()
215 static const std::string signature = std::string(
216 DBUS_TYPE_ARRAY_AS_STRING) + Signature<T>::value();
217 return signature.c_str();
223 struct Signature<std::vector<T> > : public ArraySignature<T>
229 struct Signature<std::list<T> > : public ArraySignature<T>
235 struct Signature<std::set<T> > : public ArraySignature<T>
240 template<typename K, typename V>
241 struct Signature<std::pair<K, V> >
243 static inline const char* value()
245 static const std::string signature = std::string(
246 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING)
247 + Signature<K>::value() + Signature<V>::value()
248 + DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
249 return signature.c_str();
254 template<typename K, typename V>
255 struct Signature<std::map<K, V> > : public ArraySignature<std::pair<K, V> >
262 #endif // DPL_DBUS_SIGNATURE_H