GList *mowned_dev_list = NULL;
comp_group_invite_info_t *group_invite_info = NULL;
comp_mot_device_t *my_device = NULL;
+int find_mot_enb_dev_retry_cnt;
+int find_mowned_dev_retry_cnt;
+
+#define RETRY_INTERVAL 100
+#define RETRY_TIMEOUT 2
+#define RETRY_COUNT 20
/* Called when daemon is start. */
int comp_group_initialize()
// Find MOT enabled devices
void comp_group_add_new_mot_device(comp_mot_device_t *device)
{
+ GList *iter = NULL;
+ gboolean is_exist = FALSE;
+
LOG_BEGIN();
- mot_enb_dev_list = g_list_append(mot_enb_dev_list, device);
+ iter = mot_enb_dev_list;
+ while(iter != NULL) {
+ comp_mot_device_t *temp = (comp_mot_device_t *)iter->data;
+
+ if (g_strcmp0(temp->device_id, device->device_id) == 0) {
+ LOG_DEBUG("Device %s already exists in mot enable device list",
+ device->device_id);
+ is_exist = TRUE;
+ break;
+ }
+
+ iter = g_list_next(iter);
+ }
+
+ if (is_exist == FALSE) {
+ LOG_DEBUG("Add device with uuid %s to mot enabled device list",
+ device->device_id);
+ mot_enb_dev_list = g_list_append(mot_enb_dev_list, device);
+ }
LOG_END();
}
return 0;
}
+static gboolean __retry_find_mot_enable_device(gpointer data)
+{
+ int ret;
+ LOG_BEGIN();
+
+ LOG_DEBUG("Retry to find mot enabled devices count %d",
+ find_mot_enb_dev_retry_cnt);
+
+ ret = agent_find_mot_enable_devices(RETRY_TIMEOUT);
+ if (ret != COMP_ERROR_NONE) {
+ LOG_ERR("Failed to find mot enable devices : %s",
+ comp_log_get_error_string(ret));
+ }
+
+ LOG_END();
+ return FALSE;
+}
+
void comp_group_notify_mot_enable_device_done(int device_count)
{
GVariant *device_data;
+ int count = g_list_length(mot_enb_dev_list);
LOG_BEGIN();
device_data = comp_group_get_remote_mot_enabled_devices();
- notify_device_found(device_count, device_data);
+ notify_device_found(count, device_data);
+
+ if (find_mot_enb_dev_retry_cnt < RETRY_COUNT) {
+ find_mot_enb_dev_retry_cnt += 1;
+ g_timeout_add(RETRY_INTERVAL, __retry_find_mot_enable_device, NULL);
+ }
LOG_END();
}
g_list_free_full (mot_enb_dev_list, _mot_enb_dev_list_free_func);
mot_enb_dev_list = NULL;
+ find_mot_enb_dev_retry_cnt = 0;
+
ret = agent_find_mot_enable_devices(timeout);
if (ret != COMP_ERROR_NONE) {
LOG_ERR("Failed to find mot enable devices : %s",
void comp_group_add_new_mowned_device(comp_mot_device_t *device)
{
+ GList *iter = NULL;
+ gboolean is_exist = FALSE;
+
LOG_BEGIN();
- mowned_dev_list = g_list_append(mowned_dev_list, device);
+ iter = mowned_dev_list;
+ while(iter != NULL) {
+ comp_mot_device_t *temp = (comp_mot_device_t *)iter->data;
+
+ if (g_strcmp0(temp->device_id, device->device_id) == 0) {
+ LOG_DEBUG("Device %s already exists in mowned device list",
+ device->device_id);
+ is_exist = TRUE;
+ break;
+ }
+
+ iter = g_list_next(iter);
+ }
+
+ if (is_exist == FALSE) {
+ LOG_DEBUG("Add device with uuid %s to mowned device list",
+ device->device_id);
+ mowned_dev_list = g_list_append(mowned_dev_list, device);
+ }
LOG_END();
}
return 0;
}
+static gboolean __retry_find_mowned_devices(gpointer data)
+{
+ int ret;
+
+ LOG_BEGIN();
+
+ LOG_DEBUG("Retry to find mowned devices count %d",
+ find_mowned_dev_retry_cnt);
+
+ ret = agent_find_mowned_devices(RETRY_TIMEOUT);
+ if (ret != COMP_ERROR_NONE) {
+ LOG_ERR("Failed to find mowned devices : %s",
+ comp_log_get_error_string(ret));
+ }
+
+ LOG_END();
+
+ return FALSE;
+}
+
void comp_group_notify_mowned_device_find_done(int device_count)
{
GVariant *device_data;
+ int count = g_list_length(mowned_dev_list);
LOG_BEGIN();
device_data = comp_group_get_mowned_devices();
- notify_mowned_device_found(device_count, device_data);
+ notify_mowned_device_found(count, device_data);
+
+ if (find_mowned_dev_retry_cnt < RETRY_COUNT) {
+ find_mowned_dev_retry_cnt += 1;
+ g_timeout_add(RETRY_INTERVAL, __retry_find_mowned_devices, NULL);
+ }
LOG_END();
}
g_list_free_full(mowned_dev_list, _mot_enb_dev_list_free_func);
mowned_dev_list = NULL;
+ find_mowned_dev_retry_cnt = 0;
+
ret = agent_find_mowned_devices(timeout);
if (ret != COMP_ERROR_NONE) {
LOG_ERR("Failed to find mowned devices : %s",