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_global_control.h"
27 ZblibDriverZclGlobalControlOps_t *ops; /**< Operations */
28 } ZblibDriverZclglobalControlPrivData_t;
30 static gboolean __zblib_driver_zcl_global_control_dispatcher(ZigBeeDriver *driver, guint request_id)
32 ZigBeeService *service = NULL;
33 ZblibDriverZclglobalControlPrivData_t *priv_data = NULL;
34 ZblibDriverZclGlobalControlOps_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_GLOBAL_CONTROL_OPS_READ_ATTRIBUTES_REQ: {
58 zblib_check_null_ret_error("ops->read_attributes_req",
59 ops->read_attributes_req, FALSE);
61 ret = ops->read_attributes_req(driver, request_id);
65 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_REQ: {
66 zblib_check_null_ret_error("ops->write_attributes_req",
67 ops->write_attributes_req, FALSE);
69 ret = ops->write_attributes_req(driver, request_id);
73 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_UNDIVIDED_REQ: {
74 zblib_check_null_ret_error("ops->write_attributes_undivided_req",
75 ops->write_attributes_undivided_req, FALSE);
77 ret = ops->write_attributes_undivided_req(driver, request_id);
81 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_NO_RESP: {
82 zblib_check_null_ret_error("ops->write_attributes_no_resp",
83 ops->write_attributes_no_resp, FALSE);
85 ret = ops->write_attributes_no_resp(driver, request_id);
89 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_WRITE_ATTRIBUTES_STRUCTURED: {
90 zblib_check_null_ret_error("ops->write_attributes_structured",
91 ops->write_attributes_structured, FALSE);
93 ret = ops->write_attributes_structured(driver, request_id);
97 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_ATTRIBUTES_STRUCTURED: {
98 zblib_check_null_ret_error("ops->read_attributes_structured",
99 ops->read_attributes_structured, FALSE);
101 ret = ops->read_attributes_structured(driver, request_id);
105 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_CONFIGURE_REPORTING_REQ: {
106 zblib_check_null_ret_error("ops->configure_reporting_req",
107 ops->configure_reporting_req, FALSE);
109 ret = ops->configure_reporting_req(driver, request_id);
113 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_READ_CONFIGURE_REPORTING: {
114 zblib_check_null_ret_error("ops->read_configure_reporting",
115 ops->read_configure_reporting, FALSE);
117 ret = ops->read_configure_reporting(driver, request_id);
121 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_ATTRIBUTES: {
122 zblib_check_null_ret_error("ops->discover_attributes",
123 ops->discover_attributes, FALSE);
125 ret = ops->discover_attributes(driver, request_id);
129 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_ATTRIBUTES_EXTENDED: {
130 zblib_check_null_ret_error("ops->discover_attributes_extended",
131 ops->discover_attributes_extended, FALSE);
133 ret = ops->discover_attributes_extended(driver, request_id);
137 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_COMMANDS_RECEIVED: {
138 zblib_check_null_ret_error("ops->discover_commands_received",
139 ops->discover_commands_received, FALSE);
141 ret = ops->discover_commands_received(driver, request_id);
145 case ZBLIB_ZCL_GLOBAL_CONTROL_OPS_DISCOVER_COMMANDS_GENERATED: {
146 zblib_check_null_ret_error("ops->discover_commands_generated",
147 ops->discover_commands_generated, FALSE);
149 ret = ops->discover_commands_generated(driver, request_id);
157 Z_LOGD("ret: [%d]", ret);
162 static void __zblib_driver_zcl_global_control_free_hook(ZigBeeDriver *driver)
164 ZblibDriverZclglobalControlPrivData_t *priv_data = NULL;
166 zblib_check_null_ret("driver", driver);
168 /* Fetch private data */
169 priv_data = zblib_driver_ref_object(driver);
170 zblib_check_null_ret("priv_data", priv_data);
176 ZigBeeDriver *zblib_driver_zcl_global_control_new(ZigBeePlugin *plugin,
177 const gchar *driver_name,
178 ZblibDriverZclGlobalControlOps_t *ops)
180 ZigBeeDriver *driver = NULL;
181 ZblibDriverZclglobalControlPrivData_t *priv_data = NULL;
184 zblib_check_null_ret_error("plugin", plugin, NULL);
186 /* Create new driver */
187 driver = zblib_driver_new(plugin, driver_name, ZBLIB_DRIVER_TYPE_ZCL_GLOBAL_CONTROL);
188 zblib_check_null_ret_error("driver", driver, NULL);
190 /* Allocate memory for private data */
191 priv_data = g_malloc0(sizeof(ZblibDriverZclglobalControlPrivData_t));
193 /* Update private data */
194 priv_data->ops = ops;
196 /* Link private data to driver */
197 ret = zblib_driver_link_object(driver, priv_data);
199 Z_LOGE("zblib_driver_link_object failed!");
201 /* Free allocated resources */
208 /* Set operations dispatcher function */
209 ret = zblib_driver_set_dispatcher(driver, __zblib_driver_zcl_global_control_dispatcher);
211 Z_LOGE("zblib_driver_set_dispatcher failed!");
213 /* Free allocated resources */
220 /* Set free hook function */
221 ret = zblib_driver_set_free_hook(driver, __zblib_driver_zcl_global_control_free_hook);
223 Z_LOGE("zblib_driver_set_free_hook failed!");
225 /* Free allocated resources */
235 void zblib_driver_zcl_global_control_free(ZigBeeDriver *driver)
237 zblib_check_null_ret("driver", driver);
240 zblib_driver_free(driver);