#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)
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)
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)
int input_int = 0;
BEGIN();
+ found_group_list = NULL;
if (!test_get_user_int("==> Input timeout value (sec)"
" - (Enter for skip) :", &input_int))
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)
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;
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;
{"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},
/*-----------*/
/* 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);
/* 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
}
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)
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;
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);
}
}
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);
}
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;
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);
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;
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;
+}
<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">
/* 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;
/*
"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;
}
/*
"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;
}
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)
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)
<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">