d80dbf71a4b418d56d5592f07fec7ca237e24e4f
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-service / src / zigbee_service.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 #include <dlog.h>
25
26 #include <zblib.h>
27 #include <zblib_service.h>
28
29 #include "zigbee_service.h"
30
31 #ifndef ZIGBEE_DEFAULT_PLUGINS_PATH
32 #define ZIGBEE_DEFAULT_PLUGINS_PATH "/usr/lib/zigbee/plugins/"
33 #endif
34
35 /* Zigbee service initialization */
36 gboolean zigbee_service_init(ZigBeeService *service)
37 {
38         const char *zigbee_plugin_path = ZIGBEE_DEFAULT_PLUGINS_PATH;
39
40         if (service == NULL) {
41                 Z_LOGE("service is NULL");
42                 return FALSE;
43         }
44
45         /* Load ZigBee plug-ins */
46         if (G_UNLIKELY(TRUE != zblib_service_load_plugins(service, zigbee_plugin_path))) {
47                 Z_LOGE("Load plug-ins failed!");
48                 return FALSE;
49         }
50
51         Z_TIME_CHECK("Loading Plugins Complete");
52
53         /* Initialize ZigBee plug-ins */
54         if (G_UNLIKELY(TRUE != zblib_service_initialize_plugins(service))) {
55                 Z_LOGE("Initialize plug-ins failed!");
56                 return FALSE;
57         }
58
59         Z_TIME_CHECK("Initializing Plugins Complete. Starting Daemon");
60
61         return TRUE;
62 }
63
64 /* Zigbee service de-initialization */
65 void zigbee_service_deinit(ZigBeeService *service)
66 {
67         if (service == NULL) {
68                 Z_LOGE("service is NULL");
69                 return;
70         }
71
72         /* Unload ZigBee plug-ins */
73         if (G_UNLIKELY(TRUE != zblib_service_unload_plugins(service))) {
74                 Z_LOGE("Unload plug-ins failed!");
75                 return;
76         }
77
78         Z_TIME_CHECK("Unload Plugins Complete");
79 }
80