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_server_serialization.h
18 * @author Tomasz Swierczek (t.swierczek@samsung.com)
20 * @brief Header file for DBus data serialization to GVariant
23 #ifndef DPL_DBUS_DBUS_SERVER_SERIALIZATION_H_
24 #define DPL_DBUS_DBUS_SERVER_SERIALIZATION_H_
31 struct ServerSerialization {
32 template<typename ... Args>
33 static GVariant* serialize(Args ... args)
35 GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE_TUPLE);
36 if (NULL == builder) {
39 serializeBuilder(builder, args ...);
40 return g_variant_builder_end(builder);
43 // serialization on GVariantBuilder
44 template<typename T, typename ... Args>
45 static void serializeBuilder(GVariantBuilder* builder,
49 serializeElem(builder, arg);
50 serializeBuilder(builder, args ...);
54 static void serializeBuilder(GVariantBuilder* builder, const T& arg)
56 serializeElem(builder, arg);
59 // type specialization
60 static void serializeElem(GVariantBuilder* builder, int arg)
62 g_variant_builder_add_value(builder, g_variant_new_int32(arg));
65 static void serializeElem(GVariantBuilder* builder, unsigned arg)
67 g_variant_builder_add_value(builder, g_variant_new_uint32(arg));
70 static void serializeElem(GVariantBuilder* builder, bool arg)
72 g_variant_builder_add_value(builder, g_variant_new_boolean(arg));
75 static void serializeElem(GVariantBuilder* builder, float arg)
77 gdouble d = static_cast<gdouble>(arg);
78 g_variant_builder_add_value(builder, g_variant_new_double(d));
81 static void serializeElem(GVariantBuilder* builder, const char* arg)
83 g_variant_builder_add_value(builder, g_variant_new_string(arg));
86 static void serializeElem(GVariantBuilder* builder,
87 const std::string& arg)
89 g_variant_builder_add_value(builder, g_variant_new_string(arg.c_str()));
95 #endif // DPL_DBUS_DBUS_SERVER_SERIALIZATION_H_