Fix FC when cloning representation
[platform/core/iot/iotcon.git] / test / iotcon-test-device-client.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
17 #include <glib.h>
18 #include <iotcon.h>
19 #include "test.h"
20
21 static void _request_device_info(iotcon_device_info_h info, iotcon_error_e result, void *user_data)
22 {
23         int ret;
24         char *device_name = NULL;
25         char *spec_ver = NULL;
26         char *device_id = NULL;
27         char *data_model_ver = NULL;
28
29         RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result (%d)", result);
30
31         ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_NAME, &device_name);
32         if (IOTCON_ERROR_NONE != ret) {
33                 ERR("iotcon_device_info_get_property() Fail(%d)", ret);
34                 return;
35         }
36
37         ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_SPEC_VER, &spec_ver);
38         if (IOTCON_ERROR_NONE != ret) {
39                 ERR("iotcon_device_info_get_property() Fail(%d)", ret);
40                 return;
41         }
42
43         ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_ID, &device_id);
44         if (IOTCON_ERROR_NONE != ret) {
45                 ERR("iotcon_device_info_get_property() Fail(%d)", ret);
46                 return;
47         }
48
49         ret = iotcon_device_info_get_property(info, IOTCON_DEVICE_INFO_DATA_MODEL_VER,
50                         &data_model_ver);
51         if (IOTCON_ERROR_NONE != ret) {
52                 ERR("iotcon_device_info_get_property() Fail(%d)", ret);
53                 return;
54         }
55
56         INFO("Get Device Info");
57         INFO("device_name : %s", device_name);
58         INFO("spec_version : %s", spec_ver);
59         INFO("device_id : %s", device_id);
60         INFO("data_model_version : %s", data_model_ver);
61 }
62
63 static void _request_platform_info(iotcon_platform_info_h info, iotcon_error_e result, void *user_data)
64 {
65         int ret;
66         char *platform_id = NULL;
67         char *manuf_name = NULL;
68         char *manuf_url = NULL;
69         char *model_number = NULL;
70         char *date_of_manuf = NULL;
71         char *platform_ver = NULL;
72         char *os_ver = NULL;
73         char *hardware_ver = NULL;
74         char *firmware_ver = NULL;
75         char *support_url = NULL;
76         char *system_time = NULL;
77
78         RETM_IF(IOTCON_ERROR_NONE != result, "Invalid result (%d)", result);
79
80         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_ID, &platform_id);
81         if (IOTCON_ERROR_NONE != ret) {
82                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
83                 return;
84         }
85
86         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MANUF_NAME,
87                         &manuf_name);
88         if (IOTCON_ERROR_NONE != ret) {
89                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
90                 return;
91         }
92
93         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MANUF_URL,
94                         &manuf_url);
95         if (IOTCON_ERROR_NONE != ret) {
96                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
97                 return;
98         }
99
100         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_MODEL_NUMBER,
101                         &model_number);
102         if (IOTCON_ERROR_NONE != ret) {
103                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
104                 return;
105         }
106
107         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_DATE_OF_MANUF,
108                         &date_of_manuf);
109         if (IOTCON_ERROR_NONE != ret) {
110                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
111                 return;
112         }
113
114         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_PLATFORM_VER,
115                         &platform_ver);
116         if (IOTCON_ERROR_NONE != ret) {
117                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
118                 return;
119         }
120
121         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_OS_VER, &os_ver);
122         if (IOTCON_ERROR_NONE != ret) {
123                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
124                 return;
125         }
126
127         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_HARDWARE_VER,
128                         &hardware_ver);
129         if (IOTCON_ERROR_NONE != ret) {
130                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
131                 return;
132         }
133
134         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_FIRMWARE_VER,
135                         &firmware_ver);
136         if (IOTCON_ERROR_NONE != ret) {
137                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
138                 return;
139         }
140
141         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_SUPPORT_URL,
142                         &support_url);
143         if (IOTCON_ERROR_NONE != ret) {
144                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
145                 return;
146         }
147
148         ret = iotcon_platform_info_get_property(info, IOTCON_PLATFORM_INFO_SYSTEM_TIME,
149                         &system_time);
150         if (IOTCON_ERROR_NONE != ret) {
151                 ERR("iotcon_platform_info_get_property() Fail(%d)", ret);
152                 return;
153         }
154
155         INFO("Get Platform Info");
156         INFO("platform_id : %s", platform_id);
157         INFO("manuf_name : %s", manuf_name);
158         INFO("manuf_url : %s", manuf_url);
159         INFO("model_number : %s", model_number);
160         INFO("date_of_manufacture : %s", date_of_manuf);
161         INFO("platform_ver : %s", platform_ver);
162         INFO("os_ver : %s", os_ver);
163         INFO("hardware_ver : %s", hardware_ver);
164         INFO("firmware_ver : %s", firmware_ver);
165         INFO("support_url : %s", support_url);
166         INFO("system_time : %s", system_time);
167 }
168
169 int main()
170 {
171         int ret;
172         GMainLoop *loop;
173
174         loop = g_main_loop_new(NULL, FALSE);
175
176         /* connect iotcon */
177         ret = iotcon_connect();
178         if (IOTCON_ERROR_NONE != ret) {
179                 ERR("iotcon_connect() Fail(%d)", ret);
180                 return -1;
181         }
182
183         ret = iotcon_get_device_info(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
184                         _request_device_info, NULL);
185         if (IOTCON_ERROR_NONE != ret) {
186                 ERR("iotcon_get_device_info() Fail(%d)", ret);
187                 iotcon_disconnect();
188                 return -1;
189         }
190
191         ret = iotcon_get_platform_info(IOTCON_MULTICAST_ADDRESS, IOTCON_CONNECTIVITY_IPV4,
192                         _request_platform_info, NULL);
193         if (IOTCON_ERROR_NONE != ret) {
194                 ERR("iotcon_get_platform_info() Fail(%d)", ret);
195                 iotcon_disconnect();
196                 return -1;
197         }
198
199         g_main_loop_run(loop);
200
201         g_main_loop_unref(loop);
202
203         /* disconnect iotcon */
204         iotcon_disconnect();
205
206         return 0;
207 }