Change fn manager
authorJihoon Jung <jh8801.jung@samsung.com>
Thu, 14 Dec 2017 08:27:54 +0000 (17:27 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:37 +0000 (19:38 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
src/fn-manager/fn_group.c
src/fn-manager/fn_iot.c
src/fn-manager/fn_log.c
src/fn-manager/fn_manager.c
src/fn-manager/fn_resource.c
src/include/fn_group.h
src/include/fn_iot.h
src/include/fn_log.h
src/include/fn_resource.h

index 21088653e23f3af25c203e9fb2cd1ff9ba99ee53..9ab14a71e6ec918b54ade3c8a40e9c8f6b4b412c 100755 (executable)
@@ -20,10 +20,12 @@ int fn_group_create(char *group_name)
        return ret;
 }
 
-int fn_group_discovery(fn_resource_type_e resource_type, fn_resource_h *resources, int *count)
+int fn_group_discovery(fn_group_h *groups, int *count)
 {
+       int ret;
        //if I'm owner, get the device list and info in network.
        //if I'm client, get the owner and group list.
+       ret = fn_iot_discovery_resource(FN_RESOURCE_TYPE_GROUP);
        return FN_ERROR_NONE;
 }
 
index 53d4576d61abbf9509149c675fb8c1eed346c0a4..6c586719b2448b268567ae4bbe5ce704a6c87f5e 100755 (executable)
@@ -11,7 +11,13 @@ int fn_iot_initialize()
 static void _request_handler(iotcon_resource_h resource, iotcon_request_h request,
        void *user_data)
 {
+       //get resource element from fn resource list or, parsing resource uri
 
+       //if request type is "get" and resource type is "group",
+               //then OWNER send device information to CLIENT(Device info Exchange)
+       //if request type is "put" and resource type is "operation",
+               //then It is join request. CLIENT send device information to OWNER(Device info Exchange)
+       //resource type "operation" don't have "get" request type.
 }
 
 int fn_iot_add_resource(fn_resource_type_e resource_type, char *name)
@@ -31,19 +37,19 @@ int fn_iot_add_resource(fn_resource_type_e resource_type, char *name)
 
        ret = iotcon_resource_types_add(resource_types, fn_resource_get_type(resource_type));
        if (IOTCON_ERROR_NONE != ret) {
-               LOG_ERR("iotcon_resource_types_add failed! : %d", get_error_message(ret));
+               LOG_ERR("iotcon_resource_types_add failed! : %s", get_error_message(ret));
                goto EXIT;
        }
 
        ret = iotcon_resource_interfaces_create(&resource_ifaces);
        if (IOTCON_ERROR_NONE != ret) {
-               LOG_ERR("iotcon_resource_interfaces_create failed! : %d", get_error_message(ret));
+               LOG_ERR("iotcon_resource_interfaces_create failed! : %s", get_error_message(ret));
                goto EXIT;
        }
 
        ret = iotcon_resource_interfaces_add(resource_ifaces, IOTCON_INTERFACE_DEFAULT);
        if (IOTCON_ERROR_NONE != ret) {
-               LOG_ERR("iotcon_resource_interfaces_add failed! : %d", get_error_message(ret));
+               LOG_ERR("iotcon_resource_interfaces_add failed! : %s", get_error_message(ret));
                goto EXIT;
        }
 
@@ -55,9 +61,17 @@ int fn_iot_add_resource(fn_resource_type_e resource_type, char *name)
 
        ret = iotcon_resource_create(uri_path, resource_types, resource_ifaces,
                                        fn_resource_get_policies(resource_type), _request_handler, NULL, &resource);
+       if (IOTCON_ERROR_NONE != ret) {
+               LOG_ERR("iotcon_resource_create failed! : %s", get_error_message(ret));
+               goto EXIT;
+       }
 
        //get resource list of resource type
        ret = fn_resource_append(resource_type, name, resource);
+       if (FN_ERROR_NONE != ret) {
+               LOG_ERR("fn_resource_append failed! : %s", fn_log_get_error_string(ret));
+               goto EXIT;
+       }
 
 EXIT:
        if (resource_types != NULL)
@@ -71,6 +85,45 @@ EXIT:
        return FN_ERROR_NONE;
 }
 
+static bool _found_resource(iotcon_remote_resource_h resource, iotcon_error_e result,
+        void *user_data)
+{
+    int ret;
+    char *resource_uri_path = NULL;
+        iotcon_resource_types_h resource_types;
+
+    ret = iotcon_remote_resource_get_uri_path(resource, &resource_uri_path);
+    if (IOTCON_ERROR_NONE != ret)
+        return IOTCON_FUNC_CONTINUE;
+
+        ret = iotcon_remote_resource_get_types(resource, &resource_types);
+        LOG_DEBUG("resource uri : %s", resource_uri_path);
+
+    return IOTCON_FUNC_CONTINUE;
+}
+
+int fn_iot_discovery_resource(fn_resource_type_e resource_type)
+{
+       int ret;
+       iotcon_query_h query;
+
+       ret = iotcon_query_create(&query);
+       if (IOTCON_ERROR_NONE != ret)
+                /* Error handling */
+
+       ret = iotcon_query_set_resource_type(query, fn_resource_get_type(resource_type));
+       if (IOTCON_ERROR_NONE != ret)
+                /* Error handling */
+
+       LOG_DEBUG("find resource : %s", get_error_message(ret));
+
+       ret = iotcon_find_resource(IOTCON_MULTICAST_ADDRESS,
+               IOTCON_CONNECTIVITY_IP | IOTCON_CONNECTIVITY_PREFER_UDP,
+               query, _found_resource, NULL);
+
+       LOG_DEBUG("find resource : %s", get_error_message(ret));
+}
+
 int fn_iot_delete_resource(fn_resource_type_e resource_type)
 {
        //delete resource from resource list using resource_type and index
index 1cdd294a3c7244c8dc3fb3eda9490203c20cbfe5..bd8a81ea5e7712cbfb2405617cc3c320b6372958 100755 (executable)
@@ -27,7 +27,22 @@ const char *fn_log_get_error_string(int result) {
        }
 }
 
