#include <fn_group.h>
+Group *group_dbus_get_object();
+
gboolean group_create(Group *group, GDBusMethodInvocation *invocation, gchar *group_name,
gpointer user_data);
gboolean group_device_eject(Group *group, GDBusMethodInvocation *invocation,
gpointer user_data);
+void notify_group_added(GVariant *group_data);
+
#endif
#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;
/* 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
<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>
#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();
return TRUE;
}
+
+void notify_group_added(GVariant *group_data)
+{
+ group_emit_group_added(group_dbus_get_object(), group_data);
+}
#include <fn_group.h>
+GList *found_group_list;
+
/* Called when daemon is start. */
int fn_group_initialize()
{
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)
#include <fn_iot.h>
+#include <fn_group.h>
int fn_iot_initialize()
{
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)
{
char *resource_device_id;
char *resource_device_name;
char *resource_host;
+ char *resource_type;
LOG_DEBUG("Resource Found");
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;
}