2 * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Suresh Kumar N (suresh.n@samsung.com)
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 #include <zblib_driver.h>
21 #include <zblib_plugin.h>
22 #include <zblib_service.h>
23 #include <zblib_request.h>
25 #include "zblib_driver_service.h"
29 ZblibDriverServiceOps_t *ops; /**< Operations */
30 } ZblibDriverServicePrivData_t;
33 static gboolean __zblib_driver_service_dispatcher(ZigBeeDriver *driver, guint request_id)
35 ZigBeeService *service = NULL;
36 ZblibDriverServicePrivData_t *priv_data = NULL;
37 ZblibDriverServiceOps_t *ops = NULL;
42 zblib_check_null_ret_error("driver", driver, FALSE);
44 service = zblib_driver_ref_service(driver);
45 zblib_check_null_ret_error("service", service, FALSE);
47 /* Fetch private data */
48 priv_data = zblib_driver_ref_object(driver);
49 zblib_check_null_ret_error("priv_data", priv_data, FALSE);
52 zblib_check_null_ret_error("ops", ops, FALSE);
54 /* Fetch request_type using request_id */
55 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
58 ops_id = zblib_request_get_ops_id(request_type);
60 case ZBLIB_SERVICE_OPS_ZB_HW_RESET: {
61 zblib_check_null_ret_error("ops->zb_hw_reset",
62 ops->zb_hw_reset, FALSE);
64 ret = ops->zb_hw_reset(driver, request_id);
68 case ZBLIB_SERVICE_OPS_FORM_NETWORK: {
69 zblib_check_null_ret_error("ops->form_network",
70 ops->form_network, FALSE);
72 ret = ops->form_network(driver, request_id);
76 case ZBLIB_SERVICE_OPS_COEX_START: {
77 zblib_check_null_ret_error("ops->coex_start",
78 ops->coex_start, FALSE);
80 ret = ops->coex_start(driver, request_id);
84 case ZBLIB_SERVICE_OPS_COEX_STOP: {
85 zblib_check_null_ret_error("ops->coex_stop",
86 ops->coex_stop, FALSE);
88 ret = ops->coex_stop(driver, request_id);
92 case ZBLIB_SERVICE_OPS_LEAVE_NETWORK: {
93 zblib_check_null_ret_error("ops->leave_network",
94 ops->leave_network, FALSE);
96 ret = ops->leave_network(driver, request_id);
100 case ZBLIB_SERVICE_OPS_GET_NETWORK_INFO: {
101 zblib_check_null_ret_error("ops->get_network_info",
102 ops->get_network_info, FALSE);
104 ret = ops->get_network_info(driver, request_id);
108 case ZBLIB_SERVICE_OPS_PERMIT_JOIN: {
109 zblib_check_null_ret_error("ops->permit_join",
110 ops->permit_join, FALSE);
112 ret = ops->permit_join(driver, request_id);
116 case ZBLIB_SERVICE_OPS_LEAVE_REQUEST: {
117 zblib_check_null_ret_error("ops->leave_request",
118 ops->leave_request, FALSE);
120 ret = ops->leave_request(driver, request_id);
124 case ZBLIB_SERVICE_OPS_GET_DEVICE_LIST: {
125 zblib_check_null_ret_error("ops->get_device_list",
126 ops->get_device_list, FALSE);
128 ret = ops->get_device_list(driver, request_id);
132 case ZBLIB_SERVICE_OPS_GET_MAC: {
133 zblib_check_null_ret_error("ops->get_mac",
134 ops->get_mac, FALSE);
136 ret = ops->get_mac(driver, request_id);
140 case ZBLIB_SERVICE_OPS_GET_DEVICE_INFO: {
141 zblib_check_null_ret_error("ops->get_device_info",
142 ops->get_device_info, FALSE);
144 ret = ops->get_device_info(driver, request_id);
148 case ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST: {
149 zblib_check_null_ret_error("ops->get_endpoint_list",
150 ops->get_endpoint_list, FALSE);
152 ret = ops->get_endpoint_list(driver, request_id);
156 case ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST: {
157 zblib_check_null_ret_error("ops->get_cluster_list",
158 ops->get_cluster_list, FALSE);
160 ret = ops->get_cluster_list(driver, request_id);
164 case ZBLIB_SERVICE_OPS_GET_NODE_TYPE: {
165 zblib_check_null_ret_error("ops->get_node_type",
166 ops->get_node_type, FALSE);
168 ret = ops->get_node_type(driver, request_id);
176 Z_LOGD("ret: [%d]", ret);
182 static void __zblib_driver_service_free_hook(ZigBeeDriver *driver)
184 ZblibDriverServicePrivData_t *priv_data = NULL;
186 zblib_check_null_ret("driver", driver);
188 /* Fetch private data */
189 priv_data = zblib_driver_ref_object(driver);
190 zblib_check_null_ret("priv_data", priv_data);
196 ZigBeeDriver *zblib_driver_service_new(ZigBeePlugin *plugin,
197 const gchar *driver_name,
198 ZblibDriverServiceOps_t *ops)
200 ZigBeeDriver *driver = NULL;
201 ZigBeeService *service = NULL;
202 ZblibDriverServicePrivData_t *priv_data = NULL;
205 zblib_check_null_ret_error("plugin", plugin, NULL);
207 /* Create new driver */
208 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_SERVICE);
209 zblib_check_null_ret_error("driver", driver, NULL);
211 /* Allocate memory for private data */
212 priv_data = g_malloc0(sizeof(ZblibDriverServicePrivData_t));
214 /* Update private data */
215 priv_data->ops = ops;
217 /* Link service to driver */
218 service = zblib_plugin_ref_service(plugin);
219 if (NULL == service) {
220 /* LCOV_EXCL_START */
221 Z_LOGE("zblib_plugin_ref_service failed!");
223 /* Free allocated resources */
230 zblib_driver_link_service(driver, service);
232 /* Link private data to driver */
233 ret = zblib_driver_link_object(driver, priv_data);
235 /* LCOV_EXCL_START */
236 Z_LOGE("zblib_driver_link_object failed!");
238 /* Free allocated resources */
246 /* Set operations dispatcher function */
247 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_service_dispatcher);
249 /* LCOV_EXCL_START */
250 Z_LOGE("zblib_driver_set_dispatcher failed!");
252 /* Free allocated resources */
260 /* Set free hook function */
261 ret = zblib_driver_set_free_hook(driver, __zblib_driver_service_free_hook);
263 /* LCOV_EXCL_START */
264 Z_LOGE("zblib_driver_set_free_hook failed!");
266 /* Free allocated resources */
271 /* LCOV_EXCL_START */
277 /* LCOV_EXCL_START */
278 void zblib_driver_service_free(ZigBeeDriver *driver)
280 zblib_check_null_ret("driver", driver);
283 zblib_driver_free(driver);