Modified to prevent IME's start automatically in on-demand mode
[platform/core/uifw/isf.git] / ism / src / scim_helper_launcher.cpp
1 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
2
3 /*
4  * Smart Common Input Method
5  *
6  * Copyright (c) 2004-2005 James Su <suzhe@tsinghua.org.cn>
7  * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
8  *
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with this program; if not, write to the
22  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
23  * Boston, MA  02111-1307  USA
24  *
25  * Modifications by Samsung Electronics Co., Ltd.
26  * 1. Call set_arg_info () before run_helper ()
27  *
28  * $Id: scim_helper_launcher.cpp,v 1.6 2005/05/16 01:25:46 suzhe Exp $
29  *
30  */
31
32 #define Uses_SCIM_HELPER_MODULE
33 #define Uses_SCIM_GLOBAL_CONFIG
34 #define Uses_SCIM_CONFIG_PATH
35 #include <stdlib.h>
36 #include "scim_private.h"
37 #include "scim.h"
38 #include <unistd.h>
39
40 using namespace scim;
41
42 int main (int argc, char *argv [])
43 {
44     int i = 0;
45     int j = 0;
46     String config;
47     String display;
48     String helper;
49     String appid;
50     //bool   daemon = false;
51
52     char *p =  getenv ("DISPLAY");
53     if (p) display = String (p);
54
55     //In the normal situation, config should be set by CMD,
56     //if not provide, we assume have something wrong in
57     //server side, so using simple config as default
58     config = scim_global_config_read (SCIM_GLOBAL_CONFIG_DEFAULT_CONFIG_MODULE, String ("simple"));
59
60     while (i < argc) {
61         if (++i >= argc) break;
62
63         if (String ("-c") == argv [i] ||
64             String ("--config") == argv [i]) {
65             if (++i >= argc) {
66                 std::cerr << "No argument for option " << argv [i-1] << "\n";
67                 exit (-1);
68             }
69             config = argv [i];
70             continue;
71         }
72
73         if (String ("-d") == argv [i] ||
74             String ("--daemon") == argv [i]) {
75             //daemon = true;
76             continue;
77         }
78
79         if (String ("--display") == argv [i]) {
80             if (++i >= argc) {
81                 std::cerr << "No argument for option " << argv [i-1] << "\n";
82                 exit (-1);
83             }
84             display = argv [i];
85             continue;
86         }
87
88         if (String ("-h") == argv [i] ||
89             String ("--help") == argv [i]) {
90             std::cout << "Usage: " << argv [0] << " [options] module appid\n\n"
91                       << "The options are:\n"
92                       << "  -c, --config name    Use specified config module, default is \"simple\".\n"
93                       << "  -d, --daemon         Run as daemon.\n"
94                       << "  --display name       run setup on a specified DISPLAY.\n"
95                       << "  -h, --help           Show this help message.\n"
96                       << "module                 The name of the Helper module\n"
97                       << "appid                  The appid of the Helper to be launched.\n";
98             return 0;
99         }
100
101         if (String ("-v") == argv [i] ||
102             String ("--verbose") == argv [i]) {
103             if (++i >= argc) {
104                 std::cerr << "No argument for option " << argv [i-1] << "\n";
105                 return -1;
106             }
107             DebugOutput::set_verbose_level (atoi (argv [i]));
108             continue;
109         }
110
111         if (String ("-m") == argv [i] ||
112             String ("--mask") == argv [i]) {
113             if (++i >= argc) {
114                 std::cerr << "No argument for option " << argv [i-1] << "\n";
115                 return -1;
116             }
117             if (String (argv [i]) != "none") {
118                 std::vector<String> debug_mask_list;
119                 scim_split_string_list (debug_mask_list, argv [i], ',');
120                 DebugOutput::disable_debug (SCIM_DEBUG_AllMask);
121                 for (size_t k=0; k<debug_mask_list.size (); k++)
122                     DebugOutput::enable_debug_by_name (debug_mask_list [k]);
123             }
124             continue;
125         }
126
127         if (String ("-o") == argv [i] ||
128             String ("--output") == argv [i]) {
129             if (++i >= argc) {
130                 std::cerr << "No argument for option " << argv [i-1] << "\n";
131                 return -1;
132             }
133             DebugOutput::set_output (String (argv [i]));
134             continue;
135         }
136
137         ++j;
138
139         if (j == 1) {
140             helper = String (argv [i]);
141             continue;
142         } else if (j == 2) {
143             appid = String (argv [i]);
144             continue;
145         }
146     }
147
148     String exec = argv[0];
149
150     if (exec != String (SCIM_HELPER_LAUNCHER_PROGRAM)) {
151         /* 3rd party shared object type IME */
152         helper = String ("lib") + exec.substr (exec.find_last_of (SCIM_PATH_DELIM) + 1);
153         appid = String ("");
154     }
155
156     SCIM_DEBUG_MAIN(1) << "scim-helper-launcher: " << config << " " << display << " " << helper << " " << appid << "\n";
157     ISF_SAVE_LOG ("Helper ISE (%s %s) is launching...", helper.c_str (), appid.c_str ());
158
159     if (!helper.length ()) {
160         ISF_SAVE_LOG ("Module name is missing");
161
162         std::cerr << "Module name is missing.\n";
163         return -1;
164     }
165
166     HelperModule helper_module (helper);
167
168     if (!helper_module.valid () || helper_module.number_of_helpers () == 0) {
169         ISF_SAVE_LOG ("Unable to load helper module(%s)", helper.c_str ());
170
171         std::cerr << "Unable to load helper module(" << helper << ")\n";
172         return -1;
173     }
174
175     ConfigPointer config_pointer = ConfigBase::get (true, config);
176
177     if (config_pointer.null ()) {
178         config_pointer = new DummyConfig ();
179     }
180
181 //    if (daemon) scim_daemon ();
182
183     helper_module.set_arg_info (argc, argv);
184     helper_module.run_helper (appid, config_pointer, display);
185     helper_module.unload ();
186
187     if (!config_pointer.null ())
188         config_pointer.reset ();
189     ConfigBase::set (0);
190     ISF_SAVE_LOG ("Helper ISE (%s) is destroyed!!!", appid.c_str ());
191 }
192
193 /*
194 vi:ts=4:nowrap:ai:expandtab
195 */