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_
32 struct ServerSerialization {
34 template<typename ...Args>
35 static GVariant* serialize(Args... args)
37 GVariantBuilder* builder = g_variant_builder_new(G_VARIANT_TYPE_TUPLE);
38 if (NULL == builder) {
41 serializeBuilder(builder, args ...);
42 return g_variant_builder_end(builder);
45 // serialization on GVariantBuilder
46 template<typename T, typename ...Args>
47 static void serializeBuilder(GVariantBuilder* builder,
51 serializeElem(builder, arg);
52 serializeBuilder(builder, args ...);
56 static void serializeBuilder(GVariantBuilder* builder, const T& arg)
58 serializeElem(builder, arg);
61 // type specialization
62 static void serializeElem(GVariantBuilder* builder, int arg)
64 g_variant_builder_add_value(builder, g_variant_new_int32(arg));
67 static void serializeElem(GVariantBuilder* builder, unsigned arg)
69 g_variant_builder_add_value(builder, g_variant_new_uint32(arg));
72 static void serializeElem(GVariantBuilder* builder, bool arg)
74 g_variant_builder_add_value(builder, g_variant_new_boolean(arg));
77 static void serializeElem(GVariantBuilder* builder, float arg)
79 gdouble d = static_cast<gdouble>(arg);
80 g_variant_builder_add_value(builder, g_variant_new_double(d));
83 static void serializeElem(GVariantBuilder* builder, const char* arg)
85 g_variant_builder_add_value(builder, g_variant_new_string(arg));
88 static void serializeElem(GVariantBuilder* builder,
89 const std::string& arg)
91 g_variant_builder_add_value(builder, g_variant_new_string(arg.c_str()));
98 #endif // DPL_DBUS_DBUS_SERVER_SERIALIZATION_H_