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.
19 #include "zigbee_service_interface_common.h"
21 #include <zblib_driver_zcl_fan_control.h>
23 static void on_fan_control_set_fan_mode_resp(ZigBeeServiceInterface *service_interface,
24 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
26 ZigbeeServiceInterfaceRespCbData_t *cb_data =
27 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
30 NOT_USED(service_interface);
33 NOT_USED(resp_data_len);
36 static gboolean on_fan_control_set_fan_mode(ZigbeeZcl_fan_control *fan_control_object,
37 GDBusMethodInvocation *invocation,
42 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
43 ZigbeeZclFanControlSetFanMode_t req;
44 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
46 GVariantIter *iter = NULL;
51 memset(&req, 0x0, sizeof(ZigbeeZclFanControlSetFanMode_t));
53 /* Update request structure */
54 g_variant_get(eui64, "ay", &iter);
55 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
57 if (i >= ZIGBEE_EUI64_SIZE)
60 req.endpoint = endpoint;
62 /* Allocate response callback data */
64 zigbee_service_dbus_interface_create_resp_cb_data(fan_control_object,
66 if (NULL == resp_cb_data) {
67 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
69 /* Send failure response */
70 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
75 /* Dispatch request */
76 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
77 ZBLIB_DRIVER_TYPE_ZCL_FAN_CONTROL,
78 ZBLIB_ZCL_FAN_CONTROL_OPS_SET_FAN_MODE,
80 on_fan_control_set_fan_mode_resp, resp_cb_data);
82 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
84 /* Free response callback data */
85 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
87 /* Send failure response */
88 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
96 static void on_fan_control_get_fan_mode_resp(ZigBeeServiceInterface *service_interface,
97 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
99 ZigbeeServiceInterfaceRespCbData_t *cb_data =
100 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
103 NOT_USED(service_interface);
104 NOT_USED(request_id);
106 NOT_USED(resp_data_len);
109 static gboolean on_fan_control_get_fan_mode(ZigbeeZcl_fan_control *fan_control_object,
110 GDBusMethodInvocation *invocation,
115 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
116 ZigbeeZclFanControlGetFanMode_t req;
117 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
119 GVariantIter *iter = NULL;
124 memset(&req, 0x0, sizeof(ZigbeeZclFanControlGetFanMode_t));
126 /* Update request structure */
127 g_variant_get(eui64, "ay", &iter);
128 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
130 if (i >= ZIGBEE_EUI64_SIZE)
133 req.endpoint = endpoint;
135 /* Allocate response callback data */
137 zigbee_service_dbus_interface_create_resp_cb_data(fan_control_object,
138 invocation, NULL, 0);
139 if (NULL == resp_cb_data) {
140 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
142 /* Send failure response */
143 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
148 /* Dispatch request */
149 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
150 ZBLIB_DRIVER_TYPE_ZCL_FAN_CONTROL,
151 ZBLIB_ZCL_FAN_CONTROL_OPS_GET_FAN_MODE,
153 on_fan_control_get_fan_mode_resp, resp_cb_data);
155 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
157 /* Free response callback data */
158 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
160 /* Send failure response */
161 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
169 static void on_fan_control_set_fan_mode_sequence_resp(ZigBeeServiceInterface *service_interface,
170 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
172 ZigbeeServiceInterfaceRespCbData_t *cb_data =
173 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
176 NOT_USED(service_interface);
177 NOT_USED(request_id);
179 NOT_USED(resp_data_len);
182 static gboolean on_fan_control_set_fan_mode_sequence(
183 ZigbeeZcl_fan_control *fan_control_object,
184 GDBusMethodInvocation *invocation,
189 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
190 ZigbeeZclFanControlSetFanModeSequence_t req;
191 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
193 GVariantIter *iter = NULL;
198 memset(&req, 0x0, sizeof(ZigbeeZclFanControlSetFanModeSequence_t));
200 /* Update request structure */
201 g_variant_get(eui64, "ay", &iter);
202 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
204 if (i >= ZIGBEE_EUI64_SIZE)
207 req.endpoint = endpoint;
209 /* Allocate response callback data */
211 zigbee_service_dbus_interface_create_resp_cb_data(fan_control_object,
212 invocation, NULL, 0);
213 if (NULL == resp_cb_data) {
214 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
216 /* Send failure response */
217 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
222 /* Dispatch request */
223 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
224 ZBLIB_DRIVER_TYPE_ZCL_FAN_CONTROL,
225 ZBLIB_ZCL_FAN_CONTROL_OPS_SET_FAN_MODE_SEQUENCE,
227 on_fan_control_set_fan_mode_sequence_resp, resp_cb_data);
229 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
231 /* Free response callback data */
232 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
234 /* Send failure response */
235 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
243 static void on_fan_control_get_fan_mode_sequence_resp(ZigBeeServiceInterface *service_interface,
244 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
246 ZigbeeServiceInterfaceRespCbData_t *cb_data =
247 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
250 NOT_USED(service_interface);
251 NOT_USED(request_id);
253 NOT_USED(resp_data_len);
256 static gboolean on_fan_control_get_fan_mode_sequence(
257 ZigbeeZcl_fan_control *fan_control_object,
258 GDBusMethodInvocation *invocation,
263 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
264 ZigbeeZclFanControlGetFanModeSequence_t req;
265 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
267 GVariantIter *iter = NULL;
272 memset(&req, 0x0, sizeof(ZigbeeZclFanControlGetFanModeSequence_t));
274 /* Update request structure */
275 g_variant_get(eui64, "ay", &iter);
276 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
278 if (i >= ZIGBEE_EUI64_SIZE)
281 req.endpoint = endpoint;
283 /* Allocate response callback data */
285 zigbee_service_dbus_interface_create_resp_cb_data(fan_control_object,
286 invocation, NULL, 0);
287 if (NULL == resp_cb_data) {
288 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
290 /* Send failure response */
291 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
296 /* Dispatch request */
297 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
298 ZBLIB_DRIVER_TYPE_ZCL_FAN_CONTROL,
299 ZBLIB_ZCL_FAN_CONTROL_OPS_GET_FAN_MODE_SEQUENCE,
301 on_fan_control_get_fan_mode_sequence_resp, resp_cb_data);
303 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
305 /* Free response callback data */
306 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
308 /* Send failure response */
309 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
317 void zigbee_service_dbus_interface_zcl_fan_control_notification(ZigBeeServiceInterface *service_interface,
318 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
320 if (NULL == service_interface) {
321 Z_LOGE("service_interface is NULL");
327 NOT_USED(noti_data_len);
328 NOT_USED(noti_cb_data);
331 gboolean zigbee_service_dbus_interface_zcl_fan_control_init(ZigBeeServiceInterface *service_interface,
332 ZigbeeObjectSkeleton *zigbee_object)
334 ZigbeeZcl_fan_control *fan_control_object;
336 if (NULL == service_interface) {
337 Z_LOGE("service_interface is NULL");
341 fan_control_object = zigbee_zcl_fan_control_skeleton_new();
342 zigbee_object_skeleton_set_zcl_fan_control(zigbee_object, fan_control_object);
343 g_object_unref(fan_control_object);
345 Z_LOGI("fan_control_object: [%p]", fan_control_object);
348 * Register signal handlers for 'fan_control' interface
350 g_signal_connect(fan_control_object,
351 "handle-set-fan-mode",
352 G_CALLBACK(on_fan_control_set_fan_mode), service_interface);
354 g_signal_connect(fan_control_object,
355 "handle-get-fan-mode",
356 G_CALLBACK(on_fan_control_get_fan_mode), service_interface);
358 g_signal_connect(fan_control_object,
359 "handle-set-fan-mode-sequence",
360 G_CALLBACK(on_fan_control_set_fan_mode_sequence), service_interface);
362 g_signal_connect(fan_control_object,
363 "handle-get-fan-mode-sequence",
364 G_CALLBACK(on_fan_control_get_fan_mode_sequence), service_interface);