net: add checking device state before run command 16/146316/2
authorMunkyu Im <munkyu.im@samsung.com>
Mon, 28 Aug 2017 04:54:06 +0000 (13:54 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 5 Sep 2017 10:31:33 +0000 (10:31 +0000)
If device state is "device", run sdb command.

Change-Id: I8ee09a24e07514613f899ec012eac2dea376846c
Signed-off-by: Munkyu Im <munkyu.im@samsung.com>
tizen/src/util/net_helper.c

index c6298d8..b97acbf 100644 (file)
@@ -389,6 +389,43 @@ static void suspend_lock_state(int state)
     ecs_suspend_lock_state(state);
 }
 
+static bool is_ready(void)
+{
+    FILE *fp;
+    char state_name[BUF_SIZE] = { 0, };
+#ifndef CONFIG_WIN32
+    const char *sdb_path = "../../../../../tools/sdb";
+    const char *bin_dir = get_bin_path();
+    char *cmd_get_state = g_strdup_printf("\"%s%s\" -s emulator-%d get-state 2> /dev/null",
+            bin_dir, sdb_path, get_vm_device_serial_number());
+#else
+    const char *sdb_path = "..\\..\\..\\..\\..\\tools\\sdb.exe";
+    const char *bin_dir = get_bin_path();
+    char *cmd_get_state = g_strdup_printf("\"%s%s\" -s emulator-%d get-state 2> NUL",
+            bin_dir, sdb_path, get_vm_device_serial_number());
+#endif
+    fp = popen(cmd_get_state, "r");
+    if (fp == NULL) {
+        LOG_WARNING("Failed to run command\n");
+        g_free(cmd_get_state);
+        return false;
+    }
+
+    if (fgets(state_name, sizeof(state_name), fp)) {
+        g_strstrip(state_name);
+        if (strncmp(state_name, "device", 6) == 0) {
+            g_free(cmd_get_state);
+            pclose(fp);
+            LOG_INFO("device is ready to get command");
+            return true;
+        }
+    }
+
+    g_free(cmd_get_state);
+    pclose(fp);
+    return false;
+}
+
 static void *get_user_home_path(void *args)
 {
     FILE *fp;
@@ -418,15 +455,6 @@ static void *get_user_home_path(void *args)
     char *cmd_get_home = g_strdup_printf("\"%s%s\" -s emulator-%d shell id -un 2> NUL",
             bin_dir, sdb_path, get_vm_device_serial_number());
 #endif
-    //FIXME: (sdb) cannot check sdb root status
-    fp = popen(cmd_root_off, "r");
-    if (fp == NULL) {
-        LOG_WARNING("Failed to run command\n");
-        g_free(cmd_root_off);
-        return NULL;
-    }
-    g_free(cmd_root_off);
-    pclose(fp);
     while (true) {
         if (trial >= MAX_TRIAL) {
             sleep_time = 2000;
@@ -438,6 +466,20 @@ static void *get_user_home_path(void *args)
 #else
         usleep(sleep_time * 1000);
 #endif
+         if (!is_ready()) {
+             continue;
+         }
+
+        //FIXME: (sdb) cannot check sdb root status
+        fp = popen(cmd_root_off, "r");
+        if (fp == NULL) {
+            LOG_WARNING("Failed to run command\n");
+            g_free(cmd_root_off);
+            break;
+        }
+        g_free(cmd_root_off);
+        pclose(fp);
+
         fp = popen(cmd_get_home, "r");
         if (fp == NULL) {
             LOG_WARNING("Failed to run command\n");