fn-manager: Notify new group found using GroupAdded signal
authorSaurav Babu <saurav.babu@samsung.com>
Tue, 9 Jan 2018 13:13:24 +0000 (18:43 +0530)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:38 +0000 (19:38 +0900)
Signed-off-by: Saurav Babu <saurav.babu@samsung.com>
src/fn-manager/include/fn_gdbus_group.h
src/fn-manager/include/fn_group.h
src/fn-manager/src/familynet_gdbus.xml
src/fn-manager/src/fn_gdbus.c
src/fn-manager/src/fn_gdbus_group.c
src/fn-manager/src/fn_group.c
src/fn-manager/src/fn_iot.c

index 54851ae1e2a3698b7039e05d20ef1f61e429f961..e7097520180fc25ed02cfa38ffad42fca2a52ece 100644 (file)
@@ -3,6 +3,8 @@
 
 #include <fn_group.h>
 
+Group *group_dbus_get_object();
+
 gboolean group_create(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
        gpointer user_data);
 
@@ -27,4 +29,6 @@ gboolean group_device_invite(Group *group, GDBusMethodInvocation *invocation,
 gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
        gpointer user_data);
 
+void notify_group_added(GVariant *group_data);
+
 #endif
index 38764332207e9527253001c16af0e42637adb9db..96bf9e07ad0637b45ac016adfec535d9cd2b7659 100644 (file)
@@ -4,7 +4,11 @@
 #include <fn_iot.h>
 
 typedef struct {
+       char *uri_path;
+       char *device_id;
+       char *host_addr;
        char *group_name;
+       char *resource_type;
        fn_group_type_e type;
 } fn_group_t;
 
@@ -17,6 +21,8 @@ int fn_group_destroy(fn_group_t *handle);
 
 /* Find Remote groups */
 int fn_group_find();
+int fn_group_add_new(char *uri_path, char *device_id, char *device_name,
+                                        char *host_addr, char *resource_type);
 
 /* Join the remote devices in my daemon */
 int fn_group_get_groups(fn_group_t ***handles, int *count); //Get all of group in my daemon
index d2be665bd6ec90dca0cf6163ec2b81dcabe70c78..d3a508d01cba9c38d6ded64a55d552d6d6615ec3 100644 (file)
                        <arg type="aa{sv}" name="groups" direction="out" />
                        <arg type="i" name="result" direction="out" />
                </method>
+
+               <!-- Signal (D-Bus) definitions -->
+               <signal name="GroupAdded">
+                       <arg type="a{sv}" name="group_info" direction="out" />
+               </signal>
        </interface>
 </node>
index 2e6ab2a11a2c292ffdbedd781df0cd800fe36f19..4e769adedfd121fa5e78bc91d9bb01484aaf0c1a 100644 (file)
@@ -1,13 +1,19 @@
 #include <fn_gdbus.h>
 #include <sys/types.h>
 
+static Group *group_skeleton;
+
+Group *group_dbus_get_object()
+{
+       return group_skeleton;
+}
+
 static bool __group_init(GDBusConnection *connection)
 {
        gboolean ret = FALSE;
        GError *error = NULL;
 
        GDBusObjectManagerServer *group;
-       Group *group_skeleton;
 
        // Add interface to default object path
        group_skeleton = group_skeleton_new();
index 2d316c024f79ae89032f0538bb260577bd3acefd..54757ce4124f15cec5cac63732dd0fad7d30c4be 100644 (file)
@@ -77,3 +77,8 @@ gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
 
        return TRUE;
 }
+
+void notify_group_added(GVariant *group_data)
+{
+       group_emit_group_added(group_dbus_get_object(), group_data);
+}
index 11d972e3c41c9d68194d9738780982450fe935de..4f572999508a581619ddaf5e95d8c4f8023d490a 100644 (file)
@@ -1,5 +1,7 @@
 #include <fn_group.h>
 
