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"
30 * @brief The maximum length which can be held in a manufacturer name.
34 #define ICL_MANUFACTURER_NAME_LENGTH_MAX 15
37 * @brief The maximum length which can be held in a manufacturer url.
41 #define ICL_MANUFACTURER_URL_LENGTH_MAX 32
45 iotcon_device_info_cb cb;
51 iotcon_platform_info_cb cb;
54 } icl_platform_info_s;
57 API int iotcon_register_device_info(const char *device_name)
63 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
64 RETV_IF(NULL == device_name, IOTCON_ERROR_INVALID_PARAMETER);
66 arg_info = icl_dbus_device_info_to_gvariant(device_name);
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);
71 error_code = icl_dbus_convert_dbus_error(error->code);
73 g_variant_unref(arg_info);
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;
96 char *device_name, *sid, *spec_version, *data_model_version;
98 g_variant_get(parameters, "(&s&s&s&s)", &device_name, &sid, &spec_version,
102 cb(device_name, sid, spec_version, data_model_version, cb_container->user_data);
106 API int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
109 GError *error = NULL;
111 int ret, signal_number, error_code;
112 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
113 icl_device_info_s *cb_container;
115 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
116 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
117 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
119 signal_number = icl_dbus_generate_signal_number();
121 ic_dbus_call_get_device_info_sync(icl_dbus_get_object(), host_address,
122 signal_number, &ret, NULL, &error);
124 ERR("ic_dbus_call_get_device_info_sync() Fail(%s)", error->message);
125 error_code = icl_dbus_convert_dbus_error(error->code);
130 if (IOTCON_ERROR_NONE != ret) {
131 ERR("iotcon-daemon Fail(%d)", ret);
132 return icl_dbus_convert_daemon_error(ret);
135 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DEVICE,
138 cb_container = calloc(1, sizeof(icl_device_info_s));
139 if (NULL == cb_container) {
140 ERR("calloc() Fail(%d)", errno);
141 return IOTCON_ERROR_OUT_OF_MEMORY;
144 cb_container->cb = cb;
145 cb_container->user_data = user_data;
147 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
148 _icl_device_info_cb);
150 ERR("icl_dbus_subscribe_signal() Fail");
151 return IOTCON_ERROR_DBUS;
154 cb_container->id = sub_id;
160 /* The length of manufacturer_name should be less than and equal to 16.
161 * The length of manufacturer_url should be less than and equal to 32. */
162 API int iotcon_register_platform_info(iotcon_platform_info_s *platform_info)
165 GError *error = NULL;
168 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
170 if (NULL == platform_info->platform_id
171 || NULL == platform_info->manuf_name
172 || NULL == platform_info->manuf_url
173 || NULL == platform_info->model_number
174 || NULL == platform_info->date_of_manufacture
175 || NULL == platform_info->platform_ver
176 || NULL == platform_info->os_ver
177 || NULL == platform_info->hardware_ver
178 || NULL == platform_info->firmware_ver
179 || NULL == platform_info->support_url
180 || NULL == platform_info->system_time) {
181 ERR("one of parameter is NULL");
182 return IOTCON_ERROR_INVALID_PARAMETER;
185 if (platform_info->manuf_name
186 && (ICL_MANUFACTURER_NAME_LENGTH_MAX < strlen(platform_info->manuf_name))) {
187 ERR("The length of manufacturer_name(%s) is invalid.", platform_info->manuf_name);
188 return IOTCON_ERROR_INVALID_PARAMETER;
191 if (platform_info->manuf_url
192 && (ICL_MANUFACTURER_URL_LENGTH_MAX < strlen(platform_info->manuf_url))) {
193 ERR("The length of manufacturer_url(%s) is invalid.", platform_info->manuf_url);
194 return IOTCON_ERROR_INVALID_PARAMETER;
197 arg_info = icl_dbus_platform_info_to_gvariant(platform_info);
198 ic_dbus_call_register_platform_info_sync(icl_dbus_get_object(), arg_info, &ret,
201 ERR("ic_dbus_call_register_platform_info_sync() Fail(%s)", error->message);
202 error_code = icl_dbus_convert_dbus_error(error->code);
204 g_variant_unref(arg_info);
208 if (IOTCON_ERROR_NONE != ret) {
209 ERR("iotcon-daemon Fail(%d)", ret);
210 return icl_dbus_convert_daemon_error(ret);
217 static void _icl_platform_info_cb(GDBusConnection *connection,
218 const gchar *sender_name,
219 const gchar *object_path,
220 const gchar *interface_name,
221 const gchar *signal_name,
222 GVariant *parameters,
226 iotcon_platform_info_s *info = calloc(1, sizeof(iotcon_platform_info_s));
227 icl_platform_info_s *cb_container = user_data;
228 iotcon_platform_info_cb cb = cb_container->cb;
230 g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
236 &info->date_of_manufacture,
244 /* From iotivity, we can get uri_path. But, the value is always "/oic/p". */
247 cb(info, cb_container->user_data);
251 API int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
254 GError *error = NULL;
256 int ret, signal_number, error_code;
257 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
258 icl_platform_info_s *cb_container;
260 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
261 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
262 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
264 signal_number = icl_dbus_generate_signal_number();
266 ic_dbus_call_get_platform_info_sync(icl_dbus_get_object(), host_address,
267 signal_number, &ret, NULL, &error);
269 ERR("ic_dbus_call_get_platform_info_sync() Fail(%s)", error->message);
270 error_code = icl_dbus_convert_dbus_error(error->code);
275 if (IOTCON_ERROR_NONE != ret) {
276 ERR("iotcon-daemon Fail(%d)", ret);
277 return icl_dbus_convert_daemon_error(ret);
280 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PLATFORM,
283 cb_container = calloc(1, sizeof(icl_platform_info_s));
284 if (NULL == cb_container) {
285 ERR("calloc() Fail(%d)", errno);
286 return IOTCON_ERROR_OUT_OF_MEMORY;
289 cb_container->cb = cb;
290 cb_container->user_data = user_data;
292 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
293 _icl_platform_info_cb);
295 ERR("icl_dbus_subscribe_signal() Fail");
296 return IOTCON_ERROR_DBUS;
299 cb_container->id = sub_id;