upload isf tizen beta package
[framework/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  *
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this program; if not, write to the
21  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22  * Boston, MA  02111-1307  USA
23  *
24  * $Id: scim_helper_launcher.cpp,v 1.6 2005/05/16 01:25:46 suzhe Exp $
25  *
26  */
27
28 #define Uses_SCIM_HELPER_MODULE
29 #define Uses_SCIM_GLOBAL_CONFIG
30 #define Uses_SCIM_CONFIG_PATH
31 #include <stdlib.h>
32 #include "scim_private.h"
33 #include "scim.h"
34 #include <privilege-control.h>
35
36 using namespace scim;
37
38 int main (int argc, char *argv [])
39 {
40     int i = 0;
41     int j = 0;
42     String config;
43     String display;
44     String helper;
45     String uuid;
46     bool   daemon = false;
47
48     control_privilege ();
49
50     char *p =  getenv ("DISPLAY");
51     if (p) display = String (p);
52
53     config = scim_global_config_read (SCIM_GLOBAL_CONFIG_DEFAULT_CONFIG_MODULE, String ("simple"));
54
55     while (i < argc) {
56         if (++i >= argc) break;
57
58         if (String ("-c") == argv [i] ||
59             String ("--config") == argv [i]) {
60             if (++i >= argc) {
61                 std::cerr << "No argument for option " << argv [i-1] << "\n";
62                 exit (-1);
63             }
64             config = argv [i];
65             continue;
66         }
67
68         if (String ("-d") == argv [i] ||
69             String ("--daemon") == argv [i]) {
70             daemon = true;
71             continue;
72         }
73
74         if (String ("--display") == argv [i]) {
75             if (++i >= argc) {
76                 std::cerr << "No argument for option " << argv [i-1] << "\n";
77                 exit (-1);
78             }
79             display = argv [i];
80             continue;
81         }
82
83         if (String ("-h") == argv [i] ||
84             String ("--help") == argv [i]) {
85             std::cout << "Usage: " << argv [0] << " [options] module uuid\n\n"
86                       << "The options are:\n"
87                       << "  -c, --config name    Use specified config module, default is \"simple\".\n"
88                       << "  -d, --daemon         Run as daemon.\n"
89                       << "  --display name       run setup on a specified DISPLAY.\n"
90                       << "  -h, --help           Show this help message.\n"
91                       << "module                 The name of the Helper module\n"
92                       << "uuid                   The uuid of the Helper to be launched.\n";
93             return 0;
94         }
95
96         if (String ("-v") == argv [i] ||
97             String ("--verbose") == argv [i]) {
98             if (++i >= argc) {
99                 std::cerr << "No argument for option " << argv [i-1] << "\n";
100                 return -1;
101             }
102             DebugOutput::set_verbose_level (atoi (argv [i]));
103             continue;
104         }
105
106         if (String ("-m") == argv [i] ||
107             String ("--mask") == argv [i]) {
108             if (++i >= argc) {
109                 std::cerr << "No argument for option " << argv [i-1] << "\n";
110                 return -1;
111             }
112             if (String (argv [i]) != "none") {
113                 std::vector<String> debug_mask_list;
114                 scim_split_string_list (debug_mask_list, argv [i], ',');
115                 DebugOutput::disable_debug (SCIM_DEBUG_AllMask);
116                 for (size_t j=0; j<debug_mask_list.size (); j++)
117                     DebugOutput::enable_debug_by_name (debug_mask_list [j]);
118             }
119             continue;
120         }
121
122         if (String ("-o") == argv [i] ||
123             String ("--output") == argv [i]) {
124             if (++i >= argc) {
125                 std::cerr << "No argument for option " << argv [i-1] << "\n";
126                 return -1;
127             }
128             DebugOutput::set_output (String (argv [i]));
129             continue;
130         }
131
132         ++j;
133
134         if (j == 1) {
135             helper = String (argv [i]);
136             continue;
137         } else if (j == 2) {
138             uuid = String (argv [i]);
139             continue;
140         }
141
142         std::cerr << "Invalid command line option: " << argv [i] << "\n";
143         return -1;
144     }
145
146     SCIM_DEBUG_MAIN(1) << "scim-helper-launcher: " << config << " " << display << " " << helper << " " << uuid << "\n";
147
148     if (!helper.length () || !uuid.length ()) {
149         std::cerr << "Module name or Helper UUID is missing.\n";
150         return -1;
151     }
152
153     HelperModule helper_module (helper);
154
155     if (!helper_module.valid () || helper_module.number_of_helpers () == 0) {
156         std::cerr << "Unable to load Helper module: " << helper << "\n";
157         return -1;
158     }
159
160     ConfigModule config_module (config);
161
162     ConfigPointer config_pointer;
163
164     if (config_module.valid ()) {
165         config_pointer = config_module.create_config ();
166     }
167
168     if (config_pointer.null ()) {
169         config_pointer = new DummyConfig ();
170     }
171
172 //    if (daemon) scim_daemon ();
173
174     helper_module.run_helper (uuid, config_pointer, display);
175
176     if (!config_pointer.null ())
177         config_pointer.reset ();
178
179     exit (0);
180 }
181
182 /*
183 vi:ts=4:nowrap:ai:expandtab
184 */