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;
37 Z_LOGE("driver is NULL");
41 service = zblib_driver_ref_service(driver);
42 if (NULL == service) {
43 Z_LOGE("service is NULL");
47 /* Fetch request_type using request_id */
48 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
51 ops_id = zblib_request_get_ops_id(request_type);
53 case ZBLIB_SERVICE_OPS_ENABLE: {
57 case ZBLIB_SERVICE_OPS_DISABLE: {
61 case ZBLIB_SERVICE_OPS_ZB_HW_RESET: {
65 case ZBLIB_SERVICE_OPS_FORM_NETWORK: {
69 case ZBLIB_SERVICE_OPS_COEX_START: {
73 case ZBLIB_SERVICE_OPS_COEX_STOP: {
77 case ZBLIB_SERVICE_OPS_LEAVE_NETWORK: {
81 case ZBLIB_SERVICE_OPS_GET_NETWORK_INFO: {
85 case ZBLIB_SERVICE_OPS_PERMIT_JOIN: {
89 case ZBLIB_SERVICE_OPS_LEAVE_REQUEST: {
93 case ZBLIB_SERVICE_OPS_GET_DEVICE_LIST: {
97 case ZBLIB_SERVICE_OPS_GET_MAC: {
101 case ZBLIB_SERVICE_OPS_GET_DEVICE_INFO: {
105 case ZBLIB_SERVICE_OPS_GET_ENDPOINT_LIST: {
109 case ZBLIB_SERVICE_OPS_GET_CLUSTER_LIST: {
113 case ZBLIB_SERVICE_OPS_GET_NODE_TYPE: {
124 static void __zblib_driver_service_free_hook(ZigBeeDriver *driver)
126 ZblibDriverServicePrivData_t *priv_data = NULL;
128 if (NULL == driver) {
129 Z_LOGE("driver is NULL");
133 /* Fetch private data */
134 priv_data = zblib_driver_ref_object(driver);
135 if (NULL == priv_data) {
136 Z_LOGE("priv_data is NULL");
144 ZigBeeDriver *zblib_driver_service_new(ZigBeePlugin *plugin,
145 const gchar *driver_name,
146 ZblibDriverServiceOps_t *ops)
148 ZigBeeDriver *driver = NULL;
149 ZblibDriverServicePrivData_t *priv_data = NULL;
152 if (NULL == plugin) {
153 Z_LOGE("plugin is NULL");
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");
164 /* Allocate memory for private data */
165 priv_data = g_malloc0(sizeof(ZblibDriverServicePrivData_t));
167 /* Update private data */
168 priv_data->ops = ops;
170 /* Link private data to driver */
171 ret = zblib_driver_link_object(driver, priv_data);
173 Z_LOGE("zblib_driver_link_object failed!");
175 /* Free allocated resources */
182 /* Set operations dispatcher function */
183 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_service_dispatcher);
185 Z_LOGE("zblib_driver_set_dispatcher failed!");
187 /* Free allocated resources */
194 /* Set free hook function */
195 ret = zblib_driver_set_free_hook(driver, __zblib_driver_service_free_hook);
197 Z_LOGE("zblib_driver_set_free_hook failed!");
199 /* Free allocated resources */
209 void zblib_driver_service_free(ZigBeeDriver *driver)
211 if (NULL == driver) {
212 Z_LOGE("driver is NULL");
217 zblib_driver_free(driver);