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>
24 static void *_service_interface_ref_zigbee_zcl_poll_control(
25 ZigBeeServiceInterface *service_interface)
27 ZigbeeObjectSkeleton *zigbee_object = NULL;
28 ZigbeeCustomData_t *custom_data = NULL;
29 ZigbeeZcl_poll_control *poll_object = NULL;
31 custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
32 if (NULL == custom_data) {
33 Z_LOGE("D-BUS service interface custom_data is NULL!");
37 /* Get zigbee object */
38 zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
39 if (NULL == zigbee_object) {
40 Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
44 poll_object = zigbee_object_get_zcl_poll_control(ZIGBEE_OBJECT(zigbee_object));
48 static void on_zcl_poll_control_check_in_response_resp(ZigBeeServiceInterface *service_interface,
49 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
51 ZigbeeServiceInterfaceRespCbData_t *cb_data =
52 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
54 ZigbeeZcl_poll_control *poll_object = NULL;
55 GDBusMethodInvocation *invocation = NULL;
57 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
59 NOT_USED(service_interface);
62 if (NULL == resp_data || 0 == resp_data_len) {
63 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
68 poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
69 zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
71 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
72 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
74 zigbee_zcl_poll_control_complete_check_in_response(poll_object, invocation, payload->result);
79 static gboolean on_zcl_poll_control_check_in_response(ZigbeeZcl_poll_control *zcl_poll_control_object,
80 GDBusMethodInvocation *invocation,
83 gchar start_fast_polling,
84 gshort fast_poll_timeout,
87 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
88 ZigbeeZclPollControlCheckInResponse_t req;
89 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
93 memset(&req, 0x0, sizeof(ZigbeeZclPollControlCheckInResponse_t));
95 /* Update request structure */
96 req.node_id = node_id;
97 req.dest_ep = dest_ep;
98 req.start_fast_polling = start_fast_polling;
99 req.fast_poll_timeout = fast_poll_timeout;
101 /* Allocate response callback data */
103 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
104 invocation, NULL, 0);
105 if (NULL == resp_cb_data) {
106 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
108 /* Send failure response */
109 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
114 /* Dispatch request */
115 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
116 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
117 ZBLIB_ZCL_POLL_CONTROL_OPS_CHECK_IN_RESPONSE,
119 on_zcl_poll_control_check_in_response_resp, resp_cb_data);
121 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
123 /* Free response callback data */
124 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
126 /* Send failure response */
127 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
135 static void on_zcl_poll_control_fast_poll_stop_resp(ZigBeeServiceInterface *service_interface,
136 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
138 ZigbeeServiceInterfaceRespCbData_t *cb_data =
139 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
141 ZigbeeZcl_poll_control *poll_object = NULL;
142 GDBusMethodInvocation *invocation = NULL;
144 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
146 NOT_USED(service_interface);
147 NOT_USED(request_id);
149 if (NULL == resp_data || 0 == resp_data_len) {
150 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
155 poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
156 zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
158 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
159 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
161 zigbee_zcl_poll_control_complete_fast_poll_stop(poll_object, invocation, payload->result);
166 static gboolean on_zcl_poll_control_fast_poll_stop(ZigbeeZcl_poll_control *zcl_poll_control_object,
167 GDBusMethodInvocation *invocation,
172 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
173 ZigbeeZclPollControlFastPollStop_t req;
174 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
178 memset(&req, 0x0, sizeof(ZigbeeZclPollControlFastPollStop_t));
180 /* Update request structure */
181 req.node_id = node_id;
182 req.dest_ep = dest_ep;
184 /* Allocate response callback data */
186 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
187 invocation, NULL, 0);
188 if (NULL == resp_cb_data) {
189 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
191 /* Send failure response */
192 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
197 /* Dispatch request */
198 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
199 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
200 ZBLIB_ZCL_POLL_CONTROL_OPS_FAST_POLL_STOP,
202 on_zcl_poll_control_fast_poll_stop_resp, resp_cb_data);
204 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
206 /* Free response callback data */
207 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
209 /* Send failure response */
210 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
218 static void on_zcl_poll_control_set_long_poll_interval_resp(ZigBeeServiceInterface *service_interface,
219 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
221 ZigbeeServiceInterfaceRespCbData_t *cb_data =
222 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
224 ZigbeeZcl_poll_control *poll_object = NULL;
225 GDBusMethodInvocation *invocation = NULL;
227 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
229 NOT_USED(service_interface);
230 NOT_USED(request_id);
232 if (NULL == resp_data || 0 == resp_data_len) {
233 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
238 poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
239 zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
241 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
242 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
244 zigbee_zcl_poll_control_complete_set_long_poll_interval(poll_object, invocation, payload->result);
249 static gboolean on_zcl_poll_control_set_long_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
250 GDBusMethodInvocation *invocation,
253 guint new_long_poll_interval,
256 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
257 ZigbeeZclPollControlSetLongPollInterval_t req;
258 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
262 memset(&req, 0x0, sizeof(ZigbeeZclPollControlSetLongPollInterval_t));
264 /* Update request structure */
265 req.node_id = node_id;
266 req.dest_ep = dest_ep;
267 req.new_long_poll_interval = new_long_poll_interval;
269 /* Allocate response callback data */
271 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
272 invocation, NULL, 0);
273 if (NULL == resp_cb_data) {
274 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
276 /* Send failure response */
277 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
282 /* Dispatch request */
283 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
284 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
285 ZBLIB_ZCL_POLL_CONTROL_OPS_SET_LONG_POLL_INTERVAL,
287 on_zcl_poll_control_set_long_poll_interval_resp, resp_cb_data);
289 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
291 /* Free response callback data */
292 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
294 /* Send failure response */
295 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
303 static void on_zcl_poll_control_set_short_poll_interval_resp(ZigBeeServiceInterface *service_interface,
304 guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
306 ZigbeeServiceInterfaceRespCbData_t *cb_data =
307 (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
309 ZigbeeZcl_poll_control *poll_object = NULL;
310 GDBusMethodInvocation *invocation = NULL;
312 ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
314 NOT_USED(service_interface);
315 NOT_USED(request_id);
317 if (NULL == resp_data || 0 == resp_data_len) {
318 Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
323 poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
324 zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
326 invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
327 zblib_check_null_free_and_ret("invocation", invocation, cb_data);
329 zigbee_zcl_poll_control_complete_set_short_poll_interval(poll_object, invocation, payload->result);
334 static gboolean on_zcl_poll_control_set_short_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
335 GDBusMethodInvocation *invocation,
338 guint new_short_poll_interval,
341 ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
342 ZigbeeZclPollControlSetShortPollInterval_t req;
343 ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
347 memset(&req, 0x0, sizeof(ZigbeeZclPollControlSetShortPollInterval_t));
349 /* Update request structure */
350 req.node_id = node_id;
351 req.dest_ep = dest_ep;
352 req.new_short_poll_interval = new_short_poll_interval;
354 /* Allocate response callback data */
356 zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
357 invocation, NULL, 0);
358 if (NULL == resp_cb_data) {
359 Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
361 /* Send failure response */
362 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
367 /* Dispatch request */
368 ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
369 ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
370 ZBLIB_ZCL_POLL_CONTROL_OPS_SET_SHORT_POLL_INTERVAL,
372 on_zcl_poll_control_set_short_poll_interval_resp, resp_cb_data);
374 Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
376 /* Free response callback data */
377 zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
379 /* Send failure response */
380 ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
388 void zigbee_service_dbus_interface_zcl_poll_control_notification(ZigBeeServiceInterface *service_interface,
389 guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
391 ZigbeeZcl_poll_control *poll_object;
393 zblib_check_null_ret("service_interface", service_interface);
395 if (NULL == noti_data || 0 == noti_data_len) {
396 Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
400 poll_object = _service_interface_ref_zigbee_zcl_poll_control(service_interface);
401 zblib_check_null_ret("poll_object", poll_object);
403 NOT_USED(noti_cb_data);
406 case ZBLIB_ZCL_POLL_CONTROL_NOTI_CHECKIN_RESPONSE: {
407 ZigbeeZclPollControlCheckinResponseNoti_t *rsp =
408 (ZigbeeZclPollControlCheckinResponseNoti_t*)noti_data;
410 Z_LOGD("checkin_response from : [0x%X]", rsp->node_id);
412 zigbee_zcl_poll_control_emit_checkin_response(poll_object, rsp->node_id, rsp->src_ep);
416 Z_LOGE("Unexpected notification [%x]", noti_id);
420 /* ZigbeeZcl_poll_control should be dereferenced */
421 g_object_unref(poll_object);
425 gboolean zigbee_service_dbus_interface_zcl_poll_control_init(ZigBeeServiceInterface *service_interface,
426 ZigbeeObjectSkeleton *zigbee_object)
428 ZigbeeZcl_poll_control *zcl_poll_control_object;
430 if (NULL == service_interface) {
431 /* LCOV_EXCL_START */
432 Z_LOGE("service_interface is NULL");
437 zcl_poll_control_object = zigbee_zcl_poll_control_skeleton_new();
438 zigbee_object_skeleton_set_zcl_poll_control(zigbee_object, zcl_poll_control_object);
439 g_object_unref(zcl_poll_control_object);
441 Z_LOGI("zcl_poll_control_object: [%p]", zcl_poll_control_object);
444 * Register signal handlers for 'zcl_poll_control' interface
446 g_signal_connect(zcl_poll_control_object,
447 "handle-check-in-response",
448 G_CALLBACK(on_zcl_poll_control_check_in_response), service_interface);
450 g_signal_connect(zcl_poll_control_object,
451 "handle-fast-poll-stop",
452 G_CALLBACK(on_zcl_poll_control_fast_poll_stop), service_interface);
454 g_signal_connect(zcl_poll_control_object,
455 "handle-set-long-poll-interval",
456 G_CALLBACK(on_zcl_poll_control_set_long_poll_interval), service_interface);
458 g_signal_connect(zcl_poll_control_object,
459 "handle-set-short-poll-interval",
460 G_CALLBACK(on_zcl_poll_control_set_short_poll_interval), service_interface);