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_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(ZigbeeFan_control *fan_control_object,
37 GDBusMethodInvocation *invocation,
42 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
43 ZigbeeFanControlSetFanMode_t req;
44 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
46 GVariantIter *iter = NULL;
51 memset(&req, 0x0, sizeof(ZigbeeFanControlSetFanMode_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_FAN_CONTROL,
78 ZBLIB_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(ZigbeeFan_control *fan_control_object,
110 GDBusMethodInvocation *invocation,
115 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
116 ZigbeeFanControlGetFanMode_t req;
117 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
119 GVariantIter *iter = NULL;
124 memset(&req, 0x0, sizeof(ZigbeeFanControlGetFanMode_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_FAN_CONTROL,
151 ZBLIB_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(ZigbeeFan_control *fan_control_object,
183 GDBusMethodInvocation *invocation,
188 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
189 ZigbeeFanControlSetFanModeSequence_t req;
190 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
192 GVariantIter *iter = NULL;
197 memset(&req, 0x0, sizeof(ZigbeeFanControlSetFanModeSequence_t));
199 /* Update request structure */
200 g_variant_get(eui64, "ay", &iter);
201 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
203 if (i >= ZIGBEE_EUI64_SIZE)
206 req.endpoint = endpoint;
208 /* Allocate response callback data */
210 zigbee_service_dbus_interface_create_resp_cb_data(fan_control_object,
211 invocation, NULL, 0);
212 if (NULL == resp_cb_data) {
213 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
215 /* Send failure response */
216 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
221 /* Dispatch request */
222 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
223 ZBLIB_DRIVER_TYPE_FAN_CONTROL,
224 ZBLIB_FAN_CONTROL_OPS_SET_FAN_MODE_SEQUENCE,
226 on_fan_control_set_fan_mode_sequence_resp, resp_cb_data);
228 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
230 /* Free response callback data */
231 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
233 /* Send failure response */
234 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
242 static void on_fan_control_get_fan_mode_sequence_resp(ZigBeeServiceInterface *service_interface,
243 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
245 ZigbeeServiceInterfaceRespCbData_t *cb_data =
246 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
249 NOT_USED(service_interface);
250 NOT_USED(request_id);
252 NOT_USED(resp_data_len);
255 static gboolean on_fan_control_get_fan_mode_sequence(ZigbeeFan_control *fan_control_object,
256 GDBusMethodInvocation *invocation,
261 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
262 ZigbeeFanControlGetFanModeSequence_t req;
263 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
265 GVariantIter *iter = NULL;
270 memset(&req, 0x0, sizeof(ZigbeeFanControlGetFanModeSequence_t));
272 /* Update request structure */
273 g_variant_get(eui64, "ay", &iter);
274 while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
276 if (i >= ZIGBEE_EUI64_SIZE)
279 req.endpoint = endpoint;
281 /* Allocate response callback data */
283 zigbee_service_dbus_interface_create_resp_cb_data(fan_control_object,
284 invocation, NULL, 0);
285 if (NULL == resp_cb_data) {
286 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
288 /* Send failure response */
289 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
294 /* Dispatch request */
295 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
296 ZBLIB_DRIVER_TYPE_FAN_CONTROL,
297 ZBLIB_FAN_CONTROL_OPS_GET_FAN_MODE_SEQUENCE,
299 on_fan_control_get_fan_mode_sequence_resp, resp_cb_data);
301 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
303 /* Free response callback data */
304 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
306 /* Send failure response */
307 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
315 gboolean zigbee_service_dbus_interface_fan_control_init(ZigBeeServiceInterface *service_interface,
316 ZigbeeObjectSkeleton *zigbee_object)
318 ZigbeeFan_control *fan_control_object;
320 if (NULL == service_interface) {
321 Z_LOGE("service_interface is NULL");
325 fan_control_object = zigbee_fan_control_skeleton_new();
326 zigbee_object_skeleton_set_fan_control(zigbee_object, fan_control_object);
327 g_object_unref(fan_control_object);
329 Z_LOGI("fan_control_object: [%p]", fan_control_object);
332 * Register signal handlers for 'fan_control' interface
334 g_signal_connect(fan_control_object,
335 "handle-set-fan-mode",
336 G_CALLBACK(on_fan_control_set_fan_mode), service_interface);
338 g_signal_connect(fan_control_object,
339 "handle-get-fan-mode",
340 G_CALLBACK(on_fan_control_get_fan_mode), service_interface);
342 g_signal_connect(fan_control_object,
343 "handle-set-fan-mode-sequence",
344 G_CALLBACK(on_fan_control_set_fan_mode_sequence), service_interface);
346 g_signal_connect(fan_control_object,
347 "handle-get-fan-mode-sequence",
348 G_CALLBACK(on_fan_control_get_fan_mode_sequence), service_interface);