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_request.h>
24 #include "zblib_driver_zcl_level_control.h"
28 ZblibDriverZclLevelControlOps_t *ops; /**< Operations */
29 } ZblibDriverZclLevelControlPrivData_t;
32 static gboolean __zblib_driver_zcl_level_control_dispatcher(ZigBeeDriver *driver, guint request_id)
34 ZigBeeService *service = NULL;
35 ZblibDriverZclLevelControlPrivData_t *priv_data = NULL;
36 ZblibDriverZclLevelControlOps_t *ops = NULL;
41 zblib_check_null_ret_error("driver", driver, FALSE);
43 service = zblib_driver_ref_service(driver);
44 zblib_check_null_ret_error("service", service, FALSE);
46 /* Fetch private data */
47 priv_data = zblib_driver_ref_object(driver);
48 zblib_check_null_ret_error("priv_data", priv_data, FALSE);
51 zblib_check_null_ret_error("ops", ops, FALSE);
53 /* Fetch request_type using request_id */
54 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
57 ops_id = zblib_request_get_ops_id(request_type);
59 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_MOVE_TO_LEVEL: {
60 zblib_check_null_ret_error("ops->move_to_level",
61 ops->move_to_level, FALSE);
63 ret = ops->move_to_level(driver, request_id);
67 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_MOVE: {
68 zblib_check_null_ret_error("ops->move",
71 ret = ops->move(driver, request_id);
75 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_STEP: {
76 zblib_check_null_ret_error("ops->step",
79 ret = ops->step(driver, request_id);
83 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_MOVE_TO_LEVEL_WITH_ON_OFF: {
84 zblib_check_null_ret_error("ops->move_to_level_with_on_off",
85 ops->move_to_level_with_on_off, FALSE);
87 ret = ops->move_to_level_with_on_off(driver, request_id);
91 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_MOVE_WITH_ON_OFF: {
92 zblib_check_null_ret_error("ops->move_with_on_off",
93 ops->move_with_on_off, FALSE);
95 ret = ops->move_with_on_off(driver, request_id);
99 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_STEP_WITH_ON_OFF: {
100 zblib_check_null_ret_error("ops->step_with_on_off",
101 ops->step_with_on_off, FALSE);
103 ret = ops->step_with_on_off(driver, request_id);
107 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_STOP: {
108 zblib_check_null_ret_error("ops->stop",
111 ret = ops->stop(driver, request_id);
119 Z_LOGD("ret: [%d]", ret);
125 static void __zblib_driver_zcl_level_control_free_hook(ZigBeeDriver *driver)
127 ZblibDriverZclLevelControlPrivData_t *priv_data = NULL;
129 zblib_check_null_ret("driver", driver);
131 /* Fetch private data */
132 priv_data = zblib_driver_ref_object(driver);
133 zblib_check_null_ret("priv_data", priv_data);
139 ZigBeeDriver *zblib_driver_zcl_level_control_new(ZigBeePlugin *plugin,
140 const gchar *driver_name,
141 ZblibDriverZclLevelControlOps_t *ops)
143 ZigBeeDriver *driver = NULL;
144 ZigBeeService *service = NULL;
145 ZblibDriverZclLevelControlPrivData_t *priv_data = NULL;
148 zblib_check_null_ret_error("plugin", plugin, NULL);
150 /* Create new driver */
151 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_LEVEL_CONTROL);
152 zblib_check_null_ret_error("driver", driver, NULL);
154 /* Allocate memory for private data */
155 priv_data = g_malloc0(sizeof(ZblibDriverZclLevelControlPrivData_t));
157 /* Update private data */
158 priv_data->ops = ops;
160 /* Link service to driver */
161 service = zblib_plugin_ref_service(plugin);
162 if (NULL == service) {
163 /* LCOV_EXCL_START */
164 Z_LOGE("zblib_plugin_ref_service failed!");
166 /* Free allocated resources */
173 zblib_driver_link_service(driver, service);
175 /* Link private data to driver */
176 ret = zblib_driver_link_object(driver, priv_data);
178 /* LCOV_EXCL_START */
179 Z_LOGE("zblib_driver_link_object failed!");
181 /* Free allocated resources */
189 /* Set operations dispatcher function */
190 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_level_control_dispatcher);
192 /* LCOV_EXCL_START */
193 Z_LOGE("zblib_driver_set_dispatcher failed!");
195 /* Free allocated resources */
203 /* Set free hook function */
204 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_level_control_free_hook);
206 /* LCOV_EXCL_START */
207 Z_LOGE("zblib_driver_set_free_hook failed!");
209 /* Free allocated resources */
220 /* LCOV_EXCL_START */
221 void zblib_driver_zcl_level_control_free(ZigBeeDriver *driver)
223 zblib_check_null_ret("driver", driver);
226 zblib_driver_free(driver);