Add isf_control_set_socket_connect_timeout API 91/181291/4
authorInHong Han <inhong1.han@samsung.com>
Tue, 12 Jun 2018 00:59:03 +0000 (09:59 +0900)
committerInHong Han <inhong1.han@samsung.com>
Thu, 14 Jun 2018 08:36:12 +0000 (17:36 +0900)
Change-Id: I6e381ccc0d6d757a4e036b08d5a86e0a134f1a19

ism/src/isf_control.cpp
ism/src/isf_control.h
ism/src/isf_imcontrol_client.cpp
ism/src/isf_imcontrol_client.h

index b769dc0..cb44448 100644 (file)
@@ -600,6 +600,13 @@ EXAPI int isf_control_prelaunch_ise (void)
     return ret;
 }
 
+EXAPI int isf_control_set_socket_connect_timeout (int msec)
+{
+    IMControlClient imcontrol_client;
+    imcontrol_client.set_socket_connect_timeout (msec);
+
+    return 0;
+}
 
 /*
 vi:ts=4:nowrap:ai:expandtab
index 22c3e0e..9301a55 100644 (file)
@@ -349,6 +349,19 @@ int isf_control_hide_ime (void);
  */
 int isf_control_prelaunch_ise (void);
 
+/**
+ * @brief Sets the timeout for socket connect requests.
+ *
+ * @remarks If the socket connection fails, retry the connection internally until the run-time has reached the timeout.
+ *
+ * @since_tizen 5.0
+ *
+ * @param[in] msec The socket connect timeout. The timeout has a minimum unit of 100ms.
+ *
+ * @return 0 on success, otherwise return -1
+ */
+int isf_control_set_socket_connect_timeout (int msec);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
index edbf6f1..a767c6b 100644 (file)
 #include <string.h>
 #include "scim.h"
 
+#define MINIMUM_TIMEOUT 100
 
 namespace scim
 {
 
 typedef Signal1<void, int> IMControlClientSignalVoid;
+static int m_retry_count = 600;
 
 #if ENABLE_LAZY_LAUNCH
 static bool check_panel (const String &display)
@@ -157,19 +159,15 @@ public:
             ret = m_socket_imclient2panel.connect (addr);
             ret2 = m_socket_panel2imclient.connect (addr);
             if (!ret) {
-                scim_usleep (100000);
 #if ENABLE_LAZY_LAUNCH
                 if (!check_socket_frontend ())
                     launch_socket_frontend ();
                 if (!check_panel (display))
                     scim_launch_panel (true, "socket", display, NULL);
 #endif
-                for (int i = 0; i < 200; ++i) {
-                    if (m_socket_imclient2panel.connect (addr)) {
-                        ret = true;
-                        break;
-                    }
-                    scim_usleep (100000);
+                if (m_socket_imclient2panel.connect (addr)) {
+                    ret = true;
+                    break;
                 }
             }
 
@@ -180,7 +178,7 @@ public:
             m_socket_imclient2panel.close ();
             m_socket_panel2imclient.close ();
 
-            if (count++ >= 3) break;
+            if (count++ >= m_retry_count) break;
 
             scim_usleep (100000);
         }
@@ -597,6 +595,13 @@ public:
             return false;
         }
     }
+
+    void set_socket_connect_timeout (int msec) {
+        if (msec < MINIMUM_TIMEOUT)
+            m_retry_count = 1;
+        else
+            m_retry_count = msec / MINIMUM_TIMEOUT;
+    }
 };
 
 IMControlClient::IMControlClient ()
@@ -732,6 +737,11 @@ bool IMControlClient::launch_helper_ise (void)
 {
     return m_impl->launch_helper_ise ();
 }
+
+void IMControlClient::set_socket_connect_timeout (int msec)
+{
+    return m_impl->set_socket_connect_timeout (msec);
+}
 };
 
 /*
index 10685b8..0a43a61 100644 (file)
@@ -68,6 +68,7 @@ public:
     void enable_remote_input (void);
     void disable_remote_input (void);
     bool launch_helper_ise (void);
+    void set_socket_connect_timeout (int msec);
 };
 
 }