Support executable IME type 58/62258/2
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 15 Mar 2016 05:59:28 +0000 (14:59 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 15 Mar 2016 06:08:16 +0000 (15:08 +0900)
Change-Id: I4a033339c05ce26fd34b6544f6cbf5dcca267754

ism/extras/efl_panel/isf_panel_efl.cpp
ism/modules/frontend/Makefile.am
ism/modules/frontend/scim_socket_frontend.cpp
ism/modules/frontend/scim_socket_frontend.h

index 4a56464..bd9de76 100644 (file)
@@ -121,6 +121,7 @@ using namespace scim;
 
 #define E_PROP_DEVICEMGR_INPUTWIN                       "DeviceMgr Input Window"
 
+#define SCIM_HELPER_LAUNCHER_PROGRAM (SCIM_LIBEXECDIR "/scim-helper-launcher")
 
 /////////////////////////////////////////////////////////////////////////////
 // Declaration of external variables.
@@ -1721,17 +1722,23 @@ static bool set_active_ise (const String &uuid, bool launch_ise)
                 ise_changed = set_keyboard_ise (_ime_info[i].appid);
             else if (TOOLBAR_HELPER_MODE == _ime_info[i].mode) {
                 if (_ime_info[i].is_enabled) {
-                    /* If IME so is deleted somehow, main() in scim_helper_launcher.cpp will return -1.
-                       Checking HelperModule validity seems necessary here. */
-                    HelperModule helper_module (_ime_info[i].module_name);
-                    if (helper_module.valid ())
+                    if (_ime_info[i].exec == String (SCIM_HELPER_LAUNCHER_PROGRAM)) {
+                        /* If IME so is deleted somehow, main() in scim_helper_launcher.cpp will return -1.
+                           Checking HelperModule validity seems necessary here. */
+                        HelperModule helper_module (_ime_info[i].module_name);
+                        if (helper_module.valid ())
+                            valid = true;
+                        helper_module.unload ();
+                    }
+                    else {
+                        /* executable type */
                         valid = true;
-                    helper_module.unload ();
+                    }
 
                     if (valid)
                         ise_changed = set_helper_ise (_ime_info[i].appid, launch_ise);
                     else
-                        LOGW ("Helper ISE(appid=\"%s\",moudle_name=\"%s\") is not valid.\n", _ime_info[i].appid.c_str (),_ime_info[i].module_name.c_str ());
+                        LOGW ("Helper ISE(appid=\"%s\",module_name=\"%s\") is not valid.\n", _ime_info[i].appid.c_str (), _ime_info[i].module_name.c_str ());
                 }
                 else {
                     LOGW ("Helper ISE(appid=\"%s\") is not enabled.\n", _ime_info[i].appid.c_str ());
index 34c0377..1eb6a94 100644 (file)
@@ -72,13 +72,14 @@ x11_la_LIBADD      = imdkit/libXimd.la \
 
 socket_la_SOURCES  = scim_socket_frontend.cpp
 
-socket_la_CXXFLAGS = @DLOG_CFLAGS@ @ECORE_CFLAGS@
+socket_la_CXXFLAGS = @DLOG_CFLAGS@ @ECORE_CFLAGS@ @PKGMGR_INFO_CFLAGS@
 
 socket_la_LDFLAGS  = -avoid-version \
                      -rpath $(moduledir) \
                      -module \
                      @DLOG_LIBS@ \
                      @ECORE_LIBS@ \
+                     @PKGMGR_INFO_LIBS@ \
                      @LIBTOOL_EXPORT_OPTIONS@
 
 socket_la_LIBADD   = $(top_builddir)/ism/src/libscim@SCIM_EPOCH@.la
index cc97df7..f998f46 100644 (file)
@@ -68,6 +68,9 @@
 #include <unistd.h>
 #include <signal.h>
 #include <dlog.h>
+#if HAVE_PKGMGR_INFO
+#include <pkgmgr-info.h>
+#endif
 
 #ifdef LOG_TAG
 # undef LOG_TAG
@@ -207,6 +210,34 @@ void SocketFrontEnd::get_helper_list (const Socket &client)
   #define SCIM_HELPER_LAUNCHER_PROGRAM  (SCIM_LIBEXECDIR "/scim-helper-launcher")
 #endif
 static std::vector<String>  __active_helpers;
+static String scim_helper_path;
+
+void SocketFrontEnd::launch_helper (const char *name, const char *appid, const char *config, const char *display)
+{
+    int pid;
+
+    pid = fork ();
+
+    if (pid < 0) return;
+
+    if (pid == 0) {
+        const char *argv [] = { scim_helper_path.c_str (),
+                           "--daemon",
+                           "--config", config,
+                           "--display", display,
+                           const_cast<char*> (name),
+                           const_cast<char*> (appid),
+                           0};
+
+        SCIM_DEBUG_MAIN (2) << " Call scim-helper-launcher.\n";
+        ISF_SAVE_LOG ("Exec scim_helper_launcher(%s %s)\n", name, appid);
+
+        setsid ();
+        LOGD ("launch execpath : %s\n", scim_helper_path.c_str ());
+        execv (scim_helper_path.c_str (), const_cast<char **>(argv));
+        exit (-1);
+    }
+}
 
 void SocketFrontEnd::run_helper (const Socket &client)
 {
@@ -224,48 +255,56 @@ void SocketFrontEnd::run_helper (const Socket &client)
     }
     ISF_SAVE_LOG ("uuid(%s), config(%s), display(%s)\n", uuid.c_str (), config.c_str (), display.c_str ());
 
-    for (i = 0; i < __helpers.size (); ++i) {
-        if (__helpers [i].first.uuid == uuid && __helpers [i].second.length ()) {
-
-            __active_helpers.push_back (__helpers [i].first.name);
+    char *execpath = NULL;
+    int ret;
+    pkgmgrinfo_appinfo_h appinfo_handle;
 
-            int pid;
+    /* get app info handle */
+    ret = pkgmgrinfo_appinfo_get_appinfo (uuid.c_str (), &appinfo_handle);
+    if (ret != PMINFO_R_OK) {
+        LOGW ("pkgmgrinfo_appinfo_get_appinfo failed %s %d \n", uuid.c_str (), ret);
+        return;
+    }
 
-            pid = fork ();
+    /* Get exec path */
+    ret = pkgmgrinfo_appinfo_get_exec (appinfo_handle, &execpath);
+    if (ret != PMINFO_R_OK) {
+        pkgmgrinfo_appinfo_destroy_appinfo (appinfo_handle);
+        return;
+    }
 
-            if (pid < 0) return;
+    LOGD ("exec path : %s\n", execpath);
+    scim_helper_path = String (execpath);
 
-            if (pid == 0) {
+    if (appinfo_handle) {
+        pkgmgrinfo_appinfo_destroy_appinfo (appinfo_handle);
+        appinfo_handle = NULL;
+    }
 
-                const char *argv [] = { SCIM_HELPER_LAUNCHER_PROGRAM,
-                                   "--daemon",
-                                   "--config", const_cast<char*> (config.c_str ()),
-                                   "--display", const_cast<char*> (display.c_str ()),
-                                   const_cast<char*> (__helpers [i].second.c_str ()),
-                                   const_cast<char*> (__helpers [i].first.uuid.c_str ()),
-                                   0};
+    if (scim_helper_path != String (SCIM_HELPER_LAUNCHER_PROGRAM)) {
+        /* exe type IME */
+        launch_helper (NULL, NULL, config.c_str (), display.c_str ());
+        m_send_trans.put_command (SCIM_TRANS_CMD_OK);
+    }
+    else {
+        /* shared object (so) type IME */
+        for (i = 0; i < __helpers.size (); ++i) {
+            if (__helpers [i].first.uuid == uuid && __helpers [i].second.length ()) {
 
-                SCIM_DEBUG_MAIN (2) << " Call scim-helper-launcher.\n";
-                ISF_SAVE_LOG ("Exec scim_helper_launcher(%s)\n", __helpers [i].second.c_str ());
+                __active_helpers.push_back (__helpers [i].first.name);
 
-                setsid ();
-                execv (SCIM_HELPER_LAUNCHER_PROGRAM, const_cast<char **>(argv));
-                exit (-1);
+                launch_helper (__helpers [i].second.c_str (), __helpers [i].first.uuid.c_str (), config.c_str (), display.c_str ());
+                break;
             }
-
-            //int status;
-            //waitpid (pid, &status, 0);
-
-            break;
         }
-    }
 
-    if (i > 0 && i == __helpers.size ()) {
-        ISF_SAVE_LOG ("Can't find and exec scim_helper_launcher appid=\"%s\"\n", uuid.c_str ());
-        m_send_trans.put_command (SCIM_TRANS_CMD_FAIL);
+        if (i > 0 && i == __helpers.size ()) {
+            ISF_SAVE_LOG ("Can't find and exec scim_helper_launcher appid=\"%s\"\n", uuid.c_str ());
+            m_send_trans.put_command (SCIM_TRANS_CMD_FAIL);
+        }
+        else
+            m_send_trans.put_command (SCIM_TRANS_CMD_OK);
     }
-    else
-        m_send_trans.put_command (SCIM_TRANS_CMD_OK);
 
     SCIM_DEBUG_MAIN (2) << " exit run_helper ().\n";
 }
index 097b054..324441a 100644 (file)
@@ -168,6 +168,7 @@ public:
 private:
     void load_helper_modules (const std::vector<String> &load_engine_list);
     void get_helper_list (const Socket &client);
+    void launch_helper (const char *name, const char *appid, const char *config, const char *display);
     void run_helper (const Socket &client);
 
     void get_active_ise_list (int client_id);