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;
31 static gboolean __zblib_driver_zcl_level_control_dispatcher(ZigBeeDriver *driver, guint request_id)
33 ZigBeeService *service = NULL;
34 ZblibDriverZclLevelControlPrivData_t *priv_data = NULL;
35 ZblibDriverZclLevelControlOps_t *ops = NULL;
40 zblib_check_null_ret_error("driver", driver, FALSE);
42 service = zblib_driver_ref_service(driver);
43 zblib_check_null_ret_error("service", service, FALSE);
45 /* Fetch private data */
46 priv_data = zblib_driver_ref_object(driver);
47 zblib_check_null_ret_error("priv_data", priv_data, FALSE);
50 zblib_check_null_ret_error("ops", ops, FALSE);
52 /* Fetch request_type using request_id */
53 request_type = zblib_request_ref_request_type_by_request_id(service, request_id);
56 ops_id = zblib_request_get_ops_id(request_type);
58 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_MOVE_TO_LEVEL: {
59 zblib_check_null_ret_error("ops->move_to_level",
60 ops->move_to_level, FALSE);
62 ret = ops->move_to_level(driver, request_id);
66 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_MOVE: {
67 zblib_check_null_ret_error("ops->move",
70 ret = ops->move(driver, request_id);
74 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_STEP: {
75 zblib_check_null_ret_error("ops->step",
78 ret = ops->step(driver, request_id);
82 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_MOVE_TO_LEVEL_WITH_ON_OFF: {
83 zblib_check_null_ret_error("ops->move_to_level_with_on_off",
84 ops->move_to_level_with_on_off, FALSE);
86 ret = ops->move_to_level_with_on_off(driver, request_id);
90 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_MOVE_WITH_ON_OFF: {
91 zblib_check_null_ret_error("ops->move_with_on_off",
92 ops->move_with_on_off, FALSE);
94 ret = ops->move_with_on_off(driver, request_id);
98 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_STEP_WITH_ON_OFF: {
99 zblib_check_null_ret_error("ops->step_with_on_off",
100 ops->step_with_on_off, FALSE);
102 ret = ops->step_with_on_off(driver, request_id);
106 case ZBLIB_ZCL_LEVEL_CONTROL_OPS_STOP: {
107 zblib_check_null_ret_error("ops->stop",
110 ret = ops->stop(driver, request_id);
118 Z_LOGD("ret: [%d]", ret);
123 static void __zblib_driver_zcl_level_control_free_hook(ZigBeeDriver *driver)
125 ZblibDriverZclLevelControlPrivData_t *priv_data = NULL;
127 zblib_check_null_ret("driver", driver);
129 /* Fetch private data */
130 priv_data = zblib_driver_ref_object(driver);
131 zblib_check_null_ret("priv_data", priv_data);
137 ZigBeeDriver *zblib_driver_zcl_level_control_new(ZigBeePlugin *plugin,
138 const gchar *driver_name,
139 ZblibDriverZclLevelControlOps_t *ops)
141 ZigBeeDriver *driver = NULL;
142 ZigBeeService *service = NULL;
143 ZblibDriverZclLevelControlPrivData_t *priv_data = NULL;
146 zblib_check_null_ret_error("plugin", plugin, NULL);
148 /* Create new driver */
149 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_LEVEL_CONTROL);
150 zblib_check_null_ret_error("driver", driver, NULL);
152 /* Allocate memory for private data */
153 priv_data = g_malloc0(sizeof(ZblibDriverZclLevelControlPrivData_t));
155 /* Update private data */
156 priv_data->ops = ops;
158 /* Link service to driver */
159 service = zblib_plugin_ref_service(plugin);
160 if (NULL == service) {
161 Z_LOGE("zblib_plugin_ref_service failed!");
163 /* Free allocated resources */
169 zblib_driver_link_service(driver, service);
171 /* Link private data to driver */
172 ret = zblib_driver_link_object(driver, priv_data);
174 Z_LOGE("zblib_driver_link_object failed!");
176 /* Free allocated resources */
183 /* Set operations dispatcher function */
184 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_level_control_dispatcher);
186 Z_LOGE("zblib_driver_set_dispatcher failed!");
188 /* Free allocated resources */
195 /* Set free hook function */
196 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_level_control_free_hook);
198 Z_LOGE("zblib_driver_set_free_hook failed!");
200 /* Free allocated resources */
210 void zblib_driver_zcl_level_control_free(ZigBeeDriver *driver)
212 zblib_check_null_ret("driver", driver);
215 zblib_driver_free(driver);