Add demo scenario
authorJihoon Jung <jh8801.jung@samsung.com>
Fri, 12 Jan 2018 08:28:38 +0000 (17:28 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:40 +0000 (19:38 +0900)
Signed-off-by: Jihoon Jung <jh8801.jung@samsung.com>
capi/demo/companion_demo.c
capi/include/companion.h
capi/src/companion.c
capi/src/companion_gdbus.xml
src/companion-manager/include/comp_enum.h
src/companion-manager/src/comp_iot.c
src/companion-manager/src/comp_resource.c
src/companion-manager/src/companion_gdbus.xml

index ca85ef7b80197d44e7aad247ac758028e97a2085..6600c72f8d89ee72906ffb8e14cefc565977a3bc 100755 (executable)
@@ -8,7 +8,7 @@
 #include <companion.h>
 
 #define BUFFER_LEN 100
-#define TEST_CASE_MAX 5
+#define TEST_CASE_MAX 10
 
 #define PRT(format, args...) printf("%s:%d() "format, __FUNCTION__, __LINE__, ##args)
 #define TC_PRT(format, args...) PRT(format"\n", ##args)
@@ -24,6 +24,9 @@ typedef struct {
        int (*tc_func)(void);
 } tc_table_t;
 
+GList *found_group_list;
+GList *found_device_list;
+
 static bool test_get_user_int(const char *msg, int *num)
 {
        if (msg == NULL || num == NULL)
@@ -113,6 +116,8 @@ bool _group_found_cb(companion_group_type_e type, companion_group_h group, void
        companion_group_information_get_uri_path(group, &uri_path);
 
        TC_PRT("found group type : %d, uri : %s", type, uri_path);
+
+       found_group_list = g_list_prepend(found_group_list, group);
 }
 
 void _group_finish_cb(int result, void *user_data)
@@ -127,6 +132,7 @@ int companion_group_find_test(void)
        int input_int = 0;
 
        BEGIN();
+       found_group_list = NULL;
 
        if (!test_get_user_int("==> Input timeout value (sec)"
                                                 " - (Enter for skip) :", &input_int))
@@ -149,12 +155,13 @@ int companion_group_find_test(void)
 int companion_group_get_found_groups_test(void)
 {
        int ret = 0;
-       int input_int = 0;
        int count;
        companion_group_h *groups;
 
        BEGIN();
 
+       found_group_list = NULL;
+
        ret = companion_group_get_found_groups(&groups ,&count);
 
        if (ret == 0)
@@ -162,7 +169,7 @@ int companion_group_get_found_groups_test(void)
        else
                TC_PRT("group find failed, ret [%d]", ret);
 
-       TC_PRT("Found groups device count : ", count);
+       TC_PRT("Found group count : ", count);
 
        for (int i = 0; i < count; i++) {
                companion_group_type_e type;
@@ -170,12 +177,126 @@ int companion_group_get_found_groups_test(void)
                companion_group_information_get_type(groups[i], &type);
                companion_group_information_get_uri_path(groups[i], &uri_path);
                TC_PRT("%d. type : %d, uri path : %s", i+1, type, uri_path);
+               found_group_list = g_list_prepend(found_group_list, groups[i]);
+       }
+
+       END();
+       return ret;
+}
+
+bool _device_found_cb(companion_device_h device, void *user_data)
+{
+       char *device_id;
+       char *friendly_name;
+       char *device_type;
+
+       companion_device_information_get_device_id(device, &device_id);
+       companion_device_information_get_friendly_name(device, &friendly_name);
+       companion_device_information_get_device_type(device, &device_type);
+
+       TC_PRT("found device device_id : %s, friendly_name : %s, device_type : %s", device_id, friendly_name, device_type);
+
+       found_device_list = g_list_prepend(found_device_list, device);
+}
+
+int companion_device_find_test(void)
+{
+       int ret = 0;
+       int input_int = 0;
+
+       BEGIN();
+       found_device_list = NULL;
+
+       if (!test_get_user_int("==> Input timeout value (sec)"
+                                                " - (Enter for skip) :", &input_int))
+       {
+               input_int = 5;
+               TC_PRT("default timeout value [%d]", input_int);
+       }
+
+       companion_device_find(input_int, _device_found_cb, _group_finish_cb, NULL);
+
+       if (ret == 0)
+               TC_PRT("group find successful");
+       else
+               TC_PRT("group find failed, ret [%d]", ret);
+
+       END();
+       return ret;
+}
+
+int companion_device_get_found_devices_test(void)
+{
+       int ret = 0;
+       int count = 0;
+       companion_device_h *devices;
+
+       BEGIN();
+
+       found_device_list = NULL;
+
+       ret = companion_device_get_found_devices(&devices ,&count);
+
+       if (ret == 0)
+               TC_PRT("device find successful");
+       else
+               TC_PRT("device find failed, ret [%d]", ret);
+
+       TC_PRT("Found device count : ", count);
+
+       for (int i = 0; i < count; i++) {
+               char *uuid;
+               char *friendly_name;
+               char *device_type;
+
+               companion_device_information_get_device_id(devices[i], &uuid);
+               companion_device_information_get_friendly_name(devices[i], &friendly_name);
+               companion_device_information_get_device_type(devices[i], &device_type);
+
+               TC_PRT("%d. uuid : %s, friendly_name : %s, device_type : %s", i+1, uuid, friendly_name, device_type);
+               found_device_list = g_list_prepend(found_device_list, devices[i]);
        }
 
        END();
        return ret;
 }
 
+int companion_device_invite_test(void)
+{
+       int ret = 0;
+       BEGIN();
+
+       /* using stored group list and device list */
+
+       END();
+       return ret;
+}
+
+int companion_device_eject_test(void)
+{
+       int ret = 0;
+       BEGIN();
+
+       /* using stored group list and device list */
+
+       END();
+       return ret;
+}
+
+//send_data_callback : if the remote device not invited, then callback is called include result failed.
+//send_data_callback : if the remote device invited, then callback result successful.
+
+int companion_send_data_to_remote_device_test(void)
+{
+       int ret = 0;
+       BEGIN();
+       // device : in, "123" : in, send_data_callback : in
+       //ret = companion_send_data(device, "123", send_data_callback);
+
+       END();
+       return ret;
+}
+
 int companion_deinitialize_test(void)
 {
        int ret = 0;
@@ -199,6 +320,11 @@ tc_table_t tc_table[] = {
        {"companion_group_create_test",  2,     companion_group_create_test},
        {"companion_group_find_test",  3,       companion_group_find_test},
        {"companion_group_get_found_groups_test",  4,   companion_group_get_found_groups_test},
+       {"companion_device_find_test",  5,      companion_device_find_test},
+       {"companion_device_get_found_devices_test",  6, companion_device_get_found_devices_test},
+       {"companion_device_invite_test",  7,    companion_device_invite_test},
+       {"companion_device_eject_test",  8,     companion_device_eject_test},
+       {"companion_send_data_to_remote_device_test",  9,       companion_send_data_to_remote_device_test},
        {"companion_deinitialize_test",  TEST_CASE_MAX, companion_deinitialize_test},
 
        /*-----------*/
index 70fcfd226f70cff7044b108be2c72ac8f3cded71..8db0fc29d38aa2882434f8a65a48744706e2570c 100755 (executable)
@@ -39,23 +39,27 @@ int companion_group_leave(companion_group_h group, companion_group_finish_cb cal
 /* companion_group_delete : remove group. if group handle is remote group, then the api return fail error */
 int companion_group_delete(companion_group_h group);
 int companion_group_merge(companion_group_h dest_group, companion_group_h src_group);
+int companion_group_get_member_devices(companion_group_h group, companion_device_h **devices, int *count);
 
-/* Group Device Module */
-/* The "Group Device" is element of group. Only one group device per target.
-       I do not like this " group device " term. :/
+
+/* Device Module */
+/* The "Device" is only one group device per target.
    If you have any good terms, I would appreciate your suggestions.*/
 
 /* companion_group_device_find : Find the group devices on the network. (exclude myself) */
 int companion_device_find(int timeout, companion_device_found_cb found_cb,
        companion_group_finish_cb finish_cb, void *user_data);
 
+/* companion_group_join : join to remote group. if group handle is my daemon's, then the api return fail error */
+int companion_device_get_found_devices(companion_device_h **devices, int *count);
+
 /* companion_group_device_invite : Invite a remote group device to my group. */
 int companion_device_invite(companion_group_h group,
-       companion_device_h group_device, companion_group_finish_cb callback, void *user_data); //Join to device in group (async)
+       companion_device_h device, char *PIN, companion_group_finish_cb callback, void *user_data);
 
 /* companion_group_device_eject : Eject a remote group device from my group. */
 int companion_device_eject(companion_group_h group,
-       companion_device_h group_device, companion_group_finish_cb callback, void *user_data); //dismiss from group (async)
+       companion_device_h device, companion_group_finish_cb callback, void *user_data);
 
 /* Group Information Module */
 int companion_group_information_get_type(companion_group_h group, companion_group_type_e *type);
@@ -64,12 +68,10 @@ int companion_group_information_get_uri_path(companion_group_h group, char **uri
 
 /* Group Device Information Module */
 /* I think the information in the group device is the same as the "device informations" */
+int companion_device_information_get_device_id(companion_device_h device, char **device_id);
+int companion_device_information_get_friendly_name(companion_device_h device, char **friendly_name);
+int companion_device_information_get_device_type(companion_device_h device, char **device_type);
 
-/*
-int companion_group_device_information_get_ip?(companion_group_device_h group_handle, ???);
-int companion_group_device_information_get_address?(companion_group_device_h group_handle, ???);
-int companion_group_device_information_get_???(companion_group_device_h group_handle, ???);
-*/
 
 #ifdef __cplusplus
 }
index 8dbb7ed4fe1669377b7731f749efc59d4fe645bd..1e42f5f4ee528951d7bea6d84f3206d6628380c8 100755 (executable)
@@ -39,13 +39,27 @@ typedef struct _companion_group_t
        companion_group_type_e type;
 } companion_group_t;
 
-typedef struct _event_cb_t {
+typedef struct _companion_device_t
+{
+       char *device_id;
+       char *friendly_name;
+       char *device_type;
+} companion_device_t;
+
+typedef struct _group_event_cb_t {
         companion_group_found_cb found_cb;
                  companion_group_finish_cb finish_cb;
         void *user_data;
-} event_cb_t;
+} group_event_cb_t;
+
+typedef struct _device_event_cb_t {
+        companion_device_found_cb found_cb;
+                 companion_group_finish_cb finish_cb;
+        void *user_data;
+} device_event_cb_t;
 
-static __thread GSList *event_cb_list = NULL;
+static __thread GSList *group_event_cb_list = NULL;
+static __thread GSList *device_event_cb_list = NULL;
 
 static companion_group_t *_create_group_handle(char *uri_path, char *device_id,
        char *group_name, char *host_addr, char *resource_type, companion_group_type_e type)
@@ -62,7 +76,18 @@ static companion_group_t *_create_group_handle(char *uri_path, char *device_id,
        return group;
 }
 
-static void _group_found_cb(Group *object,
+static companion_device_t *_create_device_handle(char *device_id, char *friendly_name, char *device_type)
+{
+       companion_device_t *device = g_new0(companion_device_t, 1);
+
+       device->device_id = g_strdup(device_id);
+       device->friendly_name = g_strdup(friendly_name);
+       device->device_type = g_strdup(device_type);
+
+       return device;
+}
+
+static void __group_found_cb(Group *object,
         GVariant *va, gpointer user_data)
 {
        GVariantIter *iter = NULL;
@@ -97,17 +122,54 @@ static void _group_found_cb(Group *object,
 
        group = _create_group_handle(uri_path, device_id, group_name, host_addr, resource_type, type);
 
-       for (GSList *l = event_cb_list; l != NULL; l = l->next) {
-               event_cb_t *event_s = (event_cb_t *)l->data;
+       for (GSList *l = group_event_cb_list; l != NULL; l = l->next) {
+               group_event_cb_t *event_s = (group_event_cb_t *)l->data;
                event_s->found_cb(type, group, event_s->user_data);
        }
 }
 
+static void __device_found_cb(Group *object,
+        GVariant *va, gpointer user_data)
+{
+       GVariantIter *iter = NULL;
+       const gchar *key;
+       GVariant *key_value;
+       companion_device_t *device = NULL;
+       char *device_id;
+       char *friendly_name;
+       char *device_type;
+
+       g_variant_get(va, "a{sv}", &iter);
+       while (g_variant_iter_loop(iter, "{sv}", &key, &key_value)) {
+               if (g_strcmp0(key, "UUID") == 0) {
+                       device_id = g_variant_get_string(key_value, NULL);
+               } else if (g_strcmp0(key, "FriendlyName") == 0) {
+                       friendly_name = g_variant_get_string(key_value, NULL);
+               } else if (g_strcmp0(key, "DeviceType") == 0) {
+                       device_type = g_variant_get_string(key_value, NULL);
+               }
+       }
+
+       g_variant_iter_free(iter);
+
+       device = _create_device_handle(device_id, friendly_name, device_type);
+
+       for (GSList *l = device_event_cb_list; l != NULL; l = l->next) {
+               device_event_cb_t *event_s = (device_event_cb_t *)l->data;
+               event_s->found_cb(device, event_s->user_data);
+       }
+}
+
 static void _finish_cb(Group *object,
         gint ret, gpointer user_data)
 {
-       for (GSList *l = event_cb_list; l != NULL; l = l->next) {
-               event_cb_t *event_s = (event_cb_t *)l->data;
+       for (GSList *gl = group_event_cb_list; gl != NULL; gl = gl->next) {
+               group_event_cb_t *event_s = (group_event_cb_t *)gl->data;
+               event_s->finish_cb(ret, event_s->user_data);
+       }
+
+       for (GSList *dl = device_event_cb_list; dl != NULL; dl = dl->next) {
+               device_event_cb_t *event_s = (device_event_cb_t *)dl->data;
                event_s->finish_cb(ret, event_s->user_data);
        }
 }
@@ -124,7 +186,8 @@ static void _group_proxy_init(void)
                 NULL,
                 &error);
 
-       g_signal_connect(group_proxy, "group-found", G_CALLBACK(_group_found_cb), NULL);
+       g_signal_connect(group_proxy, "group-found", G_CALLBACK(__group_found_cb), NULL);
+       g_signal_connect(group_proxy, "device-found", G_CALLBACK(__device_found_cb), NULL);
        g_signal_connect(group_proxy, "finish", G_CALLBACK(_finish_cb), NULL);
 }
 
@@ -217,9 +280,9 @@ int companion_group_find(int timeout, companion_group_found_cb found_cb, compani
        GError *error = NULL;
 
        /* set event cb */
-       event_cb_t *event_t;
+       group_event_cb_t *event_t;
 
-       event_t = g_try_new0(event_cb_t, 1);
+       event_t = g_try_new0(group_event_cb_t, 1);
        if (event_t == NULL)
                          return -1;
 
@@ -227,7 +290,7 @@ int companion_group_find(int timeout, companion_group_found_cb found_cb, compani
        event_t->finish_cb = finish_cb;
        event_t->user_data = user_data;
 
-       event_cb_list = g_slist_prepend(event_cb_list, event_t);
+       group_event_cb_list = g_slist_prepend(group_event_cb_list, event_t);
 
        /* get groups from daemon using gdbus */
        group_call_find_sync(group_proxy, timeout, &ret, NULL, &error);
@@ -295,12 +358,50 @@ int companion_group_get_found_groups(companion_group_h **groups, int *count)
        return ret;
 }
 
+int companion_device_find(int timeout, companion_device_found_cb found_cb,
+       companion_group_finish_cb finish_cb, void *user_data)
+{
+       int ret = 0;
+       GError *error = NULL;
+
+       /* set event cb */
+       device_event_cb_t *event_t;
+
+       event_t = g_try_new0(device_event_cb_t, 1);
+       if (event_t == NULL)
+                         return -1;
+
+       event_t->found_cb = found_cb;
+       event_t->finish_cb = finish_cb;
+       event_t->user_data = user_data;
+
+       device_event_cb_list = g_slist_prepend(device_event_cb_list, event_t);
+
+       /* get groups from daemon using gdbus */
+       group_call_device_find_sync(group_proxy, timeout, &ret, NULL, &error);
+
+       return ret;
+
+}
+
+/* companion_group_join : join to remote group. if group handle is my daemon's, then the api return fail error */
+int companion_device_get_found_devices(companion_device_h **devices, int *count)
+{
+
+}
+
 /* group merge */
 int companion_group_merge(companion_group_h dest_group, companion_group_h src_group)
 {
        return 0;
 }
 
+int companion_device_invite(companion_group_h group,
+       companion_device_h device, char *PIN, companion_group_finish_cb callback, void *user_data)
+{
+
+}
+
 int companion_group_information_get_type(companion_group_h group, companion_group_type_e *type)
 {
        *type = ((companion_group_t *)group)->type;
@@ -322,3 +423,23 @@ int companion_group_information_get_uri_path(companion_group_h group, char **uri
        return 0;
 }
 
+int companion_device_information_get_device_id(companion_device_h device, char **device_id)
+{
+       *device_id = g_strdup(((companion_device_t *)device)->device_id);
+
+       return 0;
+
+}
+int companion_device_information_get_friendly_name(companion_device_h device, char **friendly_name)
+{
+       *friendly_name = g_strdup(((companion_device_t *)device)->friendly_name);
+
+       return 0;
+
+}
+int companion_device_information_get_device_type(companion_device_h device, char **device_type)
+{
+       *device_type = g_strdup(((companion_device_t *)device)->device_type);
+
+       return 0;
+}
index 52f883dcaa3232ef5b4ae7af904c99ff08ef443e..787c43a92a22a03f748e39a7bcf249c9139b559f 100755 (executable)
@@ -35,8 +35,7 @@
                        <arg type="i" name="result" direction="out" />
                </method>
                <method name="DeviceFind">
-                       <arg type="i" name="group_count" direction="out" />
-                       <arg type="aa{sv}" name="groups" direction="out" />
+                       <arg type="i" name="timeout" direction="in" />
                        <arg type="i" name="result" direction="out" />
                </method>
                <method name="DeviceInvite">
index b32cccfe0bf3b04496cfb20d3361b44259bd7d90..1442e2ba2ba85baf09a0391e43a1b51811740e49 100755 (executable)
@@ -25,8 +25,9 @@ typedef enum {
 /* resource type enum */
 typedef enum {
        COMP_RESOURCE_TYPE_GROUP = 0,
-       COMP_RESOURCE_TYPE_DEVICE = 0,
+       COMP_RESOURCE_TYPE_DEVICE,
        COMP_RESOURCE_TYPE_OPERATION,
+       COMP_RESOURCE_TYPE_DATA,
        COMP_RESOURCE_TYPE_MAX
 } comp_resource_type_e;
 
index adfdc52787fa8f4460615be1248e6b12b558a011..2a4ca510820d448ff5d9ee5002d286aecc2c6639 100755 (executable)
@@ -29,12 +29,12 @@ static bool _request_device_info(iotcon_device_info_h info, iotcon_error_e resul
        /*
                "Group device" resource
                The Group device resource is only one per device.
-          resource type is core.fn.group.device
+          resource type is core.comp.group.device
                This resource has device information as an attribute.
-               The resource uri is /fn/group/device + certain uuid.
-               ex) /fn/group/device123123
+               The resource uri is /comp/group/device + certain uuid.
+               ex) /comp/group/device123123
        */
-       //fn_iot_add_resource(FN_RESOURCE_TYPE_GROUP_DEVICE, fn_ctx->device_uuid);
+       //comp_iot_add_resource(FN_RESOURCE_TYPE_GROUP_DEVICE, comp_ctx->device_uuid);
 
        return false;
 }
@@ -70,13 +70,21 @@ int comp_iot_initialize()
        /*
                "operation" resource
                The operation resource is a control command channel between daemon and daemon.
-          resource type is core.fn.operation
-          Within this function we create a default operation resource. (uri is /fn/operation/1)
+          resource type is core.comp.operation
+          Within this function we create a default operation resource. (uri is /comp/operation/1)
           If we need more control channels, increase the number.
-               ex) /fn/operation/2, /fn/operation/3
+               ex) /comp/operation/2, /comp/operation/3
        */
        comp_iot_add_resource(COMP_RESOURCE_TYPE_OPERATION, "1");
 
+       /*
+               "DATA" resource
+               To show the send data to remote daemon.
+               It can be used when the remote device is mot enable and pairwise.
+               ex) /comp/data/1
+       */
+       comp_iot_add_resource(COMP_RESOURCE_TYPE_DATA, "1");
+
        return COMP_ERROR_NONE;
 }
 
@@ -84,7 +92,7 @@ static void _request_handler(iotcon_resource_h resource, iotcon_request_h reques
        void *user_data)
 {
        LOG_DEBUG("thread id is ");
-       //get resource element from fn resource list or, parsing resource uri
+       //get resource element from comp 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)
index 9505fb6a77e3fa7760d58cd8bf0358b002e12674..013f5d9fe92f3c82be24914953ccd7092c85c81c 100755 (executable)
@@ -4,10 +4,12 @@
 static comp_rd_t comp_rds[] = {
        {COMP_RESOURCE_TYPE_GROUP, "core.comp.group", "/comp/group/",
                IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE},
-       {COMP_RESOURCE_TYPE_GROUP, "core.comp.device", "/comp/device/",
+       {COMP_RESOURCE_TYPE_DEVICE, "core.comp.device", "/comp/device/",
                IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE},
        {COMP_RESOURCE_TYPE_OPERATION, "core.comp.operation", "/comp/operation/",
                IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE},
+       {COMP_RESOURCE_TYPE_DATA, "core.comp.data", "/comp/data/",
+               IOTCON_RESOURCE_DISCOVERABLE | IOTCON_RESOURCE_OBSERVABLE},
 };
 
 int comp_resource_append(comp_resource_type_e resource_type, char *uri, iotcon_resource_h resource)
index 1e5bb3eb765860716ebeb31a554b7995fb8e2886..cb6b78850d20b857d67c5b47e3762ef65a754efd 100755 (executable)
@@ -35,6 +35,7 @@
                        <arg type="i" name="result" direction="out" />
                </method>
                <method name="DeviceFind">
+                       <arg type="i" name="timeout" direction="in" />
                        <arg type="i" name="result" direction="out" />
                </method>
                <method name="DeviceInvite">