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;
32 static gboolean __zblib_driver_zcl_color_control_dispatcher(ZigBeeDriver *driver, guint request_id)
34 ZigBeeService *service = NULL;
35 ZblibDriverZclColorControlPrivData_t *priv_data = NULL;
36 ZblibDriverZclColorControlOps_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_COLOR_CONTROL_OPS_MOVE_TO_HUE: {
60 zblib_check_null_ret_error("ops->move_to_hue",
61 ops->move_to_hue, FALSE);
63 ret = ops->move_to_hue(driver, request_id);
67 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_HUE: {
68 zblib_check_null_ret_error("ops->move_hue",
69 ops->move_hue, FALSE);
71 ret = ops->move_hue(driver, request_id);
75 case ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_HUE: {
76 zblib_check_null_ret_error("ops->step_hue",
77 ops->step_hue, FALSE);
79 ret = ops->step_hue(driver, request_id);
83 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_STAURATION: {
84 zblib_check_null_ret_error("ops->move_to_saturation",
85 ops->move_to_saturation, FALSE);
87 ret = ops->move_to_saturation(driver, request_id);
91 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_STAURATION: {
92 zblib_check_null_ret_error("ops->move_saturation",
93 ops->move_saturation, FALSE);
95 ret = ops->move_saturation(driver, request_id);
99 case ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_STAURATION: {
100 zblib_check_null_ret_error("ops->step_saturation",
101 ops->step_saturation, FALSE);
103 ret = ops->step_saturation(driver, request_id);
107 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_HUE_AND_SATURATION: {
108 zblib_check_null_ret_error("ops->move_to_hue_and_saturation",
109 ops->move_to_hue_and_saturation, FALSE);
111 ret = ops->move_to_hue_and_saturation(driver, request_id);
115 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_TO_COLOR: {
116 zblib_check_null_ret_error("ops->move_to_color",
117 ops->move_to_color, FALSE);
119 ret = ops->move_to_color(driver, request_id);
123 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_COLOR: {
124 zblib_check_null_ret_error("ops->move_color",
125 ops->move_color, FALSE);
127 ret = ops->move_color(driver, request_id);
131 case ZBLIB_ZCL_COLOR_CONTROL_OPS_STEP_COLOR: {
132 zblib_check_null_ret_error("ops->step_color",
133 ops->step_color, FALSE);
135 ret = ops->step_color(driver, request_id);
139 case ZBLIB_ZCL_COLOR_CONTROL_OPS_MOVE_COLOR_TEMPERATURE: {
140 zblib_check_null_ret_error("ops->move_color_temperature",
141 ops->move_color_temperature, FALSE);
143 ret = ops->move_color_temperature(driver, request_id);
151 Z_LOGD("ret: [%d]", ret);
157 static void __zblib_driver_zcl_color_control_free_hook(ZigBeeDriver *driver)
159 ZblibDriverZclColorControlPrivData_t *priv_data = NULL;
161 zblib_check_null_ret("driver", driver);
163 /* Fetch private data */
164 priv_data = zblib_driver_ref_object(driver);
165 zblib_check_null_ret("priv_data", priv_data);
171 ZigBeeDriver *zblib_driver_zcl_color_control_new(ZigBeePlugin *plugin,
172 const gchar *driver_name,
173 ZblibDriverZclColorControlOps_t *ops)
175 ZigBeeDriver *driver = NULL;
176 ZigBeeService *service = NULL;
177 ZblibDriverZclColorControlPrivData_t *priv_data = NULL;
180 zblib_check_null_ret_error("plugin", plugin, NULL);
182 /* Create new driver */
183 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_COLOR_CONTROL);
184 zblib_check_null_ret_error("driver", driver, NULL);
186 /* Allocate memory for private data */
187 priv_data = g_malloc0(sizeof(ZblibDriverZclColorControlPrivData_t));
189 /* Update private data */
190 priv_data->ops = ops;
192 /* Link service to driver */
193 service = zblib_plugin_ref_service(plugin);
194 if (NULL == service) {
195 /* LCOV_EXCL_START */
196 Z_LOGE("zblib_plugin_ref_service failed!");
198 /* Free allocated resources */
205 zblib_driver_link_service(driver, service);
207 /* Link private data to driver */
208 ret = zblib_driver_link_object(driver, priv_data);
210 /* LCOV_EXCL_START */
211 Z_LOGE("zblib_driver_link_object failed!");
213 /* Free allocated resources */
221 /* Set operations dispatcher function */
222 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_color_control_dispatcher);
224 /* LCOV_EXCL_START */
225 Z_LOGE("zblib_driver_set_dispatcher failed!");
227 /* Free allocated resources */
235 /* Set free hook function */
236 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_color_control_free_hook);
238 /* LCOV_EXCL_START */
239 Z_LOGE("zblib_driver_set_free_hook failed!");
241 /* Free allocated resources */
252 /* LCOV_EXCL_START */
253 void zblib_driver_zcl_color_control_free(ZigBeeDriver *driver)
255 zblib_check_null_ret("driver", driver);
258 zblib_driver_free(driver);