+GList *found_group_list;
+
 /* Called when daemon is start. */
 int fn_group_initialize()
 {
@@ -65,6 +67,47 @@ int fn_group_find()
        return FN_ERROR_NONE;
 }
 
+int fn_group_add_new(char *uri_path, char *device_id, char *device_name,
+                                        char *host_addr, char *resource_type)
+{
+       int ret;
+       fn_group_t *group;
+       GVariantBuilder builder;
+       GVariant *group_data;
+
+       LOG_BEGIN();
+
+       group = g_try_malloc0(sizeof(fn_group_t));
+       group->uri_path = g_strdup(uri_path);
+       group->device_id = g_strdup(device_id);
+       group->group_name = g_strdup(device_name);
+       group->host_addr = g_strdup(host_addr);
+       group->resource_type =  g_strdup(resource_type);
+
+       found_group_list = g_list_prepend(found_group_list, group);
+
+       g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
+
+       g_variant_builder_add(&builder, "{sv}", "URI",
+                                                 g_variant_new_string(group->uri_path));
+       g_variant_builder_add(&builder, "{sv}", "DeviceID",
+                                                 g_variant_new_string(group->device_id));
+       g_variant_builder_add(&builder, "{sv}", "GroupName",
+                                                 g_variant_new_string(group->group_name));
+       g_variant_builder_add(&builder, "{sv}", "HostAddress",
+                                                 g_variant_new_string(group->host_addr));
+       g_variant_builder_add(&builder, "{sv}", "GroupDeviceType",
+                                                 g_variant_new_string(group->resource_type));
+
+       group_data = g_variant_builder_end(&builder);
+
+       notify_group_added(group_data);
+
+       LOG_END();
+
+       return FN_ERROR_NONE;
+}
+
 /* Join the remote devices in my daemon */
 int fn_group_get_groups(fn_group_t ***handles, int *count){} //Get all of group in my daemon
 int fn_group_get_remote_devices(/* callback */){} //Get all of device in network (Async)
index 985fc39311bfedf826d6946fdb00f42362680cf9..e3cfa8a99a9c5eac173a64e1b83c75e1ae5cff40 100644 (file)
@@ -1,4 +1,5 @@
 #include <fn_iot.h>
+#include <fn_group.h>
 
 int fn_iot_initialize()
 {
@@ -142,6 +143,17 @@ int fn_iot_bind_resource(fn_resource_type_e parent_resource_type, char *parent_u
        return FN_ERROR_NONE;
 }
 
+static bool _get_res_type_cb(const char *string, void *user_data)
+{
+       char **resource_type = user_data;
+
+       *resource_type = g_strdup(string);
+
+       LOG_DEBUG("resource type : %s", *resource_type);
+
+       return IOTCON_FUNC_CONTINUE;
+}
+
 static bool _found_resource(iotcon_remote_resource_h resource,
                                                iotcon_error_e result, void *user_data)
 {
@@ -151,6 +163,7 @@ static bool _found_resource(iotcon_remote_resource_h resource,
        char *resource_device_id;
        char *resource_device_name;
        char *resource_host;
+       char *resource_type;
 
        LOG_DEBUG("Resource Found");
 
@@ -193,6 +206,18 @@ static bool _found_resource(iotcon_remote_resource_h resource,
                return IOTCON_FUNC_CONTINUE;
        }
 
+       ret = iotcon_resource_types_foreach(resource_types, _get_res_type_cb,
+                       &resource_type);
+       if (IOTCON_ERROR_NONE != ret) {
+               LOG_ERR("Failed to get foreach resource types");
+               return IOTCON_FUNC_CONTINUE;
+       }
+
+       fn_group_add_new(resource_uri_path, resource_device_id,
+                                        resource_device_name, resource_host, resource_type);
+
+       g_free(resource_type);
+
        return IOTCON_FUNC_CONTINUE;
 }