#include "zigbee_service_interface_common.h"
+#include <zblib_driver_zcl_poll_control.h>
+
+static void *_service_interface_ref_zigbee_zcl_poll_control(
+ ZigBeeServiceInterface *service_interface)
+{
+ ZigbeeObjectSkeleton *zigbee_object = NULL;
+ ZigbeeCustomData_t *custom_data = NULL;
+ ZigbeeZcl_poll_control *poll_object = NULL;
+
+ custom_data = (ZigbeeCustomData_t *)zblib_service_interface_ref_user_data(service_interface);
+ if (NULL == custom_data) {
+ Z_LOGE("D-BUS service interface custom_data is NULL!");
+ return NULL;
+ }
+
+ /* Get zigbee object */
+ zigbee_object = g_hash_table_lookup(custom_data->objects, ZIGBEE_SERVICE_PATH);
+ if (NULL == zigbee_object) {
+ Z_LOGW("Cannot find ZigBee D-BUS interface object!", zigbee_object);
+ return NULL;
+ }
+
+ poll_object = zigbee_object_get_zcl_poll_control(ZIGBEE_OBJECT(zigbee_object));
+ return poll_object;
+}
+
+static void on_zcl_poll_control_check_in_response_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeZcl_poll_control *poll_object = NULL;
+ GDBusMethodInvocation *invocation = NULL;
+
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+ g_free(cb_data);
+ return;
+ }
+
+ poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_zcl_poll_control_complete_check_in_response(poll_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_zcl_poll_control_check_in_response(ZigbeeZcl_poll_control *zcl_poll_control_object,
GDBusMethodInvocation *invocation,
gshort node_id,
- gchar dst_ep,
+ gchar dest_ep,
gchar start_fast_polling,
gshort fast_poll_timeout,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeZclPollControlCheckInResponse_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(zcl_poll_control_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(node_id);
- NOT_USED(dst_ep);
- NOT_USED(start_fast_polling);
- NOT_USED(fast_poll_timeout);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ memset(&req, 0x0, sizeof(ZigbeeZclPollControlCheckInResponse_t));
+
+ /* Update request structure */
+ req.node_id = node_id;
+ req.dest_ep = dest_ep;
+ req.start_fast_polling = start_fast_polling;
+ req.fast_poll_timeout = fast_poll_timeout;
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
+ ZBLIB_ZCL_POLL_CONTROL_OPS_CHECK_IN_RESPONSE,
+ &req, sizeof(req),
+ on_zcl_poll_control_check_in_response_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_zcl_poll_control_fast_poll_stop_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeZcl_poll_control *poll_object = NULL;
+ GDBusMethodInvocation *invocation = NULL;
+
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+ g_free(cb_data);
+ return;
+ }
+
+ poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_zcl_poll_control_complete_fast_poll_stop(poll_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_zcl_poll_control_fast_poll_stop(ZigbeeZcl_poll_control *zcl_poll_control_object,
GDBusMethodInvocation *invocation,
gshort node_id,
- gchar dst_ep,
+ gchar dest_ep,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeZclPollControlFastPollStop_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(zcl_poll_control_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(node_id);
- NOT_USED(dst_ep);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ memset(&req, 0x0, sizeof(ZigbeeZclPollControlFastPollStop_t));
+
+ /* Update request structure */
+ req.node_id = node_id;
+ req.dest_ep = dest_ep;
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
+ ZBLIB_ZCL_POLL_CONTROL_OPS_FAST_POLL_STOP,
+ &req, sizeof(req),
+ on_zcl_poll_control_fast_poll_stop_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_zcl_poll_control_set_long_poll_interval_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeZcl_poll_control *poll_object = NULL;
+ GDBusMethodInvocation *invocation = NULL;
+
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+ g_free(cb_data);
+ return;
+ }
+
+ poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_zcl_poll_control_complete_set_long_poll_interval(poll_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_zcl_poll_control_set_long_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
GDBusMethodInvocation *invocation,
gshort node_id,
- gchar dst_ep,
+ gchar dest_ep,
guint new_long_poll_interval,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeZclPollControlSetLongPollInterval_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(zcl_poll_control_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(node_id);
- NOT_USED(dst_ep);
- NOT_USED(new_long_poll_interval);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ memset(&req, 0x0, sizeof(ZigbeeZclPollControlSetLongPollInterval_t));
+
+ /* Update request structure */
+ req.node_id = node_id;
+ req.dest_ep = dest_ep;
+ req.new_long_poll_interval = new_long_poll_interval;
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
+ ZBLIB_ZCL_POLL_CONTROL_OPS_SET_LONG_POLL_INTERVAL,
+ &req, sizeof(req),
+ on_zcl_poll_control_set_long_poll_interval_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
+static void on_zcl_poll_control_set_short_poll_interval_resp(ZigBeeServiceInterface *service_interface,
+ guint request_id, gpointer resp_data, guint resp_data_len, gpointer resp_cb_data)
+{
+ ZigbeeServiceInterfaceRespCbData_t *cb_data =
+ (ZigbeeServiceInterfaceRespCbData_t *)resp_cb_data;
+
+ ZigbeeZcl_poll_control *poll_object = NULL;
+ GDBusMethodInvocation *invocation = NULL;
+
+ ZigbeeGeneralResp_t *payload = (ZigbeeGeneralResp_t *)resp_data;
+
+ NOT_USED(service_interface);
+ NOT_USED(request_id);
+
+ if (NULL == resp_data || 0 == resp_data_len) {
+ Z_LOGE("resp_data=%p or resp_data_len=%d is null", resp_data, resp_data_len);
+ g_free(cb_data);
+ return;
+ }
+
+ poll_object = zigbee_service_dbus_interface_ref_interface_object(cb_data);
+ zblib_check_null_free_and_ret("poll_object", poll_object, cb_data);
+
+ invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
+ zblib_check_null_free_and_ret("invocation", invocation, cb_data);
+
+ zigbee_zcl_poll_control_complete_set_short_poll_interval(poll_object, invocation, payload->result);
+
+ g_free(cb_data);
+}
+
static gboolean on_zcl_poll_control_set_short_poll_interval(ZigbeeZcl_poll_control *zcl_poll_control_object,
GDBusMethodInvocation *invocation,
gshort node_id,
- gchar dst_ep,
+ gchar dest_ep,
guint new_short_poll_interval,
gpointer user_data)
{
- ZigBeeService *service = (ZigBeeService *)user_data;
+ ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+ ZigbeeZclPollControlSetShortPollInterval_t req;
+ ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
- NOT_USED(zcl_poll_control_object);
- NOT_USED(invocation);
- NOT_USED(service);
- NOT_USED(node_id);
- NOT_USED(dst_ep);
- NOT_USED(new_short_poll_interval);
+ gboolean ret;
- /*
- * TODO -
- * Create and send request for processing
- */
+ memset(&req, 0x0, sizeof(ZigbeeZclPollControlSetShortPollInterval_t));
+
+ /* Update request structure */
+ req.node_id = node_id;
+ req.dest_ep = dest_ep;
+ req.new_short_poll_interval = new_short_poll_interval;
+
+ /* Allocate response callback data */
+ resp_cb_data =
+ zigbee_service_dbus_interface_create_resp_cb_data(zcl_poll_control_object,
+ invocation, NULL, 0);
+ if (NULL == resp_cb_data) {
+ Z_LOGE("zigbee_service_dbus_interface_create_resp_cb_data failed!");
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
+
+ /* Dispatch request */
+ ret = zigbee_service_dbus_interface_dispatch_request(service_interface,
+ ZBLIB_DRIVER_TYPE_ZCL_POLL_CONTROL,
+ ZBLIB_ZCL_POLL_CONTROL_OPS_SET_SHORT_POLL_INTERVAL,
+ &req, sizeof(req),
+ on_zcl_poll_control_set_short_poll_interval_resp, resp_cb_data);
+ if (FALSE == ret) {
+ Z_LOGE("zigbee_service_dbus_interface_dispatch_request failed!");
+
+ /* Free response callback data */
+ zigbee_service_dbus_interface_destroy_resp_cb_data(resp_cb_data);
+
+ /* Send failure response */
+ ZIGBEE_DBUS_FAIL_RESPONSE(invocation, ZIGBEE_DBUS_DEFAULT_REQ_FAILED_MSG);
+
+ return TRUE;
+ }
return TRUE;
}
-gboolean zigbee_service_dbus_interface_zcl_poll_control_init(ZigBeeService *service,
+void zigbee_service_dbus_interface_zcl_poll_control_notification(ZigBeeServiceInterface *service_interface,
+ guint noti_id, gpointer noti_data, guint noti_data_len, gpointer noti_cb_data)
+{
+ ZigbeeZcl_poll_control *poll_object;
+
+ zblib_check_null_ret("service_interface", service_interface);
+
+ if (NULL == noti_data || 0 == noti_data_len) {
+ Z_LOGE("noti_data=%p or noti_data_len=%d is null", noti_data, noti_data_len);
+ return;
+ }
+
+ poll_object = _service_interface_ref_zigbee_zcl_poll_control(service_interface);
+ zblib_check_null_ret("poll_object", poll_object);
+
+ NOT_USED(noti_cb_data);
+
+ switch (noti_id) {
+ case ZBLIB_ZCL_POLL_CONTROL_NOTI_CHECKIN_RESPONSE: {
+ ZigbeeZclPollControlCheckinResponseNoti_t *rsp =
+ (ZigbeeZclPollControlCheckinResponseNoti_t*)noti_data;
+
+ Z_LOGD("checkin_response from : [0x%X]", rsp->node_id);
+
+ zigbee_zcl_poll_control_emit_checkin_response(poll_object, rsp->node_id, rsp->src_ep);
+ }
+ break;
+ default:
+ Z_LOGE("Unexpected notification [%x]", noti_id);
+ break;
+ }
+
+ /* ZigbeeZcl_poll_control should be dereferenced */
+ g_object_unref(poll_object);
+}
+
+gboolean zigbee_service_dbus_interface_zcl_poll_control_init(ZigBeeServiceInterface *service_interface,
ZigbeeObjectSkeleton *zigbee_object)
{
ZigbeeZcl_poll_control *zcl_poll_control_object;
- if (NULL == service) {
- Z_LOGE("service is NULL");
+ if (NULL == service_interface) {
+ Z_LOGE("service_interface is NULL");
return FALSE;
}
*/
g_signal_connect(zcl_poll_control_object,
"handle-check-in-response",
- G_CALLBACK(on_zcl_poll_control_check_in_response), service);
+ G_CALLBACK(on_zcl_poll_control_check_in_response), service_interface);
g_signal_connect(zcl_poll_control_object,
"handle-fast-poll-stop",
- G_CALLBACK(on_zcl_poll_control_fast_poll_stop), service);
+ G_CALLBACK(on_zcl_poll_control_fast_poll_stop), service_interface);
g_signal_connect(zcl_poll_control_object,
"handle-set-long-poll-interval",
- G_CALLBACK(on_zcl_poll_control_set_long_poll_interval), service);
+ G_CALLBACK(on_zcl_poll_control_set_long_poll_interval), service_interface);
g_signal_connect(zcl_poll_control_object,
"handle-set-short-poll-interval",
- G_CALLBACK(on_zcl_poll_control_set_short_poll_interval), service);
+ G_CALLBACK(on_zcl_poll_control_set_short_poll_interval), service_interface);
return TRUE;
}