2 * Copyright (c) 2015 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.
24 #include "icl-resource.h"
25 #include "icl-resource-types.h"
26 #include "icl-resource-interfaces.h"
27 #include "icl-options.h"
28 #include "icl-query.h"
29 #include "icl-request.h"
30 #include "icl-response.h"
31 #include "icl-remote-resource.h"
32 #include "icl-representation.h"
33 #include "icl-device.h"
34 #include "icl-payload.h"
35 #include "icl-observation.h"
36 #include "icl-dbus-type.h"
38 const char** icl_dbus_resource_interfaces_to_array(iotcon_resource_interfaces_h ifaces)
41 GList *node = ifaces->iface_list;
42 int len = g_list_length(node);
45 ERR("Empty Resource Interface List");
49 const char **array = calloc(len + 1, sizeof(char*));
51 ERR("calloc() Fail(%d)", errno);
55 for (node = ifaces->iface_list; node; node = node->next, i++)
56 array[i] = node->data;
63 const char** icl_dbus_resource_types_to_array(iotcon_resource_types_h types)
66 GList *node = types->type_list;
67 int len = g_list_length(node);
70 ERR("Empty Resource Type List");
74 const char **array = calloc(len + 1, sizeof(char*));
76 ERR("calloc() Fail(%d)", errno);
80 for (node = types->type_list; node; node = node->next, i++)
81 array[i] = node->data;
88 GVariant* icl_dbus_representation_to_gvariant(struct icl_representation_s *repr)
90 GVariantBuilder builder;
93 g_variant_builder_init(&builder, G_VARIANT_TYPE("av"));
96 repr_gvar = icl_representation_to_gvariant(repr);
97 if (NULL == repr_gvar) {
98 ERR("icl_representation_to_gvariant() Fail");
99 g_variant_builder_clear(&builder);
102 g_variant_builder_add(&builder, "v", repr_gvar);
105 return g_variant_builder_end(&builder);
109 GVariant* icl_dbus_response_to_gvariant(struct icl_resource_response *response)
115 GVariantBuilder options;
116 gpointer option_id, option_data;
118 g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
119 if (response->header_options) {
120 g_hash_table_iter_init(&iter, response->header_options->hash);
121 while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
122 g_variant_builder_add(&options, "(qs)", GPOINTER_TO_INT(option_id),
127 repr_gvar = icl_representation_to_gvariant(response->repr);
128 if (NULL == repr_gvar) {
129 ERR("icl_representation_to_gvariant() Fail");
130 g_variant_builder_clear(&options);
134 value = g_variant_new("(a(qs)ivxx)",
138 response->oic_request_h,
139 response->oic_resource_h);
145 GVariant* icl_dbus_remote_resource_to_gvariant(struct icl_remote_resource *resource)
151 GVariantBuilder options;
152 gpointer option_id, option_data;
154 g_variant_builder_init(&options, G_VARIANT_TYPE("a(qs)"));
155 if (resource->header_options) {
156 g_hash_table_iter_init(&iter, resource->header_options->hash);
157 while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
158 g_variant_builder_add(&options, "(qs)", GPOINTER_TO_INT(option_id),
163 is_secure = resource->properties & IOTCON_RESOURCE_SECURE;
164 value = g_variant_new("(ssba(qs)i)", resource->uri_path, resource->host_address,
165 is_secure, &options, resource->connectivity_type);
171 GVariant* icl_dbus_device_info_to_gvariant(iotcon_device_info_h device_info)
175 value = g_variant_new("(s)", device_info->device_name);
181 GVariant* icl_dbus_platform_info_to_gvariant(iotcon_platform_info_h platform_info)
185 value = g_variant_new("(sssssssssss)",
186 platform_info->platform_id,
187 platform_info->manuf_name,
188 platform_info->manuf_url,
189 platform_info->model_number,
190 platform_info->date_of_manuf,
191 platform_info->platform_ver,
192 platform_info->os_ver,
193 platform_info->hardware_ver,
194 platform_info->firmware_ver,
195 platform_info->support_url,
196 platform_info->system_time);
202 GVariant* icl_dbus_query_to_gvariant(iotcon_query_h query)
207 GVariantBuilder builder;
209 g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)"));
211 g_hash_table_iter_init(&iter, query->hash);
212 while (g_hash_table_iter_next(&iter, &key, &value))
213 g_variant_builder_add(&builder, "(ss)", key, value);
216 return g_variant_builder_end(&builder);
220 GVariant* icl_dbus_options_to_gvariant(iotcon_options_h options)
223 GVariantBuilder builder;
224 gpointer option_id, option_data;
226 g_variant_builder_init(&builder, G_VARIANT_TYPE("a(qs)"));
228 g_hash_table_iter_init(&iter, options->hash);
229 while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
230 g_variant_builder_add(&builder, "(qs)", GPOINTER_TO_INT(option_id),
235 return g_variant_builder_end(&builder);
239 GVariant* icl_dbus_observers_to_gvariant(iotcon_observers_h observers)
242 GVariantBuilder builder;
244 g_variant_builder_init(&builder, G_VARIANT_TYPE("ai"));
246 for (node = observers->observers_list; node; node = node->next)
247 g_variant_builder_add(&builder, "i", GPOINTER_TO_INT(node->data));
250 return g_variant_builder_end(&builder);