Implementation for service methods
authorJiwan Kim <ji-wan.kim@samsung.com>
Tue, 31 Jan 2017 10:56:18 +0000 (19:56 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Thu, 11 May 2017 09:10:25 +0000 (18:10 +0900)
Change-Id: Ib2989da2d6e6264c7cb8413d0f02c788b5a37d4e
Signed-off-by: Jiwan Kim <ji-wan.kim@samsung.com>
common/include/zigbee_service_type.h
common/include/zigbee_types.h
zigbee-daemon/zigbee-interface/introspection/service.xml
zigbee-daemon/zigbee-interface/src/zigbee_service_dbus_interface_service.c
zigbee-daemon/zigbee-lib/include/zblib_types.h

index c1c33ce..9b01eb8 100644 (file)
@@ -87,7 +87,7 @@ typedef struct {
 typedef struct {
        int result; /**< Result */
        char enabled; /**< Enabled / Disabled result */
-} ZigbeeServiceServiceState_t;
+} ZigbeeServiceServiceStateResp_t;
 
 /**
  * @brief Definition for get network info structure.
@@ -100,7 +100,7 @@ typedef struct {
        short pan_id; /**< PAN ID (an Network address) */
        char channel; /**< Channel number */
        char radio_tx_power;  /**< Power (dBm) */
-} ZigbeeServiceGetNetworkInfo_t;
+} ZigbeeServiceGetNetworkInfoResp_t;
 
 /**
  * @brief Definition for service 'get_node_type' response.
@@ -109,7 +109,7 @@ typedef struct {
 typedef struct {
        int result; /**< Result */
        char node_type; /**< Node Type */
-} ZigbeeServiceServiceNodeType_t;
+} ZigbeeServiceServiceNodeTypeResp_t;
 
 /**
  * @brief Definition for service get mac structure.
@@ -118,7 +118,58 @@ typedef struct {
 typedef struct {
        int result; /**< Result */
        char eui64[ZIGBEE_EUI64_SIZE]; /**< EUI64 (an IEEE address) */
-} ZigbeeServiceGetMac_t;
+} ZigbeeServiceGetMacResp_t;
+
+/**
+ * @brief Definition for service get details of device info structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       short node_id; /**< Node ID (an Network address) */
+       char node_type; /**< Node Type (an Network address) */
+       char eui64[ZIGBEE_EUI64_SIZE]; /**< EUI64 (an IEEE address) */
+       char endpoint_count; /**< The number of endpoints */
+       char endpoints[ZIGBEE_MAX_ENDPOINTS]; /**< Endpoints */
+} ZigbeeServiceGetDeviceInfoDetailResp_t;
+
+/**
+ * @brief Definition for service get device info structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       int result; /**< Result */
+       int count; /**< The number of detail item */
+       ZigbeeServiceGetDeviceInfoDetailResp_t *list;
+} ZigbeeServiceGetDeviceInfoResp_t;
+
+/**
+ * @brief Definition for service get endpoint list structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       int result; /**< Result */
+       int endpoint_count; /**< The number of endpoints */
+       char endpoints[ZIGBEE_MAX_ENDPOINTS]; /**< Endpoints */
+} ZigbeeServiceGetEndpointListResp_t;
+
+/**
+ * @brief Definition for service get cluster list structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       int result; /**< Result */
+       int cluster_count; /**< The number of clusters */
+       char clusters[ZIGBEE_MAX_CLUSTERS]; /**< Clusters */
+} ZigbeeServiceGetClusterListResp_t;
+
+/**
+ * @brief Definition for service get node type structure.
+ * @since_tizen 3.0
+ */
+typedef struct {
+       int result; /**< Result */
+       char node_type; /**< Node Type (an Network address) */
+} ZigbeeServiceGetNodeTypeResp_t;
 
 /* --------------------------------------------------------------------------------------
  * For Notifications
@@ -133,6 +184,17 @@ typedef struct {
 } ZigbeeServiceServiceFormNetworkDone_t;
 
 /**
+ * @brief Definition for service 'child_joined' response.
+ * @since_tizen 4.0
+ */
+typedef struct {
+       char eui64[ZIGBEE_EUI64_SIZE]; /**< EUI64 (an IEEE address) */
+       int endpoint_count; /**< The number of endpoints */
+       char endpoints[ZIGBEE_MAX_ENDPOINTS]; /**< Endpoints */
+       short node_id; /**< Node ID (an Network address) */
+} ZigbeeServiceServiceChildJoined_t;
+
+/**
  * @brief Definition for service 'child_rejoined' response.
  * @since_tizen 4.0
  */
