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>
37 static inline const char* value()
39 static const char signature[] =
40 { (char) SimpleType<T>::value, 0 };
45 // signed integer types
47 struct __SignedIntegerType;
50 struct __SignedIntegerType<1>
52 static const int value = DBUS_TYPE_INT16;
56 struct __SignedIntegerType<2>
58 static const int value = DBUS_TYPE_INT16;
62 struct __SignedIntegerType<4>
64 static const int value = DBUS_TYPE_INT32;
68 struct __SignedIntegerType<8>
70 static const int value = DBUS_TYPE_INT64;
73 // unsigned integer types
75 struct __UnsignedIntegerType;
78 struct __UnsignedIntegerType<1>
80 static const int value = DBUS_TYPE_BYTE;
83 struct __UnsignedIntegerType<2>
85 static const int value = DBUS_TYPE_UINT16;
88 struct __UnsignedIntegerType<4>
90 static const int value = DBUS_TYPE_UINT32;
93 struct __UnsignedIntegerType<8>
95 static const int value = DBUS_TYPE_UINT64;
100 struct SimpleType<bool>
102 static const int value = DBUS_TYPE_BOOLEAN;
106 struct SimpleType<char>
108 static const int value = __UnsignedIntegerType<sizeof(char)>::value;
112 struct SimpleType<signed char>
114 static const int value = __SignedIntegerType<sizeof(signed char)>::value;
118 struct SimpleType<unsigned char>
120 static const int value =
121 __UnsignedIntegerType<sizeof(unsigned char)>::value;
125 struct SimpleType<short>
127 static const int value = __SignedIntegerType<sizeof(short)>::value;
131 struct SimpleType<unsigned short>
133 static const int value =
134 __UnsignedIntegerType<sizeof(unsigned short)>::value;
138 struct SimpleType<int>
140 static const int value = __SignedIntegerType<sizeof(int)>::value;
144 struct SimpleType<unsigned int>
146 static const int value =
147 __UnsignedIntegerType<sizeof(unsigned int)>::value;
151 struct SimpleType<long>
153 static const int value = __SignedIntegerType<sizeof(long)>::value;
157 struct SimpleType<unsigned long>
159 static const int value =
160 __UnsignedIntegerType<sizeof(unsigned long)>::value;
164 struct SimpleType<long long>
166 static const int value = __SignedIntegerType<sizeof(long long)>::value;
170 struct SimpleType<unsigned long long>
172 static const int value = __UnsignedIntegerType<
173 sizeof(unsigned long long)>::value;
177 struct SimpleType<float>
179 static const int value = DBUS_TYPE_DOUBLE;
183 struct SimpleType<double>
185 static const int value = DBUS_TYPE_DOUBLE;
189 struct SimpleType<const char *>
191 static const int value = DBUS_TYPE_STRING;
195 struct SimpleType<char *>
197 static const int value = DBUS_TYPE_STRING;
201 struct SimpleType<std::string>
203 static const int value = DBUS_TYPE_STRING;
206 // STL containers signatures
210 struct ArraySignature
212 static inline const char* value()
214 static const std::string signature = std::string(
215 DBUS_TYPE_ARRAY_AS_STRING) + Signature<T>::value();
216 return signature.c_str();
222 struct Signature<std::vector<T> > : public ArraySignature<T>
227 struct Signature<std::list<T> > : public ArraySignature<T>
232 struct Signature<std::set<T> > : public ArraySignature<T>
236 template<typename K, typename V>
237 struct Signature<std::pair<K, V> >
239 static inline const char* value()
241 static const std::string signature = std::string(
242 DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING)
243 + Signature<K>::value() + Signature<V>::value()
244 + DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
245 return signature.c_str();
250 template<typename K, typename V>
251 struct Signature<std::map<K, V> > : public ArraySignature<std::pair<K, V> >
256 #endif // DPL_DBUS_SIGNATURE_H