Base patch (skeleton code)
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / src / main.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Contact: Suresh Kumar N (suresh.n@samsung.com)
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <glib.h>
24
25 #include <zblib.h>
26 #include <zblib_service.h>
27 #include <zblib_plugin.h>
28
29 #include <zigbee_service_interface.h>
30 #include <zigbee_service.h>
31
32 #define NOTUSED(var) (var = var)
33
34 /**< ZigBee Service */
35 ZigBeeService *zigbee_service;
36
37 int main(int arg, char **argv)
38 {
39         ZigBeeService *service = NULL;
40         int ret_code = 0;
41         gboolean ret;
42
43 #if !GLIB_CHECK_VERSION(2, 35, 0)
44         g_type_init();
45 #endif
46 #if !GLIB_CHECK_VERSION(2, 31, 0)
47         g_thread_init(NULL);
48 #endif
49         NOTUSED(arg);
50         NOTUSED(argv);
51
52         Z_LOGI("service mainloop start");
53
54         /* Create ZigBee service */
55         zigbee_service = service = zblib_service_new();
56
57         /* Initialize ZigBee service interface layer */
58         ret = zigbee_service_interface_init(service);
59         if (G_UNLIKELY(FALSE == ret)) {
60                 Z_LOGE("zigbee_service_interface_init failed!");
61                 goto END;
62         }
63
64         /* Initialize ZigBee service */
65         ret = zigbee_service_init(service);
66         if (G_UNLIKELY(FALSE == ret)) {
67                 Z_LOGE("zigbee_service_init failed!");
68                 goto END;
69         }
70
71         /* Run ZigBee service */
72         ret = zblib_service_run(service);
73         if (G_UNLIKELY(FALSE == ret)) {
74                 Z_LOGE("Run service failed!");
75                 ret_code = EXIT_FAILURE;
76         }
77
78 END:
79         /* De-initialize ZigBee service */
80         zigbee_service_deinit(service);
81
82         /* De-initialize ZigBee service interface layer */
83         zigbee_service_interface_deinit(service);
84
85         /* Free ZigBee service */
86         zblib_service_free(service);
87         zigbee_service = NULL;
88
89         return ret_code;
90 }