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 iotcon_device_info_cb cb;
36 iotcon_platform_info_cb cb;
39 } icl_platform_info_s;
42 API int iotcon_register_device_info(const char *device_name)
48 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
49 RETV_IF(NULL == device_name, IOTCON_ERROR_INVALID_PARAMETER);
51 arg_info = icl_dbus_device_info_to_gvariant(device_name);
52 ic_dbus_call_register_device_info_sync(icl_dbus_get_object(), arg_info, &ret,
55 ERR("ic_dbus_call_register_device_info_sync() Fail(%s)", error->message);
57 g_variant_unref(arg_info);
58 return IOTCON_ERROR_DBUS;
61 if (IOTCON_ERROR_NONE != ret) {
62 ERR("iotcon-daemon Fail(%d)", ret);
63 return icl_dbus_convert_daemon_error(ret);
70 static void _icl_device_info_cb(GDBusConnection *connection,
71 const gchar *sender_name,
72 const gchar *object_path,
73 const gchar *interface_name,
74 const gchar *signal_name,
78 icl_device_info_s *cb_container = user_data;
79 iotcon_device_info_cb cb = cb_container->cb;
80 char *device_name, *sid, *spec_version, *data_model_version;
82 g_variant_get(parameters, "(&s&s&s&s)", &device_name, &sid, &spec_version,
86 cb(device_name, sid, spec_version, data_model_version, cb_container->user_data);
90 API int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
97 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
98 icl_device_info_s *cb_container;
100 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
101 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
102 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
104 signal_number = icl_dbus_generate_signal_number();
106 ic_dbus_call_get_device_info_sync(icl_dbus_get_object(), host_address,
107 signal_number, &ret, NULL, &error);
109 ERR("ic_dbus_call_get_device_info_sync() Fail(%s)", error->message);
111 return IOTCON_ERROR_DBUS;
114 if (IOTCON_ERROR_NONE != ret) {
115 ERR("iotcon-daemon Fail(%d)", ret);
116 return icl_dbus_convert_daemon_error(ret);
119 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_DEVICE,
122 cb_container = calloc(1, sizeof(icl_device_info_s));
123 if (NULL == cb_container) {
124 ERR("calloc() Fail(%d)", errno);
125 return IOTCON_ERROR_OUT_OF_MEMORY;
128 cb_container->cb = cb;
129 cb_container->user_data = user_data;
131 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
132 _icl_device_info_cb);
134 ERR("icl_dbus_subscribe_signal() Fail");
135 return IOTCON_ERROR_DBUS;
138 cb_container->id = sub_id;
144 /* The length of manufacturer_name should be less than and equal to 16.
145 * The length of manufacturer_url should be less than and equal to 32. */
146 API int iotcon_register_platform_info(iotcon_platform_info_s platform_info)
149 GError *error = NULL;
152 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
154 if (NULL == platform_info.platform_id
155 || NULL == platform_info.manuf_name
156 || NULL == platform_info.manuf_url
157 || NULL == platform_info.model_number
158 || NULL == platform_info.date_of_manufacture
159 || NULL == platform_info.platform_ver
160 || NULL == platform_info.os_ver
161 || NULL == platform_info.hardware_ver
162 || NULL == platform_info.firmware_ver
163 || NULL == platform_info.support_url
164 || NULL == platform_info.system_time) {
165 ERR("one of parameter is NULL");
166 return IOTCON_ERROR_INVALID_PARAMETER;
169 if (platform_info.manuf_name
170 && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(platform_info.manuf_name))) {
171 ERR("The length of manufacturer_name(%s) is invalid.", platform_info.manuf_name);
172 return IOTCON_ERROR_INVALID_PARAMETER;
175 if (platform_info.manuf_url
176 && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(platform_info.manuf_url))) {
177 ERR("The length of manufacturer_url(%s) is invalid.", platform_info.manuf_url);
178 return IOTCON_ERROR_INVALID_PARAMETER;
181 arg_info = icl_dbus_platform_info_to_gvariant(&platform_info);
182 ic_dbus_call_register_platform_info_sync(icl_dbus_get_object(), arg_info, &ret,
185 ERR("ic_dbus_call_register_platform_info_sync() Fail(%s)", error->message);
187 g_variant_unref(arg_info);
188 return IOTCON_ERROR_DBUS;
191 if (IOTCON_ERROR_NONE != ret) {
192 ERR("iotcon-daemon Fail(%d)", ret);
193 return icl_dbus_convert_daemon_error(ret);
200 static void _icl_platform_info_cb(GDBusConnection *connection,
201 const gchar *sender_name,
202 const gchar *object_path,
203 const gchar *interface_name,
204 const gchar *signal_name,
205 GVariant *parameters,
209 iotcon_platform_info_s info = {0};
210 icl_platform_info_s *cb_container = user_data;
211 iotcon_platform_info_cb cb = cb_container->cb;
213 g_variant_get(parameters, "(&s&s&s&s&s&s&s&s&s&s&s&s)",
219 &info.date_of_manufacture,
227 /* From iotivity, we can get uri_path. But, the value is always "/oic/p". */
230 cb(info, cb_container->user_data);
234 API int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
238 GError *error = NULL;
241 char signal_name[IC_DBUS_SIGNAL_LENGTH] = {0};
242 icl_platform_info_s *cb_container;
244 RETV_IF(NULL == icl_dbus_get_object(), IOTCON_ERROR_DBUS);
245 RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
246 RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
248 signal_number = icl_dbus_generate_signal_number();
250 ic_dbus_call_get_platform_info_sync(icl_dbus_get_object(), host_address,
251 signal_number, &ret, NULL, &error);
253 ERR("ic_dbus_call_get_platform_info_sync() Fail(%s)", error->message);
255 return IOTCON_ERROR_DBUS;
258 if (IOTCON_ERROR_NONE != ret) {
259 ERR("iotcon-daemon Fail(%d)", ret);
260 return icl_dbus_convert_daemon_error(ret);
263 snprintf(signal_name, sizeof(signal_name), "%s_%u", IC_DBUS_SIGNAL_PLATFORM,
266 cb_container = calloc(1, sizeof(icl_platform_info_s));
267 if (NULL == cb_container) {
268 ERR("calloc() Fail(%d)", errno);
269 return IOTCON_ERROR_OUT_OF_MEMORY;
272 cb_container->cb = cb;
273 cb_container->user_data = user_data;
275 sub_id = icl_dbus_subscribe_signal(signal_name, cb_container, free,
276 _icl_platform_info_cb);
278 ERR("icl_dbus_subscribe_signal() Fail");
279 return IOTCON_ERROR_DBUS;
282 cb_container->id = sub_id;