Adding service interface layer logic for request processing
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_on_off.c
index a269b0f..15eda35 100644 (file)
 
 #include "zigbee_service_interface_common.h"
 
+#include <zblib_driver_on_off.h>
+
+static void on_on_off_set_on_off_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;
+
+       NOT_USED(cb_data);
+       NOT_USED(service_interface);
+       NOT_USED(request_id);
+       NOT_USED(resp_data);
+       NOT_USED(resp_data_len);
+}
+
 static gboolean on_on_off_set_on_off(ZigbeeOn_off *on_off_object,
        GDBusMethodInvocation *invocation,
        gshort node_id,
@@ -25,52 +40,125 @@ static gboolean on_on_off_set_on_off(ZigbeeOn_off *on_off_object,
        gchar on_off_type,
        gpointer user_data)
 {
-       ZigBeeService *service = (ZigBeeService *)user_data;
+       ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+       ZigbeeOnOffSetOnOff_t req;
+       ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
 
-       NOT_USED(on_off_object);
-       NOT_USED(invocation);
-       NOT_USED(service);
-       NOT_USED(node_id);
-       NOT_USED(endpoint);
-       NOT_USED(on_off_type);
+       gboolean ret;
 
-       /*
-        * TODO -
-        * Create and send request for processing
-        */
+       memset(&req, 0x0, sizeof(ZigbeeOnOffSetOnOff_t));
+
+       /* Update request structure */
+       req.node_id = node_id;
+       req.endpoint = endpoint;
+       req.on_off_type = on_off_type;
+
+       /* Allocate response callback data */
+       resp_cb_data =
+               zigbee_service_dbus_interface_create_resp_cb_data(on_off_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_ON_OFF,
+               ZBLIB_ON_OFF_OPS_SET_ON_OFF,
+               &req, sizeof(req),
+               on_on_off_set_on_off_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_on_off_get_on_off_state_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;
+
+       NOT_USED(cb_data);
+       NOT_USED(service_interface);
+       NOT_USED(request_id);
+       NOT_USED(resp_data);
+       NOT_USED(resp_data_len);
+}
+
 static gboolean on_on_off_get_on_off_state(ZigbeeOn_off *on_off_object,
        GDBusMethodInvocation *invocation,
        gshort node_id,
        gchar endpoint,
        gpointer user_data)
 {
-       ZigBeeService *service = (ZigBeeService *)user_data;
+       ZigBeeServiceInterface *service_interface = (ZigBeeServiceInterface *)user_data;
+       ZigbeeOnOffGetOnOffState_t req;
+       ZigbeeServiceInterfaceRespCbData_t *resp_cb_data = NULL;
 
-       NOT_USED(on_off_object);
-       NOT_USED(invocation);
-       NOT_USED(service);
-       NOT_USED(node_id);
-       NOT_USED(endpoint);
+       gboolean ret;
 
-       /*
-        * TODO -
-        * Create and send request for processing
-        */
+       memset(&req, 0x0, sizeof(ZigbeeOnOffGetOnOffState_t));
+
+       /* Update request structure */
+       req.node_id = node_id;
+       req.endpoint = endpoint;
+
+       /* Allocate response callback data */
+       resp_cb_data =
+               zigbee_service_dbus_interface_create_resp_cb_data(on_off_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_ON_OFF,
+               ZBLIB_ON_OFF_OPS_GET_ON_OFF_STATE,
+               &req, sizeof(req),
+               on_on_off_get_on_off_state_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_on_off_init(ZigBeeService *service,
+gboolean zigbee_service_dbus_interface_on_off_init(ZigBeeServiceInterface *service_interface,
        ZigbeeObjectSkeleton *zigbee_object)
 {
        ZigbeeOn_off *on_off_object;
 
-       if (NULL == service) {
-               Z_LOGE("service is NULL");
+       if (NULL == service_interface) {
+               Z_LOGE("service_interface is NULL");
                return FALSE;
        }
 
@@ -85,11 +173,11 @@ gboolean zigbee_service_dbus_interface_on_off_init(ZigBeeService *service,
         */
        g_signal_connect(on_off_object,
                "handle-set-on-off",
-               G_CALLBACK(on_on_off_set_on_off), service);
+               G_CALLBACK(on_on_off_set_on_off), service_interface);
 
        g_signal_connect(on_off_object,
                "handle-get-on-off-state",
-               G_CALLBACK(on_on_off_get_on_off_state), service);
+               G_CALLBACK(on_on_off_get_on_off_state), service_interface);
 
        return TRUE;
 }