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_request.h>
23 #include "zblib_driver_service.h"
27 ZblibDriverServiceOps_t *ops; /**< Operations */
28 } ZblibDriverServicePrivData_t;
30 static gboolean __zblib_driver_service_dispatcher(ZigBeeDriver *driver, guint request_id)
32 ZigBeeService *service = NULL;
33 ZblibDriverServicePrivData_t *priv_data = NULL;
34 ZblibDriverServiceOps_t *ops = NULL;
39 zblib_check_null_ret_error("driver", driver, FALSE);
41 service = zblib_driver_ref_service(driver);
42 zblib_check_null_ret_error("service", service, FALSE);
44 /* Fetch private data */
45 priv_data = zblib_driver_ref_object(driver);
46 zblib_check_null_ret_error("priv_data", priv_data, FALSE);
49 zblib_check_null_ret_error("ops", ops, FALSE);
51 /* Fetch request_type using request_id */
52 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
55 ops_id = zblib_request_get_ops_id(request_type);
57 case ZBLIB_SERVICE_OPS_ENABLE: {
58 zblib_check_null_ret_error("ops->enable",
61 ret = ops->enable(driver, request_id);
65 case ZBLIB_SERVICE_OPS_DISABLE: {
66 zblib_check_null_ret_error("ops->disable",
69 ret = ops->disable(driver, request_id);
73 case ZBLIB_SERVICE_OPS_ZB_HW_RESET: {
74 zblib_check_null_ret_error("ops->zb_hw_reset",
75 ops->zb_hw_reset, FALSE);
77 ret = ops->zb_hw_reset(driver, request_id);
81 case ZBLIB_SERVICE_OPS_FORM_NETWORK: {
82 zblib_check_null_ret_error("ops->form_network",
83 ops->form_network, FALSE);
85 ret = ops->form_network(driver, request_id);
89 case ZBLIB_SERVICE_OPS_COEX_START: {
90 zblib_check_null_ret_error("ops->coex_start",
91 ops->coex_start, FALSE);
93 ret = ops->coex_start(driver, request_id);
97 case ZBLIB_SERVICE_OPS_COEX_STOP: {
98 zblib_check_null_ret_error("ops->coex_stop",
99 ops->coex_stop, FALSE);
101 ret = ops->coex_stop(driver, request_id);
105 case ZBLIB_SERVICE_OPS_LEAVE_NETWORK: {
106 zblib_check_null_ret_error("ops->leave_network",
107 ops->leave_network, FALSE);
109 ret = ops->leave_network(driver, request_id);
113 case ZBLIB_SERVICE_OPS_GET_NETWORK_INFO: {
114 zblib_check_null_ret_error("ops->get_network_info",
115 ops->get_network_info, FALSE);
117 ret = ops->get_network_info(driver, request_id);
121 case ZBLIB_SERVICE_OPS_PERMIT_JOIN: {
122 zblib_check_null_ret_error("ops->permit_join",
123 ops->permit_join, FALSE);
125 ret = ops->permit_join(driver, request_id);
129 case ZBLIB_SERVICE_OPS_LEAVE_REQUEST: {
130 zblib_check_null_ret_error("ops->leave_request",
131 ops->leave_request, FALSE);
133 ret = ops->leave_request(driver, request_id);
137 case ZBLIB_SERVICE_OPS_GET_DEVICE_LIST: {
138 zblib_check_null_ret_error("ops->get_device_list",
139 ops->get_device_list, FALSE);
141 ret = ops->get_device_list(driver, request_id);
145 case ZBLIB_SERVICE_OPS_GET_MAC: {
146 zblib_check_null_ret_error("ops->get_mac",
147 ops->get_mac, FALSE);
149 ret = ops->get_mac(driver, request_id);
153 case ZBLIB_SERVICE_OPS_GET_DEVICE_INFO: {
154 zblib_check_null_ret_error("ops->get_device_info",
155 ops->get_device_info, FALSE);
157 ret = ops->get_device_info(driver, request_id);
161 case ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST: {
162 zblib_check_null_ret_error("ops->get_endpoint_list",
163 ops->get_endpoint_list, FALSE);
165 ret = ops->get_endpoint_list(driver, request_id);
169 case ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST: {
170 zblib_check_null_ret_error("ops->get_cluster_list",
171 ops->get_cluster_list, FALSE);
173 ret = ops->get_cluster_list(driver, request_id);
177 case ZBLIB_SERVICE_OPS_GET_NODE_TYPE: {
178 zblib_check_null_ret_error("ops->get_node_type",
179 ops->get_node_type, FALSE);
181 ret = ops->get_node_type(driver, request_id);
189 Z_LOGD("ret: [%d]", ret);
194 static void __zblib_driver_service_free_hook(ZigBeeDriver *driver)
196 ZblibDriverServicePrivData_t *priv_data = NULL;
198 zblib_check_null_ret("driver", driver);
200 /* Fetch private data */
201 priv_data = zblib_driver_ref_object(driver);
202 zblib_check_null_ret("priv_data", priv_data);
208 ZigBeeDriver *zblib_driver_service_new(ZigBeePlugin *plugin,
209 const gchar *driver_name,
210 ZblibDriverServiceOps_t *ops)
212 ZigBeeDriver *driver = NULL;
213 ZblibDriverServicePrivData_t *priv_data = NULL;
216 zblib_check_null_ret_error("plugin", plugin, NULL);
218 /* Create new driver */
219 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_SERVICE);
220 zblib_check_null_ret_error("driver", driver, NULL);
222 /* Allocate memory for private data */
223 priv_data = g_malloc0(sizeof(ZblibDriverServicePrivData_t));
225 /* Update private data */
226 priv_data->ops = ops;
228 /* Link private data to driver */
229 ret = zblib_driver_link_object(driver, priv_data);
231 Z_LOGE("zblib_driver_link_object failed!");
233 /* Free allocated resources */
240 /* Set operations dispatcher function */
241 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_service_dispatcher);
243 Z_LOGE("zblib_driver_set_dispatcher failed!");
245 /* Free allocated resources */
252 /* Set free hook function */
253 ret = zblib_driver_set_free_hook(driver, __zblib_driver_service_free_hook);
255 Z_LOGE("zblib_driver_set_free_hook failed!");
257 /* Free allocated resources */
267 void zblib_driver_service_free(ZigBeeDriver *driver)
269 zblib_check_null_ret("driver", driver);
272 zblib_driver_free(driver);