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_color_control.h"
28 ZblibDriverZclColorControlOps_t *ops; /**< Operations */
29 } ZblibDriverZclColorControlPrivData_t;
31 static gboolean __zblib_driver_zcl_color_control_dispatcher(ZigBeeDriver *driver, guint request_id)
33 ZigBeeService *service = NULL;
34 ZblibDriverZclColorControlPrivData_t *priv_data = NULL;
35 ZblibDriverZclColorControlOps_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_COLOR_CONTROL_OPS_MOVE_TO_HUE: {
59 zblib_check_null_ret_error("ops->move_to_hue",
60 ops->move_to_hue, FALSE);
62 ret = ops->move_to_hue(driver, request_id);
66 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_HUE: {
67 zblib_check_null_ret_error("ops->move_hue",
68 ops->move_hue, FALSE);
70 ret = ops->move_hue(driver, request_id);
74 case ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_HUE: {
75 zblib_check_null_ret_error("ops->step_hue",
76 ops->step_hue, FALSE);
78 ret = ops->step_hue(driver, request_id);
82 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_STAURATION: {
83 zblib_check_null_ret_error("ops->move_to_saturation",
84 ops->move_to_saturation, FALSE);
86 ret = ops->move_to_saturation(driver, request_id);
90 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_STAURATION: {
91 zblib_check_null_ret_error("ops->move_saturation",
92 ops->move_saturation, FALSE);
94 ret = ops->move_saturation(driver, request_id);
98 case ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_STAURATION: {
99 zblib_check_null_ret_error("ops->step_saturation",
100 ops->step_saturation, FALSE);
102 ret = ops->step_saturation(driver, request_id);
106 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_HUE_AND_SATURATION: {
107 zblib_check_null_ret_error("ops->move_to_hue_and_saturation",
108 ops->move_to_hue_and_saturation, FALSE);
110 ret = ops->move_to_hue_and_saturation(driver, request_id);
114 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_COLOR: {
115 zblib_check_null_ret_error("ops->move_to_color",
116 ops->move_to_color, FALSE);
118 ret = ops->move_to_color(driver, request_id);
122 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_COLOR: {
123 zblib_check_null_ret_error("ops->move_color",
124 ops->move_color, FALSE);
126 ret = ops->move_color(driver, request_id);
130 case ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_COLOR: {
131 zblib_check_null_ret_error("ops->step_color",
132 ops->step_color, FALSE);
134 ret = ops->step_color(driver, request_id);
138 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_COLOR_TEMPERATURE: {
139 zblib_check_null_ret_error("ops->move_color_temperature",
140 ops->move_color_temperature, FALSE);
142 ret = ops->move_color_temperature(driver, request_id);
150 Z_LOGD("ret: [%d]", ret);
155 static void __zblib_driver_zcl_color_control_free_hook(ZigBeeDriver *driver)
157 ZblibDriverZclColorControlPrivData_t *priv_data = NULL;
159 zblib_check_null_ret("driver", driver);
161 /* Fetch private data */
162 priv_data = zblib_driver_ref_object(driver);
163 zblib_check_null_ret("priv_data", priv_data);
169 ZigBeeDriver *zblib_driver_zcl_color_control_new(ZigBeePlugin *plugin,
170 const gchar *driver_name,
171 ZblibDriverZclColorControlOps_t *ops)
173 ZigBeeDriver *driver = NULL;
174 ZigBeeService *service = NULL;
175 ZblibDriverZclColorControlPrivData_t *priv_data = NULL;
178 zblib_check_null_ret_error("plugin", plugin, NULL);
180 /* Create new driver */
181 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL);
182 zblib_check_null_ret_error("driver", driver, NULL);
184 /* Allocate memory for private data */
185 priv_data = g_malloc0(sizeof(ZblibDriverZclColorControlPrivData_t));
187 /* Update private data */
188 priv_data->ops = ops;
190 /* Link service to driver */
191 service = zblib_plugin_ref_service(plugin);
192 if (NULL == service) {
193 Z_LOGE("zblib_plugin_ref_service failed!");
195 /* Free allocated resources */
201 zblib_driver_link_service(driver, service);
203 /* Link private data to driver */
204 ret = zblib_driver_link_object(driver, priv_data);
206 Z_LOGE("zblib_driver_link_object failed!");
208 /* Free allocated resources */
215 /* Set operations dispatcher function */
216 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_color_control_dispatcher);
218 Z_LOGE("zblib_driver_set_dispatcher failed!");
220 /* Free allocated resources */
227 /* Set free hook function */
228 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_color_control_free_hook);
230 Z_LOGE("zblib_driver_set_free_hook failed!");
232 /* Free allocated resources */
242 void zblib_driver_zcl_color_control_free(ZigBeeDriver *driver)
244 zblib_check_null_ret("driver", driver);
247 zblib_driver_free(driver);