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_fan_control.h"
27 ZblibDriverFanControlOps_t *ops; /**< Operations */
28 } ZblibDriverFanControlPrivData_t;
30 static gboolean __zblib_driver_zcl_fan_control_dispatcher(ZigBeeDriver *driver, guint request_id)
32 ZigBeeService *service = NULL;
33 ZblibDriverFanControlPrivData_t *priv_data = NULL;
34 ZblibDriverFanControlOps_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_FAN_CONTROL_OPS_SET_FAN_MODE: {
58 zblib_check_null_ret_error("ops->set_fan_mode",
59 ops->set_fan_mode, FALSE);
61 ret = ops->set_fan_mode(driver, request_id);
65 case ZBLIB_FAN_CONTROL_OPS_GET_FAN_MODE: {
66 zblib_check_null_ret_error("ops->get_fan_mode",
67 ops->get_fan_mode, FALSE);
69 ret = ops->get_fan_mode(driver, request_id);
73 case ZBLIB_FAN_CONTROL_OPS_SET_FAN_MODE_SEQUENCE: {
74 zblib_check_null_ret_error("ops->set_fan_mode_sequence",
75 ops->set_fan_mode_sequence, FALSE);
77 ret = ops->set_fan_mode_sequence(driver, request_id);
81 case ZBLIB_FAN_CONTROL_OPS_GET_FAN_MODE_SEQUENCE: {
82 zblib_check_null_ret_error("ops->get_fan_mode_sequence",
83 ops->get_fan_mode_sequence, FALSE);
85 ret = ops->get_fan_mode_sequence(driver, request_id);
93 Z_LOGD("ret: [%d]", ret);
98 static void __zblib_driver_zcl_fan_control_free_hook(ZigBeeDriver *driver)
100 ZblibDriverFanControlPrivData_t *priv_data = NULL;
102 zblib_check_null_ret("driver", driver);
104 /* Fetch private data */
105 priv_data = zblib_driver_ref_object(driver);
106 zblib_check_null_ret("priv_data", priv_data);
112 ZigBeeDriver *zblib_driver_zcl_fan_control_new(ZigBeePlugin *plugin,
113 const gchar *driver_name,
114 ZblibDriverFanControlOps_t *ops)
116 ZigBeeDriver *driver = NULL;
117 ZblibDriverFanControlPrivData_t *priv_data = NULL;
120 zblib_check_null_ret_error("plugin", plugin, NULL);
122 /* Create new driver */
123 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_FAN_CONTROL);
124 zblib_check_null_ret_error("driver", driver, NULL);
126 /* Allocate memory for private data */
127 priv_data = g_malloc0(sizeof(ZblibDriverFanControlPrivData_t));
129 /* Update private data */
130 priv_data->ops = ops;
132 /* Link private data to driver */
133 ret = zblib_driver_link_object(driver, priv_data);
135 Z_LOGE("zblib_driver_link_object failed!");
137 /* Free allocated resources */
144 /* Set operations dispatcher function */
145 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_fan_control_dispatcher);
147 Z_LOGE("zblib_driver_set_dispatcher failed!");
149 /* Free allocated resources */
156 /* Set free hook function */
157 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_fan_control_free_hook);
159 Z_LOGE("zblib_driver_set_free_hook failed!");
161 /* Free allocated resources */
171 void zblib_driver_zcl_fan_control_free(ZigBeeDriver *driver)
173 zblib_check_null_ret("driver", driver);
176 zblib_driver_free(driver);