migration to iotivity ver 0.9.1
[platform/core/iot/iotcon.git] / lib / icl-device.c
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 #include <stdlib.h>
17 #include <string.h>
18 #include <errno.h>
19 #include <glib.h>
20
21 #include "iotcon.h"
22 #include "icl.h"
23 #include "icl-ioty.h"
24 #include "icl-dbus.h"
25
26 #ifdef DEVICE_INFO_IMPL /* not implemented in iotivity 0.9.1 */
27 /* The length of manufacturer_name should be less than and equal to 16.
28  * The length of manufacturer_url should be less than and equal to 32. */
29 int iotcon_register_device_info(iotcon_device_info_s device_info)
30 {
31         int ret;
32
33         if (device_info.manuf_name
34                         && (IOTCON_MANUFACTURER_NAME_LENGTH_MAX < strlen(device_info.manuf_name))) {
35                 ERR("The length of manufacturer_name(%s) is invalid.", device_info.manuf_name);
36                 return IOTCON_ERROR_INVALID_PARAMETER;
37         }
38
39         if (device_info.manuf_url
40                         && (IOTCON_MANUFACTURER_URL_LENGTH_MAX < strlen(device_info.manuf_url))) {
41                 ERR("The length of manufacturer_url(%s) is invalid.", device_info.manuf_url);
42                 return IOTCON_ERROR_INVALID_PARAMETER;
43         }
44
45         ret = icl_dbus_register_device_info(device_info);
46         if (IOTCON_ERROR_NONE != ret)
47                 ERR("icl_dbus_register_device_info() Fail(%d)", ret);
48
49         return ret;
50 }
51
52 int iotcon_get_device_info(const char *host_address, iotcon_device_info_cb cb,
53                 void *user_data)
54 {
55         int ret = IOTCON_ERROR_NONE;
56
57         RETV_IF(NULL == host_address, IOTCON_ERROR_INVALID_PARAMETER);
58         RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
59
60         ret = icl_dbus_get_device_info(host_address, cb, user_data);
61         if (IOTCON_ERROR_NONE != ret) {
62                 ERR("icl_dbus_get_device_info() Fail(%d)", ret);
63                 return ret;
64         }
65
66         return IOTCON_ERROR_NONE;
67 }
68 #endif
69
70 API int iotcon_register_platform_info(iotcon_platform_info_s platform_info)
71 {
72         int ret;
73
74         ret = icl_dbus_register_platform_info(platform_info);
75         if (IOTCON_ERROR_NONE != ret)
76                 ERR("ic_ioty_register_platform_info() Fail(%d)", ret);
77
78         return ret;
79 }
80
81
82 API int iotcon_get_platform_info(const char *host_address, iotcon_platform_info_cb cb,
83                 void *user_data)
84 {
85         int ret = IOTCON_ERROR_NONE;
86
87         RETV_IF(NULL == cb, IOTCON_ERROR_INVALID_PARAMETER);
88
89         ret = icl_dbus_get_platform_info(host_address, cb, user_data);
90         if (IOTCON_ERROR_NONE != ret) {
91                 ERR("ic_ioty_get_platform_info() Fail(%d)", ret);
92                 return ret;
93         }
94
95         return IOTCON_ERROR_NONE;
96 }