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.
27 #include "icl-dbus-type.h"
29 #ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
31 iotcon_device_info_cb cb;
38 iotcon_platform_info_cb cb;
41 } icl_platform_info_s;
44 #ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
45 /* The length of manufacturer_name should be less than and equal to 16.
46 * The length of manufacturer_url should be less than and equal to 32. */
47 int iotcon_register_device_info(iotcon_device_info_s device_info)
53 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
55 if (device_info.manuf_name
56 && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(device_info.manuf_name))) {
57 ERR("The length of manufacturer_name(%s) is invalid.", device_info.manuf_name);
58 return IOTCON_ERROR_INVALID_PARAMETER;
61 if (device_info.manuf_url
62 && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(device_info.manuf_url))) {
63 ERR("The length of manufacturer_url(%s) is invalid.", device_info.manuf_url);
64 return IOTCON_ERROR_INVALID_PARAMETER;
67 arg_info = icl_dbus_device_info_to_gvariant(&device_info);
68 ic_dbus_call_register_device_info_sync(icl_dbus_get_object(), arg_info, &ret,
71 ERR("ic_dbus_call_register_device_info_sync() Fail(%s)", error->message);
73 g_variant_unref(arg_info);
74 return IOTCON_ERROR_DBUS;
77 if (IOTCON_ERROR_NONE != ret) {
78 ERR("iotcon-daemon Fail(%d)", ret);
79 return icl_dbus_convert_daemon_error(ret);
86 static void _icl_device_info_cb(GDBusConnection *connection,
87 const gchar *sender_name,
88 const gchar *object_path,
89 const gchar *interface_name,
90 const gchar *signal_name,
94 icl_device_info_s *cb_container = user_data;
95 iotcon_device_info_cb cb = cb_container->cb;
97 iotcon_device_info_s info = {0};
99 g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
108 &info.date_of_manufacture,
113 info.name = ic_utils_dbus_decode_str(info.name);
114 info.host_name = ic_utils_dbus_decode_str(info.host_name);
115 info.uuid = ic_utils_dbus_decode_str(info.uuid);
116 info.content_type = ic_utils_dbus_decode_str(info.content_type);
117 info.version = ic_utils_dbus_decode_str(info.version);
118 info.manuf_name = ic_utils_dbus_decode_str(info.manuf_name);
119 info.manuf_url = ic_utils_dbus_decode_str(info.manuf_url);
120 info.model_number = ic_utils_dbus_decode_str(info.model_number);
121 info.date_of_manufacture = ic_utils_dbus_decode_str(info.date_of_manufacture);
122 info.platform_ver = ic_utils_dbus_decode_str(info.platform_ver);
123 info.firmware_ver = ic_utils_dbus_decode_str(info.firmware_ver);
124 info.support_url = ic_utils_dbus_decode_str(info.support_url);
127 cb(info, cb_container->user_data);
131 int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
135 GError *error = NULL;
138 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
139 icl_device_info_s *cb_container;
141 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
142 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
143 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
145 signal_number = icl_dbus_generate_signal_number();
147 ic_dbus_call_get_device_info_sync(icl_dbus_get_object(), host_address,
148 signal_number, &ret, NULL, &error);
150 ERR("ic_dbus_call_get_device_info_sync() Fail(%s)", error->message);
152 return IOTCON_ERROR_DBUS;
155 if (IOTCON_ERROR_NONE != ret) {
156 ERR("iotcon-daemon Fail(%d)", ret);
157 return icl_dbus_convert_daemon_error(ret);
160 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DEVICE,
163 cb_container = calloc(1, sizeof(icl_device_info_container_s));
164 if (NULL == cb_container) {
165 ERR("calloc() Fail(%d)", errno);
166 return IOTCON_ERROR_OUT_OF_MEMORY;
169 cb_container->cb = cb;
170 cb_container->user_data = user_data;
172 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
173 _icl_device_info_cb);
175 ERR("icl_dbus_subscribe_signal() Fail");
176 return IOTCON_ERROR_DBUS;
179 cb_container->id = sub_id;
186 /* The length of manufacturer_name should be less than and equal to 16.
187 * The length of manufacturer_url should be less than and equal to 32. */
188 API int iotcon_register_platform_info(iotcon_platform_info_s platform_info)
191 GError *error = NULL;
194 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
196 if (NULL == platform_info.platform_id
197 || NULL == platform_info.manuf_name
198 || NULL == platform_info.manuf_url
199 || NULL == platform_info.model_number
200 || NULL == platform_info.date_of_manufacture
201 || NULL == platform_info.platform_ver
202 || NULL == platform_info.os_ver
203 || NULL == platform_info.hardware_ver
204 || NULL == platform_info.firmware_ver
205 || NULL == platform_info.support_url
206 || NULL == platform_info.system_time) {
207 ERR("one of parameter is NULL");
208 return IOTCON_ERROR_INVALID_PARAMETER;
211 if (platform_info.manuf_name
212 && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(platform_info.manuf_name))) {
213 ERR("The length of manufacturer_name(%s) is invalid.", platform_info.manuf_name);
214 return IOTCON_ERROR_INVALID_PARAMETER;
217 if (platform_info.manuf_url
218 && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(platform_info.manuf_url))) {
219 ERR("The length of manufacturer_url(%s) is invalid.", platform_info.manuf_url);
220 return IOTCON_ERROR_INVALID_PARAMETER;
223 arg_info = icl_dbus_platform_info_to_gvariant(&platform_info);
224 ic_dbus_call_register_platform_info_sync(icl_dbus_get_object(), arg_info, &ret,
227 ERR("ic_dbus_call_register_platform_info_sync() Fail(%s)", error->message);
229 g_variant_unref(arg_info);
230 return IOTCON_ERROR_DBUS;
233 if (IOTCON_ERROR_NONE != ret) {
234 ERR("iotcon-daemon Fail(%d)", ret);
235 return icl_dbus_convert_daemon_error(ret);
242 static void _icl_platform_info_cb(GDBusConnection *connection,
243 const gchar *sender_name,
244 const gchar *object_path,
245 const gchar *interface_name,
246 const gchar *signal_name,
247 GVariant *parameters,
251 char *repr_json = NULL;
253 icl_platform_info_s *cb_container = user_data;
254 iotcon_platform_info_cb cb = cb_container->cb;
256 g_variant_get(parameters, "(&s)", &repr_json);
257 if (IC_STR_EQUAL == strcmp(IC_STR_NULL, repr_json)) {
258 ERR("Invalid Representation");
262 repr = icl_repr_create_repr(repr_json);
265 cb(repr, cb_container->user_data);
267 iotcon_repr_free(repr);
271 API int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
275 GError *error = NULL;
278 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
279 icl_platform_info_s *cb_container;
281 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
282 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
283 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
285 signal_number = icl_dbus_generate_signal_number();
287 ic_dbus_call_get_platform_info_sync(icl_dbus_get_object(), host_address,
288 signal_number, &ret, NULL, &error);
290 ERR("ic_dbus_call_get_platform_info_sync() Fail(%s)", error->message);
292 return IOTCON_ERROR_DBUS;
295 if (IOTCON_ERROR_NONE != ret) {
296 ERR("iotcon-daemon Fail(%d)", ret);
297 return icl_dbus_convert_daemon_error(ret);
300 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PLATFORM,
303 cb_container = calloc(1, sizeof(icl_platform_info_s));
304 if (NULL == cb_container) {
305 ERR("calloc() Fail(%d)", errno);
306 return IOTCON_ERROR_OUT_OF_MEMORY;
309 cb_container->cb = cb;
310 cb_container->user_data = user_data;
312 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
313 _icl_platform_info_cb);
315 ERR("icl_dbus_subscribe_signal() Fail");
316 return IOTCON_ERROR_DBUS;
319 cb_container->id = sub_id;