/* 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 */
/* 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" */
#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 { \
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)
{
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;
+}
+
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) {
/* 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;
}
+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",
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;
}
ret = 0;
notify_group_finish(ret);
+
+ return false;
}
int fn_iot_discovery_resource(fn_resource_type_e resource_type, int timeout)
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},
};