index 0b96d42..7e7333d 100644 (file)
 #define ZIGBEE_EUI64_SIZE 8
 
 /**
+ * @brief Definition for maximum count of endpoints in bytes (8).
+ * @since_tizen 3.0
+ */
+#define ZIGBEE_MAX_ENDPOINTS 10
+
+/**
+ * @brief Definition for maximum count of clusters in bytes (8).
+ * @since_tizen 3.0
+ */
+#define ZIGBEE_MAX_CLUSTERS 10
+
+/**
  * @brief Definition for custom send payload/data length (128).
  * @since_tizen 3.0
  */
index 7b1e3d2..d8e4f71 100644 (file)
@@ -57,7 +57,7 @@
                <method name='get_endpoint_list'>
                        <arg type='ay' name='eui64' direction='in'/>
                        <arg type='i' name='result' direction='out'/>
-                       <arg type='ay' name='endpoint_list' direction='out'/>
+                       <arg type='a(y)' name='endpoint_list' direction='out'/>
                </method>
                <method name='get_cluster_list'>
                        <arg type='ay' name='eui64' direction='in'/>
                        <arg type='q' name='pan_id'/>
                </signal>
                <signal name='child_joined'>
-                       <arg type='ayyayq' name='child_addr'/>
+                       <arg type='a(y)' name='eui64'/>
+                       <arg type='y' name='endpoint_count'/>
+                       <arg type='a(y)' name='endpoint_list'/>
+                       <arg type='q' name='nodeId'/>
                </signal>
                <signal name='child_rejoined'>
                        <arg type='ay' name='child_addr'/>
index 46fa03e..4f4ab7f 100644 (file)
@@ -51,8 +51,8 @@ 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);
@@ -567,8 +567,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;
 
@@ -892,8 +892,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 +972,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 +995,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 +1074,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 +1093,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);
 }
@@ -1133,6 +1168,9 @@ 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_clusters = NULL;
 
        NOT_USED(service_interface);
        NOT_USED(request_id);
@@ -1149,8 +1187,11 @@ 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_clusters = g_variant_new_from_data(G_VARIANT_TYPE("aq"),
+               payload->clusters, payload->cluster_count, TRUE, NULL, NULL);
+
+       zigbee_service_complete_get_cluster_list(service_object, invocation,
+               payload->result, v_clusters);
 
        g_free(cb_data);
 }
@@ -1223,8 +1264,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);
@@ -1333,7 +1374,26 @@ 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: {
index ba8f2ce..8ffd77e 100644 (file)
  * For Responses
  * -------------------------------------------------------------------------------------*/
 
-/* Previous 'status' return value uses vendor return code directly.
- * It need to be changed */
+/* Enumeration for zigbee library error code. */
 typedef enum
 {
        ZBLIB_ERROR_NONE = 0, /**< Successful */
+       ZBLIB_ERROR_INVALID_PARAMETER, /**< parameter error */
+       ZBLIB_ERROR_PARAMETER_OUT_OF_RANGE, /**< out of range error */
+       ZBLIB_ERROR_INVALID_ENDPOINT, /**< endpoint 0 is reserved for ZDP */
+       ZBLIB_ERROR_INVALID_ADDRESS, /**< wrong address */
+       ZBLIB_ERROR_OUT_OF_MEMORY, /**< out of memory */
+       ZBLIB_ERROR_INVALID_DATA, /**< Invalid data available */
+       ZBLIB_ERROR_IO_ERROR, /**< DBus error */
+       ZBLIB_ERROR_NO_DATA, /**< No data available */
+       ZBLIB_ERROR_NOT_SUPPORTED, /**< not supported */
        ZBLIB_ERROR_UNKNOWN /**< Unknown error */
 } zblib_error_e;