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_query_to_gvariant(iotcon_query_h query)
176 GVariantBuilder builder;
178 g_variant_builder_init(&builder, G_VARIANT_TYPE("a(ss)"));
180 g_hash_table_iter_init(&iter, query->hash);
181 while (g_hash_table_iter_next(&iter, &key, &value))
182 g_variant_builder_add(&builder, "(ss)", key, value);
185 return g_variant_builder_end(&builder);
189 GVariant* icl_dbus_options_to_gvariant(iotcon_options_h options)
192 GVariantBuilder builder;
193 gpointer option_id, option_data;
195 g_variant_builder_init(&builder, G_VARIANT_TYPE("a(qs)"));
197 g_hash_table_iter_init(&iter, options->hash);
198 while (g_hash_table_iter_next(&iter, &option_id, &option_data)) {
199 g_variant_builder_add(&builder, "(qs)", GPOINTER_TO_INT(option_id),
204 return g_variant_builder_end(&builder);
208 GVariant* icl_dbus_observers_to_gvariant(iotcon_observers_h observers)
211 GVariantBuilder builder;
213 g_variant_builder_init(&builder, G_VARIANT_TYPE("ai"));
215 for (node = observers->observers_list; node; node = node->next)
216 g_variant_builder_add(&builder, "i", GPOINTER_TO_INT(node->data));
219 return g_variant_builder_end(&builder);