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_poll_control.h>
23 static void *_service_interface_ref_zigbee_zcl_poll_control(
24 ZigBeeServiceInterface *service_interface)
26 ZigbeeObjectSkeleton *zigbee_object = NULL;
27 ZigbeeCustomData_t *custom_data = NULL;
28 ZigbeeZcl_poll_control *poll_object = NULL;
30 custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
31 if (NULL == custom_data) {
32 Z_LOGE("D-BUS service interface custom_data is NULL!");
36 /* Get zigbee object */
37 zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
38 if (NULL == zigbee_object) {
39 Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
43 poll_object = zigbee_object_get_zcl_poll_control(ZIGBEE_OBJECT(zigbee_object));
47 static void on_zcl_poll_control_check_in_response_resp(ZigBeeServiceInterface *service_interface,
48 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
50 ZigbeeServiceInterfaceRespCbData_t *cb_data =
51 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
53 ZigbeeZcl_poll_control *poll_object = NULL;
54 GDBusMethodInvocation *invocation = NULL;
56 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
58 NOT_USED(service_interface);
61 if (NULL == resp_data || 0 == resp_data_len) {
62 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
67 poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
68 zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
70 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
71 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
73 zigbee_zcl_poll_control_complete_check_in_response(poll_object, invocation, payload->result);
78 static gboolean on_zcl_poll_control_check_in_response(ZigbeeZcl_poll_control *zcl_poll_control_object,
79 GDBusMethodInvocation *invocation,
82 gchar start_fast_polling,
83 gshort fast_poll_timeout,
86 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
87 ZigbeeZclPollControlCheckInResponse_t req;
88 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
92 memset(&req, 0x0, sizeof(ZigbeeZclPollControlCheckInResponse_t));
94 /* Update request structure */
95 req.node_id = node_id;
96 req.dest_ep = dest_ep;
97 req.start_fast_polling = start_fast_polling;
98 req.fast_poll_timeout = fast_poll_timeout;
100 /* Allocate response callback data */
102 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
103 invocation, NULL, 0);
104 if (NULL == resp_cb_data) {
105 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
107 /* Send failure response */
108 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
113 /* Dispatch request */
114 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
115 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
116 ZBLIB_ZCL_POLL_CONTROL_OPS_CHECK_IN_RESPONSE,
118 on_zcl_poll_control_check_in_response_resp, resp_cb_data);
120 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
122 /* Free response callback data */
123 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
125 /* Send failure response */
126 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
134 static void on_zcl_poll_control_fast_poll_stop_resp(ZigBeeServiceInterface *service_interface,
135 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
137 ZigbeeServiceInterfaceRespCbData_t *cb_data =
138 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
140 ZigbeeZcl_poll_control *poll_object = NULL;
141 GDBusMethodInvocation *invocation = NULL;
143 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
145 NOT_USED(service_interface);
146 NOT_USED(request_id);
148 if (NULL == resp_data || 0 == resp_data_len) {
149 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
154 poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
155 zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
157 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
158 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
160 zigbee_zcl_poll_control_complete_fast_poll_stop(poll_object, invocation, payload->result);
165 static gboolean on_zcl_poll_control_fast_poll_stop(ZigbeeZcl_poll_control *zcl_poll_control_object,
166 GDBusMethodInvocation *invocation,
171 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
172 ZigbeeZclPollControlFastPollStop_t req;
173 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
177 memset(&req, 0x0, sizeof(ZigbeeZclPollControlFastPollStop_t));
179 /* Update request structure */
180 req.node_id = node_id;
181 req.dest_ep = dest_ep;
183 /* Allocate response callback data */
185 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
186 invocation, NULL, 0);
187 if (NULL == resp_cb_data) {
188 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
190 /* Send failure response */
191 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
196 /* Dispatch request */
197 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
198 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
199 ZBLIB_ZCL_POLL_CONTROL_OPS_FAST_POLL_STOP,
201 on_zcl_poll_control_fast_poll_stop_resp, resp_cb_data);
203 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
205 /* Free response callback data */
206 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
208 /* Send failure response */
209 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
217 static void on_zcl_poll_control_set_long_poll_interval_resp(ZigBeeServiceInterface *service_interface,
218 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
220 ZigbeeServiceInterfaceRespCbData_t *cb_data =
221 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
223 ZigbeeZcl_poll_control *poll_object = NULL;
224 GDBusMethodInvocation *invocation = NULL;
226 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
228 NOT_USED(service_interface);
229 NOT_USED(request_id);
231 if (NULL == resp_data || 0 == resp_data_len) {
232 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
237 poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
238 zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
240 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
241 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
243 zigbee_zcl_poll_control_complete_set_long_poll_interval(poll_object, invocation, payload->result);
248 static gboolean on_zcl_poll_control_set_long_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
249 GDBusMethodInvocation *invocation,
252 guint new_long_poll_interval,
255 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
256 ZigbeeZclPollControlSetLongPollInterval_t req;
257 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
261 memset(&req, 0x0, sizeof(ZigbeeZclPollControlSetLongPollInterval_t));
263 /* Update request structure */
264 req.node_id = node_id;
265 req.dest_ep = dest_ep;
266 req.new_long_poll_interval = new_long_poll_interval;
268 /* Allocate response callback data */
270 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
271 invocation, NULL, 0);
272 if (NULL == resp_cb_data) {
273 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
275 /* Send failure response */
276 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
281 /* Dispatch request */
282 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
283 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
284 ZBLIB_ZCL_POLL_CONTROL_OPS_SET_LONG_POLL_INTERVAL,
286 on_zcl_poll_control_set_long_poll_interval_resp, resp_cb_data);
288 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
290 /* Free response callback data */
291 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
293 /* Send failure response */
294 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
302 static void on_zcl_poll_control_set_short_poll_interval_resp(ZigBeeServiceInterface *service_interface,
303 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
305 ZigbeeServiceInterfaceRespCbData_t *cb_data =
306 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
308 ZigbeeZcl_poll_control *poll_object = NULL;
309 GDBusMethodInvocation *invocation = NULL;
311 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
313 NOT_USED(service_interface);
314 NOT_USED(request_id);
316 if (NULL == resp_data || 0 == resp_data_len) {
317 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
322 poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
323 zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
325 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
326 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
328 zigbee_zcl_poll_control_complete_set_short_poll_interval(poll_object, invocation, payload->result);
333 static gboolean on_zcl_poll_control_set_short_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
334 GDBusMethodInvocation *invocation,
337 guint new_short_poll_interval,
340 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
341 ZigbeeZclPollControlSetShortPollInterval_t req;
342 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
346 memset(&req, 0x0, sizeof(ZigbeeZclPollControlSetShortPollInterval_t));
348 /* Update request structure */
349 req.node_id = node_id;
350 req.dest_ep = dest_ep;
351 req.new_short_poll_interval = new_short_poll_interval;
353 /* Allocate response callback data */
355 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
356 invocation, NULL, 0);
357 if (NULL == resp_cb_data) {
358 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
360 /* Send failure response */
361 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
366 /* Dispatch request */
367 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
368 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
369 ZBLIB_ZCL_POLL_CONTROL_OPS_SET_SHORT_POLL_INTERVAL,
371 on_zcl_poll_control_set_short_poll_interval_resp, resp_cb_data);
373 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
375 /* Free response callback data */
376 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
378 /* Send failure response */
379 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
387 void zigbee_service_dbus_interface_zcl_poll_control_notification(ZigBeeServiceInterface *service_interface,
388 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
390 ZigbeeZcl_poll_control *poll_object;
392 zblib_check_null_ret("service_interface", service_interface);
394 if (NULL == noti_data || 0 == noti_data_len) {
395 Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
399 poll_object = _service_interface_ref_zigbee_zcl_poll_control(service_interface);
400 zblib_check_null_ret("poll_object", poll_object);
402 NOT_USED(noti_cb_data);
405 case ZBLIB_ZCL_POLL_CONTROL_NOTI_CHECKIN_RESPONSE: {
406 ZigbeeZclPollControlCheckinResponseNoti_t *rsp =
407 (ZigbeeZclPollControlCheckinResponseNoti_t*)noti_data;
409 Z_LOGD("checkin_response from : [0x%X]", rsp->node_id);
411 zigbee_zcl_poll_control_emit_checkin_response(poll_object, rsp->node_id, rsp->src_ep);
415 Z_LOGE("Unexpected notification [%x]", noti_id);
419 /* ZigbeeZcl_poll_control should be dereferenced */
420 g_object_unref(poll_object);
423 gboolean zigbee_service_dbus_interface_zcl_poll_control_init(ZigBeeServiceInterface *service_interface,
424 ZigbeeObjectSkeleton *zigbee_object)
426 ZigbeeZcl_poll_control *zcl_poll_control_object;
428 if (NULL == service_interface) {
429 Z_LOGE("service_interface is NULL");
433 zcl_poll_control_object = zigbee_zcl_poll_control_skeleton_new();
434 zigbee_object_skeleton_set_zcl_poll_control(zigbee_object, zcl_poll_control_object);
435 g_object_unref(zcl_poll_control_object);
437 Z_LOGI("zcl_poll_control_object: [%p]", zcl_poll_control_object);
440 * Register signal handlers for 'zcl_poll_control' interface
442 g_signal_connect(zcl_poll_control_object,
443 "handle-check-in-response",
444 G_CALLBACK(on_zcl_poll_control_check_in_response), service_interface);
446 g_signal_connect(zcl_poll_control_object,
447 "handle-fast-poll-stop",
448 G_CALLBACK(on_zcl_poll_control_fast_poll_stop), service_interface);
450 g_signal_connect(zcl_poll_control_object,
451 "handle-set-long-poll-interval",
452 G_CALLBACK(on_zcl_poll_control_set_long_poll_interval), service_interface);
454 g_signal_connect(zcl_poll_control_object,
455 "handle-set-short-poll-interval",
456 G_CALLBACK(on_zcl_poll_control_set_short_poll_interval), service_interface);