Add exclude section for impossible lines to be excuted in TCT
[platform/core/api/inputmethod.git] / inputmethod / src / inputmethod.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <vector>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <dlog.h>
22 #include <sclcore.h>
23 #include <unistd.h>
24 #include <privilege_checker_private.h>
25 #include "inputmethod_private.h"
26 #include <inputmethod.h>
27 #include "inputmethod_internal.h"
28
29 using namespace std;
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34 #define LOG_TAG "INPUTMETHOD"
35
36 using namespace scl;
37
38 class CCoreEventCallback : public ISCLCoreEventCallback
39 {
40     void on_init();
41     void on_run(int argc, char **argv);
42     void on_exit();
43     void on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos);
44     void on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor);
45     void on_focus_out(sclint ic, const sclchar *ic_uuid);
46     void on_focus_in(sclint ic, const sclchar *ic_uuid);
47     void on_ise_show(sclint ic, const int degree, Ise_Context &context);
48     void on_ise_hide(sclint ic, const sclchar *ic_uuid);
49     void on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height);
50     void on_set_language(sclu32 language);
51     void on_set_imdata(sclchar *buf, sclu32 len);
52     void on_get_imdata(sclchar **buf, sclu32 *len);
53     void on_get_language_locale(sclint ic, sclchar **locale);
54     void on_set_return_key_type(sclu32 type);
55     void on_set_return_key_disable(sclu32 disabled);
56     void on_set_layout(sclu32 layout);
57     void on_reset_input_context(sclint ic, const sclchar *uuid);
58     void on_process_key_event(scim::KeyEvent &key, sclu32 *ret);
59     void on_process_key_event_with_keycode(scim::KeyEvent &key, sclu32 *ret, sclu32 keycode);
60     void on_set_display_language(const sclchar *language);
61     void on_set_rotation_degree(sclint degree);
62     void on_set_accessibility_state(sclboolean state);
63     void on_create_option_window(sclwindow window, SCLOptionWindowType type);
64     void on_destroy_option_window(sclwindow window);
65     void on_check_option_window_availability(sclboolean *ret);
66     void on_set_caps_mode(sclu32 mode);
67     void on_candidate_show(sclint ic, const sclchar *ic_uuid);
68     void on_candidate_hide(sclint ic, const sclchar *ic_uuid);
69     void on_update_lookup_table(SclCandidateTable &table);
70     void on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret);
71     void on_set_prediction_hint(const sclchar *prediction_hint);
72     void on_set_mime_type(const sclchar *mime_type);
73     void on_set_prediction_hint_data(const sclchar *key, const sclchar *value);
74     void on_set_optimization_hint(sclu32 hint);
75 };
76
77 typedef struct
78 {
79     ime_focus_in_cb focus_in;   /**< Called when an edit field has focus */
80     ime_focus_out_cb focus_out; /**< Called when an edit field loses focus */
81     ime_surrounding_text_updated_cb surrounding_text_updated;   /**< Called when an edit field responds to a request with the surrounding text */
82     ime_input_context_reset_cb input_context_reset;             /**< Called to reset the input context of an edit field */
83     ime_cursor_position_updated_cb cursor_position_updated;     /**< Called when the position of the cursor in an edit field changes */
84     ime_language_requested_cb language_requested;   /**< Called when an edit field requests the language from the input panel */
85     ime_language_set_cb language_set;   /**< Called to set the preferred language to the input panel */
86     ime_imdata_set_cb imdata_set;       /**< Called to set the application specific data to deliver to the input panel */
87     ime_imdata_requested_cb imdata_requested;       /**< Called when an associated text input UI control requests the application specific data from the input panel */
88     ime_layout_set_cb layout_set;       /**< Called when an edit field requests the input panel to set its layout */
89     ime_return_key_type_set_cb return_key_type_set;     /**< Called when an edit field requests the input panel to set the "return" key label */
90     ime_return_key_state_set_cb return_key_state_set;   /**< Called when an edit field requests the input panel to enable or disable the "return" key state */
91     ime_geometry_requested_cb geometry_requested;       /**< Called when an edit field requests the position and size from the input panel */
92     ime_process_key_event_cb process_key_event;         /**< Called when the key event is received from the external keyboard devices */
93     ime_process_key_event_with_keycode_cb process_key_event_with_keycode; /**< Called when the key event is received from the external keyboard devices */
94     ime_display_language_changed_cb display_language_changed;   /**< Called when the system display language is changed */
95     ime_rotation_degree_changed_cb rotation_degree_changed;     /**< Called when the device is rotated */
96     ime_accessibility_state_changed_cb accessibility_state_changed; /**< Called when Accessibility in Settings application is on or off */
97     ime_option_window_created_cb option_window_created;     /**< Called to create the option window */
98     ime_option_window_destroyed_cb option_window_destroyed; /**< Called to destroy the option window */
99     ime_caps_mode_changed_cb caps_mode_changed;
100     ime_candidate_show_cb candidate_show;
101     ime_candidate_hide_cb candidate_hide;
102     ime_lookup_table_changed_cb lookup_table_changed;
103     ime_process_input_device_event_cb process_input_device_event;   /**< Called when the event is received from the unconventional input devices */
104     ime_prediction_hint_set_cb prediction_hint_set;
105     ime_mime_type_set_request_cb mime_type_set;
106     ime_prediction_hint_data_set_cb prediction_hint_data_set;
107     ime_optimization_hint_set_cb optimization_hint_set;
108     void *focus_in_user_data;
109     void *focus_out_user_data;
110     void *surrounding_text_updated_user_data;
111     void *input_context_reset_user_data;
112     void *cursor_position_updated_user_data;
113     void *language_requested_user_data;
114     void *language_set_user_data;
115     void *imdata_set_user_data;
116     void *imdata_requested_user_data;
117     void *layout_set_user_data;
118     void *return_key_type_set_user_data;
119     void *return_key_state_set_user_data;
120     void *geometry_requested_user_data;
121     void *process_key_event_user_data;
122     void *process_key_event_with_keycode_user_data;
123     void *display_language_changed_user_data;
124     void *rotation_degree_changed_user_data;
125     void *accessibility_state_changed_user_data;
126     void *option_window_created_user_data;
127     void *option_window_destroyed_user_data;
128     void *caps_mode_changed_user_data;
129     void *candidate_show_user_data;
130     void *candidate_hide_user_data;
131     void *lookup_table_changed_user_data;
132     void *process_input_device_event_user_data;
133     void *prediction_hint_set_user_data;
134     void *mime_type_set_user_data;
135     void *prediction_hint_data_set_user_data;
136     void *optimization_hint_set_user_data;
137 } ime_event_callback_s;
138
139 typedef struct {
140     ime_input_device_type_e device_type;
141     void *event_data;
142 } ime_device_event_s;
143
144 static ime_callback_s g_basic_callback = {NULL};
145 static ime_event_callback_s g_event_callback = {NULL};
146 static void *g_user_data = NULL;
147 static bool g_running = false;
148
149 static CCoreEventCallback g_core_event_callback;
150 CSCLCore g_core(&g_core_event_callback);
151
152 static bool g_checked_privilege = false;
153 static bool g_permission_allowed = false;
154
155 extern "C" {
156     extern void ime_app_main(int argc, char **argv);
157 }
158
159 //LCOV_EXCL_START
160 void CCoreEventCallback::on_init()
161 {
162     if (g_basic_callback.create) {
163         g_basic_callback.create(g_user_data);
164     }
165 }
166
167 void CCoreEventCallback::on_run(int argc, char **argv)
168 {
169     LOGD("on_run");
170     ime_app_main(argc, argv);
171 }
172
173 void CCoreEventCallback::on_exit()
174 {
175     LOGD("on_exit");
176     if (g_basic_callback.terminate) {
177         g_basic_callback.terminate(g_user_data);
178     }
179 }
180
181 void CCoreEventCallback::on_update_cursor_position(sclint ic, const sclchar *ic_uuid, sclint cursor_pos)
182 {
183     if (g_event_callback.cursor_position_updated) {
184         g_event_callback.cursor_position_updated(cursor_pos, g_event_callback.cursor_position_updated_user_data);
185     }
186 }
187
188 void CCoreEventCallback::on_update_surrounding_text(sclint ic, const sclchar *text, sclint cursor)
189 {
190     if (g_event_callback.surrounding_text_updated) {
191         g_event_callback.surrounding_text_updated(ic, text, cursor, g_event_callback.surrounding_text_updated_user_data);
192     }
193 }
194
195 void CCoreEventCallback::on_focus_out(sclint ic, const sclchar *ic_uuid)
196 {
197     if (g_event_callback.focus_out) {
198         g_event_callback.focus_out(ic, g_event_callback.focus_out_user_data);
199     }
200 }
201
202 void CCoreEventCallback::on_focus_in(sclint ic, const sclchar *ic_uuid)
203 {
204     if (g_event_callback.focus_in) {
205         g_event_callback.focus_in(ic, g_event_callback.focus_in_user_data);
206     }
207 }
208
209 void CCoreEventCallback::on_ise_show(sclint ic, const int degree, Ise_Context &context)
210 {
211     if (g_basic_callback.show) {
212         struct _ime_context input_context;
213
214         memset(&input_context, 0, sizeof(struct _ime_context));
215         input_context.layout = context.layout;
216         input_context.layout_variation = context.layout_variation;
217         input_context.cursor_pos = context.cursor_pos;
218         input_context.autocapital_type = context.autocapital_type;
219         input_context.return_key_type = context.return_key_type;
220         input_context.return_key_disabled = context.return_key_disabled;
221         input_context.prediction_allow = context.prediction_allow;
222         input_context.password_mode = context.password_mode;
223         input_context.imdata_size = context.imdata_size;
224         input_context.input_hint = context.input_hint;
225         input_context.bidi_direction = context.bidi_direction;
226         input_context.language = context.language;
227         input_context.client_window = context.client_window;
228         input_context.caps_mode = context.caps_mode;
229
230         g_basic_callback.show(ic, static_cast<ime_context_h>(&input_context), g_user_data);
231     }
232 }
233
234 void CCoreEventCallback::on_ise_hide(sclint ic, const sclchar *ic_uuid)
235 {
236     if (g_basic_callback.hide) {
237         g_basic_callback.hide(ic, g_user_data);
238     }
239 }
240
241 void CCoreEventCallback::on_get_geometry(sclu32 *pos_x, sclu32 *pos_y, sclu32 *width, sclu32 *height)
242 {
243     int geometry_pos_x = 0;
244     int geometry_pos_y = 0;
245     int geometry_width = 0;
246     int geometry_height = 0;
247
248     if (g_event_callback.geometry_requested) {
249         g_event_callback.geometry_requested(g_event_callback.geometry_requested_user_data, &geometry_pos_x, &geometry_pos_y, &geometry_width, &geometry_height);
250     }
251
252     if (pos_x)
253         *pos_x = geometry_pos_x;
254
255     if (pos_y)
256         *pos_y = geometry_pos_y;
257
258     if (width)
259         *width = geometry_width;
260
261     if (height)
262         *height = geometry_height;
263 }
264
265 void CCoreEventCallback::on_set_language(sclu32 language)
266 {
267     if (g_event_callback.language_set) {
268         g_event_callback.language_set((Ecore_IMF_Input_Panel_Lang)language, g_event_callback.language_set_user_data);
269     }
270 }
271
272 void CCoreEventCallback::on_set_imdata(sclchar *buf, sclu32 len)
273 {
274     if (g_event_callback.imdata_set) {
275         g_event_callback.imdata_set((void *)buf, len, g_event_callback.imdata_set_user_data);
276     }
277 }
278
279 void CCoreEventCallback::on_get_imdata(sclchar **buf, sclu32 *len)
280 {
281     if (g_event_callback.imdata_requested) {
282         g_event_callback.imdata_requested(g_event_callback.imdata_set_user_data, (void **)buf, len);
283     }
284 }
285
286 void CCoreEventCallback::on_get_language_locale(sclint ic, sclchar **locale)
287 {
288     if (g_event_callback.language_requested) {
289         g_event_callback.language_requested(g_event_callback.language_requested_user_data, locale);
290     }
291 }
292
293 void CCoreEventCallback::on_set_return_key_type(sclu32 type)
294 {
295     if (g_event_callback.return_key_type_set) {
296         g_event_callback.return_key_type_set((Ecore_IMF_Input_Panel_Return_Key_Type)type, g_event_callback.return_key_type_set_user_data);
297     }
298 }
299
300 void CCoreEventCallback::on_set_return_key_disable(sclu32 disabled)
301 {
302     bool return_key_disabled = !!disabled;
303
304     if (g_event_callback.return_key_state_set) {
305         g_event_callback.return_key_state_set(return_key_disabled, g_event_callback.return_key_state_set_user_data);
306     }
307 }
308
309 void CCoreEventCallback::on_set_layout(sclu32 layout)
310 {
311     if (g_event_callback.layout_set) {
312         g_event_callback.layout_set(static_cast<Ecore_IMF_Input_Panel_Layout>(layout), g_event_callback.layout_set_user_data);
313     }
314 }
315
316 void CCoreEventCallback::on_reset_input_context(sclint ic, const sclchar *uuid)
317 {
318     if (g_event_callback.input_context_reset) {
319         g_event_callback.input_context_reset(g_event_callback.input_context_reset_user_data);
320     }
321 }
322
323 void CCoreEventCallback::on_process_key_event(scim::KeyEvent &key, sclu32 *ret)
324 {
325     if (g_event_callback.process_key_event) {
326         struct _ime_device_info dev_info = {key.dev_name.c_str(),
327             static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
328         bool processed = g_event_callback.process_key_event(static_cast<ime_key_code_e>(key.code), static_cast<ime_key_mask_e>(key.mask),
329             static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
330
331         if (ret) {
332             if (processed)
333                 *ret = 1;
334             else
335                 *ret = 0;
336         }
337     } else {
338         if (ret) {
339             *ret = 0;
340         }
341     }
342 }
343
344 void CCoreEventCallback::on_process_key_event_with_keycode(scim::KeyEvent &key, sclu32 *ret, sclu32 keycode)
345 {
346     if (g_event_callback.process_key_event_with_keycode) {
347         struct _ime_device_info dev_info = {key.dev_name.c_str(),
348             static_cast<Ecore_IMF_Device_Class>(key.dev_class), static_cast<Ecore_IMF_Device_Subclass>(key.dev_subclass)};
349         bool processed = g_event_callback.process_key_event_with_keycode(keycode, static_cast<ime_key_code_e>(key.code), static_cast<ime_key_mask_e>(key.mask),
350                 static_cast<ime_device_info_h>(&dev_info), g_event_callback.process_key_event_user_data);
351
352         if (ret) {
353             if (processed)
354                 *ret = 1;
355             else
356                 *ret = 0;
357         }
358     } else {
359         if (ret) {
360             *ret = 0;
361         }
362     }
363 }
364
365 void CCoreEventCallback::on_set_display_language(const sclchar *language)
366 {
367     if (g_event_callback.display_language_changed) {
368         g_event_callback.display_language_changed(language, g_event_callback.display_language_changed_user_data);
369     }
370 }
371
372 void CCoreEventCallback::on_set_rotation_degree(sclint degree)
373 {
374     if (g_event_callback.rotation_degree_changed) {
375         g_event_callback.rotation_degree_changed(degree, g_event_callback.rotation_degree_changed_user_data);
376     }
377 }
378
379 void CCoreEventCallback::on_set_accessibility_state(sclboolean state)
380 {
381     if (g_event_callback.accessibility_state_changed) {
382         g_event_callback.accessibility_state_changed(state, g_event_callback.accessibility_state_changed_user_data);
383     }
384 }
385
386 void CCoreEventCallback::on_create_option_window(sclwindow window, SCLOptionWindowType type)
387 {
388     if (g_event_callback.option_window_created) {
389         g_event_callback.option_window_created(static_cast<Evas_Object*>(window), static_cast<ime_option_window_type_e>(type), g_event_callback.option_window_created_user_data);
390     }
391 }
392
393 void CCoreEventCallback::on_destroy_option_window(sclwindow window)
394 {
395     if (g_event_callback.option_window_destroyed) {
396         g_event_callback.option_window_destroyed(static_cast<Evas_Object*>(window), g_event_callback.option_window_destroyed_user_data);
397     }
398 }
399
400 void CCoreEventCallback::on_check_option_window_availability(sclboolean *ret)
401 {
402     if (ret) {
403         if (g_event_callback.option_window_created) // Instead of each 3rd party keyboard, inputmethod will reply the availability of the option (setting).
404             *ret = true;
405         else
406             *ret = false;
407     }
408 }
409
410 void CCoreEventCallback::on_set_caps_mode(sclu32 mode)
411 {
412     if (g_event_callback.caps_mode_changed) {
413         g_event_callback.caps_mode_changed(mode, g_event_callback.caps_mode_changed_user_data);
414     }
415 }
416
417 void CCoreEventCallback::on_candidate_show(sclint ic, const sclchar *ic_uuid)
418 {
419     if (g_event_callback.candidate_show) {
420         g_event_callback.candidate_show(ic, g_event_callback.candidate_show_user_data);
421     }
422 }
423
424 void CCoreEventCallback::on_candidate_hide(sclint ic, const sclchar *ic_uuid)
425 {
426     if (g_event_callback.candidate_hide) {
427         g_event_callback.candidate_hide(ic, g_event_callback.candidate_hide_user_data);
428     }
429 }
430
431 void CCoreEventCallback::on_update_lookup_table(SclCandidateTable &table)
432 {
433     Eina_List *string_list = NULL;
434
435     if (g_event_callback.lookup_table_changed) {
436         vector<string>::iterator iter = table.candidate.begin();
437         for (; iter != table.candidate.end(); ++iter) {
438             string_list = eina_list_append(string_list, iter->c_str());
439         }
440
441         g_event_callback.lookup_table_changed(string_list, g_event_callback.lookup_table_changed_user_data);
442     }
443 }
444
445 void CCoreEventCallback::on_process_input_device_event(sclu32 &type, sclchar *data, size_t &len, sclu32 *ret)
446 {
447     typedef struct {
448         int ecore_event_id;
449         ime_input_device_type_e device_type;
450     } ime_device_type_conv_table;
451
452     ime_device_type_conv_table conv_table[] = {
453         { ECORE_EVENT_DETENT_ROTATE , IME_INPUT_DEVICE_TYPE_ROTARY },
454     };
455
456     ime_input_device_type_e device_type = IME_INPUT_DEVICE_TYPE_UNKNOWN;
457     for (unsigned int loop = 0; loop < sizeof(conv_table) / sizeof(ime_device_type_conv_table); loop++) {
458         if ((unsigned int)(conv_table[loop].ecore_event_id) == type) {
459             device_type = conv_table[loop].device_type;
460         }
461     }
462
463     if (g_event_callback.process_input_device_event) {
464         ime_device_event_s device_event;
465         device_event.device_type = device_type;
466         device_event.event_data = static_cast<void*>(data);
467         void *input_data = static_cast<void*>(&device_event);
468         void *user_data = g_event_callback.process_input_device_event_user_data;
469
470         g_event_callback.process_input_device_event(device_type, input_data, user_data);
471
472         if (ret) {
473             *ret = 1;
474         }
475     } else {
476         if (ret) {
477             *ret = 0;
478         }
479     }
480 }
481
482 void CCoreEventCallback::on_set_prediction_hint(const sclchar *prediction_hint)
483 {
484     if (g_event_callback.prediction_hint_set) {
485         g_event_callback.prediction_hint_set(prediction_hint, g_event_callback.prediction_hint_set_user_data);
486     }
487 }
488
489 void CCoreEventCallback::on_set_mime_type(const sclchar *mime_type)
490 {
491     if (g_event_callback.mime_type_set) {
492         g_event_callback.mime_type_set(mime_type, g_event_callback.mime_type_set_user_data);
493     }
494 }
495
496 void CCoreEventCallback::on_set_prediction_hint_data(const sclchar *key, const sclchar *value)
497 {
498     if (g_event_callback.prediction_hint_data_set) {
499         g_event_callback.prediction_hint_data_set(key, value, g_event_callback.prediction_hint_data_set_user_data);
500     }
501 }
502
503 void CCoreEventCallback::on_set_optimization_hint(sclu32 hint)
504 {
505     if (g_event_callback.optimization_hint_set) {
506         g_event_callback.optimization_hint_set((ime_optimization_hint_e)hint, g_event_callback.optimization_hint_set_user_data);
507     }
508 }
509
510 void ime_privilege_cache_init()
511 {
512     g_permission_allowed = false;
513     g_checked_privilege = false;
514 }
515 //LCOV_EXCL_STOP
516
517 ime_error_e _check_privilege()
518 {
519     char uid[16];
520     ime_error_e ret = IME_ERROR_NONE;
521
522     if (g_checked_privilege) {
523         return g_permission_allowed ? IME_ERROR_NONE : IME_ERROR_PERMISSION_DENIED;
524     }
525
526     if (inputmethod_cynara_initialize() == false) {
527         //LCOV_EXCL_START
528         g_permission_allowed = false;
529         g_checked_privilege = true;
530         LOGE("inputmethod_cynara_initialize () == false");
531         //LCOV_EXCL_STOP
532         return IME_ERROR_PERMISSION_DENIED;
533     }
534
535     snprintf(uid, 16, "%d", getuid());
536     if (check_privilege(uid, IME_PRIVILEGE) == false) {
537         LOGE("check_privilege(uid, IME_PRIVILEGE) == false. uid : %s", uid); //LCOV_EXCL_LINE
538         ret = IME_ERROR_PERMISSION_DENIED;
539     }
540
541     g_permission_allowed = (ret == IME_ERROR_NONE);
542     g_checked_privilege = true;
543
544     inputmethod_cynara_finish();
545
546     return ret;
547 }
548
549 //LCOV_EXCL_START
550 bool g_from_dotnet = false;
551 EXPORT_API int ime_set_dotnet_flag(bool set)
552 {
553     ime_error_e retVal = IME_ERROR_NONE;
554
555     retVal = _check_privilege();
556     if (retVal != IME_ERROR_NONE) return retVal;
557
558     g_from_dotnet = set;
559
560     return retVal;
561 }
562 //LCOV_EXCL_STOP
563
564 EXPORT_API int ime_run(ime_callback_s *basic_cb, void *user_data)
565 {
566     ime_error_e retVal = IME_ERROR_NONE;
567
568     if (g_running) {
569         //LCOV_EXCL_START
570         LOGE("inputmethod main loop is already running.");
571         return IME_ERROR_OPERATION_FAILED;
572         //LCOV_EXCL_STOP
573     }
574
575     if (!basic_cb) {
576         LOGE("basic callbacks pointer is null.");
577         return IME_ERROR_INVALID_PARAMETER;
578     }
579
580     retVal = _check_privilege();
581     if (retVal != IME_ERROR_NONE) return retVal;
582
583     g_basic_callback = *basic_cb;
584
585     if (!g_basic_callback.create || !g_basic_callback.terminate ||
586         !g_basic_callback.show || !g_basic_callback.hide) {
587         LOGE("mandatory callback functions are not set");
588         memset(&g_basic_callback, 0, sizeof(ime_callback_s));
589         memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
590         return IME_ERROR_NO_CALLBACK_FUNCTION;
591     }
592
593     //LCOV_EXCL_START
594     g_user_data = user_data;
595     g_running = true;
596
597     if (g_from_dotnet) {
598         LOGD("ime_run is called from dotnet");
599         return IME_ERROR_NONE;
600     }
601
602     try {
603         g_core.run();
604     } catch (...) {
605         LOGW("exception is thrown from g_core.run()\n");
606     }
607
608     memset(&g_basic_callback, 0, sizeof(ime_callback_s));
609     memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
610     g_user_data = NULL;
611     g_running = false;
612
613     return IME_ERROR_NONE;
614     //LCOV_EXCL_STOP
615 }
616
617 EXPORT_API int ime_event_set_focus_in_cb(ime_focus_in_cb callback_func, void *user_data)
618 {
619     ime_error_e retVal = IME_ERROR_NONE;
620
621     if (!callback_func) {
622         LOGW("IME_ERROR_INVALID_PARAMETER");
623         return IME_ERROR_INVALID_PARAMETER;
624     }
625
626     retVal = _check_privilege();
627     if (retVal != IME_ERROR_NONE) return retVal;
628
629     g_event_callback.focus_in = callback_func;
630     g_event_callback.focus_in_user_data = user_data;
631
632     return IME_ERROR_NONE;
633 }
634
635 EXPORT_API int ime_event_set_focus_out_cb(ime_focus_out_cb callback_func, void *user_data)
636 {
637     ime_error_e retVal = IME_ERROR_NONE;
638
639     if (!callback_func) {
640         LOGW("IME_ERROR_INVALID_PARAMETER");
641         return IME_ERROR_INVALID_PARAMETER;
642     }
643
644     retVal = _check_privilege();
645     if (retVal != IME_ERROR_NONE) return retVal;
646
647     g_event_callback.focus_out = callback_func;
648     g_event_callback.focus_out_user_data = user_data;
649
650     return IME_ERROR_NONE;
651 }
652
653 EXPORT_API int ime_event_set_surrounding_text_updated_cb(ime_surrounding_text_updated_cb callback_func, void *user_data)
654 {
655     ime_error_e retVal = IME_ERROR_NONE;
656
657     if (!callback_func) {
658         LOGW("IME_ERROR_INVALID_PARAMETER");
659         return IME_ERROR_INVALID_PARAMETER;
660     }
661
662     retVal = _check_privilege();
663     if (retVal != IME_ERROR_NONE) return retVal;
664
665     g_event_callback.surrounding_text_updated = callback_func;
666     g_event_callback.surrounding_text_updated_user_data = user_data;
667
668     return IME_ERROR_NONE;
669 }
670
671 EXPORT_API int ime_event_set_input_context_reset_cb(ime_input_context_reset_cb callback_func, void *user_data)
672 {
673     ime_error_e retVal = IME_ERROR_NONE;
674
675     if (!callback_func) {
676         LOGW("IME_ERROR_INVALID_PARAMETER");
677         return IME_ERROR_INVALID_PARAMETER;
678     }
679
680     retVal = _check_privilege();
681     if (retVal != IME_ERROR_NONE) return retVal;
682
683     g_event_callback.input_context_reset = callback_func;
684     g_event_callback.input_context_reset_user_data = user_data;
685
686     return IME_ERROR_NONE;
687 }
688
689 EXPORT_API int ime_event_set_cursor_position_updated_cb(ime_cursor_position_updated_cb callback_func, void *user_data)
690 {
691     ime_error_e retVal = IME_ERROR_NONE;
692
693     if (!callback_func) {
694         LOGW("IME_ERROR_INVALID_PARAMETER");
695         return IME_ERROR_INVALID_PARAMETER;
696     }
697
698     retVal = _check_privilege();
699     if (retVal != IME_ERROR_NONE) return retVal;
700
701     g_event_callback.cursor_position_updated = callback_func;
702     g_event_callback.cursor_position_updated_user_data = user_data;
703
704     return IME_ERROR_NONE;
705 }
706
707 EXPORT_API int ime_event_set_language_requested_cb(ime_language_requested_cb callback_func, void *user_data)
708 {
709     ime_error_e retVal = IME_ERROR_NONE;
710
711     if (!callback_func) {
712         LOGW("IME_ERROR_INVALID_PARAMETER");
713         return IME_ERROR_INVALID_PARAMETER;
714     }
715
716     retVal = _check_privilege();
717     if (retVal != IME_ERROR_NONE) return retVal;
718
719     g_event_callback.language_requested = callback_func;
720     g_event_callback.language_requested_user_data = user_data;
721
722     return IME_ERROR_NONE;
723 }
724
725 EXPORT_API int ime_event_set_language_set_cb(ime_language_set_cb callback_func, void *user_data)
726 {
727     ime_error_e retVal = IME_ERROR_NONE;
728
729     if (!callback_func) {
730         LOGW("IME_ERROR_INVALID_PARAMETER");
731         return IME_ERROR_INVALID_PARAMETER;
732     }
733
734     retVal = _check_privilege();
735     if (retVal != IME_ERROR_NONE) return retVal;
736
737     g_event_callback.language_set = callback_func;
738     g_event_callback.language_set_user_data = user_data;
739
740     return IME_ERROR_NONE;
741 }
742
743 EXPORT_API int ime_event_set_imdata_set_cb(ime_imdata_set_cb callback_func, void *user_data)
744 {
745     ime_error_e retVal = IME_ERROR_NONE;
746
747     if (!callback_func) {
748         LOGW("IME_ERROR_INVALID_PARAMETER");
749         return IME_ERROR_INVALID_PARAMETER;
750     }
751
752     retVal = _check_privilege();
753     if (retVal != IME_ERROR_NONE) return retVal;
754
755     g_event_callback.imdata_set = callback_func;
756     g_event_callback.imdata_set_user_data = user_data;
757
758     return IME_ERROR_NONE;
759 }
760
761 EXPORT_API int ime_event_set_imdata_requested_cb(ime_imdata_requested_cb callback_func, void *user_data)
762 {
763     ime_error_e retVal = IME_ERROR_NONE;
764
765     if (!callback_func) {
766         LOGW("IME_ERROR_INVALID_PARAMETER");
767         return IME_ERROR_INVALID_PARAMETER;
768     }
769
770     retVal = _check_privilege();
771     if (retVal != IME_ERROR_NONE) return retVal;
772
773     g_event_callback.imdata_requested = callback_func;
774     g_event_callback.imdata_requested_user_data = user_data;
775
776     return IME_ERROR_NONE;
777 }
778
779 EXPORT_API int ime_event_set_layout_set_cb(ime_layout_set_cb callback_func, void *user_data)
780 {
781     ime_error_e retVal = IME_ERROR_NONE;
782
783     if (!callback_func) {
784         LOGW("IME_ERROR_INVALID_PARAMETER");
785         return IME_ERROR_INVALID_PARAMETER;
786     }
787
788     retVal = _check_privilege();
789     if (retVal != IME_ERROR_NONE) return retVal;
790
791     g_event_callback.layout_set = callback_func;
792     g_event_callback.layout_set_user_data = user_data;
793
794     return IME_ERROR_NONE;
795 }
796
797 EXPORT_API int ime_event_set_return_key_type_set_cb(ime_return_key_type_set_cb callback_func, void *user_data)
798 {
799     ime_error_e retVal = IME_ERROR_NONE;
800
801     if (!callback_func) {
802         LOGW("IME_ERROR_INVALID_PARAMETER");
803         return IME_ERROR_INVALID_PARAMETER;
804     }
805
806     retVal = _check_privilege();
807     if (retVal != IME_ERROR_NONE) return retVal;
808
809     g_event_callback.return_key_type_set = callback_func;
810     g_event_callback.return_key_type_set_user_data = user_data;
811
812     return IME_ERROR_NONE;
813 }
814
815 EXPORT_API int ime_event_set_return_key_state_set_cb(ime_return_key_state_set_cb callback_func, void *user_data)
816 {
817     ime_error_e retVal = IME_ERROR_NONE;
818
819     if (!callback_func) {
820         LOGW("IME_ERROR_INVALID_PARAMETER");
821         return IME_ERROR_INVALID_PARAMETER;
822     }
823
824     retVal = _check_privilege();
825     if (retVal != IME_ERROR_NONE) return retVal;
826
827     g_event_callback.return_key_state_set = callback_func;
828     g_event_callback.return_key_state_set_user_data = user_data;
829
830     return IME_ERROR_NONE;
831 }
832
833 EXPORT_API int ime_event_set_geometry_requested_cb(ime_geometry_requested_cb callback_func, void *user_data)
834 {
835     ime_error_e retVal = IME_ERROR_NONE;
836
837     if (!callback_func) {
838         LOGW("IME_ERROR_INVALID_PARAMETER");
839         return IME_ERROR_INVALID_PARAMETER;
840     }
841
842     retVal = _check_privilege();
843     if (retVal != IME_ERROR_NONE) return retVal;
844
845     g_event_callback.geometry_requested = callback_func;
846     g_event_callback.geometry_requested_user_data = user_data;
847
848     return IME_ERROR_NONE;
849 }
850
851 EXPORT_API int ime_event_set_process_key_event_cb(ime_process_key_event_cb callback_func, void *user_data)
852 {
853     ime_error_e retVal = IME_ERROR_NONE;
854
855     if (!callback_func) {
856         LOGW("IME_ERROR_INVALID_PARAMETER");
857         return IME_ERROR_INVALID_PARAMETER;
858     }
859
860     retVal = _check_privilege();
861     if (retVal != IME_ERROR_NONE) return retVal;
862
863     g_event_callback.process_key_event = callback_func;
864     g_event_callback.process_key_event_user_data = user_data;
865
866     return IME_ERROR_NONE;
867 }
868
869 EXPORT_API int ime_event_set_process_key_event_with_keycode_cb(ime_process_key_event_with_keycode_cb callback_func, void *user_data)
870 {
871     ime_error_e retVal = IME_ERROR_NONE;
872
873     if (!callback_func) {
874         LOGW("IME_ERROR_INVALID_PARAMETER");
875         return IME_ERROR_INVALID_PARAMETER;
876     }
877
878     retVal = _check_privilege();
879     if (retVal != IME_ERROR_NONE) return retVal;
880
881     g_event_callback.process_key_event_with_keycode = callback_func;
882     g_event_callback.process_key_event_with_keycode_user_data = user_data;
883
884     return IME_ERROR_NONE;
885 }
886
887 EXPORT_API int ime_event_set_display_language_changed_cb(ime_display_language_changed_cb callback_func, void *user_data)
888 {
889     ime_error_e retVal = IME_ERROR_NONE;
890
891     if (!callback_func) {
892         LOGW("IME_ERROR_INVALID_PARAMETER");
893         return IME_ERROR_INVALID_PARAMETER;
894     }
895
896     retVal = _check_privilege();
897     if (retVal != IME_ERROR_NONE) return retVal;
898
899     g_event_callback.display_language_changed = callback_func;
900     g_event_callback.display_language_changed_user_data = user_data;
901
902     return IME_ERROR_NONE;
903 }
904
905 EXPORT_API int ime_event_set_rotation_degree_changed_cb(ime_rotation_degree_changed_cb callback_func, void *user_data)
906 {
907     ime_error_e retVal = IME_ERROR_NONE;
908
909     if (!callback_func) {
910         LOGW("IME_ERROR_INVALID_PARAMETER");
911         return IME_ERROR_INVALID_PARAMETER;
912     }
913
914     retVal = _check_privilege();
915     if (retVal != IME_ERROR_NONE) return retVal;
916
917     g_event_callback.rotation_degree_changed = callback_func;
918     g_event_callback.rotation_degree_changed_user_data = user_data;
919
920     return IME_ERROR_NONE;
921 }
922
923 EXPORT_API int ime_event_set_accessibility_state_changed_cb(ime_accessibility_state_changed_cb callback_func, void *user_data)
924 {
925     ime_error_e retVal = IME_ERROR_NONE;
926
927     if (!callback_func) {
928         LOGW("IME_ERROR_INVALID_PARAMETER");
929         return IME_ERROR_INVALID_PARAMETER;
930     }
931
932     retVal = _check_privilege();
933     if (retVal != IME_ERROR_NONE) return retVal;
934
935     g_event_callback.accessibility_state_changed = callback_func;
936     g_event_callback.accessibility_state_changed_user_data = user_data;
937
938     return IME_ERROR_NONE;
939 }
940
941 EXPORT_API int ime_event_set_option_window_created_cb(ime_option_window_created_cb callback_func, void *user_data)
942 {
943     ime_error_e retVal = IME_ERROR_NONE;
944
945     if (!callback_func) {
946         LOGW("IME_ERROR_INVALID_PARAMETER");
947         return IME_ERROR_INVALID_PARAMETER;
948     }
949
950     retVal = _check_privilege();
951     if (retVal != IME_ERROR_NONE) return retVal;
952
953     g_event_callback.option_window_created = callback_func;
954     g_event_callback.option_window_created_user_data = user_data;
955
956     return IME_ERROR_NONE;
957 }
958
959 EXPORT_API int ime_event_set_option_window_destroyed_cb(ime_option_window_destroyed_cb callback_func, void *user_data)
960 {
961     ime_error_e retVal = IME_ERROR_NONE;
962
963     if (!callback_func) {
964         LOGW("IME_ERROR_INVALID_PARAMETER");
965         return IME_ERROR_INVALID_PARAMETER;
966     }
967
968     retVal = _check_privilege();
969     if (retVal != IME_ERROR_NONE) return retVal;
970
971     g_event_callback.option_window_destroyed = callback_func;
972     g_event_callback.option_window_destroyed_user_data = user_data;
973
974     return IME_ERROR_NONE;
975 }
976
977 //LCOV_EXCL_START
978 EXPORT_API int ime_event_set_caps_mode_changed_cb(ime_caps_mode_changed_cb callback_func, void *user_data)
979 {
980     ime_error_e retVal = IME_ERROR_NONE;
981
982     if (!callback_func) {
983         LOGW("IME_ERROR_INVALID_PARAMETER");
984         return IME_ERROR_INVALID_PARAMETER;
985     }
986
987     retVal = _check_privilege();
988     if (retVal != IME_ERROR_NONE) return retVal;
989
990     g_event_callback.caps_mode_changed = callback_func;
991     g_event_callback.caps_mode_changed_user_data = user_data;
992
993     return IME_ERROR_NONE;
994 }
995
996 EXPORT_API int ime_event_set_candidate_show_cb(ime_candidate_show_cb callback_func, void *user_data)
997 {
998     ime_error_e retVal = IME_ERROR_NONE;
999
1000     if (!callback_func) {
1001         LOGW("IME_ERROR_INVALID_PARAMETER");
1002         return IME_ERROR_INVALID_PARAMETER;
1003     }
1004
1005     retVal = _check_privilege();
1006     if (retVal != IME_ERROR_NONE) return retVal;
1007
1008     g_event_callback.candidate_show = callback_func;
1009     g_event_callback.candidate_show_user_data = user_data;
1010
1011     return IME_ERROR_NONE;
1012 }
1013
1014 EXPORT_API int ime_event_set_candidate_hide_cb(ime_candidate_hide_cb callback_func, void *user_data)
1015 {
1016     ime_error_e retVal = IME_ERROR_NONE;
1017
1018     if (!callback_func) {
1019         LOGW("IME_ERROR_INVALID_PARAMETER");
1020         return IME_ERROR_INVALID_PARAMETER;
1021     }
1022
1023     retVal = _check_privilege();
1024     if (retVal != IME_ERROR_NONE) return retVal;
1025
1026     g_event_callback.candidate_hide = callback_func;
1027     g_event_callback.candidate_hide_user_data = user_data;
1028
1029     return IME_ERROR_NONE;
1030 }
1031
1032 EXPORT_API int ime_event_set_lookup_table_changed_cb(ime_lookup_table_changed_cb callback_func, void *user_data)
1033 {
1034     ime_error_e retVal = IME_ERROR_NONE;
1035
1036     if (!callback_func) {
1037         LOGW("IME_ERROR_INVALID_PARAMETER");
1038         return IME_ERROR_INVALID_PARAMETER;
1039     }
1040
1041     retVal = _check_privilege();
1042     if (retVal != IME_ERROR_NONE) return retVal;
1043
1044     g_event_callback.lookup_table_changed = callback_func;
1045     g_event_callback.lookup_table_changed_user_data = user_data;
1046
1047     return IME_ERROR_NONE;
1048 }
1049 //LCOV_EXCL_STOP
1050
1051 EXPORT_API int ime_send_key_event(ime_key_code_e keycode, ime_key_mask_e keymask, bool forward_key)
1052 {
1053     ime_error_e retVal = IME_ERROR_NONE;
1054
1055     if (!g_running) {
1056         LOGW("IME_ERROR_NOT_RUNNING");
1057         return IME_ERROR_NOT_RUNNING;
1058     }
1059
1060     //LCOV_EXCL_START
1061     retVal = _check_privilege();
1062     if (retVal != IME_ERROR_NONE) return retVal;
1063
1064     if (forward_key)
1065         g_core.forward_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1066     else
1067         g_core.send_key_event(-1, NULL, (sclu32)keycode, (sclu16)keymask);
1068     //LCOV_EXCL_STOP
1069
1070     return IME_ERROR_NONE;
1071 }
1072
1073 EXPORT_API int ime_commit_string(const char *str)
1074 {
1075     ime_error_e retVal = IME_ERROR_NONE;
1076
1077     if (!str) {
1078         LOGW("IME_ERROR_INVALID_PARAMETER");
1079         return IME_ERROR_INVALID_PARAMETER;
1080     }
1081
1082     if (!g_running) {
1083         LOGW("IME_ERROR_NOT_RUNNING");
1084         return IME_ERROR_NOT_RUNNING;
1085     }
1086
1087     //LCOV_EXCL_START
1088     retVal = _check_privilege();
1089     if (retVal != IME_ERROR_NONE) return retVal;
1090
1091     SECURE_LOGI("commit string : %s", str);
1092     g_core.commit_string(-1, NULL, str);
1093
1094     return IME_ERROR_NONE;
1095     //LCOV_EXCL_STOP
1096 }
1097
1098 EXPORT_API int ime_show_preedit_string(void)
1099 {
1100     ime_error_e retVal = IME_ERROR_NONE;
1101
1102     if (!g_running) {
1103         LOGW("IME_ERROR_NOT_RUNNING");
1104         return IME_ERROR_NOT_RUNNING;
1105     }
1106
1107     //LCOV_EXCL_START
1108     retVal = _check_privilege();
1109     if (retVal != IME_ERROR_NONE) return retVal;
1110
1111     g_core.show_preedit_string(-1, NULL);
1112
1113     return IME_ERROR_NONE;
1114     //LCOV_EXCL_STOP
1115 }
1116
1117 EXPORT_API int ime_hide_preedit_string(void)
1118 {
1119     ime_error_e retVal = IME_ERROR_NONE;
1120
1121     if (!g_running) {
1122         LOGW("IME_ERROR_NOT_RUNNING");
1123         return IME_ERROR_NOT_RUNNING;
1124     }
1125
1126     //LCOV_EXCL_START
1127     retVal = _check_privilege();
1128     if (retVal != IME_ERROR_NONE) return retVal;
1129
1130     g_core.hide_preedit_string(-1, NULL);
1131
1132     return IME_ERROR_NONE;
1133     //LCOV_EXCL_STOP
1134 }
1135
1136 EXPORT_API int ime_update_preedit_string(const char *str, Eina_List *attrs)
1137 {
1138     ime_error_e retVal = IME_ERROR_NONE;
1139
1140     if (!str) {
1141         LOGW("IME_ERROR_INVALID_PARAMETER");
1142         return IME_ERROR_INVALID_PARAMETER;
1143     }
1144
1145     if (!g_running) {
1146         LOGW("IME_ERROR_NOT_RUNNING");
1147         return IME_ERROR_NOT_RUNNING;
1148     }
1149
1150     //LCOV_EXCL_START
1151     retVal = _check_privilege();
1152     if (retVal != IME_ERROR_NONE) return retVal;
1153
1154     scim::AttributeList attrv;
1155     void *data = NULL;
1156     ime_preedit_attribute *attr = NULL;
1157
1158     if (attrs) {
1159         EINA_LIST_FREE(attrs, data) {
1160             attr = (ime_preedit_attribute *)data;
1161             if (attr) {
1162                 attrv.push_back(scim::Attribute(attr->start, attr->length, (scim::AttributeType)attr->type, attr->value));
1163                 free(attr);
1164             }
1165         }
1166     }
1167
1168     SECURE_LOGI("preedit string : '%s'", str);
1169     g_core.update_preedit_string(-1, NULL, str, attrv);
1170
1171     return IME_ERROR_NONE;
1172     //LCOV_EXCL_STOP
1173 }
1174
1175 EXPORT_API int ime_request_surrounding_text(int maxlen_before, int maxlen_after)
1176 {
1177     ime_error_e retVal = IME_ERROR_NONE;
1178
1179     if (!g_event_callback.surrounding_text_updated) {
1180         LOGW("IME_ERROR_NO_CALLBACK_FUNCTION");
1181         return IME_ERROR_NO_CALLBACK_FUNCTION;
1182     }
1183
1184     if (!g_running) {
1185         LOGW("IME_ERROR_NOT_RUNNING");
1186         return IME_ERROR_NOT_RUNNING;
1187     }
1188
1189     //LCOV_EXCL_START
1190     retVal = _check_privilege();
1191     if (retVal != IME_ERROR_NONE) return retVal;
1192
1193     g_core.get_surrounding_text(NULL, maxlen_before, maxlen_after);
1194
1195     return IME_ERROR_NONE;
1196     //LCOV_EXCL_STOP
1197 }
1198
1199 EXPORT_API int ime_delete_surrounding_text(int offset, int len)
1200 {
1201     ime_error_e retVal = IME_ERROR_NONE;
1202
1203     if (len <= 0) {
1204         LOGW("IME_ERROR_INVALID_PARAMETER");
1205         return IME_ERROR_INVALID_PARAMETER;
1206     }
1207
1208     if (!g_running) {
1209         LOGW("IME_ERROR_NOT_RUNNING");
1210         return IME_ERROR_NOT_RUNNING;
1211     }
1212
1213     //LCOV_EXCL_START
1214     retVal = _check_privilege();
1215     if (retVal != IME_ERROR_NONE) return retVal;
1216
1217     LOGI("offset: %d, len : %d", offset, len);
1218     g_core.delete_surrounding_text(offset, len);
1219
1220     return IME_ERROR_NONE;
1221     //LCOV_EXCL_STOP
1222 }
1223
1224 EXPORT_API int ime_get_surrounding_text(int maxlen_before, int maxlen_after, char **text, int *cursor_pos)
1225 {
1226     ime_error_e retVal = IME_ERROR_NONE;
1227
1228     if (!text || !cursor_pos) {
1229         LOGW("IME_ERROR_INVALID_PARAMETER");
1230         return IME_ERROR_INVALID_PARAMETER;
1231     }
1232
1233     if (!g_running) {
1234         LOGW("IME_ERROR_NOT_RUNNING");
1235         return IME_ERROR_NOT_RUNNING;
1236     }
1237
1238     //LCOV_EXCL_START
1239     retVal = _check_privilege();
1240     if (retVal != IME_ERROR_NONE) return retVal;
1241
1242     int cursor = 0;
1243
1244     int ret = g_core.get_surrounding_text(maxlen_before, maxlen_after, text, cursor);
1245     if (ret == -1) {
1246         LOGW("IME_ERROR_OUR_OF_MEMORY");
1247         return IME_ERROR_OUT_OF_MEMORY;
1248     }
1249
1250     if (cursor_pos)
1251         *cursor_pos = cursor;
1252
1253     return IME_ERROR_NONE;
1254     //LCOV_EXCL_STOP
1255 }
1256
1257 EXPORT_API int ime_set_selection(int start, int end)
1258 {
1259     ime_error_e retVal = IME_ERROR_NONE;
1260
1261     if (start < 0) {
1262         LOGW("IME_ERROR_INVALID_PARAMETER");
1263         return IME_ERROR_INVALID_PARAMETER;
1264     }
1265
1266     if (!g_running) {
1267         LOGW("IME_ERROR_NOT_RUNNING");
1268         return IME_ERROR_NOT_RUNNING;
1269     }
1270
1271     //LCOV_EXCL_START
1272     retVal = _check_privilege();
1273     if (retVal != IME_ERROR_NONE) return retVal;
1274
1275     LOGI("start: %d, end : %d", start, end);
1276     g_core.set_selection(start, end);
1277
1278     return IME_ERROR_NONE;
1279     //LCOV_EXCL_STOP
1280 }
1281
1282 EXPORT_API int ime_get_selected_text(char **text)
1283 {
1284     ime_error_e retVal = IME_ERROR_NONE;
1285
1286     if (!text) {
1287         LOGW("IME_ERROR_INVALID_PARAMETER");
1288         return IME_ERROR_INVALID_PARAMETER;
1289     }
1290
1291     if (!g_running) {
1292         LOGW("IME_ERROR_NOT_RUNNING");
1293         return IME_ERROR_NOT_RUNNING;
1294     }
1295
1296     //LCOV_EXCL_START
1297     retVal = _check_privilege();
1298     if (retVal != IME_ERROR_NONE) return retVal;
1299
1300     g_core.get_selection_text(text);
1301
1302     return IME_ERROR_NONE;
1303     //LCOV_EXCL_STOP
1304 }
1305
1306 EXPORT_API Evas_Object* ime_get_main_window(void)
1307 {
1308     ime_error_e retVal = IME_ERROR_NONE;
1309
1310     Evas_Object *win = NULL;
1311
1312     retVal = _check_privilege();
1313     if (retVal != IME_ERROR_NONE) {
1314         //LCOV_EXCL_START
1315         LOGE("_check_privilege returned %d.", retVal);
1316         set_last_result(retVal);
1317         return NULL;
1318         //LCOV_EXCL_STOP
1319     }
1320
1321     if (!g_running) {
1322         set_last_result(IME_ERROR_NOT_RUNNING);
1323         LOGW("IME_ERROR_NOT_RUNNING");
1324         return NULL;
1325     }
1326
1327     //LCOV_EXCL_START
1328     win = static_cast<Evas_Object*>(g_core.get_main_window());
1329     if (win) {
1330         set_last_result(IME_ERROR_NONE);
1331     } else {
1332         set_last_result(IME_ERROR_OPERATION_FAILED);
1333         LOGW("IME_ERROR_OPERATION_FAILED");
1334     }
1335
1336     return win;
1337     //LCOV_EXCL_STOP
1338 }
1339
1340 EXPORT_API int ime_set_size(int portrait_width, int portrait_height, int landscape_width, int landscape_height)
1341 {
1342     ime_error_e retVal = IME_ERROR_NONE;
1343
1344     SclSize portrait_size, landscape_size;
1345
1346     if (portrait_width < 1 || portrait_height < 1 || landscape_width < 1 || landscape_height < 1) {
1347         LOGW("IME_ERROR_INVALID_PARAMETER");
1348         return IME_ERROR_INVALID_PARAMETER;
1349     }
1350
1351     if (!g_running) {
1352         LOGW("IME_ERROR_NOT_RUNNING");
1353         return IME_ERROR_NOT_RUNNING;
1354     }
1355
1356     //LCOV_EXCL_START
1357     retVal = _check_privilege();
1358     if (retVal != IME_ERROR_NONE) return retVal;
1359
1360     portrait_size.width = portrait_width;
1361     portrait_size.height = portrait_height;
1362
1363     landscape_size.width = landscape_width;
1364     landscape_size.height = landscape_height;
1365
1366     g_core.set_keyboard_size_hints(portrait_size, landscape_size);
1367
1368     return IME_ERROR_NONE;
1369     //LCOV_EXCL_STOP
1370 }
1371
1372 EXPORT_API int ime_create_option_window(void)
1373 {
1374     ime_error_e retVal = IME_ERROR_NONE;
1375
1376     if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1377         LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1378         return IME_ERROR_NO_CALLBACK_FUNCTION;
1379     }
1380
1381     if (!g_running) {
1382         LOGW("IME_ERROR_NOT_RUNNING");
1383         return IME_ERROR_NOT_RUNNING;
1384     }
1385
1386     //LCOV_EXCL_START
1387     retVal = _check_privilege();
1388     if (retVal != IME_ERROR_NONE) return retVal;
1389
1390     if (g_core.create_option_window()) {
1391         return IME_ERROR_NONE;
1392     } else {
1393         LOGW("IME_ERROR_OPERATION_FAILED");
1394         return IME_ERROR_OPERATION_FAILED;
1395     }
1396     //LCOV_EXCL_STOP
1397 }
1398
1399 EXPORT_API int ime_destroy_option_window(Evas_Object *window)
1400 {
1401     ime_error_e retVal = IME_ERROR_NONE;
1402
1403     if (!g_event_callback.option_window_created || !g_event_callback.option_window_destroyed) {
1404         LOGW("ime_create_option_window_cb() and ime_destroy_option_window_cb() callback functions are not set.");
1405         return IME_ERROR_NO_CALLBACK_FUNCTION;
1406     }
1407
1408     if (!window) {
1409         LOGW("Window pointer is null.");
1410         return IME_ERROR_INVALID_PARAMETER;
1411     }
1412
1413     if (!g_running) {
1414         LOGW("IME_ERROR_NOT_RUNNING");
1415         return IME_ERROR_NOT_RUNNING;
1416     }
1417
1418     //LCOV_EXCL_START
1419     retVal = _check_privilege();
1420     if (retVal != IME_ERROR_NONE) return retVal;
1421
1422     g_core.destroy_option_window(window);
1423
1424     return IME_ERROR_NONE;
1425     //LCOV_EXCL_STOP
1426 }
1427
1428 //LCOV_EXCL_START
1429 EXPORT_API int ime_set_imengine(const char *engine_id)
1430 {
1431     ime_error_e retVal = IME_ERROR_NONE;
1432
1433     if (!engine_id) {
1434         LOGW("IME_ERROR_INVALID_PARAMETER");
1435         return IME_ERROR_INVALID_PARAMETER;
1436     }
1437
1438     retVal = _check_privilege();
1439     if (retVal != IME_ERROR_NONE) return retVal;
1440
1441     g_core.set_keyboard_ise_by_uuid(engine_id);
1442
1443     return IME_ERROR_NONE;
1444 }
1445
1446 EXPORT_API int ime_flush_imengine(void)
1447 {
1448     ime_error_e retVal = IME_ERROR_NONE;
1449
1450     if (!g_running) {
1451         LOGW("IME_ERROR_NOT_RUNNING");
1452         return IME_ERROR_NOT_RUNNING;
1453     }
1454
1455     retVal = _check_privilege();
1456     if (retVal != IME_ERROR_NONE) return retVal;
1457
1458     g_core.flush_keyboard_ise();
1459
1460     return IME_ERROR_NONE;
1461 }
1462
1463 EXPORT_API int ime_send_imengine_event(int command, unsigned int value)
1464 {
1465     ime_error_e retVal = IME_ERROR_NONE;
1466
1467     if (!g_running) {
1468         LOGW("IME_ERROR_NOT_RUNNING");
1469         return IME_ERROR_NOT_RUNNING;
1470     }
1471
1472     retVal = _check_privilege();
1473     if (retVal != IME_ERROR_NONE) return retVal;
1474
1475     g_core.send_imengine_event(-1, NULL, command, value);
1476
1477     return IME_ERROR_NONE;
1478 }
1479
1480 EXPORT_API int ime_reset_imengine(void)
1481 {
1482     ime_error_e retVal = IME_ERROR_NONE;
1483
1484     if (!g_running) {
1485         LOGW("IME_ERROR_NOT_RUNNING");
1486         return IME_ERROR_NOT_RUNNING;
1487     }
1488
1489     retVal = _check_privilege();
1490     if (retVal != IME_ERROR_NONE) return retVal;
1491
1492     g_core.reset_keyboard_ise();
1493
1494     return IME_ERROR_NONE;
1495 }
1496
1497 EXPORT_API int ime_update_input_context(unsigned int type, unsigned int value)
1498 {
1499     ime_error_e retVal = IME_ERROR_NONE;
1500
1501     if (!g_running) {
1502         LOGW("IME_ERROR_NOT_RUNNING");
1503         return IME_ERROR_NOT_RUNNING;
1504     }
1505
1506     retVal = _check_privilege();
1507     if (retVal != IME_ERROR_NONE) return retVal;
1508
1509     g_core.update_input_context(type, value);
1510
1511     return IME_ERROR_NONE;
1512 }
1513 //LCOV_EXCL_STOP
1514
1515 EXPORT_API int ime_request_hide(void)
1516 {
1517     ime_error_e retVal = IME_ERROR_NONE;
1518
1519     if (!g_running) {
1520         LOGW("IME_ERROR_NOT_RUNNING");
1521         return IME_ERROR_NOT_RUNNING;
1522     }
1523
1524     //LCOV_EXCL_START
1525     retVal = _check_privilege();
1526     if (retVal != IME_ERROR_NONE) return retVal;
1527
1528     g_core.request_ise_hide();
1529
1530     return IME_ERROR_NONE;
1531     //LCOV_EXCL_STOP
1532 }
1533
1534 //LCOV_EXCL_START
1535 EXPORT_API int ime_initialize(void)
1536 {
1537     ime_error_e retVal = IME_ERROR_NONE;
1538
1539     retVal = _check_privilege();
1540     if (retVal != IME_ERROR_NONE) return retVal;
1541
1542     g_core.init();
1543     g_running = false;
1544
1545     return retVal;
1546 }
1547
1548 EXPORT_API int ime_prepare(void)
1549 {
1550     ime_error_e retVal = IME_ERROR_NONE;
1551
1552     if (g_running) {
1553         LOGE("inputmethod main loop is already running.");
1554         return IME_ERROR_OPERATION_FAILED;
1555     }
1556
1557     retVal = _check_privilege();
1558     if (retVal != IME_ERROR_NONE) return retVal;
1559
1560     g_core.prepare();
1561
1562     g_running = true;
1563
1564     return retVal;
1565 }
1566
1567 EXPORT_API int ime_finalize(void)
1568 {
1569     ime_error_e retVal = IME_ERROR_NONE;
1570
1571     retVal = _check_privilege();
1572     if (retVal != IME_ERROR_NONE) return retVal;
1573
1574     g_core.fini();
1575     g_running = false;
1576     memset(&g_basic_callback, 0, sizeof(ime_callback_s));
1577     memset(&g_event_callback, 0, sizeof(ime_event_callback_s));
1578     g_user_data = NULL;
1579
1580     return retVal;
1581 }
1582
1583 EXPORT_API int ime_select_candidate(unsigned int index)
1584 {
1585     ime_error_e retVal = IME_ERROR_NONE;
1586
1587     if (!g_running) {
1588         LOGW("IME_ERROR_NOT_RUNNING");
1589         return IME_ERROR_NOT_RUNNING;
1590     }
1591
1592     retVal = _check_privilege();
1593     if (retVal != IME_ERROR_NONE) return retVal;
1594
1595     g_core.select_candidate(index);
1596
1597     return IME_ERROR_NONE;
1598 }
1599 //LCOV_EXCL_STOP
1600
1601 EXPORT_API int ime_send_private_command(const char *command)
1602 {
1603     ime_error_e retVal = IME_ERROR_NONE;
1604
1605     if (!command) {
1606         LOGW("IME_ERROR_INVALID_PARAMETER");
1607         return IME_ERROR_INVALID_PARAMETER;
1608     }
1609
1610     if (!g_running) {
1611         LOGW("IME_ERROR_NOT_RUNNING");
1612         return IME_ERROR_NOT_RUNNING;
1613     }
1614
1615     //LCOV_EXCL_START
1616     retVal = _check_privilege();
1617     if (retVal != IME_ERROR_NONE) return retVal;
1618
1619     g_core.send_private_command(command);
1620
1621     return IME_ERROR_NONE;
1622     //LCOV_EXCL_STOP
1623 }
1624
1625 EXPORT_API int ime_commit_content(const char *content, const char *description, const char *mime_type)
1626 {
1627     ime_error_e retVal = IME_ERROR_NONE;
1628
1629     if (!content || !description || !mime_type) {
1630         LOGW("IME_ERROR_INVALID_PARAMETER");
1631         return IME_ERROR_INVALID_PARAMETER;
1632     }
1633
1634     retVal = _check_privilege();
1635     if (retVal != IME_ERROR_NONE) return retVal;
1636
1637     if (!g_running) {
1638         LOGW("IME_ERROR_NOT_RUNNING");
1639         return IME_ERROR_NOT_RUNNING;
1640     }
1641
1642     //LCOV_EXCL_START
1643     LOGI("content : '%s', description : '%s', mime_type : '%s'", content, description, mime_type);
1644     g_core.commit_content(content, description, mime_type);
1645
1646     return IME_ERROR_NONE;
1647     //LCOV_EXCL_STOP
1648 }
1649
1650 EXPORT_API int ime_context_get_layout(ime_context_h context, Ecore_IMF_Input_Panel_Layout *layout)
1651 {
1652     ime_error_e retVal = IME_ERROR_NONE;
1653
1654     if (!context || !layout) {
1655         LOGW("IME_ERROR_INVALID_PARAMETER");
1656         return IME_ERROR_INVALID_PARAMETER;
1657     }
1658
1659     retVal = _check_privilege();
1660     if (retVal != IME_ERROR_NONE) return retVal;
1661
1662     if (!g_running) {
1663         LOGW("IME_ERROR_NOT_RUNNING");
1664         return IME_ERROR_NOT_RUNNING;
1665     }
1666
1667     //LCOV_EXCL_START
1668     *layout = context->layout;
1669
1670     return IME_ERROR_NONE;
1671     //LCOV_EXCL_STOP
1672 }
1673
1674 EXPORT_API int ime_context_get_layout_variation(ime_context_h context, ime_layout_variation_e *layout_variation)
1675 {
1676     ime_error_e retVal = IME_ERROR_NONE;
1677
1678     if (!context || !layout_variation) {
1679         LOGW("IME_ERROR_INVALID_PARAMETER");
1680         return IME_ERROR_INVALID_PARAMETER;
1681     }
1682
1683     retVal = _check_privilege();
1684     if (retVal != IME_ERROR_NONE) return retVal;
1685
1686     if (!g_running) {
1687         LOGW("IME_ERROR_NOT_RUNNING");
1688         return IME_ERROR_NOT_RUNNING;
1689     }
1690
1691     //LCOV_EXCL_START
1692     *layout_variation = static_cast<ime_layout_variation_e>(context->layout_variation);
1693
1694     return IME_ERROR_NONE;
1695     //LCOV_EXCL_STOP
1696 }
1697
1698 EXPORT_API int ime_context_get_cursor_position(ime_context_h context, int *cursor_pos)
1699 {
1700     ime_error_e retVal = IME_ERROR_NONE;
1701
1702     if (!context || !cursor_pos) {
1703         LOGW("IME_ERROR_INVALID_PARAMETER");
1704         return IME_ERROR_INVALID_PARAMETER;
1705     }
1706
1707     retVal = _check_privilege();
1708     if (retVal != IME_ERROR_NONE) return retVal;
1709
1710     if (!g_running) {
1711         LOGW("IME_ERROR_NOT_RUNNING");
1712         return IME_ERROR_NOT_RUNNING;
1713     }
1714
1715     //LCOV_EXCL_START
1716     *cursor_pos = context->cursor_pos;
1717
1718     return IME_ERROR_NONE;
1719     //LCOV_EXCL_STOP
1720 }
1721
1722 EXPORT_API int ime_context_get_autocapital_type(ime_context_h context, Ecore_IMF_Autocapital_Type *autocapital_type)
1723 {
1724     ime_error_e retVal = IME_ERROR_NONE;
1725
1726     if (!context || !autocapital_type) {
1727         LOGW("IME_ERROR_INVALID_PARAMETER");
1728         return IME_ERROR_INVALID_PARAMETER;
1729     }
1730
1731     retVal = _check_privilege();
1732     if (retVal != IME_ERROR_NONE) return retVal;
1733
1734     if (!g_running) {
1735         LOGW("IME_ERROR_NOT_RUNNING");
1736         return IME_ERROR_NOT_RUNNING;
1737     }
1738
1739     //LCOV_EXCL_START
1740     *autocapital_type = context->autocapital_type;
1741
1742     return IME_ERROR_NONE;
1743     //LCOV_EXCL_STOP
1744 }
1745
1746 EXPORT_API int ime_context_get_return_key_type(ime_context_h context, Ecore_IMF_Input_Panel_Return_Key_Type *return_key_type)
1747 {
1748     ime_error_e retVal = IME_ERROR_NONE;
1749
1750     if (!context || !return_key_type) {
1751         LOGW("IME_ERROR_INVALID_PARAMETER");
1752         return IME_ERROR_INVALID_PARAMETER;
1753     }
1754
1755     retVal = _check_privilege();
1756     if (retVal != IME_ERROR_NONE) return retVal;
1757
1758     if (!g_running) {
1759         LOGW("IME_ERROR_NOT_RUNNING");
1760         return IME_ERROR_NOT_RUNNING;
1761     }
1762
1763     //LCOV_EXCL_START
1764     *return_key_type = context->return_key_type;
1765
1766     return IME_ERROR_NONE;
1767     //LCOV_EXCL_STOP
1768 }
1769
1770 EXPORT_API int ime_context_get_return_key_state(ime_context_h context, bool *return_key_state)
1771 {
1772     ime_error_e retVal = IME_ERROR_NONE;
1773
1774     if (!context || !return_key_state) {
1775         LOGW("IME_ERROR_INVALID_PARAMETER");
1776         return IME_ERROR_INVALID_PARAMETER;
1777     }
1778
1779     retVal = _check_privilege();
1780     if (retVal != IME_ERROR_NONE) return retVal;
1781
1782     if (!g_running) {
1783         LOGW("IME_ERROR_NOT_RUNNING");
1784         return IME_ERROR_NOT_RUNNING;
1785     }
1786
1787     //LCOV_EXCL_START
1788     *return_key_state = static_cast<bool>(context->return_key_disabled);
1789
1790     return IME_ERROR_NONE;
1791     //LCOV_EXCL_STOP
1792 }
1793
1794 EXPORT_API int ime_context_get_prediction_mode(ime_context_h context, bool *prediction_mode)
1795 {
1796     ime_error_e retVal = IME_ERROR_NONE;
1797
1798     if (!context || !prediction_mode) {
1799         LOGW("IME_ERROR_INVALID_PARAMETER");
1800         return IME_ERROR_INVALID_PARAMETER;
1801     }
1802
1803     retVal = _check_privilege();
1804     if (retVal != IME_ERROR_NONE) return retVal;
1805
1806     if (!g_running) {
1807         LOGW("IME_ERROR_NOT_RUNNING");
1808         return IME_ERROR_NOT_RUNNING;
1809     }
1810
1811     //LCOV_EXCL_START
1812     *prediction_mode = static_cast<bool>(context->prediction_allow);
1813
1814     return IME_ERROR_NONE;
1815     //LCOV_EXCL_STOP
1816 }
1817
1818 EXPORT_API int ime_context_get_password_mode(ime_context_h context, bool *password_mode)
1819 {
1820     ime_error_e retVal = IME_ERROR_NONE;
1821
1822     if (!context || !password_mode) {
1823         LOGW("IME_ERROR_INVALID_PARAMETER");
1824         return IME_ERROR_INVALID_PARAMETER;
1825     }
1826
1827     retVal = _check_privilege();
1828     if (retVal != IME_ERROR_NONE) return retVal;
1829
1830     if (!g_running) {
1831         LOGW("IME_ERROR_NOT_RUNNING");
1832         return IME_ERROR_NOT_RUNNING;
1833     }
1834
1835     //LCOV_EXCL_START
1836     *password_mode = static_cast<bool>(context->password_mode);
1837
1838     return IME_ERROR_NONE;
1839     //LCOV_EXCL_STOP
1840 }
1841
1842 EXPORT_API int ime_context_get_input_hint(ime_context_h context, Ecore_IMF_Input_Hints *input_hint)
1843 {
1844     ime_error_e retVal = IME_ERROR_NONE;
1845
1846     if (!context || !input_hint) {
1847         LOGW("IME_ERROR_INVALID_PARAMETER");
1848         return IME_ERROR_INVALID_PARAMETER;
1849     }
1850
1851     retVal = _check_privilege();
1852     if (retVal != IME_ERROR_NONE) return retVal;
1853
1854     if (!g_running) {
1855         LOGW("IME_ERROR_NOT_RUNNING");
1856         return IME_ERROR_NOT_RUNNING;
1857     }
1858
1859     //LCOV_EXCL_START
1860     *input_hint = context->input_hint;
1861
1862     return IME_ERROR_NONE;
1863     //LCOV_EXCL_STOP
1864 }
1865
1866 EXPORT_API int ime_context_get_bidi_direction(ime_context_h context, Ecore_IMF_BiDi_Direction *bidi)
1867 {
1868     ime_error_e retVal = IME_ERROR_NONE;
1869
1870     if (!context || !bidi) {
1871         LOGW("IME_ERROR_INVALID_PARAMETER");
1872         return IME_ERROR_INVALID_PARAMETER;
1873     }
1874
1875     retVal = _check_privilege();
1876     if (retVal != IME_ERROR_NONE) return retVal;
1877
1878     if (!g_running) {
1879         LOGW("IME_ERROR_NOT_RUNNING");
1880         return IME_ERROR_NOT_RUNNING;
1881     }
1882
1883     //LCOV_EXCL_START
1884     *bidi = context->bidi_direction;
1885
1886     return IME_ERROR_NONE;
1887     //LCOV_EXCL_STOP
1888 }
1889
1890 EXPORT_API int ime_context_get_language(ime_context_h context, Ecore_IMF_Input_Panel_Lang *language)
1891 {
1892     ime_error_e retVal = IME_ERROR_NONE;
1893
1894     if (!context || !language) {
1895         LOGW("IME_ERROR_INVALID_PARAMETER");
1896         return IME_ERROR_INVALID_PARAMETER;
1897     }
1898
1899     retVal = _check_privilege();
1900     if (retVal != IME_ERROR_NONE) return retVal;
1901
1902     if (!g_running) {
1903         LOGW("IME_ERROR_NOT_RUNNING");
1904         return IME_ERROR_NOT_RUNNING;
1905     }
1906
1907     //LCOV_EXCL_START
1908     *language = context->language;
1909
1910     return IME_ERROR_NONE;
1911     //LCOV_EXCL_STOP
1912 }
1913
1914 //LCOV_EXCL_START
1915 EXPORT_API int ime_context_get_caps_mode(ime_context_h context, bool *caps_mode)
1916 {
1917     ime_error_e retVal = IME_ERROR_NONE;
1918
1919     if (!context || !caps_mode) {
1920         LOGW("IME_ERROR_INVALID_PARAMETER");
1921         return IME_ERROR_INVALID_PARAMETER;
1922     }
1923
1924     retVal = _check_privilege();
1925     if (retVal != IME_ERROR_NONE) return retVal;
1926
1927     if (!g_running) {
1928         LOGW("IME_ERROR_NOT_RUNNING");
1929         return IME_ERROR_NOT_RUNNING;
1930     }
1931
1932     *caps_mode = static_cast<bool>(context->caps_mode);
1933
1934     return IME_ERROR_NONE;
1935 }
1936 //LCOV_EXCL_STOP
1937
1938 EXPORT_API int ime_device_info_get_name(ime_device_info_h dev_info, char **dev_name)
1939 {
1940     ime_error_e retVal = IME_ERROR_NONE;
1941
1942     if (!dev_info || !dev_name) {
1943         LOGW("IME_ERROR_INVALID_PARAMETER");
1944         return IME_ERROR_INVALID_PARAMETER;
1945     }
1946
1947     retVal = _check_privilege();
1948     if (retVal != IME_ERROR_NONE) return retVal;
1949
1950     if (!g_running) {
1951         LOGW("IME_ERROR_NOT_RUNNING");
1952         return IME_ERROR_NOT_RUNNING;
1953     }
1954
1955     //LCOV_EXCL_START
1956     if (!dev_info->dev_name)
1957         *dev_name = strdup("");
1958     else
1959         *dev_name = strdup(dev_info->dev_name);
1960
1961     return IME_ERROR_NONE;
1962     //LCOV_EXCL_STOP
1963 }
1964
1965 EXPORT_API int ime_device_info_get_class(ime_device_info_h dev_info, Ecore_IMF_Device_Class *dev_class)
1966 {
1967     ime_error_e retVal = IME_ERROR_NONE;
1968
1969     if (!dev_info || !dev_class) {
1970         LOGW("IME_ERROR_INVALID_PARAMETER");
1971         return IME_ERROR_INVALID_PARAMETER;
1972     }
1973
1974     retVal = _check_privilege();
1975     if (retVal != IME_ERROR_NONE) return retVal;
1976
1977     if (!g_running) {
1978         LOGW("IME_ERROR_NOT_RUNNING");
1979         return IME_ERROR_NOT_RUNNING;
1980     }
1981
1982     //LCOV_EXCL_START
1983     *dev_class = dev_info->dev_class;
1984
1985     return IME_ERROR_NONE;
1986     //LCOV_EXCL_STOP
1987 }
1988
1989 EXPORT_API int ime_device_info_get_subclass(ime_device_info_h dev_info, Ecore_IMF_Device_Subclass *dev_subclass)
1990 {
1991     ime_error_e retVal = IME_ERROR_NONE;
1992
1993     if (!dev_info || !dev_subclass) {
1994         LOGW("IME_ERROR_INVALID_PARAMETER");
1995         return IME_ERROR_INVALID_PARAMETER;
1996     }
1997
1998     retVal = _check_privilege();
1999     if (retVal != IME_ERROR_NONE) return retVal;
2000
2001     if (!g_running) {
2002         LOGW("IME_ERROR_NOT_RUNNING");
2003         return IME_ERROR_NOT_RUNNING;
2004     }
2005
2006     //LCOV_EXCL_START
2007     *dev_subclass = dev_info->dev_subclass;
2008
2009     return IME_ERROR_NONE;
2010     //LCOV_EXCL_STOP
2011 }
2012
2013 //LCOV_EXCL_START
2014 EXPORT_API int ime_event_set_process_input_device_event_cb(ime_process_input_device_event_cb callback_func, void *user_data)
2015 {
2016     ime_error_e retVal = IME_ERROR_NONE;
2017
2018     if (!callback_func) {
2019         LOGW("IME_ERROR_INVALID_PARAMETER");
2020         return IME_ERROR_INVALID_PARAMETER;
2021     }
2022
2023     retVal = _check_privilege();
2024     if (retVal != IME_ERROR_NONE) return retVal;
2025
2026     g_event_callback.process_input_device_event = callback_func;
2027     g_event_callback.process_input_device_event_user_data = user_data;
2028
2029     return IME_ERROR_NONE;
2030 }
2031
2032 EXPORT_API int ime_event_unset_process_input_device_event_cb(void)
2033 {
2034     ime_error_e retVal = IME_ERROR_NONE;
2035
2036     retVal = _check_privilege();
2037     if (retVal != IME_ERROR_NONE) return retVal;
2038
2039     g_event_callback.process_input_device_event = NULL;
2040     g_event_callback.process_input_device_event_user_data = NULL;
2041
2042     return IME_ERROR_NONE;
2043 }
2044
2045 /* Functions for Rotary input device event */
2046 EXPORT_API int ime_input_device_rotary_get_direction(ime_input_device_event_h event_handle, ime_input_device_rotary_direction_e *direction)
2047 {
2048     ime_error_e retVal = IME_ERROR_NONE;
2049
2050     if (!event_handle || !direction) {
2051         LOGW("IME_ERROR_INVALID_PARAMETER");
2052         return IME_ERROR_INVALID_PARAMETER;
2053     }
2054
2055     ime_device_event_s *device_event = static_cast<ime_device_event_s*>(event_handle);
2056     if (device_event->device_type != IME_INPUT_DEVICE_TYPE_ROTARY) {
2057         LOGW("IME_ERROR_INVALID_PARAMETER");
2058         return IME_ERROR_INVALID_PARAMETER;
2059     }
2060
2061     retVal = _check_privilege();
2062     if (retVal != IME_ERROR_NONE) return retVal;
2063
2064     if (!g_running) {
2065         LOGW("IME_ERROR_OPERATION_FAILED");
2066         return IME_ERROR_OPERATION_FAILED;
2067     }
2068
2069     //LCOV_EXCL_START
2070     Ecore_Event_Detent_Rotate *rotary_device_event =
2071         static_cast<Ecore_Event_Detent_Rotate*>(device_event->event_data);
2072     if (rotary_device_event) {
2073         if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_CLOCKWISE) {
2074             *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_CLOCKWISE;
2075         } else if (rotary_device_event->direction == ECORE_DETENT_DIRECTION_COUNTER_CLOCKWISE) {
2076             *direction = IME_INPUT_DEVICE_ROTARY_DIRECTION_COUNTER_CLOCKWISE;
2077         }
2078     }
2079
2080     return IME_ERROR_NONE;
2081     //LCOV_EXCL_STOP
2082 }
2083 //LCOV_EXCL_STOP
2084
2085 EXPORT_API int ime_event_set_prediction_hint_set_cb(ime_prediction_hint_set_cb callback_func, void *user_data)
2086 {
2087     ime_error_e retVal = IME_ERROR_NONE;
2088
2089     if (!callback_func) {
2090         LOGW("IME_ERROR_INVALID_PARAMETER");
2091         return IME_ERROR_INVALID_PARAMETER;
2092     }
2093
2094     retVal = _check_privilege();
2095     if (retVal != IME_ERROR_NONE) return retVal;
2096
2097     g_event_callback.prediction_hint_set = callback_func;
2098     g_event_callback.prediction_hint_set_user_data = user_data;
2099
2100     return IME_ERROR_NONE;
2101 }
2102
2103 EXPORT_API int ime_event_set_mime_type_set_request_cb(ime_mime_type_set_request_cb callback_func, void *user_data)
2104 {
2105     ime_error_e retVal = IME_ERROR_NONE;
2106
2107     if (!callback_func) {
2108         LOGW("IME_ERROR_INVALID_PARAMETER");
2109         return IME_ERROR_INVALID_PARAMETER;
2110     }
2111
2112     retVal = _check_privilege();
2113     if (retVal != IME_ERROR_NONE) return retVal;
2114
2115     g_event_callback.mime_type_set = callback_func;
2116     g_event_callback.mime_type_set_user_data = user_data;
2117
2118     return IME_ERROR_NONE;
2119 }
2120
2121 EXPORT_API int ime_set_floating_mode(bool floating_mode)
2122 {
2123     ime_error_e retVal = IME_ERROR_NONE;
2124
2125     retVal = _check_privilege();
2126     if (retVal != IME_ERROR_NONE) return retVal;
2127
2128     if (!g_running) {
2129         LOGW("IME_ERROR_NOT_RUNNING");
2130         return IME_ERROR_NOT_RUNNING;
2131     }
2132
2133     //LCOV_EXCL_START
2134     g_core.set_floating_mode(floating_mode);
2135
2136     return IME_ERROR_NONE;
2137     //LCOV_EXCL_STOP
2138 }
2139
2140 EXPORT_API int ime_set_floating_drag_start(void)
2141 {
2142     ime_error_e retVal = IME_ERROR_NONE;
2143
2144     retVal = _check_privilege();
2145     if (retVal != IME_ERROR_NONE) return retVal;
2146
2147     if (!g_running) {
2148         LOGW("IME_ERROR_NOT_RUNNING");
2149         return IME_ERROR_NOT_RUNNING;
2150     }
2151
2152     //LCOV_EXCL_START
2153     g_core.set_floating_drag_enabled(true);
2154
2155     return IME_ERROR_NONE;
2156     //LCOV_EXCL_STOP
2157 }
2158
2159 EXPORT_API int ime_set_floating_drag_end(void)
2160 {
2161     ime_error_e retVal = IME_ERROR_NONE;
2162
2163     retVal = _check_privilege();
2164     if (retVal != IME_ERROR_NONE) return retVal;
2165
2166     if (!g_running) {
2167         LOGW("IME_ERROR_NOT_RUNNING");
2168         return IME_ERROR_NOT_RUNNING;
2169     }
2170
2171     //LCOV_EXCL_START
2172     g_core.set_floating_drag_enabled(false);
2173
2174     return IME_ERROR_NONE;
2175     //LCOV_EXCL_STOP
2176 }
2177
2178 //LCOV_EXCL_START
2179 EXPORT_API int ime_set_window_creation_defer_flag(bool flag)
2180 {
2181     ime_error_e retVal = IME_ERROR_NONE;
2182
2183     retVal = _check_privilege();
2184     if (retVal != IME_ERROR_NONE) return retVal;
2185
2186     g_core.set_window_creation_defer_flag(flag);
2187
2188     return IME_ERROR_NONE;
2189 }
2190 //LCOV_EXCL_STOP
2191
2192 EXPORT_API int ime_event_set_prediction_hint_data_set_cb(ime_prediction_hint_data_set_cb callback_func, void *user_data)
2193 {
2194     ime_error_e retVal = IME_ERROR_NONE;
2195
2196     if (!callback_func) {
2197         LOGW("IME_ERROR_INVALID_PARAMETER");
2198         return IME_ERROR_INVALID_PARAMETER;
2199     }
2200
2201     retVal = _check_privilege();
2202     if (retVal != IME_ERROR_NONE) return retVal;
2203
2204     g_event_callback.prediction_hint_data_set = callback_func;
2205     g_event_callback.prediction_hint_data_set_user_data = user_data;
2206
2207     return IME_ERROR_NONE;
2208 }
2209
2210 //LCOV_EXCL_START
2211 EXPORT_API int ime_event_set_optimization_hint_set_cb(ime_optimization_hint_set_cb callback_func, void *user_data)
2212 {
2213     LOGD("");
2214     ime_error_e retVal = IME_ERROR_NONE;
2215
2216     if (!callback_func) {
2217         LOGW("IME_ERROR_INVALID_PARAMETER");
2218         return IME_ERROR_INVALID_PARAMETER;
2219     }
2220
2221     LOGD("");
2222     retVal = _check_privilege();
2223     if (retVal != IME_ERROR_NONE) return retVal;
2224
2225     LOGD("");
2226     g_event_callback.optimization_hint_set = callback_func;
2227     g_event_callback.optimization_hint_set_user_data = user_data;
2228
2229     return IME_ERROR_NONE;
2230 }
2231 //LCOV_EXCL_STOP
2232
2233 EXPORT_API int ime_update_input_panel_event(ime_event_type_e type, unsigned int value)
2234 {
2235     ime_error_e retVal = IME_ERROR_NONE;
2236
2237     if (type < IME_EVENT_TYPE_LANGUAGE || type > IME_EVENT_TYPE_GEOMETRY) {
2238         LOGW("IME_ERROR_INVALID_PARAMETER");
2239         return IME_ERROR_INVALID_PARAMETER;
2240     }
2241
2242     if (!g_running) {
2243         LOGW("IME_ERROR_NOT_RUNNING");
2244         return IME_ERROR_NOT_RUNNING;
2245     }
2246
2247     //LCOV_EXCL_START
2248     retVal = _check_privilege();
2249     if (retVal != IME_ERROR_NONE) return retVal;
2250
2251     g_core.update_input_context((sclu32)type, value);
2252
2253     return IME_ERROR_NONE;
2254     //LCOV_EXCL_STOP
2255 }
2256
2257 EXPORT_API int ime_set_candidate_visibility_state(bool visible)
2258 {
2259     ime_error_e retVal = IME_ERROR_NONE;
2260
2261     if (!g_running) {
2262         LOGW("IME_ERROR_NOT_RUNNING");
2263         return IME_ERROR_NOT_RUNNING;
2264     }
2265
2266     //LCOV_EXCL_START
2267     retVal = _check_privilege();
2268     if (retVal != IME_ERROR_NONE) return retVal;
2269
2270     if (visible)
2271         g_core.show_candidate_string();
2272     else
2273         g_core.hide_candidate_string();
2274
2275     return IME_ERROR_NONE;
2276     //LCOV_EXCL_STOP
2277 }