Remove group device resource in fn-manager
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 11 Jan 2018 06:08:42 +0000 (15:08 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:38 +0000 (19:38 +0900)
- and, add capi & test of get found groups

Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
capi/include/familynet.h
capi/include/familynet_debug.h
capi/src/familynet.c
capi/unittest/familynet_unit_test.cpp
src/fn-manager/include/fn_enum.h [changed mode: 0644->0755]
src/fn-manager/src/fn_group.c
src/fn-manager/src/fn_iot.c
src/fn-manager/src/fn_resource.c [changed mode: 0644->0755]

index f52e1406ae3a3114554942dcfb633fbe754adc19..c3e00e64a4883545b730ab07e1e8f2d37fd414de 100755 (executable)
@@ -29,7 +29,7 @@ int familynet_group_create(char *group_name);
 /* familynet_group_find : find groups in my daemon + remote groups in network */
 int familynet_group_find(int timeout, familynet_group_found_cb find_cb, familynet_group_finish_cb finish_cb, void *user_data);
 /* familynet_group_find : find groups in my daemon + remote groups in network */
-int familynet_group_get_found_group(familynet_group_h **groups, int *count);
+int familynet_group_get_found_groups(familynet_group_h **groups, int *count);
 /* familynet_group_join : join to remote group. if group handle is my daemon's, then the api return fail error */
 int familynet_group_join(familynet_group_h group_handle, familynet_group_found_cb callback, void *user_data);
 /* familynet_group_join : leave from remote group. if group handle is my daemon's, then the api return fail error */
@@ -57,6 +57,8 @@ int familynet_group_device_eject(familynet_group_h group_handle,
 
 /* Group Information Module */
 int familynet_group_information_get_type(familynet_group_h group_handle, familynet_group_type_e *type);
+int familynet_group_information_get_resource_type(familynet_group_h group_handle, char **resource_type);
+int familynet_group_information_get_uri_path(familynet_group_h group_handle, char **uri_path);
 
 /* Group Device Information Module */
 /* I think the information in the group device is the same as the "device informations" */
index 96fedeb59323828788256f394601eeb82f241978..74f112b6c33a6865569e2b9b76fd01e3a235e153 100755 (executable)
@@ -12,6 +12,7 @@
 #define COLOR_CYAN  "\033[0;36m"
 #define COLOR_GRAY  "\033[0;37m"
 #define COLOR_END   "\033[0;m"
+#define LOG_TAG "FN_MANAGER_CAPI"
 
 #define _ERR(fmt, ...) \
         do { \
index c49ac0f8320d4be57e0e9474959f1107c8822d41..f64fc2cfd79ec395eb835320b917edf4e72a2c04 100755 (executable)
@@ -235,6 +235,66 @@ int familynet_group_find(int timeout, familynet_group_found_cb found_cb, familyn
        return ret;
 }
 
+int familynet_group_get_found_groups(familynet_group_h **groups, int *count)
+{
+       int ret = 0;
+       bool result = false;
+       GVariant *va = NULL;
+       GError *error = NULL;
+
+       /* get groups from daemon using gdbus */
+       group_call_get_found_groups_sync(group_proxy, &ret, &va, NULL, &error);
+       *count = g_variant_n_children(va);
+
+       _ERR("get found groups : %d", *count);
+
+       if (*count > 0) {
+               GVariantIter *iter = NULL, *iter_row = NULL;
+               GVariant *key_value;
+               const gchar *key;
+               guint i = 0;
+
+               *groups = g_new0(familynet_group_h, *count);
+
+               g_variant_get(va, "aa{sv}", &iter);
+               while (g_variant_iter_next(iter, "a{sv}", &iter_row)) {
+                       familynet_group_t *group = NULL;
+                       familynet_group_type_e type;
+                       char *uri_path;
+                       char *device_id;
+                       char *group_name;
+                       char *host_addr;
+                       char *resource_type;
+
+                       while (g_variant_iter_loop(iter_row, "{sv}", &key, &key_value)) {
+                               if (g_strcmp0(key, "URI") == 0) {
+                                       uri_path = g_variant_get_string(key_value, NULL);
+                               } else if (g_strcmp0(key, "DeviceID") == 0) {
+                                       device_id = g_variant_get_string(key_value, NULL);
+                               } else if (g_strcmp0(key, "GroupName") == 0) {
+                                       group_name = g_variant_get_string(key_value, NULL);
+                               } else if (g_strcmp0(key, "HostAddress") == 0) {
+                                       host_addr = g_variant_get_string(key_value, NULL);
+                               } else if (g_strcmp0(key, "GroupDeviceType") == 0) {
+                                       resource_type = g_variant_get_string(key_value, NULL);
+                               } else if (g_strcmp0(key, "GroupType") == 0) {
+                                       type = g_variant_get_int32(key_value);
+                               }
+                       }
+                       g_variant_iter_free(iter_row);
+
+                       group = _create_group_handle(uri_path,
+                               device_id, group_name, host_addr, resource_type, type);
+
+                       (*groups)[i++] = (familynet_group_h)group;
+               }
+               g_variant_iter_free(iter);
+       }
+       g_variant_unref(va);
+
+       return ret;
+}
+
 /* group merge */
 int familynet_group_merge(familynet_group_h dest_group, familynet_group_h src_group)
 {
@@ -249,3 +309,19 @@ int familynet_group_information_get_type(familynet_group_h group_handle, familyn
        return 0;
 }
 
+int familynet_group_information_get_resource_type(familynet_group_h group_handle, char **resource_type)
+{
+       familynet_group_t *group = (familynet_group_t *)group_handle;
+       *resource_type = g_strdup(group->resource_type);
+
+       return 0;
+}
+
+int familynet_group_information_get_uri_path(familynet_group_h group_handle, char **uri_path)
+{
+       familynet_group_t *group = (familynet_group_t *)group_handle;
+       *uri_path = g_strdup(group->uri_path);
+
+       return 0;
+}
+
index a67746201bb7afe7cfb5d3876a2348f64b1f046a..816074acb1392488a763c4fafb2a0dff1304472f 100755 (executable)
@@ -58,7 +58,19 @@ void _familynet_finish_cb(int result, void *user_data)
        cout << "find finish : " << result << endl;
        g_main_loop_quit(main_loop);
 
-
+       familynet_group_h *groups;
+       int count;
+
+       familynet_group_get_found_groups(&groups, &count);
+       cout << "Found groups device count : " << count << endl;
+
+       for (int i = 0; i < count; i++) {
+               familynet_group_type_e type;
+               char *uri_path;
+               familynet_group_information_get_type(groups[i], &type);
+               familynet_group_information_get_uri_path(groups[i], &uri_path);
+               cout << i+1 << ". device group type : " << type << ", uri_path : " << uri_path << endl;
+       }
 }
 
 TEST(familynet, familynet_group_find_p) {
old mode 100644 (file)
new mode 100755 (executable)
index d6b7acb..5dc223f
@@ -25,7 +25,6 @@ typedef enum {
 /* resource type enum */
 typedef enum {
        FN_RESOURCE_TYPE_GROUP = 0,
-       FN_RESOURCE_TYPE_GROUP_DEVICE,
        FN_RESOURCE_TYPE_OPERATION,
        FN_RESOURCE_TYPE_MAX
 } fn_resource_type_e;
index 81ffb493b62d41775de2c5eac099a79ff10a4725..1bcaef6c0488a6f8d868984ca9545d4ec0e442eb 100755 (executable)
@@ -45,12 +45,36 @@ int fn_group_destroy(fn_group_t *handle)
 
 }
 
+void _free_func (gpointer data)
+{
+       fn_group_t *group = (fn_group_t *)data;
+
+       if (group != NULL) {
+               if (group->uri_path != NULL)
+                       g_free(group->uri_path);
+               if (group->device_id != NULL)
+                       g_free(group->device_id);
+               if (group->group_name != NULL)
+                       g_free(group->group_name);
+               if (group->host_addr != NULL)
+                       g_free(group->host_addr);
+               if (group->resource_type != NULL)
+                       g_free(group->resource_type);
+
+               g_free(group);
+       }
+}
+
 int fn_group_find(int timeout)
 {
        int ret;
 
        LOG_BEGIN();
 
+       /* list freeing */
+       g_list_free_full (found_group_list, _free_func);
+       found_group_list = NULL;
+
        ret = fn_iot_discovery_resource(FN_RESOURCE_TYPE_GROUP, timeout);
        if (ret != FN_ERROR_NONE) {
                LOG_ERR("Failed to discover resource : %s",
index c7a76d652ceaa0e9fb238d9414745a21c074e334..9526118ed926b634645e364be4128f4b41ca6454 100755 (executable)
@@ -27,7 +27,7 @@ static bool _request_device_info(iotcon_device_info_h info, iotcon_error_e resul
                The resource uri is /fn/group/device + certain uuid.
                ex) /fn/group/device123123
        */
-       fn_iot_add_resource(FN_RESOURCE_TYPE_GROUP_DEVICE, fn_ctx->device_uuid);
+       //fn_iot_add_resource(FN_RESOURCE_TYPE_GROUP_DEVICE, fn_ctx->device_uuid);
 
        return false;
 }
@@ -222,6 +222,8 @@ static gboolean _timeout_cb(gpointer data)
                ret = 0;
 
        notify_group_finish(ret);
+
+       return false;
 }
 
 int fn_iot_discovery_resource(fn_resource_type_e resource_type, int timeout)
old mode 100644 (file)
new mode 100755 (executable)
index 676e3f0..ac33108
@@ -4,8 +4,6 @@
 static fn_rd_t fn_rds[] = {
        {FN_RESOURCE_TYPE_GROUP, "core.fn.group", "/fn/group/",
                IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE},
-       {FN_RESOURCE_TYPE_GROUP_DEVICE, "core.fn.group.device", "/fn/group/device",
-               IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE},
        {FN_RESOURCE_TYPE_OPERATION, "core.fn.operation", "/fn/operation/",
                IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE},
 };