Don't try to make connection from the disconnected
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 20 May 2013 11:02:28 +0000 (20:02 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 20 May 2013 11:02:28 +0000 (20:02 +0900)
Don't try to connect to the master again from the disconnected event callback.

Change-Id: If21e2d6f3f751ecf1e69da86dec64b2451175e97

packaging/liblivebox-viewer.spec
src/client.c

index 16b9a0f..df392ac 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for developing the application.
-Version: 0.13.2
+Version: 0.13.3
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index 76a91b1..18cbbec 100644 (file)
 
 static struct info {
        int fd;
+       guint timer_id;
 } s_info = {
        .fd = -1,
+       .timer_id = 0,
 };
 
 static struct packet *master_fault_package(pid_t pid, int handle, const struct packet *packet)
@@ -1312,6 +1314,19 @@ static void master_started_cb(keynode_t *node, void *data)
        }
 }
 
+static gboolean timeout_cb(gpointer data)
+{
+       if (vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL) < 0)
+               ErrPrint("Failed to add vconf for monitoring service state\n");
+       else
+               DbgPrint("vconf event callback is registered\n");
+
+       master_started_cb(NULL, NULL);
+
+       s_info.timer_id = 0;
+       return FALSE;
+}
+
 static int disconnected_cb(int handle, void *data)
 {
        if (s_info.fd != handle) {
@@ -1326,12 +1341,18 @@ static int disconnected_cb(int handle, void *data)
 
        lb_delete_all();
 
-       if (vconf_notify_key_changed(VCONFKEY_MASTER_STARTED, master_started_cb, NULL) < 0)
-               ErrPrint("Failed to add vconf for monitoring service state\n");
-       else
-               DbgPrint("vconf event callback is registered\n");
+       /* Try to reconnect after 1 sec later */
+       if (!s_info.timer_id) {
+               DbgPrint("Reconnecting timer is added\n");
+               s_info.timer_id = g_timeout_add(1000, timeout_cb, NULL);
+               if (s_info.timer_id == 0) {
+                       ErrPrint("Unable to add reconnecting timer\n");
+                       return 0;
+               }
+       } else {
+               ErrPrint("Reconnecting timer is already exists\n");
+       }
 
-       master_started_cb(NULL, NULL);
        return 0;
 }