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.
26 #include "icl-dbus-type.h"
28 #ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
30 iotcon_device_info_cb cb;
37 iotcon_platform_info_cb cb;
40 } icl_platform_info_s;
43 #ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
44 /* The length of manufacturer_name should be less than and equal to 16.
45 * The length of manufacturer_url should be less than and equal to 32. */
46 int iotcon_register_device_info(iotcon_device_info_s device_info)
52 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
54 if (device_info.manuf_name
55 && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(device_info.manuf_name))) {
56 ERR("The length of manufacturer_name(%s) is invalid.", device_info.manuf_name);
57 return IOTCON_ERROR_INVALID_PARAMETER;
60 if (device_info.manuf_url
61 && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(device_info.manuf_url))) {
62 ERR("The length of manufacturer_url(%s) is invalid.", device_info.manuf_url);
63 return IOTCON_ERROR_INVALID_PARAMETER;
66 arg_info = icl_dbus_device_info_to_gvariant(&device_info);
67 ic_dbus_call_register_device_info_sync(icl_dbus_get_object(), arg_info, &ret,
70 ERR("ic_dbus_call_register_device_info_sync() Fail(%s)", error->message);
72 g_variant_unref(arg_info);
73 return IOTCON_ERROR_DBUS;
76 if (IOTCON_ERROR_NONE != ret) {
77 ERR("iotcon-daemon Fail(%d)", ret);
78 return icl_dbus_convert_daemon_error(ret);
85 static void _icl_device_info_cb(GDBusConnection *connection,
86 const gchar *sender_name,
87 const gchar *object_path,
88 const gchar *interface_name,
89 const gchar *signal_name,
93 icl_device_info_s *cb_container = user_data;
94 iotcon_device_info_cb cb = cb_container->cb;
96 iotcon_device_info_s info = {0};
98 g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
107 &info.date_of_manufacture,
112 info.name = ic_utils_dbus_decode_str(info.name);
113 info.host_name = ic_utils_dbus_decode_str(info.host_name);
114 info.uuid = ic_utils_dbus_decode_str(info.uuid);
115 info.content_type = ic_utils_dbus_decode_str(info.content_type);
116 info.version = ic_utils_dbus_decode_str(info.version);
117 info.manuf_name = ic_utils_dbus_decode_str(info.manuf_name);
118 info.manuf_url = ic_utils_dbus_decode_str(info.manuf_url);
119 info.model_number = ic_utils_dbus_decode_str(info.model_number);
120 info.date_of_manufacture = ic_utils_dbus_decode_str(info.date_of_manufacture);
121 info.platform_ver = ic_utils_dbus_decode_str(info.platform_ver);
122 info.firmware_ver = ic_utils_dbus_decode_str(info.firmware_ver);
123 info.support_url = ic_utils_dbus_decode_str(info.support_url);
126 cb(info, cb_container->user_data);
130 int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
134 GError *error = NULL;
137 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
138 icl_device_info_s *cb_container;
140 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
141 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
142 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
144 signal_number = icl_dbus_generate_signal_number();
146 ic_dbus_call_get_device_info_sync(icl_dbus_get_object(), host_address,
147 signal_number, &ret, NULL, &error);
149 ERR("ic_dbus_call_get_device_info_sync() Fail(%s)", error->message);
151 return IOTCON_ERROR_DBUS;
154 if (IOTCON_ERROR_NONE != ret) {
155 ERR("iotcon-daemon Fail(%d)", ret);
156 return icl_dbus_convert_daemon_error(ret);
159 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DEVICE,
162 cb_container = calloc(1, sizeof(icl_device_info_container_s));
163 if (NULL == cb_container) {
164 ERR("calloc() Fail(%d)", errno);
165 return IOTCON_ERROR_OUT_OF_MEMORY;
168 cb_container->cb = cb;
169 cb_container->user_data = user_data;
171 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
172 _icl_device_info_cb);
174 ERR("icl_dbus_subscribe_signal() Fail");
175 return IOTCON_ERROR_DBUS;
178 cb_container->id = sub_id;
185 /* The length of manufacturer_name should be less than and equal to 16.
186 * The length of manufacturer_url should be less than and equal to 32. */
187 API int iotcon_register_platform_info(iotcon_platform_info_s platform_info)
190 GError *error = NULL;
193 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
195 if (platform_info.manuf_name
196 && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(platform_info.manuf_name))) {
197 ERR("The length of manufacturer_name(%s) is invalid.", platform_info.manuf_name);
198 return IOTCON_ERROR_INVALID_PARAMETER;
201 if (platform_info.manuf_url
202 && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(platform_info.manuf_url))) {
203 ERR("The length of manufacturer_url(%s) is invalid.", platform_info.manuf_url);
204 return IOTCON_ERROR_INVALID_PARAMETER;
207 arg_info = icl_dbus_platform_info_to_gvariant(&platform_info);
208 ic_dbus_call_register_platform_info_sync(icl_dbus_get_object(), arg_info, &ret,
211 ERR("ic_dbus_call_register_platform_info_sync() Fail(%s)", error->message);
213 g_variant_unref(arg_info);
214 return IOTCON_ERROR_DBUS;
217 if (IOTCON_ERROR_NONE != ret) {
218 ERR("iotcon-daemon Fail(%d)", ret);
219 return icl_dbus_convert_daemon_error(ret);
226 static void _icl_platform_info_cb(GDBusConnection *connection,
227 const gchar *sender_name,
228 const gchar *object_path,
229 const gchar *interface_name,
230 const gchar *signal_name,
231 GVariant *parameters,
234 icl_platform_info_s *cb_container = user_data;
235 iotcon_platform_info_cb cb = cb_container->cb;
237 iotcon_platform_info_s info = {0};
239 g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s)",
244 &info.date_of_manufacture,
252 info.platform_id = ic_utils_dbus_decode_str(info.platform_id);
253 info.manuf_name = ic_utils_dbus_decode_str(info.manuf_name);
254 info.manuf_url = ic_utils_dbus_decode_str(info.manuf_url);
255 info.model_number = ic_utils_dbus_decode_str(info.model_number);
256 info.date_of_manufacture = ic_utils_dbus_decode_str(info.date_of_manufacture);
257 info.platform_ver = ic_utils_dbus_decode_str(info.platform_ver);
258 info.os_ver = ic_utils_dbus_decode_str(info.os_ver);
259 info.hardware_ver = ic_utils_dbus_decode_str(info.hardware_ver);
260 info.firmware_ver = ic_utils_dbus_decode_str(info.firmware_ver);
261 info.support_url = ic_utils_dbus_decode_str(info.support_url);
262 info.system_time = ic_utils_dbus_decode_str(info.system_time);
265 cb(info, cb_container->user_data);
269 API int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
273 GError *error = NULL;
276 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
277 icl_platform_info_s *cb_container;
279 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
280 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
281 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
283 signal_number = icl_dbus_generate_signal_number();
285 ic_dbus_call_get_platform_info_sync(icl_dbus_get_object(), host_address,
286 signal_number, &ret, NULL, &error);
288 ERR("ic_dbus_call_get_platform_info_sync() Fail(%s)", error->message);
290 return IOTCON_ERROR_DBUS;
293 if (IOTCON_ERROR_NONE != ret) {
294 ERR("iotcon-daemon Fail(%d)", ret);
295 return icl_dbus_convert_daemon_error(ret);
298 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PLATFORM,
301 cb_container = calloc(1, sizeof(icl_platform_info_s));
302 if (NULL == cb_container) {
303 ERR("calloc() Fail(%d)", errno);
304 return IOTCON_ERROR_OUT_OF_MEMORY;
307 cb_container->cb = cb;
308 cb_container->user_data = user_data;
310 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
311 _icl_platform_info_cb);
313 ERR("icl_dbus_subscribe_signal() Fail");
314 return IOTCON_ERROR_DBUS;
317 cb_container->id = sub_id;