Modify API to get in/out cluster list
[platform/core/connectivity/zigbee-manager.git] / zigbee-daemon / zigbee-interface / src / zigbee_service_dbus_interface_service.c
index 46fa03e..cf97c6e 100644 (file)
@@ -51,14 +51,15 @@ static void on_service_enable_resp(ZigBeeServiceInterface *service_interface,
 
        ZigbeeService *service_object;
        GDBusMethodInvocation *invocation;
-       ZigbeeServiceServiceState_t *payload =
-               (ZigbeeServiceServiceState_t*)resp_data;
+       ZigbeeServiceServiceStateResp_t *payload =
+               (ZigbeeServiceServiceStateResp_t*)resp_data;
 
        NOT_USED(service_interface);
        NOT_USED(request_id);
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -83,8 +84,6 @@ static gboolean on_service_enable(ZigbeeService *service_object,
 
        gboolean ret;
 
-       Z_LOGE("KSR");
-
        /* Allocate response callback data */
        resp_cb_data =
                zigbee_service_dbus_interface_create_resp_cb_data(service_object,
@@ -134,6 +133,7 @@ static void on_service_disable_resp(ZigBeeServiceInterface *service_interface,
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -206,6 +206,7 @@ static void on_service_zb_hw_reset_resp(ZigBeeServiceInterface *service_interfac
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -278,6 +279,7 @@ static void on_service_form_network_resp(ZigBeeServiceInterface *service_interfa
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -350,6 +352,7 @@ static void on_service_coex_start_resp(ZigBeeServiceInterface *service_interface
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -429,6 +432,7 @@ static void on_service_coex_stop_resp(ZigBeeServiceInterface *service_interface,
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -501,6 +505,7 @@ static void on_service_leave_network_resp(ZigBeeServiceInterface *service_interf
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -567,8 +572,8 @@ static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_int
        ZigbeeService *service_object;
        GDBusMethodInvocation *invocation;
 
-       ZigbeeServiceGetNetworkInfo_t *payload =
-               (ZigbeeServiceGetNetworkInfo_t*)resp_data;
+       ZigbeeServiceGetNetworkInfoResp_t *payload =
+               (ZigbeeServiceGetNetworkInfoResp_t*)resp_data;
 
        GVariant *v_eui64 = NULL;
 
@@ -577,6 +582,7 @@ static void on_service_get_network_info_resp(ZigBeeServiceInterface *service_int
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -654,6 +660,7 @@ static void on_service_permit_join_resp(ZigBeeServiceInterface *service_interfac
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -735,6 +742,7 @@ static void on_service_leave_request_resp(ZigBeeServiceInterface *service_interf
 
        if (NULL == resp_data || 0 == resp_data_len) {
                Z_LOGE("resp_data is null");
+               g_free(cb_data);
                return;
        }
 
@@ -768,8 +776,8 @@ static gboolean on_service_leave_request(ZigbeeService *service_object,
        memset(&req, 0x0, sizeof(ZigbeeServiceLeaveRequest_t));
 
        /* Update request structure */
-       g_variant_get(eui64, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
+       g_variant_get(eui64, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
                i++;
                if (i >= ZIGBEE_EUI64_SIZE)
                        break;
@@ -777,6 +785,12 @@ static gboolean on_service_leave_request(ZigbeeService *service_object,
        req.remove_child = remove_child;
        req.rejoin = rejoin;
 
+       Z_LOGD("IEEE Address = %X:%X:%X:%X:%X:%X:%X:%X",
+               req.eui64[0], req.eui64[1], req.eui64[2], req.eui64[3],
+               req.eui64[4], req.eui64[5], req.eui64[6], req.eui64[7]);
+       Z_LOGD("remove_child [%d]", remove_child);
+       Z_LOGD("rejoin [%d]", rejoin);
+
        /* Allocate response callback data */
        resp_cb_data =
                zigbee_service_dbus_interface_create_resp_cb_data(service_object,
@@ -892,8 +906,8 @@ static void on_service_get_mac_resp(ZigBeeServiceInterface *service_interface,
 
        ZigbeeService *service_object;
        GDBusMethodInvocation *invocation;
-       ZigbeeServiceGetMac_t *payload =
-               (ZigbeeServiceGetMac_t*)resp_data;
+       ZigbeeServiceGetMacResp_t *payload =
+               (ZigbeeServiceGetMacResp_t*)resp_data;
 
        GVariant *v_eui64 = NULL;
 
@@ -972,6 +986,13 @@ static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_inte
 
        ZigbeeService *service_object;
        GDBusMethodInvocation *invocation;
+       ZigbeeServiceGetDeviceInfoResp_t *payload =
+               (ZigbeeServiceGetDeviceInfoResp_t*)resp_data;
+
+       GVariant *variant = NULL;
+       GVariantBuilder* builder = NULL;
+       int i = 0;
+       int index = 0;
 
        NOT_USED(service_interface);
        NOT_USED(request_id);
@@ -988,8 +1009,30 @@ static void on_service_get_device_info_resp(ZigBeeServiceInterface *service_inte
        invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
        zblib_check_null_free_and_ret("invocation", invocation, cb_data);
 
-       /* To-Do : zigbee_service_complete_get_device_list */
-       //zigbee_service_complete_get_device_info(service_object, invocation, resp_data);
+       builder = g_variant_builder_new(G_VARIANT_TYPE ("a(qyayyay)"));
+       for (index = 0; index < payload->count; index++) {
+               ZigbeeServiceGetDeviceInfoDetailResp_t *device = &(payload->list[index]);
+               GVariantBuilder* mac_builder = g_variant_builder_new(G_VARIANT_TYPE ("ay"));
+               GVariantBuilder* endpoint_builder = g_variant_builder_new(G_VARIANT_TYPE ("ay"));
+
+               for (i = 0; i < ZIGBEE_EUI64_SIZE; i++) {
+                       g_variant_builder_add (mac_builder, "y", device->eui64[i]);
+               }
+               for (i = 0; i < device->endpoint_count; i++) {
+                       g_variant_builder_add (endpoint_builder, "y", device->endpoints[i]);
+               }
+
+               g_variant_builder_add (builder, "(qyayyay)",
+                       device->node_id, device->node_type,
+                       mac_builder, device->endpoint_count, endpoint_builder);
+
+               g_variant_builder_unref (mac_builder);
+               g_variant_builder_unref (endpoint_builder);
+       }
+
+       variant = g_variant_builder_end(builder);
+       zigbee_service_complete_get_device_info(service_object, invocation,
+               payload->result, variant);
 
        g_free(cb_data);
 }
@@ -1045,6 +1088,9 @@ static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_in
 
        ZigbeeService *service_object;
        GDBusMethodInvocation *invocation;
+       ZigbeeServiceGetEndpointListResp_t *payload =
+               (ZigbeeServiceGetEndpointListResp_t*)resp_data;
+       GVariant *v_endpoints = NULL;
 
        NOT_USED(service_interface);
        NOT_USED(request_id);
@@ -1061,8 +1107,11 @@ static void on_service_get_endpoint_list_resp(ZigBeeServiceInterface *service_in
        invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
        zblib_check_null_free_and_ret("invocation", invocation, cb_data);
 
-       /* To fix : end-points must be changed gchar* -> GVariant ay */
-       //zigbee_service_complete_get_endpoint_list(service_object, invocation, resp_data);
+       v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+               payload->endpoints, payload->endpoint_count, TRUE, NULL, NULL);
+
+       zigbee_service_complete_get_endpoint_list(service_object, invocation,
+               payload->result, v_endpoints);
 
        g_free(cb_data);
 }
@@ -1084,8 +1133,8 @@ static gboolean on_service_get_endpoint_list(ZigbeeService *service_object,
        memset(&req, 0x0, sizeof(ZigbeeServiceGetEndpointList_t));
 
        /* Update request structure */
-       g_variant_get(eui64, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
+       g_variant_get(eui64, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
                i++;
                if (i >= ZIGBEE_EUI64_SIZE)
                        break;
@@ -1133,6 +1182,10 @@ static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_int
 
        ZigbeeService *service_object;
        GDBusMethodInvocation *invocation;
+       ZigbeeServiceGetClusterListResp_t *payload =
+               (ZigbeeServiceGetClusterListResp_t*)resp_data;
+       GVariant *v_in_clusters = NULL;
+       GVariant *v_out_clusters = NULL;
 
        NOT_USED(service_interface);
        NOT_USED(request_id);
@@ -1149,8 +1202,13 @@ static void on_service_get_cluster_list_resp(ZigBeeServiceInterface *service_int
        invocation = zigbee_service_dbus_interface_ref_invocation(cb_data);
        zblib_check_null_free_and_ret("invocation", invocation, cb_data);
 
-       /* To-Do : zigbee_service_complete_get_cluster_list */
-       //zigbee_service_complete_get_cluster_list(service_object, invocation, resp_data);
+       v_in_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
+               payload->in_clusters, payload->in_cluster_count, TRUE, NULL, NULL);
+       v_out_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
+               payload->out_clusters, payload->out_cluster_count, TRUE, NULL, NULL);
+
+       zigbee_service_complete_get_cluster_list(service_object, invocation,
+               payload->result, v_in_clusters, v_out_clusters);
 
        g_free(cb_data);
 }
@@ -1173,8 +1231,8 @@ static gboolean on_service_get_cluster_list(ZigbeeService *service_object,
        memset(&req, 0x0, sizeof(ZigbeeServiceGetClusterList_t));
 
        /* Update request structure */
-       g_variant_get(eui64, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
+       g_variant_get(eui64, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", &(req.eui64[i]))) {
                i++;
                if (i >= ZIGBEE_EUI64_SIZE)
                        break;
@@ -1223,8 +1281,8 @@ static void on_service_get_node_type_resp(ZigBeeServiceInterface *service_interf
 
        ZigbeeService *service_object;
        GDBusMethodInvocation *invocation;
-       ZigbeeServiceServiceNodeType_t *payload =
-               (ZigbeeServiceServiceNodeType_t *)resp_data;
+       ZigbeeServiceServiceNodeTypeResp_t *payload =
+               (ZigbeeServiceServiceNodeTypeResp_t *)resp_data;
 
        NOT_USED(service_interface);
        NOT_USED(request_id);
@@ -1264,8 +1322,8 @@ static gboolean on_service_get_node_type(ZigbeeService *service_object,
        memset(&req, 0x0, sizeof(ZigbeeServiceGetNodeType_t));
 
        /* Update request structure */
-       g_variant_get(eui64, "ay", &iter);
-       while (g_variant_iter_loop(iter, "y", req.eui64[i])) {
+       g_variant_get(eui64, "a(y)", &iter);
+       while (g_variant_iter_loop(iter, "(y)", req.eui64[i])) {
                i++;
                if (i >= ZIGBEE_EUI64_SIZE)
                        break;
@@ -1333,19 +1391,53 @@ void zigbee_service_dbus_interface_service_notification(ZigBeeServiceInterface *
        }
        break;
        case ZBLIB_SERVICE_NOTI_CHILD_JOINED: {
-               zigbee_service_emit_child_joined(service_object, (GVariant *)noti_data);
+               ZigbeeServiceServiceChildJoined_t *child_t =
+                       (ZigbeeServiceServiceChildJoined_t*)noti_data;
+
+               GVariant *v_eui64 = NULL;
+               GVariant *v_endpoints = NULL;
+
+               v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+                       child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
+               v_endpoints = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+                       child_t->endpoints, child_t->endpoint_count, TRUE, NULL, NULL);
+               if (NULL == v_eui64 || NULL == v_endpoints) {
+                       Z_LOGE("Failed to create variant!");
+                       if (v_eui64)
+                               g_object_unref(v_eui64);
+                       if (v_endpoints)
+                               g_object_unref(v_endpoints);
+               } else {
+                       zigbee_service_emit_child_joined(service_object,
+                               v_eui64, child_t->endpoint_count, v_endpoints, child_t->node_id);
+               }
        }
        break;
        case ZBLIB_SERVICE_NOTI_CHILD_REJOINED: {
-               ZigbeeServiceServiceChildRejoined_t ieee_addr_t;
-               memcpy(&ieee_addr_t, noti_data, noti_data_len);
-               zigbee_service_emit_child_rejoined(service_object, ieee_addr_t.eui64);
+               ZigbeeServiceServiceChildRejoined_t *child_t =
+                       (ZigbeeServiceServiceChildRejoined_t*)noti_data;
+
+               GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+                       child_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
+               if (NULL == v_eui64) {
+                       Z_LOGE("Failed to create variant!");
+               } else {
+                       zigbee_service_emit_child_rejoined(service_object, v_eui64);
+               }
        }
        break;
        case ZBLIB_SERVICE_NOTI_CHILD_LEFT: {
-               ZigbeeServiceServiceChildLeft_t child_left_t;
-               memcpy(&child_left_t, noti_data, noti_data_len);
-               zigbee_service_emit_child_left(service_object, child_left_t.eui64, child_left_t.status);
+               ZigbeeServiceServiceChildLeft_t *child_left_t =
+                       (ZigbeeServiceServiceChildLeft_t*)noti_data;
+
+               GVariant *v_eui64 = g_variant_new_from_data(G_VARIANT_TYPE("a(y)"),
+                       child_left_t->eui64, ZIGBEE_EUI64_SIZE, TRUE, NULL, NULL);
+               if (NULL == v_eui64) {
+                       Z_LOGE("Failed to create variant!");
+               } else {
+                       zigbee_service_emit_child_left(service_object,
+                               v_eui64, child_left_t->status);
+               }
        }
        break;
        case ZBLIB_SERVICE_NOTI_LEAVE_NETWORK_DONE: {