demo: Implement demo app
authorsaerome.kim <saerome.kim@samsung.com>
Tue, 16 Jan 2018 10:23:56 +0000 (19:23 +0900)
committersaerome.kim <saerome.kim@samsung.com>
Mon, 2 Jul 2018 10:38:40 +0000 (19:38 +0900)
- Added group / device 'create/clone/destory' APIs
- Fixed a bug that now showing devices/group list even discovered them

Signed-off-by: saerome.kim <saerome.kim@samsung.com>
capi/demo/comp-manager.c
capi/include/companion.h
capi/src/companion.c

index 2c266b446f961158ea754d1d57e6e6ababe0ec08..54cf83e59a6577e21d201360d473dc768003415b 100644 (file)
@@ -109,14 +109,14 @@ static int run_devices_show(MManager *mm, struct menu_data *menu)
        iter = g_list_first(found_device_list);
        while (NULL != iter) {
                device = iter->data;
-               if (device) {
+               if (!device) {
                        msgr("device list is null");
                        break;
                }
                companion_device_information_get_device_id(device, &deviceid);
                companion_device_information_get_friendly_name(device, &name);
                companion_device_information_get_device_type(device, &devicetype);
-               msgb("[%d] type:%s, name: %s type: %s", i+1, deviceid, name, devicetype);
+               msgb("[%d] deviceid: %s, name: %s type: %s", i+1, deviceid, name, devicetype);
 
                if (deviceid) {
                        free(deviceid);
@@ -309,6 +309,7 @@ bool _device_found_cb(companion_device_h device, void *user_data)
 
        return TRUE;
 }
+
 static int run_devices_find(MManager *mm, struct menu_data *menu)
 {
        int ret;
@@ -326,7 +327,7 @@ static int run_devices_find(MManager *mm, struct menu_data *menu)
        msg(" - companion_device_find() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
 
        if (found_device_list) {
-               g_list_free(found_device_list);
+               g_list_free_full(found_device_list, companion_device_information_destroy);
                found_device_list = NULL;
        }
 
@@ -389,14 +390,14 @@ static int run_group_show(MManager *mm, struct menu_data *menu)
        iter = g_list_first(found_group_list);
        while (NULL != iter) {
                group = iter->data;
-               if (group) {
+               if (!group) {
                        msgr("groups is null");
                        break;
                }
                companion_group_information_get_type(group, &type);
                companion_group_information_get_uri_path(group, &uri);
                companion_group_information_get_resource_type(group, &rt);
-               msgb("[%d] type:%s, URI: %s RT: %s", i+1, comp_group_type_to_string(type), uri, rt);
+               msgb("[%d] type: %s, URI: %s RT: %s", i+1, comp_group_type_to_string(type), uri, rt);
                if (uri) {
                        free(uri);
                        uri = NULL;
@@ -515,7 +516,7 @@ static int run_group_find(MManager *mm, struct menu_data *menu)
        msg(" - companion_group_find() ret: [0x%X] [%s]", ret, comp_error_to_string(ret));
 
        if (found_group_list) {
-               g_list_free(found_group_list);
+               g_list_free_full(found_group_list, companion_group_information_destroy);
                found_group_list = NULL;
        }
 
index 0964136cf131775b524570a8671f84b2cfef1af3..cd63c950f1230a02325e0eb98db8c12158e3bddc 100755 (executable)
@@ -82,12 +82,21 @@ int companion_device_eject(companion_group_h group,
        companion_device_h device, companion_device_eject_result_cb callback, void *user_data);
 
 /* Group Information Module */
+int companion_group_information_create(companion_group_h* group);
+int companion_group_information_clone(companion_group_h dst,
+       companion_group_h src);
+int companion_group_information_destroy(companion_group_h group);
+
 int companion_group_information_get_type(companion_group_h group, companion_group_type_e *type);
 int companion_group_information_get_resource_type(companion_group_h group, char **resource_type);
 int companion_group_information_get_uri_path(companion_group_h group, char **uri_path);
 
 /* Group Device Information Module */
 /* I think the information in the group device is the same as the "device informations" */
+int companion_device_information_create(companion_device_h* device);
+int companion_device_information_clone(companion_device_h target,
+       companion_device_h source);
+int companion_device_information_destroy(companion_device_h data);
 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);
index 71383a85c53199220e3126abd661b52e920a18ef..31bb241ddaf3dabfefbbaf10ea3aec59f4aec037 100755 (executable)
@@ -172,7 +172,7 @@ static void __device_found_cb(Group *object,
                        } else if (g_strcmp0(key, "FriendlyName") == 0) {
                                friendly_name = (char *)g_variant_get_string(key_value, NULL);
                        } else if (g_strcmp0(key, "DeviceType") == 0) {
-                               device_type = g_variant_get_string(key_value, NULL);
+                               device_type = (char *)g_variant_get_string(key_value, NULL);
                        }
                }
                g_variant_iter_free(iter_row);
@@ -296,7 +296,6 @@ int companion_deinitialize()
 int companion_group_create(char *group_name)
 {
        int ret = 0;
-       companion_group_t *group;
        GError *error = NULL;
 
        /* create group to daemon using gdbus */
@@ -324,7 +323,6 @@ int companion_group_find(int timeout, companion_group_found_cb found_cb, compani
 int companion_group_get_found_groups(companion_group_h **groups, int *count)
 {
        int ret = 0;
-       bool result = false;
        GVariant *va = NULL;
        GError *error = NULL;
 
@@ -480,6 +478,78 @@ int companion_device_eject(companion_group_h group,
        return ret;
 }
 
+int companion_group_information_create(companion_group_h* group)
+{
+       companion_group_h _group = g_malloc0(sizeof(companion_group_t));
+       *group = _group;
+
+       return 0;
+}
+
+int companion_group_information_clone(companion_group_h target,
+       companion_group_h source)
+{
+       companion_group_t * dst = (companion_group_t *)target;
+       companion_group_t * src = (companion_group_t *)source;
+
+       if (!dst || !src) {
+               _ERR("Invaild parameters: dst=%p src=%p", dst, src);
+               return -1;
+       }
+
+       if (src->uri_path) {
+               dst->uri_path = g_strdup(src->uri_path);
+       }
+       if (src->device_id) {
+               dst->device_id = g_strdup(src->device_id);
+       }
+       if (src->group_name) {
+               dst->group_name = g_strdup(src->group_name);
+       }
+       if (src->host_addr) {
+               dst->host_addr = g_strdup(src->host_addr);
+       }
+       if (src->resource_type) {
+               dst->resource_type = g_strdup(src->resource_type);
+       }
+       dst->type = src->type;
+
+       return 0;
+}
+
+int companion_group_information_destroy(companion_group_h data)
+{
+       companion_group_t * group = (companion_group_t *)data;
+
+       if (!group)
+               return -1;
+
+       if (group->uri_path) {
+               g_free(group->uri_path);
+               group->uri_path = NULL;
+       }
+       if (group->device_id) {
+               g_free(group->device_id);
+               group->device_id = NULL;
+       }
+       if (group->group_name) {
+               g_free(group->group_name);
+               group->group_name = NULL;
+       }
+       if (group->host_addr) {
+               g_free((companion_group_t *)group->host_addr);
+               group->host_addr = NULL;
+       }
+       if (group->resource_type) {
+               g_free((companion_group_t *)group->resource_type);
+               group->resource_type = NULL;
+       }
+       g_free(group);
+       group = NULL;
+
+       return 0;
+}
+
 int companion_group_information_get_type(companion_group_h group, companion_group_type_e *type)
 {
        *type = ((companion_group_t *)group)->type;
@@ -501,6 +571,66 @@ int companion_group_information_get_uri_path(companion_group_h group, char **uri
        return 0;
 }
 
+int companion_device_information_create(companion_device_h* device)
+{
+       companion_device_h _device = g_malloc0(sizeof(companion_device_t));
+       *device = _device;
+
+       return 0;
+}
+
+int companion_device_information_clone(companion_device_h target,
+       companion_device_h source)
+{
+       companion_device_t * dst = (companion_device_t *)target;
+       companion_device_t * src = (companion_device_t *)source;
+
+       if (!dst || !src) {
+               _ERR("Invaild parameters: dst=%p src=%p", dst, src);
+               return -1;
+       }
+
+       if (src->device_id) {
+               dst->device_id = g_strdup(src->device_id);
+       }
+       if (src->friendly_name) {
+               dst->friendly_name = g_strdup(src->friendly_name);
+       }
+       if (src->device_type) {
+               dst->device_type = g_strdup(src->device_type);
+       }
+
+       return 0;
+}
+
+int companion_device_information_destroy(companion_device_h data)
+{
+       companion_device_t * device = (companion_device_t *)data;
+
+       if (!device) {
+               _ERR("Invaild parameters: device=%p", device);
+               return -1;
+       }
+
+       if (device->device_id) {
+               g_free(device->device_id);
+               device->device_id = NULL;
+       }
+       if (device->friendly_name) {
+               g_free(device->friendly_name);
+               device->friendly_name = NULL;
+       }
+       if (device->device_type) {
+               g_free(device->device_type);
+               device->device_type = NULL;
+       }
+
+       g_free(device);
+       device = NULL;
+
+       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);