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_zcl_color_control.h"
27 ZblibDriverZclColorOps_t *ops; /**< Operations */
28 } ZblibDriverZclColorPrivData_t;
30 static gboolean __zblib_driver_zcl_color_control_dispatcher(ZigBeeDriver *driver, guint request_id)
32 ZigBeeService *service = NULL;
33 ZblibDriverZclColorPrivData_t *priv_data = NULL;
34 ZblibDriverZclColorOps_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_ZCL_COLOR_OPS_MOVE_TO_HUE: {
58 zblib_check_null_ret_error("ops->move_to_hue",
59 ops->move_to_hue, FALSE);
61 ret = ops->move_to_hue(driver, request_id);
65 case ZBLIB_ZCL_COLOR_OPS_MOVE_HUE: {
66 zblib_check_null_ret_error("ops->move_hue",
67 ops->move_hue, FALSE);
69 ret = ops->move_hue(driver, request_id);
73 case ZBLIB_ZCL_COLOR_OPS_STEP_HUE: {
74 zblib_check_null_ret_error("ops->step_hue",
75 ops->step_hue, FALSE);
77 ret = ops->step_hue(driver, request_id);
81 case ZBLIB_ZCL_COLOR_OPS_MOVE_TO_STAURATION: {
82 zblib_check_null_ret_error("ops->move_to_saturation",
83 ops->move_to_saturation, FALSE);
85 ret = ops->move_to_saturation(driver, request_id);
89 case ZBLIB_ZCL_COLOR_OPS_MOVE_STAURATION: {
90 zblib_check_null_ret_error("ops->move_saturation",
91 ops->move_saturation, FALSE);
93 ret = ops->move_saturation(driver, request_id);
97 case ZBLIB_ZCL_COLOR_OPS_STEP_STAURATION: {
98 zblib_check_null_ret_error("ops->step_saturation",
99 ops->step_saturation, FALSE);
101 ret = ops->step_saturation(driver, request_id);
105 case ZBLIB_ZCL_COLOR_OPS_MOVE_TO_HUE_AND_SATURATION: {
106 zblib_check_null_ret_error("ops->move_to_hue_and_saturation",
107 ops->move_to_hue_and_saturation, FALSE);
109 ret = ops->move_to_hue_and_saturation(driver, request_id);
113 case ZBLIB_ZCL_COLOR_OPS_MOVE_TO_COLOR: {
114 zblib_check_null_ret_error("ops->move_to_color",
115 ops->move_to_color, FALSE);
117 ret = ops->move_to_color(driver, request_id);
121 case ZBLIB_ZCL_COLOR_OPS_MOVE_COLOR: {
122 zblib_check_null_ret_error("ops->move_color",
123 ops->move_color, FALSE);
125 ret = ops->move_color(driver, request_id);
129 case ZBLIB_ZCL_COLOR_OPS_STEP_COLOR: {
130 zblib_check_null_ret_error("ops->step_color",
131 ops->step_color, FALSE);
133 ret = ops->step_color(driver, request_id);
137 case ZBLIB_ZCL_COLOR_OPS_MOVE_COLOR_TEMPERATURE: {
138 zblib_check_null_ret_error("ops->move_color_temperature",
139 ops->move_color_temperature, FALSE);
141 ret = ops->move_color_temperature(driver, request_id);
149 Z_LOGD("ret: [%d]", ret);
154 static void __zblib_driver_zcl_color_control_free_hook(ZigBeeDriver *driver)
156 ZblibDriverZclColorPrivData_t *priv_data = NULL;
158 zblib_check_null_ret("driver", driver);
160 /* Fetch private data */
161 priv_data = zblib_driver_ref_object(driver);
162 zblib_check_null_ret("priv_data", priv_data);
168 ZigBeeDriver *zblib_driver_zcl_color_control_new(ZigBeePlugin *plugin,
169 const gchar *driver_name,
170 ZblibDriverZclColorOps_t *ops)
172 ZigBeeDriver *driver = NULL;
173 ZblibDriverZclColorPrivData_t *priv_data = NULL;
176 zblib_check_null_ret_error("plugin", plugin, NULL);
178 /* Create new driver */
179 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_COLOR);
180 zblib_check_null_ret_error("driver", driver, NULL);
182 /* Allocate memory for private data */
183 priv_data = g_malloc0(sizeof(ZblibDriverZclColorPrivData_t));
185 /* Update private data */
186 priv_data->ops = ops;
188 /* Link private data to driver */
189 ret = zblib_driver_link_object(driver, priv_data);
191 Z_LOGE("zblib_driver_link_object failed!");
193 /* Free allocated resources */
200 /* Set operations dispatcher function */
201 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_color_control_dispatcher);
203 Z_LOGE("zblib_driver_set_dispatcher failed!");
205 /* Free allocated resources */
212 /* Set free hook function */
213 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_color_control_free_hook);
215 Z_LOGE("zblib_driver_set_free_hook failed!");
217 /* Free allocated resources */
227 void zblib_driver_zcl_color_control_free(ZigBeeDriver *driver)
229 zblib_check_null_ret("driver", driver);
232 zblib_driver_free(driver);