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"
28 #include "icl-device.h"
31 * @brief The maximum length which can be held in a manufacturer name.
35 #define ICL_MANUFACTURER_NAME_LENGTH_MAX 15
38 * @brief The maximum length which can be held in a manufacturer url.
42 #define ICL_MANUFACTURER_URL_LENGTH_MAX 32
46 iotcon_device_info_cb cb;
52 iotcon_platform_info_cb cb;
55 } icl_platform_info_s;
58 iotcon_tizen_info_cb cb;
63 API int iotcon_device_info_get_property(iotcon_device_info_h device_info,
64 iotcon_device_info_e property, char **value)
66 RETV_IF(NULL == device_info, IOTCON_ERROR_INVALID_PARAMETER);
67 RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
70 case IOTCON_DEVICE_INFO_NAME:
71 *value = device_info->device_name;
73 case IOTCON_DEVICE_INFO_SPEC_VER:
74 *value = device_info->spec_ver;
76 case IOTCON_DEVICE_INFO_ID:
77 *value = device_info->device_id;
79 case IOTCON_DEVICE_INFO_DATA_MODEL_VER:
80 *value = device_info->data_model_ver;
83 ERR("Invalid property(%d)", property);
84 return IOTCON_ERROR_INVALID_PARAMETER;
87 return IOTCON_ERROR_NONE;
90 static void _icl_device_info_cb(GDBusConnection *connection,
91 const gchar *sender_name,
92 const gchar *object_path,
93 const gchar *interface_name,
94 const gchar *signal_name,
99 struct icl_device_info info = {0};
100 icl_device_info_s *cb_container = user_data;
101 iotcon_device_info_cb cb = cb_container->cb;
103 g_variant_get(parameters, "(&s&s&s&s&s)", &uri_path, &info.device_name,
104 &info.spec_ver, &info.device_id, &info.data_model_ver);
106 /* From iotivity, we can get uri_path. But, the value is always "/oic/d". */
109 cb(&info, cb_container->user_data);
113 API int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
116 GError *error = NULL;
118 int ret, signal_number;
119 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
120 icl_device_info_s *cb_container;
122 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
123 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
124 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
126 signal_number = icl_dbus_generate_signal_number();
128 ic_dbus_call_get_device_info_sync(icl_dbus_get_object(), host_address,
129 signal_number, &ret, NULL, &error);
131 ERR("ic_dbus_call_get_device_info_sync() Fail(%s)", error->message);
132 ret = icl_dbus_convert_dbus_error(error->code);
137 if (IOTCON_ERROR_NONE != ret) {
138 ERR("iotcon-daemon Fail(%d)", ret);
139 return icl_dbus_convert_daemon_error(ret);
142 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DEVICE,
145 cb_container = calloc(1, sizeof(icl_device_info_s));
146 if (NULL == cb_container) {
147 ERR("calloc() Fail(%d)", errno);
148 return IOTCON_ERROR_OUT_OF_MEMORY;
151 cb_container->cb = cb;
152 cb_container->user_data = user_data;
154 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
155 _icl_device_info_cb);
157 ERR("icl_dbus_subscribe_signal() Fail");
159 return IOTCON_ERROR_DBUS;
162 cb_container->id = sub_id;
167 API int iotcon_platform_info_get_property(iotcon_platform_info_h platform_info,
168 iotcon_platform_info_e property, char **value)
170 RETV_IF(NULL == platform_info, IOTCON_ERROR_INVALID_PARAMETER);
171 RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
174 case IOTCON_PLATFORM_INFO_ID:
175 *value = platform_info->platform_id;
177 case IOTCON_PLATFORM_INFO_MANUF_NAME:
178 *value = platform_info->manuf_name;
180 case IOTCON_PLATFORM_INFO_MANUF_URL:
181 *value = platform_info->manuf_url;
183 case IOTCON_PLATFORM_INFO_MODEL_NUMBER:
184 *value = platform_info->model_number;
186 case IOTCON_PLATFORM_INFO_DATE_OF_MANUF:
187 *value = platform_info->date_of_manuf;
189 case IOTCON_PLATFORM_INFO_PLATFORM_VER:
190 *value = platform_info->platform_ver;
192 case IOTCON_PLATFORM_INFO_OS_VER:
193 *value = platform_info->os_ver;
195 case IOTCON_PLATFORM_INFO_HARDWARE_VER:
196 *value = platform_info->hardware_ver;
198 case IOTCON_PLATFORM_INFO_FIRMWARE_VER:
199 *value = platform_info->firmware_ver;
201 case IOTCON_PLATFORM_INFO_SUPPORT_URL:
202 *value = platform_info->support_url;
204 case IOTCON_PLATFORM_INFO_SYSTEM_TIME:
205 *value = platform_info->system_time;
208 ERR("Invalid property(%d)", property);
209 return IOTCON_ERROR_INVALID_PARAMETER;
212 return IOTCON_ERROR_NONE;
216 static void _icl_platform_info_cb(GDBusConnection *connection,
217 const gchar *sender_name,
218 const gchar *object_path,
219 const gchar *interface_name,
220 const gchar *signal_name,
221 GVariant *parameters,
225 struct icl_platform_info info = {0};
226 icl_platform_info_s *cb_container = user_data;
227 iotcon_platform_info_cb cb = cb_container->cb;
229 g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
243 /* From iotivity, we can get uri_path. But, the value is always "/oic/p". */
246 cb(&info, cb_container->user_data);
250 API int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
253 GError *error = NULL;
255 int ret, signal_number;
256 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
257 icl_platform_info_s *cb_container;
259 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
260 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
261 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
263 signal_number = icl_dbus_generate_signal_number();
265 ic_dbus_call_get_platform_info_sync(icl_dbus_get_object(), host_address,
266 signal_number, &ret, NULL, &error);
268 ERR("ic_dbus_call_get_platform_info_sync() Fail(%s)", error->message);
269 ret = icl_dbus_convert_dbus_error(error->code);
274 if (IOTCON_ERROR_NONE != ret) {
275 ERR("iotcon-daemon Fail(%d)", ret);
276 return icl_dbus_convert_daemon_error(ret);
279 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PLATFORM,
282 cb_container = calloc(1, sizeof(icl_platform_info_s));
283 if (NULL == cb_container) {
284 ERR("calloc() Fail(%d)", errno);
285 return IOTCON_ERROR_OUT_OF_MEMORY;
288 cb_container->cb = cb;
289 cb_container->user_data = user_data;
291 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
292 _icl_platform_info_cb);
294 ERR("icl_dbus_subscribe_signal() Fail");
296 return IOTCON_ERROR_DBUS;
299 cb_container->id = sub_id;
305 static void _icl_tizen_info_cb(GObject *object, GAsyncResult *g_async_res,
311 char *tizen_device_id;
312 GError *error = NULL;
313 struct icl_tizen_info info = {0};
314 icl_tizen_info_s *cb_container = user_data;
315 iotcon_tizen_info_cb cb = cb_container->cb;
317 ic_dbus_call_get_tizen_info_finish(IC_DBUS(object), &result, g_async_res, &error);
319 ERR("ic_dbus_call_get_tizen_info_finish() Fail(%s)", error->message);
321 cb(&info, IOTCON_ERROR_DBUS, cb_container->user_data);
322 /* TODO contain time out error */
327 g_variant_get(result, "(&s&si)", &device_name, &tizen_device_id, &res);
329 if (IOTCON_ERROR_NONE == res && NULL != ic_utils_dbus_decode_str(tizen_device_id)) {
330 info.device_name = ic_utils_dbus_decode_str(device_name);
331 info.tizen_device_id = tizen_device_id;
335 cb(&info, res, cb_container->user_data);
341 API int iotcon_get_tizen_info(const char *host_address, iotcon_tizen_info_cb cb,
344 icl_tizen_info_s *cb_container;
346 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
347 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
348 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
350 cb_container = calloc(1, sizeof(icl_tizen_info_s));
351 if (NULL == cb_container) {
352 ERR("calloc() Fail(%d)", errno);
353 return IOTCON_ERROR_OUT_OF_MEMORY;
356 cb_container->cb = cb;
357 cb_container->user_data = user_data;
359 ic_dbus_call_get_tizen_info(icl_dbus_get_object(), host_address, NULL,
360 _icl_tizen_info_cb, cb_container);
362 return IOTCON_ERROR_NONE;
366 API int iotcon_tizen_info_get_property(iotcon_tizen_info_h tizen_info,
367 iotcon_tizen_info_e property, char **value)
369 RETV_IF(NULL == tizen_info, IOTCON_ERROR_INVALID_PARAMETER);
370 RETV_IF(NULL == value, IOTCON_ERROR_INVALID_PARAMETER);
373 case IOTCON_TIZEN_INFO_DEVICE_NAME:
374 *value = tizen_info->device_name;
376 case IOTCON_TIZEN_INFO_TIZEN_DEVICE_ID:
377 *value = tizen_info->tizen_device_id;
380 ERR("Invalid property(%d)", property);
381 return IOTCON_ERROR_INVALID_PARAMETER;
384 return IOTCON_ERROR_NONE;