Request ID (skeleton)
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-lib / src / drivers / zblib_driver_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 <zblib.h>
20 #include <zblib_driver.h>
21 #include <zblib_request.h>
22
23 #include "zblib_driver_service.h"
24
25 /**< Private data */
26 typedef struct {
27         ZblibDriverServiceOps_t *ops; /**< Operations */
28 } ZblibDriverServicePrivData_t;
29
30 static gboolean __zblib_driver_service_dispatcher(ZigBeeDriver *driver, guint request_id)
31 {
32         ZigBeeService *service = NULL;
33         guint request_type;
34         guint ops_id;
35
36         if (NULL == driver) {
37                 Z_LOGE("driver is NULL");
38                 return FALSE;
39         }
40
41         service = zblib_driver_ref_service(driver);
42         if (NULL == service) {
43                 Z_LOGE("service is NULL");
44                 return FALSE;
45         }
46
47         /* Fetch request_type using request_id */
48         request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
49
50         /* Fetch ops ID */
51         ops_id = zblib_request_get_ops_id(request_type);
52         switch (ops_id) {
53         case ZBLIB_SERVICE_OPS_ENABLE: {
54         }
55         break;
56
57         case ZBLIB_SERVICE_OPS_DISABLE: {
58         }
59         break;
60
61         case ZBLIB_SERVICE_OPS_ZB_HW_RESET: {
62         }
63         break;
64
65         case ZBLIB_SERVICE_OPS_FORM_NETWORK: {
66         }
67         break;
68
69         case ZBLIB_SERVICE_OPS_COEX_START: {
70         }
71         break;
72
73         case ZBLIB_SERVICE_OPS_COEX_STOP: {
74         }
75         break;
76
77         case ZBLIB_SERVICE_OPS_LEAVE_NETWORK: {
78         }
79         break;
80
81         case ZBLIB_SERVICE_OPS_GET_NETWORK_INFO: {
82         }
83         break;
84
85         case ZBLIB_SERVICE_OPS_PERMIT_JOIN: {
86         }
87         break;
88
89         case ZBLIB_SERVICE_OPS_LEAVE_REQUEST: {
90         }
91         break;
92
93         case ZBLIB_SERVICE_OPS_GET_DEVICE_LIST: {
94         }
95         break;
96
97         case ZBLIB_SERVICE_OPS_GET_MAC: {
98         }
99         break;
100
101         case ZBLIB_SERVICE_OPS_GET_DEVICE_INFO: {
102         }
103         break;
104
105         case ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST: {
106         }
107         break;
108
109         case ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST: {
110         }
111         break;
112
113         case ZBLIB_SERVICE_OPS_GET_NODE_TYPE: {
114         }
115         break;
116
117         default:
118         break;
119         }
120
121         return TRUE;
122 }
123
124 static void __zblib_driver_service_free_hook(ZigBeeDriver *driver)
125 {
126         ZblibDriverServicePrivData_t *priv_data = NULL;
127
128         if (NULL == driver) {
129                 Z_LOGE("driver is NULL");
130                 return;
131         }
132
133         /* Fetch private data */
134         priv_data = zblib_driver_ref_object(driver);
135         if (NULL == priv_data) {
136                 Z_LOGE("priv_data is NULL");
137                 return;
138         }
139
140         /* Free resources */
141         g_free(priv_data);
142 }
143
144 ZigBeeDriver *zblib_driver_service_new(ZigBeePlugin *plugin,
145         const gchar *driver_name,
146         ZblibDriverServiceOps_t *ops)
147 {
148         ZigBeeDriver *driver = NULL;
149         ZblibDriverServicePrivData_t *priv_data = NULL;
150         gboolean ret;
151
152         if (NULL == plugin) {
153                 Z_LOGE("plugin is NULL");
154                 return NULL;
155         }
156
157         /* Create new driver */
158         driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_SERVICE);
159         if (NULL == driver) {
160                 Z_LOGE("driver is NULL");
161                 return NULL;
162         }
163
164         /* Allocate memory for private data */
165         priv_data = g_malloc0(sizeof(ZblibDriverServicePrivData_t));
166
167         /* Update private data */
168         priv_data->ops = ops;
169
170         /* Link private data to driver */
171         ret = zblib_driver_link_object(driver, priv_data);
172         if (FALSE == ret) {
173                 Z_LOGE("zblib_driver_link_object failed!");
174
175                 /* Free allocated resources */
176                 g_free(priv_data);
177                 g_free(driver);
178
179                 return NULL;
180         }
181
182         /* Set operations dispatcher function */
183         ret = zblib_driver_set_dispatcher(driver, __zblib_driver_service_dispatcher);
184         if (FALSE == ret) {
185                 Z_LOGE("zblib_driver_set_dispatcher failed!");
186
187                 /* Free allocated resources */
188                 g_free(priv_data);
189                 g_free(driver);
190
191                 return NULL;
192         }
193
194         /* Set free hook function */
195         ret = zblib_driver_set_free_hook(driver, __zblib_driver_service_free_hook);
196         if (FALSE == ret) {
197                 Z_LOGE("zblib_driver_set_free_hook failed!");
198
199                 /* Free allocated resources */
200                 g_free(priv_data);
201                 g_free(driver);
202
203                 return NULL;
204         }
205
206         return driver;
207 }
208
209 void zblib_driver_service_free(ZigBeeDriver *driver)
210 {
211         if (NULL == driver) {
212                 Z_LOGE("driver is NULL");
213                 return;
214         }
215
216         /* Free driver */
217         zblib_driver_free(driver);
218 }