2 * Automotive Message Broker Client Library
4 * Copyright (C) 2016 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the License)
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 #ifndef __LIBAMB_UTIL_H__
20 #define __LIBAMB_UTIL_H__
31 #include "libamb-common.h"
32 #include "libamb-client.h"
34 #define g_variant_get_gboolean g_variant_get_boolean
35 #define g_variant_get_guchar g_variant_get_byte
36 #define g_variant_get_gint16 g_variant_get_int16
37 #define g_variant_get_guint16 g_variant_get_uint16
38 #define g_variant_get_gint32 g_variant_get_int32
39 #define g_variant_get_guint32 g_variant_get_uint32
40 #define g_variant_get_gint64 g_variant_get_int64
41 #define g_variant_get_guint64 g_variant_get_uint64
42 #define g_variant_get_gdouble g_variant_get_double
45 * Generate Custom CAN Object data structure and its related utility function.
47 * @param[in] CAN Object name
48 * @param[in] data type for CAN object
49 * @param[in] Alias name that is used in AMB. If it is NULL, then this value
52 * @see amb_release_data()
54 #define CAN_OBJECT(obj_name, value_type, alias_name) \
55 struct obj_name ## Type { \
57 gint32 ValueSequence; \
61 int amb_get_ ## obj_name ## _with_zone(struct obj_name ## Type **retobj, int zone) \
69 struct obj_name ## Type *retdata = NULL; \
71 retdata = g_malloc0(sizeof(*retdata)); \
75 ret = amb_get_property_all_with_zone(&variant, #obj_name, zone); \
80 g_variant_get(variant, "(a{sv})", &iter); \
81 while(g_variant_iter_loop(iter, "{sv}", &key, &value)) { \
82 if (!g_strcmp0(key, "Zone")) { \
83 g_variant_get(value, "v", &tmp); \
84 retdata->Zone = g_variant_get_int32(tmp); \
85 g_variant_unref(tmp); \
86 } else if (!g_strcmp0(key, "ValueSequence") || !g_strcmp0(key, #alias_name "Sequence")) { \
87 g_variant_get(value, "v", &tmp); \
88 retdata->ValueSequence = g_variant_get_int32(tmp); \
89 g_variant_unref(tmp); \
90 } else if (!g_strcmp0(key, "Time")) { \
91 g_variant_get(value, "v", &tmp); \
92 retdata->Time = g_variant_get_double(tmp); \
93 g_variant_unref(tmp); \
94 } else if (!g_strcmp0(key, "Value") || !g_strcmp0(key, #alias_name)) { \
95 g_variant_get(value, "v", &tmp); \
96 retdata->Value = g_variant_get_ ## value_type(tmp); \
97 g_variant_unref(tmp); \
101 g_variant_iter_free(iter); \
102 amb_release_property_all_with_zone(variant); \
107 int amb_convert_ ## obj_name ## Type (gpointer data, struct obj_name ## Type *retdata) \
109 GVariantIter *iter; \
114 gdata = (GVariant *)data; \
115 g_variant_get(gdata, "a{sv}", &iter); \
116 while(g_variant_iter_loop(iter, "{sv}", &key, &value)) { \
117 if (!g_strcmp0(key, "Zone")) { \
118 g_variant_get(value, "i", &retdata->Zone); \
119 } else if (!g_strcmp0(key, "ValueSequence") || !g_strcmp0(key, #alias_name "Sequence")) { \
120 g_variant_get(value, "i", &retdata->ValueSequence); \
121 } else if (!g_strcmp0(key, "Time")) { \
122 g_variant_get(value, "d", &retdata->Time); \
123 } else if (!g_strcmp0(key, "Value") || !g_strcmp0(key, #alias_name)) { \
124 retdata->Value = g_variant_get_ ## value_type(value); \
127 g_variant_iter_free(iter); \
135 #endif /* __LIBAMB_UTIL_H__ */