+void __print_foreach_resource(gpointer data, gpointer user_data)
+{
+       fn_re_t *re = (fn_re_t *)data;
+       LOG_DEBUG("    ** resource : %x, name : %s", re->resource, re->name);
+}
+
 void fn_log_print_resource_list()
 {
+       fn_context_t *fn_ctx = fn_context_get_context();
+
+       LOG_DEBUG("-------------------Print resource list-----------------------");
+
+       for (int i = 0; i < FN_RESOURCE_TYPE_MAX; i++) {
+               LOG_DEBUG("Resource type %d list length : %d", i, g_list_length(fn_ctx->resource_list[i]));
+               g_list_foreach(fn_ctx->resource_list[i], __print_foreach_resource, NULL);
+       }
 
+       LOG_DEBUG("-------------------Print resource list end-------------------");
 }
index f0f7fc8f22b77defb5b7d26e0e3f7730b32fea33..7bc88593e259dcb605e8cbf4b61318f18ee1a21f 100755 (executable)
@@ -23,6 +23,19 @@ int main(int argc, char *argv[])
        //4. dbus interface initialize
        //5. Make TX interface
 
+       //example code
+       fn_context_t *fn_ctx = fn_context_get_context();
+
+       if (fn_ctx->role == FN_ROLE_OWNER) {
+               LOG_DEBUG("OWNER");
+               ret = fn_group_create("group1");
+               ret = fn_group_create("group223");
+               fn_log_print_resource_list();
+       } else {
+               LOG_DEBUG("CLIENT");
+               ret = fn_group_discovery(NULL, NULL);
+       }
+
        //6. group mgr initialize
        ret = fn_group_initialize();
        if (ret != FN_ERROR_NONE) {
@@ -33,7 +46,7 @@ int main(int argc, char *argv[])
        //7. operation mgr initialize
 
        //8. g main loop run
-       fn_context_t *fn_ctx = fn_context_get_context();
+
        fn_ctx->main_loop = g_main_loop_new(NULL, FALSE);
        g_main_loop_run(fn_ctx->main_loop);
 
index 42c21ffced233e600b32172c8102eb821c1b9481..a66278b6f85170b4918a0e0b56f2b08c390cdfca 100755 (executable)
@@ -16,8 +16,11 @@ int fn_resource_append(fn_resource_type_e resource_type, char *name, iotcon_reso
        fn_re_t *element = g_new0(fn_re_t, 1);
        element->resource = resource;
        element->name = g_strdup(name);
+       element->resource_type = resource_type;
        list = g_list_append(list, element);
 
+       fn_ctx->resource_list[resource_type] = list;
+
        return 0;
 }
 
index 9a9f8468d7074882dcc2373593c89e17d9b5042d..b3538031a79e2074b5e3b494b001f0b79ec943d6 100755 (executable)
@@ -1,9 +1,15 @@
 #ifndef __FN_GROUP_H__
 #define __FN_GROUP_H__
 
-#include <fn_log.h>
 #include <fn_iot.h>
 
+typedef struct fn_group_t *fn_group_h;
+
+typedef struct {
+       char *group_name;
+       /*and device information*/
+} fn_group_t;
+
 int fn_group_initialize();
 int fn_group_create(char *group_name);
 int fn_group_discovery();
index eee361d6e05945ce2e4a81890bf0c0641b92e5af..054b863cc8a94751f01e0520fb25868576103142 100755 (executable)
@@ -8,6 +8,7 @@
 int fn_iot_initialize();
 int fn_iot_add_resource(fn_resource_type_e resource_type, char *name);
 int fn_iot_delete_resource(fn_resource_type_e resource_type);
+int fn_iot_discovery_resource(fn_resource_type_e resource_type);
 int fn_iot_deinitialize();
 
 #endif
index 8ce5976a8bbdf9d36dd420f18307aa78898b620b..bee839bd7e622d504eeb87a168a48589eb17cebd 100755 (executable)
@@ -3,6 +3,7 @@
 
 #include <dlog.h>
 #include <fn_enum.h>
+#include <fn_resource.h>
 
 #ifdef LOG_TAG
 #undef LOG_TAG
index 8f7d57f77f102f2e6c15a88a11f450f28b9fc283..a81e7b525aed4661a426259335642840ba402963 100755 (executable)
@@ -2,16 +2,8 @@
 #define __FN_RESOURCE_H__
 
 #include <iotcon.h>
-#include <fn_log.h>
 #include <fn_context.h>
 
-typedef struct fn_resource_t *fn_resource_h;
-
-typedef struct {
-       fn_resource_type_e resource_type;
-       char *name;
-} fn_resource_t;
-
 typedef struct {
        fn_resource_type_e resource_type;
        char *type;