e533359fff8fede31b3b792e4da292b3e8cf2c25
[platform/core/uifw/libscl-core.git] / src / sclconnection-isf.cpp
1 /*
2  * Copyright (c) 2014 - 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
18 #include "sclconnection-isf.h"
19 #include "sclcoreimpl.h"
20 #include <Elementary.h>
21 #include <dlog.h>
22
23 #ifdef WEBSOCKET
24 #include "legacy_support/websocket.h"
25 extern CWebHelperAgentWebSocket g_websocket;
26 #endif
27
28 using namespace scl;
29
30 static scim::ConfigPointer _scim_config(0);
31
32 /* Slot functions for calling appropriate callback functions */
33 static void slot_exit(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
34     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
35     if (impl) {
36         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
37         if (callback) {
38             callback->on_ise_hide(ic, ic_uuid.c_str());
39             LOGD("call on_exit");
40             callback->on_exit();
41         }
42         if (agent) {
43             agent->update_ise_exit();
44         }
45     }
46     LOGD("exit");
47     elm_exit();
48 }
49
50 static void slot_attach_input_context(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
51     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
52     if (impl) {
53         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
54         if (callback) {
55             callback->on_attach_input_context(ic, ic_uuid.c_str());
56         }
57     }
58 }
59
60 static void slot_detach_input_context(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
61     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
62     if (impl) {
63         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
64         if (callback) {
65             callback->on_detach_input_context(ic, ic_uuid.c_str());
66         }
67     }
68 }
69
70 static void slot_reload_config(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
71     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
72     if (impl) {
73         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
74         if (callback) {
75             callback->on_reload_config(ic, ic_uuid.c_str());
76         }
77     }
78 }
79
80 static void slot_update_screen(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int screen_number) {
81     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
82     if (impl) {
83         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
84         if (callback) {
85             //callback->on_update_screen(ic, ic_uuid.c_str(), screen_number);
86         }
87     }
88 }
89
90 static void slot_update_spot_location(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int x, int y) {
91     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
92     if (impl) {
93         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
94         if (callback) {
95             callback->on_update_spot_location(ic, ic_uuid.c_str(), x, y);
96         }
97     }
98 }
99
100 static void slot_update_cursor_position(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int cursor_pos) {
101     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
102     if (impl) {
103         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
104         if (callback) {
105             callback->on_update_cursor_position(ic, ic_uuid.c_str(), cursor_pos);
106 #ifdef WEBSOCKET
107             g_websocket.on_update_cursor_position(ic, cursor_pos);
108 #endif
109         }
110     }
111 }
112
113 static void slot_update_surrounding_text(const scim::HelperAgent *agent, int ic, const scim::String &text, int cursor) {
114     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
115     if (impl) {
116         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
117         if (callback) {
118             callback->on_update_surrounding_text(ic, text.c_str(), cursor);
119 #ifdef WEBSOCKET
120             g_websocket.on_update_surrounding_text(ic, text.c_str(), cursor);
121 #endif
122         }
123     }
124 }
125
126 static void slot_trigger_property(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, const scim::String &property) {
127     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
128     if (impl) {
129         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
130         if (callback) {
131             callback->on_trigger_property(property.c_str());
132         }
133     }
134 }
135
136 static void slot_focus_out(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
137     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
138     if (impl) {
139         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
140         if (callback) {
141             callback->on_focus_out(ic, ic_uuid.c_str());
142 #ifdef WEBSOCKET
143             g_websocket.on_focus_out(ic);
144 #endif
145         }
146     }
147 }
148
149 static void slot_focus_in(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
150     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
151     if (impl) {
152         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
153         if (callback) {
154             callback->on_focus_in(ic, ic_uuid.c_str());
155 #ifdef WEBSOCKET
156             g_websocket.on_focus_in(ic);
157 #endif
158         }
159     }
160 }
161
162 static void slot_ise_show(const scim::HelperAgent *agent, int ic, char *buf, size_t &len) {
163     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
164     if (impl) {
165         /* Make sure the appropriate keyboard ise was selected -> is this really necessary? */
166         //impl->set_keyboard_ise_by_uuid(impl->get_keyboard_ise_uuid().c_str());
167
168         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
169         if (callback) {
170             /* Check if effect is enabled */
171             Ise_Context ise_context;
172             memset(&ise_context, 0x00, sizeof(ise_context));
173
174             if (len >= sizeof(Ise_Context)) {
175                 memcpy(&ise_context, buf, sizeof(ise_context));
176
177                 if (ise_context.imdata_size > 0) {
178                     char imdata[1024] = {0};
179                     memcpy((void *)imdata, buf + sizeof(ise_context), ise_context.imdata_size);
180                     callback->on_set_imdata(imdata, ise_context.imdata_size);
181                 }
182
183                 if (len > (sizeof(Ise_Context) + ise_context.imdata_size))
184                     callback->on_set_mime_type(buf + sizeof(ise_context) + ise_context.imdata_size);
185             } else {
186                 LOGD("\n-=-= WARNING - buf %p len %zu size %zu\n", buf, len, sizeof(ise_context));
187             }
188             CSCLCoreUI* ui = impl->get_core_ui();
189             if (ui) {
190                 ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_WILL_SHOW);
191             }
192             callback->on_ise_show(ic, impl->get_screen_rotation_degree(), ise_context);
193             if (ui) {
194                 SclSize portrait;
195                 SclSize landscape;
196                 ui->get_keyboard_size(&portrait, &landscape);
197                 /* If the ime_set_size() API is not called and IME is shown, the app can not receive the keyboard window's geometry from ISF.
198                 And the ime_set_size() API is not called unless the IME size changes.
199                 */
200                 ui->update_keyboard_geometry(portrait, landscape);
201                 ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_DID_SHOW);
202             } else
203                 LOGW("Failed to get core UI");
204
205 #ifdef WEBSOCKET
206             g_websocket.on_set_layout(ise_context.layout);
207             g_websocket.on_update_cursor_position(ic, ise_context.cursor_pos);
208             g_websocket.on_show(ic);
209 #endif
210         }
211     }
212 }
213
214 static void slot_ise_hide(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
215     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
216     if (impl) {
217         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
218         if (callback) {
219             CSCLCoreUI* ui = impl->get_core_ui();
220             if (ui) {
221                 ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_WILL_HIDE);
222             }
223             callback->on_ise_hide(ic, ic_uuid.c_str());
224             if (ui) {
225                 ui->process_keyboard_ui_state_change(KEYBOARD_UI_STATE_DID_HIDE);
226             }
227
228 #ifdef WEBSOCKET
229             g_websocket.on_hide(ic);
230 #endif
231         }
232     }
233 }
234
235 static void slot_get_geometry(const scim::HelperAgent *agent, struct scim::rectinfo &info) {
236     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
237     if (impl) {
238         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
239         if (callback) {
240             callback->on_get_geometry(&(info.pos_x), &(info.pos_y), &(info.width), &(info.height));
241         }
242     }
243 }
244
245 static void slot_set_mode(const scim::HelperAgent *agent, scim::uint32 &mode) {
246     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
247     if (impl) {
248         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
249         if (callback) {
250             callback->on_set_mode(mode);
251         }
252     }
253 }
254
255 static void slot_set_language(const scim::HelperAgent *agent, scim::uint32 &language) {
256     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
257     if (impl) {
258         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
259         if (callback) {
260             callback->on_set_language(language);
261 #ifdef WEBSOCKET
262             g_websocket.on_set_language(language);
263 #endif
264         }
265     }
266 }
267
268 static void slot_set_imdata(const scim::HelperAgent *agent, char *buf, size_t &len) {
269     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
270     if (impl) {
271         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
272         if (callback) {
273             scl32 _len = static_cast<scl32>(reinterpret_cast<size_t>(len) & 0xffffffff);
274             callback->on_set_imdata(buf, _len);
275 #ifdef WEBSOCKET
276             g_websocket.on_set_imdata(buf, len);
277 #endif
278         }
279     }
280 }
281
282 static void slot_get_imdata(const scim::HelperAgent *, char **buf, size_t &len) {
283     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
284     if (impl) {
285         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
286         if (callback) {
287             sclu32 _len = 0;
288             callback->on_get_imdata(buf, &_len);
289 #ifdef WEBSOCKET
290             g_websocket.on_get_imdata(buf, &_len);
291 #endif
292             len = _len;
293         }
294     }
295 }
296
297 static void slot_get_language_locale(const scim::HelperAgent *, int ic, char **locale) {
298     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
299     if (impl) {
300         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
301         if (callback) {
302             callback->on_get_language_locale(ic, locale);
303         }
304     }
305 }
306
307 static void slot_set_return_key_type(const scim::HelperAgent *agent, scim::uint32 &type) {
308     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
309     if (impl) {
310         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
311         if (callback) {
312             callback->on_set_return_key_type(type);
313 #ifdef WEBSOCKET
314             g_websocket.on_set_return_key_type(type);
315 #endif
316         }
317     }
318 }
319
320 static void slot_get_return_key_type(const scim::HelperAgent *agent, scim::uint32 &type) {
321     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
322     if (impl) {
323         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
324         if (callback) {
325             callback->on_get_return_key_type(&type);
326 #ifdef WEBSOCKET
327             g_websocket.on_get_return_key_type(&type);
328 #endif
329         }
330     }
331 }
332
333 static void slot_set_return_key_disable(const scim::HelperAgent *agent, scim::uint32 &disabled) {
334     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
335     if (impl) {
336         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
337         if (callback) {
338             callback->on_set_return_key_disable(disabled);
339 #ifdef WEBSOCKET
340             g_websocket.on_set_return_key_disable(disabled);
341 #endif
342         }
343     }
344 }
345
346 static void slot_get_return_key_disable(const scim::HelperAgent *agent, scim::uint32 &disabled) {
347     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
348     if (impl) {
349         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
350         if (callback) {
351             callback->on_get_return_key_disable(&disabled);
352 #ifdef WEBSOCKET
353             g_websocket.on_get_return_key_disable(&disabled);
354 #endif
355         }
356     }
357 }
358
359 static void slot_set_layout(const scim::HelperAgent *agent, scim::uint32 &layout) {
360     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
361     if (impl) {
362         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
363         if (callback) {
364             callback->on_set_layout(layout);
365 #ifdef WEBSOCKET
366             g_websocket.on_set_layout(layout);
367 #endif
368         }
369     }
370 }
371
372 static void slot_get_layout(const scim::HelperAgent *agent, scim::uint32 &layout) {
373     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
374     if (impl) {
375         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
376         if (callback) {
377             callback->on_get_layout(&layout);
378 #ifdef WEBSOCKET
379             g_websocket.on_get_layout(&layout);
380 #endif
381         }
382     }
383 }
384
385 static void slot_set_caps_mode(const scim::HelperAgent *agent, scim::uint32 &mode) {
386     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
387     if (impl) {
388         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
389         if (callback) {
390             callback->on_set_caps_mode(mode);
391         }
392     }
393 }
394
395 static void slot_reset_input_context(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
396     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
397     if (impl) {
398         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
399         if (callback) {
400             callback->on_reset_input_context(ic, uuid.c_str());
401 #ifdef WEBSOCKET
402             g_websocket.on_reset_input_context(ic);
403 #endif
404         }
405     }
406 }
407
408 static void slot_update_candidate_geometry(const scim::HelperAgent *agent, int ic, const scim::String &uuid, const scim::rectinfo &info) {
409     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
410     if (impl) {
411         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
412         if (callback) {
413             callback->on_update_candidate_geometry(ic, uuid.c_str(), info.pos_x, info.pos_y, info.width, info.height);
414         }
415     }
416 }
417 static void slot_update_keyboard_ise(const scim::HelperAgent *agent, int ic, const scim::String &uuid,
418                                                   const scim::String &ise_name, const scim::String &ise_uuid) {
419     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
420     if (impl) {
421         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
422         if (callback) {
423             callback->on_update_keyboard_ise(ic, uuid.c_str(), ise_name.c_str(), ise_uuid.c_str());
424         }
425     }
426 }
427
428 static void slot_candidate_more_window_show(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
429     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
430     if (impl) {
431         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
432         if (callback) {
433             callback->on_candidate_more_window_show(ic, uuid.c_str());
434         }
435     }
436 }
437
438 static void slot_candidate_more_window_hide(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
439     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
440     if (impl) {
441         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
442         if (callback) {
443             callback->on_candidate_more_window_hide(ic, uuid.c_str());
444         }
445     }
446 }
447
448 static void slot_select_aux(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
449     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
450     if (impl) {
451         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
452         if (callback) {
453             callback->on_select_aux(ic, uuid.c_str(), index);
454         }
455     }
456 }
457
458 static void slot_select_candidate(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
459     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
460     if (impl) {
461         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
462         if (callback) {
463             callback->on_select_candidate(ic, uuid.c_str(), index);
464         }
465     }
466 }
467
468 static void slot_candidate_table_page_up(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
469     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
470     if (impl) {
471         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
472         if (callback) {
473             callback->on_candidate_table_page_up(ic, uuid.c_str());
474         }
475     }
476 }
477
478 static void slot_candidate_table_page_down(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
479     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
480     if (impl) {
481         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
482         if (callback) {
483             callback->on_candidate_table_page_down(ic, uuid.c_str());
484         }
485     }
486 }
487
488 static void slot_update_candidate_table_page_size(const scim::HelperAgent *, int ic, const scim::String &uuid, int page_size) {
489     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
490     if (impl) {
491         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
492         if (callback) {
493             callback->on_update_candidate_table_page_size(ic, uuid.c_str(), page_size);
494         }
495     }
496 }
497
498 static void slot_update_candidate_item_layout(const scim::HelperAgent *agent, const std::vector<scim::uint32> &item) {
499     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
500     if (impl) {
501         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
502         if (callback) {
503             callback->on_update_candidate_item_layout(item);
504         }
505     }
506 }
507
508 static void slot_update_displayed_candidate_number(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int size) {
509     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
510     if (impl) {
511         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
512         if (callback) {
513             callback->on_update_displayed_candidate_number((sclu32)size);
514         }
515     }
516 }
517
518 static void slot_longpress_candidate(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int index) {
519     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
520     if (impl) {
521         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
522         if (callback) {
523             callback->on_longpress_candidate((sclu32)index);
524         }
525     }
526 }
527
528 static void slot_update_lookup_table(const scim::HelperAgent *, scim::LookupTable &table) {
529     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
530     if (impl) {
531         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
532         if (callback) {
533             SclCandidateTable lookup_table;
534             lookup_table.page_size = table.get_page_size();
535             lookup_table.current_page_start = table.get_current_page_start();
536             lookup_table.cursor_pos = table.get_cursor_pos();
537             lookup_table.cursor_visible = table.is_cursor_visible();
538             lookup_table.page_size_fixed = table.is_page_size_fixed();
539             lookup_table.candidate_labels.clear();
540             for (int page_index = 0;page_index < lookup_table.page_size;page_index++) {
541                 scim::WideString label = table.get_candidate_label(page_index);
542                 lookup_table.candidate_labels.push_back(scim::utf8_wcstombs(label).c_str());
543             }
544
545             int nCandidateSize = table.get_current_page_size();
546             for (int index = 0; index < nCandidateSize; ++index) {
547                 scim::WideString candidate_str = table.get_candidate_in_current_page(index);
548                 lookup_table.candidate.push_back(scim::utf8_wcstombs(candidate_str).c_str());
549             }
550
551             callback->on_update_lookup_table(lookup_table);
552
553             std::vector<scim::WideString> labels;
554             for (unsigned int loop = 0;loop < lookup_table.candidate_labels.size();loop++) {
555                 labels.push_back(scim::utf8_mbstowcs(lookup_table.candidate_labels.at(loop).c_str()));
556             }
557             table.set_candidate_labels(labels);
558         }
559     }
560 }
561
562 static void slot_select_associate(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
563     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
564     if (impl) {
565         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
566         if (callback) {
567             callback->on_select_associate(ic, uuid.c_str(), index);
568         }
569     }
570 }
571
572 static void slot_associate_table_page_up(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
573     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
574     if (impl) {
575         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
576         if (callback) {
577             callback->on_associate_table_page_up(ic, uuid.c_str());
578         }
579     }
580 }
581
582 static void slot_associate_table_page_down(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
583     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
584     if (impl) {
585         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
586         if (callback) {
587             callback->on_associate_table_page_down(ic, uuid.c_str());
588         }
589     }
590 }
591
592 static void slot_update_associate_table_page_size(const scim::HelperAgent *, int ic, const scim::String &uuid, int page_size) {
593     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
594     if (impl) {
595         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
596         if (callback) {
597             callback->on_update_associate_table_page_size(ic, uuid.c_str(), page_size);
598         }
599     }
600 }
601
602 static void slot_show_ise_option_window(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
603     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
604     if (impl) {
605         CSCLCoreUI *core_ui = impl->get_core_ui();
606         if (core_ui) {
607             LOGD("slot_show_ise_option_window() called!!!\n");
608             core_ui->create_option_window(OPTION_WINDOW_TYPE_SETTING_APPLICATION);
609         }
610     }
611 }
612
613 static void slot_resume_ise_option_window(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
614     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
615     if (impl) {
616         CSCLCoreUI *core_ui = impl->get_core_ui();
617         if (core_ui) {
618             LOGD("slot_resume_ise_option_window() called!!!\n");
619             core_ui->show_option_window(OPTION_WINDOW_TYPE_SETTING_APPLICATION);
620         }
621     }
622 }
623
624 static void slot_check_ise_option_window(const scim::HelperAgent *agent, sclu32 &avail) {
625     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
626     if (impl) {
627         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
628         if (callback) {
629             callback->on_check_option_window_availability(reinterpret_cast<sclboolean *>(&avail));
630         }
631     }
632 }
633
634 static void slot_process_key_event(const scim::HelperAgent *agent, scim::KeyEvent &key, scim::uint32 &ret) {
635     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
636     if (impl) {
637         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
638         if (callback) {
639             callback->on_process_key_event(key, &ret);
640 #ifdef WEBSOCKETweb_ret
641             g_websocket.on_process_key_event(key.code, key.mask, key.layout, &ret);
642 #endif
643         }
644     }
645 }
646
647 static void slot_process_key_event_with_keycode(const scim::HelperAgent *agent, scim::KeyEvent &key, scim::uint32 &ret, scim::uint32 keycode) {
648     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
649     if (impl) {
650         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
651         if (callback) {
652             callback->on_process_key_event_with_keycode(key, &ret, keycode);
653         }
654     }
655 }
656
657 static void slot_candidate_show(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
658     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
659     if (impl) {
660         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
661         if (callback) {
662             callback->on_candidate_show(ic, ic_uuid.c_str());
663         }
664     }
665 }
666
667 static void slot_candidate_hide(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
668     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
669     if (impl) {
670         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
671         if (callback) {
672             callback->on_candidate_hide(ic, ic_uuid.c_str());
673         }
674     }
675 }
676
677 static void slot_process_input_device_event(const scim::HelperAgent *agent, scim::uint32 &type, char *data, size_t &len, scim::uint32 &ret) {
678     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
679     if (impl) {
680         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
681         if (callback) {
682             /* Input Device Event callback is available in versions after 1.1 */
683             if (check_interface_version(callback, 1, 1)) {
684                 callback->on_process_input_device_event(type, data, len, &ret);
685             }
686         }
687     }
688 }
689
690 static void slot_set_prediction_hint(const scim::HelperAgent *agent, const scim::String &prediction_hint) {
691     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
692     if (impl) {
693         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
694         if (callback) {
695             callback->on_set_prediction_hint(prediction_hint.c_str());
696         }
697     }
698 }
699
700 static void slot_set_mime_type(const scim::HelperAgent *agent, const scim::String &mime_type) {
701     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
702     if (impl) {
703         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
704         if (callback) {
705             callback->on_set_mime_type(mime_type.c_str());
706         }
707     }
708 }
709
710 static void slot_set_prediction_hint_data(const scim::HelperAgent *agent, int ic, const scim::String &key, const scim::String &value) {
711     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
712     if (impl) {
713         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
714         if (callback) {
715             SECURE_LOGD("key : %s, value : %s\n", key.c_str(), value.c_str());
716             callback->on_set_prediction_hint_data(key.c_str(), value.c_str());
717         }
718     }
719 }
720
721 static void slot_set_optimization_hint(const scim::HelperAgent *agent, scim::uint32 &hint) {
722     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
723     if (impl) {
724         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
725         if (callback) {
726             SECURE_LOGD("hint : %d\n", hint);
727             callback->on_set_optimization_hint(hint);
728         }
729     }
730 }
731
732 static void slot_process_key_event_with_imengine(const scim::HelperAgent *agent, scim::KeyEvent &key, scim::uint32 &ret) {
733     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
734     if (impl) {
735         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
736         if (callback) {
737             callback->on_process_key_event_with_imengine(key, &ret);
738         }
739     }
740 }
741
742 static void slot_set_autocapital_type(const scim::HelperAgent *agent, scim::uint32 &type) {
743     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
744     if (impl) {
745         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
746         if (callback) {
747             callback->on_set_autocapital_type(type);
748         }
749     }
750 }
751
752 static void slot_set_prediction_allow(const scim::HelperAgent *agent, scim::uint32 &prediction_allow) {
753     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
754     if (impl) {
755         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
756         if (callback) {
757             callback->on_set_prediction_allow(prediction_allow);
758         }
759     }
760 }
761
762 /* Internal input handler function */
763 Eina_Bool input_handler(void *data, Ecore_Fd_Handler *fd_handler)
764 {
765     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
766     if (impl) {
767         scim::HelperAgent *agent = static_cast<scim::HelperAgent*>(data);
768         if (agent) {
769             if (agent->has_pending_event()) {
770                 if (!(agent->filter_event())) {
771                     LOGD("helper_agent.filter_event() failed!!!\n");
772                     impl->fini();
773                     elm_exit();
774                 }
775             } else {
776                 LOGD("helper_agent.has_pending_event() failed!!!\n");
777                 impl->fini();
778                 elm_exit();
779             }
780         }
781     }
782
783     return ECORE_CALLBACK_RENEW;
784 }
785
786 CSCLConnectionISF::CSCLConnectionISF()
787 {
788     m_initialized = FALSE;
789     m_fd_handler = NULL;
790
791     m_backend_identifier = "ISF";
792 }
793
794 CSCLConnectionISF::~CSCLConnectionISF()
795 {
796 }
797
798 sclboolean CSCLConnectionISF::init()
799 {
800     LOGD("Enter\n");
801
802     if (!m_initialized) {
803         m_helper_agent.signal_connect_exit(scim::slot(slot_exit));
804         m_helper_agent.signal_connect_attach_input_context(scim::slot(slot_attach_input_context));
805         m_helper_agent.signal_connect_detach_input_context(scim::slot(slot_detach_input_context));
806         m_helper_agent.signal_connect_reload_config(scim::slot(slot_reload_config));
807         m_helper_agent.signal_connect_update_screen(scim::slot(slot_update_screen));
808         m_helper_agent.signal_connect_update_spot_location(scim::slot(slot_update_spot_location));
809         m_helper_agent.signal_connect_update_cursor_position(scim::slot(slot_update_cursor_position));
810         m_helper_agent.signal_connect_update_surrounding_text(scim::slot(slot_update_surrounding_text));
811         m_helper_agent.signal_connect_trigger_property(scim::slot(slot_trigger_property));
812         //m_helper_agent.signal_connect_process_imengine_event (slot (slot_process_imengine_event));
813         m_helper_agent.signal_connect_focus_out(scim::slot(slot_focus_out));
814         m_helper_agent.signal_connect_focus_in(scim::slot(slot_focus_in));
815         m_helper_agent.signal_connect_ise_show(scim::slot(slot_ise_show));
816         m_helper_agent.signal_connect_ise_hide(scim::slot(slot_ise_hide));
817         m_helper_agent.signal_connect_get_geometry(scim::slot(slot_get_geometry));
818         m_helper_agent.signal_connect_set_mode(scim::slot(slot_set_mode));
819         m_helper_agent.signal_connect_set_language(scim::slot(slot_set_language));
820         m_helper_agent.signal_connect_set_imdata(scim::slot(slot_set_imdata));
821         m_helper_agent.signal_connect_get_imdata(scim::slot(slot_get_imdata));
822         m_helper_agent.signal_connect_get_language_locale(scim::slot(slot_get_language_locale));
823         m_helper_agent.signal_connect_set_return_key_type(scim::slot(slot_set_return_key_type));
824         m_helper_agent.signal_connect_get_return_key_type(scim::slot(slot_get_return_key_type));
825         m_helper_agent.signal_connect_set_return_key_disable(scim::slot(slot_set_return_key_disable));
826         m_helper_agent.signal_connect_get_return_key_disable(scim::slot(slot_get_return_key_disable));
827         m_helper_agent.signal_connect_get_layout(scim::slot(slot_get_layout));
828         m_helper_agent.signal_connect_set_layout(scim::slot(slot_set_layout));
829         m_helper_agent.signal_connect_set_caps_mode(scim::slot(slot_set_caps_mode));
830         m_helper_agent.signal_connect_reset_input_context(scim::slot(slot_reset_input_context));
831         m_helper_agent.signal_connect_update_candidate_geometry(scim::slot(slot_update_candidate_geometry));
832         m_helper_agent.signal_connect_update_keyboard_ise(scim::slot(slot_update_keyboard_ise));
833         //m_helper_agent.signal_connect_update_keyboard_ise_list (slot (slot_update_keyboard_ise_list));
834         m_helper_agent.signal_connect_candidate_more_window_show(scim::slot(slot_candidate_more_window_show));
835         m_helper_agent.signal_connect_candidate_more_window_hide(scim::slot(slot_candidate_more_window_hide));
836         m_helper_agent.signal_connect_select_aux(scim::slot(slot_select_aux));
837         m_helper_agent.signal_connect_select_candidate(scim::slot(slot_select_candidate));
838         m_helper_agent.signal_connect_candidate_table_page_up(scim::slot(slot_candidate_table_page_up));
839         m_helper_agent.signal_connect_candidate_table_page_down(scim::slot(slot_candidate_table_page_down));
840         m_helper_agent.signal_connect_update_candidate_table_page_size(scim::slot(slot_update_candidate_table_page_size));
841         m_helper_agent.signal_connect_update_candidate_item_layout(scim::slot(slot_update_candidate_item_layout));
842         m_helper_agent.signal_connect_update_displayed_candidate_number(scim::slot(slot_update_displayed_candidate_number));
843         m_helper_agent.signal_connect_longpress_candidate(scim::slot(slot_longpress_candidate));
844         m_helper_agent.signal_connect_update_lookup_table(scim::slot(slot_update_lookup_table));
845         m_helper_agent.signal_connect_select_associate(scim::slot(slot_select_associate));
846         m_helper_agent.signal_connect_associate_table_page_up(scim::slot(slot_associate_table_page_up));
847         m_helper_agent.signal_connect_associate_table_page_down(scim::slot(slot_associate_table_page_down));
848         m_helper_agent.signal_connect_update_associate_table_page_size(scim::slot(slot_update_associate_table_page_size));
849         m_helper_agent.signal_connect_show_option_window(scim::slot(slot_show_ise_option_window));
850         m_helper_agent.signal_connect_resume_option_window(scim::slot(slot_resume_ise_option_window));
851         m_helper_agent.signal_connect_check_option_window(scim::slot(slot_check_ise_option_window));
852         m_helper_agent.signal_connect_process_key_event(scim::slot(slot_process_key_event));
853         m_helper_agent.signal_connect_process_key_event_with_keycode(scim::slot(slot_process_key_event_with_keycode));
854         m_helper_agent.signal_connect_candidate_show(scim::slot(slot_candidate_show));
855         m_helper_agent.signal_connect_candidate_hide(scim::slot(slot_candidate_hide));
856         m_helper_agent.signal_connect_process_input_device_event(scim::slot(slot_process_input_device_event));
857         m_helper_agent.signal_connect_set_prediction_hint(scim::slot(slot_set_prediction_hint));
858         m_helper_agent.signal_connect_set_mime_type(scim::slot(slot_set_mime_type));
859         m_helper_agent.signal_connect_set_prediction_hint_data(scim::slot(slot_set_prediction_hint_data));
860         m_helper_agent.signal_connect_set_optimization_hint(scim::slot(slot_set_optimization_hint));
861         m_helper_agent.signal_connect_process_key_event_with_imengine(scim::slot(slot_process_key_event_with_imengine));
862         m_helper_agent.signal_connect_set_autocapital_type(scim::slot(slot_set_autocapital_type));
863         m_helper_agent.signal_connect_set_prediction_allow(scim::slot(slot_set_prediction_allow));
864
865         m_initialized = TRUE;
866     }
867
868     if (_scim_config.null()) {
869         scim::ConfigPointer config_pointer = scim::ConfigBase::get(true, "socket");
870         if (config_pointer.null()) {
871             config_pointer = new scim::DummyConfig();
872         }
873         _scim_config = config_pointer;
874     }
875
876     return TRUE;
877 }
878
879 void CSCLConnectionISF::fini()
880 {
881     if (!_scim_config.null()) {
882         _scim_config.reset();
883     }
884     scim::ConfigBase::set(0);
885     close_connection();
886     m_initialized = FALSE;
887 }
888
889 void CSCLConnectionISF::open_connection(const sclchar *display)
890 {
891     if (m_initialized) {
892         CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
893         if (impl) {
894             sclchar *uuid = impl->get_uuid();
895             if (uuid) {
896                 m_helper_info.uuid = uuid;
897             }
898         }
899
900         m_helper_agent.open_connection(m_helper_info, display);
901         int fd = m_helper_agent.get_connection_number();
902
903         if (fd >= 0) {
904 #ifndef WAYLAND
905             Evas_Object *main_window = NULL;
906             CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
907             if (impl) {
908                 main_window = NATIVE_WINDOW_CAST(impl->get_main_window());
909             }
910
911             Ecore_X_Window xwindow = elm_win_xwindow_get(main_window);
912             char xid[255];
913             snprintf(xid, 255, "%d", xwindow);
914             scim::Property prop(xid, "XID", "", "");
915             scim::PropertyList props;
916             props.push_back(prop);
917             m_helper_agent.register_properties(props);
918 #endif
919
920             m_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, input_handler, &m_helper_agent, NULL, NULL);
921         }
922     }
923 }
924
925 void CSCLConnectionISF::close_connection()
926 {
927     if (m_initialized) {
928         if (m_fd_handler) {
929             ecore_main_fd_handler_del(m_fd_handler);
930             m_fd_handler = NULL;
931         }
932         m_helper_agent.update_ise_exit();
933         m_helper_agent.close_connection();
934     }
935 }
936
937 void CSCLConnectionISF::config_reload()
938 {
939     if (m_initialized) {
940         m_helper_agent.reload_config();
941     }
942 }
943
944 sclboolean CSCLConnectionISF::config_read_int(const sclchar *name, sclint &value)
945 {
946     sclboolean ret = FALSE;
947     if (m_initialized && _scim_config) {
948         value = _scim_config->read(name, value);
949         ret = TRUE;
950     }
951     return ret;
952 }
953
954 sclboolean CSCLConnectionISF::config_read_string(const sclchar *name, std::string &value)
955 {
956     sclboolean ret = FALSE;
957     if (m_initialized && _scim_config) {
958         value = _scim_config->read(name, value);
959         ret = TRUE;
960     }
961     return ret;
962 }
963
964 sclboolean CSCLConnectionISF::config_write_int(const sclchar *name, sclint value)
965 {
966     sclboolean ret = FALSE;
967     if (m_initialized && _scim_config) {
968         _scim_config->write(name, value);
969         ret = TRUE;
970     }
971     return ret;
972 }
973
974 sclboolean CSCLConnectionISF::config_write_string(const sclchar *name, const std::string value)
975 {
976     sclboolean ret = FALSE;
977     if (m_initialized && _scim_config) {
978         _scim_config->write(name, value);
979         ret = TRUE;
980     }
981     return ret;
982 }
983
984 sclboolean CSCLConnectionISF::config_erase(const sclchar *name)
985 {
986     sclboolean ret = FALSE;
987     if (m_initialized && _scim_config) {
988         _scim_config->erase(name);
989         ret = TRUE;
990     }
991     return ret;
992 }
993
994 sclboolean CSCLConnectionISF::config_flush(void)
995 {
996     sclboolean ret = FALSE;
997     if (m_initialized && _scim_config) {
998         _scim_config->flush();
999         ret = TRUE;
1000     }
1001     return ret;
1002 }
1003
1004 void CSCLConnectionISF::send_imengine_event(sclint ic, const sclchar *ic_uuid, const sclint command, const sclu32 value)
1005 {
1006     if (m_initialized) {
1007         scim::String uuid;
1008         if (ic_uuid) {
1009             uuid = scim::String(ic_uuid);
1010         }
1011         scim::Transaction trans;
1012         trans.put_command(command);
1013         trans.put_data(value);
1014         m_helper_agent.send_imengine_event(ic, uuid, trans);
1015     }
1016 }
1017
1018 void CSCLConnectionISF::reset_keyboard_ise()
1019 {
1020     if (m_initialized) {
1021         m_helper_agent.reset_keyboard_ise();
1022     }
1023 }
1024
1025 void CSCLConnectionISF::flush_keyboard_ise()
1026 {
1027     if (m_initialized) {
1028         m_helper_agent.flush_keyboard_ise();
1029     }
1030 }
1031
1032 void CSCLConnectionISF::send_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
1033 {
1034     if (m_initialized) {
1035         scim::String uuid;
1036         if (ic_uuid) {
1037             uuid = scim::String(ic_uuid);
1038         }
1039         scim::KeyEvent event;
1040         event.code = keycode;
1041         event.mask = keymask;
1042         m_helper_agent.send_key_event(ic, uuid, event);
1043     }
1044 }
1045
1046 void CSCLConnectionISF::forward_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
1047 {
1048     if (m_initialized) {
1049         scim::String uuid;
1050         if (ic_uuid) {
1051             uuid = scim::String(ic_uuid);
1052         }
1053         scim::KeyEvent event;
1054         event.code = keycode;
1055         event.mask = keymask;
1056         m_helper_agent.forward_key_event(ic, uuid, event);
1057     }
1058 }
1059
1060 void CSCLConnectionISF::commit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
1061 {
1062     if (m_initialized) {
1063         scim::String uuid;
1064         if (ic_uuid) {
1065             uuid = scim::String(ic_uuid);
1066         }
1067         m_helper_agent.commit_string(ic, uuid, scim::utf8_mbstowcs(str));
1068     }
1069 }
1070
1071 void CSCLConnectionISF::select_candidate(int index)
1072 {
1073     if (m_initialized) {
1074         m_helper_agent.select_candidate(index);
1075     }
1076 }
1077
1078 void CSCLConnectionISF::show_preedit_string(sclint ic, const sclchar *ic_uuid)
1079 {
1080     if (m_initialized) {
1081         scim::String uuid;
1082         if (ic_uuid) {
1083             uuid = scim::String(ic_uuid);
1084         }
1085         m_helper_agent.show_preedit_string(ic, uuid);
1086     }
1087 }
1088
1089 void CSCLConnectionISF::show_aux_string(void)
1090 {
1091     if (m_initialized) {
1092         m_helper_agent.show_aux_string();
1093     }
1094 }
1095
1096 void CSCLConnectionISF::show_candidate_string(void)
1097 {
1098     if (m_initialized) {
1099         m_helper_agent.show_candidate_string();
1100     }
1101 }
1102
1103 void CSCLConnectionISF::show_associate_string(void)
1104 {
1105     if (m_initialized) {
1106         m_helper_agent.show_associate_string();
1107     }
1108 }
1109
1110 void CSCLConnectionISF::hide_preedit_string(sclint ic, const sclchar *ic_uuid)
1111 {
1112     if (m_initialized) {
1113         scim::String uuid;
1114         if (ic_uuid) {
1115             uuid = scim::String(ic_uuid);
1116         }
1117         m_helper_agent.hide_preedit_string(ic, uuid);
1118     }
1119 }
1120
1121 void CSCLConnectionISF::hide_aux_string(void)
1122 {
1123     if (m_initialized) {
1124         m_helper_agent.hide_aux_string();
1125     }
1126 }
1127
1128 void CSCLConnectionISF::hide_candidate_string(void)
1129 {
1130     if (m_initialized) {
1131         m_helper_agent.hide_candidate_string();
1132     }
1133 }
1134
1135 void CSCLConnectionISF::hide_associate_string(void)
1136 {
1137     if (m_initialized) {
1138         m_helper_agent.hide_associate_string();
1139     }
1140 }
1141
1142 void CSCLConnectionISF::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
1143 {
1144     if (m_initialized) {
1145         scim::AttributeList list;
1146         scim::String uuid;
1147         if (ic_uuid) {
1148             uuid = scim::String(ic_uuid);
1149         }
1150         m_helper_agent.update_preedit_string(ic, uuid, scim::utf8_mbstowcs(str), list);
1151
1152         if (str && strlen(str) > 0) {
1153             show_preedit_string(ic, ic_uuid);
1154         } else {
1155             hide_preedit_string(ic, ic_uuid);
1156         }
1157     }
1158 }
1159
1160 void CSCLConnectionISF::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str, const scim::AttributeList &attrs)
1161 {
1162     if (m_initialized) {
1163         scim::String uuid;
1164         if (ic_uuid) {
1165             uuid = scim::String(ic_uuid);
1166         }
1167         m_helper_agent.update_preedit_string(ic, uuid, scim::utf8_mbstowcs(str), attrs);
1168
1169         if (str && strlen(str) > 0) {
1170             show_preedit_string(ic, ic_uuid);
1171         } else {
1172             hide_preedit_string(ic, ic_uuid);
1173         }
1174     }
1175 }
1176
1177 void CSCLConnectionISF::update_preedit_caret(sclint caret)
1178 {
1179     if (m_initialized) {
1180         m_helper_agent.update_preedit_caret(caret);
1181     }
1182 }
1183
1184 void CSCLConnectionISF::update_aux_string(const sclchar *str)
1185 {
1186     if (m_initialized) {
1187         scim::AttributeList list;
1188         m_helper_agent.update_aux_string(scim::String(str), list);
1189     }
1190 }
1191
1192 void CSCLConnectionISF::update_input_context(sclu32 type, sclu32 value)
1193 {
1194     if (m_initialized) {
1195         m_helper_agent.update_input_context(type, value);
1196     }
1197 }
1198
1199 void CSCLConnectionISF::update_geometry(sclint x, sclint y, sclint width, sclint height)
1200 {
1201     if (m_initialized) {
1202         m_helper_agent.update_geometry(x, y, width, height);
1203     }
1204 }
1205
1206 void CSCLConnectionISF::get_surrounding_text(const sclchar *ic_uuid, sclint maxlen_before, sclint maxlen_after) const
1207 {
1208     if (m_initialized) {
1209         scim::String uuid;
1210         if (ic_uuid) {
1211             uuid = scim::String(ic_uuid);
1212         }
1213         m_helper_agent.get_surrounding_text(uuid, maxlen_before, maxlen_after);
1214     }
1215 }
1216
1217 sclint CSCLConnectionISF::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
1218 {
1219     if (m_initialized) {
1220         scim::String surrounding_text;
1221         m_helper_agent.get_surrounding_text(maxlen_before, maxlen_after, surrounding_text, cursor);
1222
1223         if (text) {
1224             *text = strdup(surrounding_text.c_str());
1225             if (*text == NULL) {
1226                 return -1;
1227             }
1228         }
1229     }
1230     return 0;
1231 }
1232
1233 void CSCLConnectionISF::delete_surrounding_text(sclint offset, sclint len) const
1234 {
1235     if (m_initialized) {
1236         m_helper_agent.delete_surrounding_text(offset, len);
1237     }
1238 }
1239
1240 void CSCLConnectionISF::set_candidate_position(sclint left, sclint top)
1241 {
1242     if (m_initialized) {
1243         m_helper_agent.set_candidate_position(left, top);
1244     }
1245 }
1246
1247 void CSCLConnectionISF::enable_soft_candidate(sclboolean enable)
1248 {
1249     if (m_initialized) {
1250         if (enable)
1251             m_helper_agent.set_candidate_style(scim::ONE_LINE_CANDIDATE, scim::SOFT_CANDIDATE_WINDOW);
1252         else
1253             m_helper_agent.set_candidate_style(scim::ONE_LINE_CANDIDATE, scim::FIXED_CANDIDATE_WINDOW);
1254     }
1255 }
1256
1257 void CSCLConnectionISF::candidate_hide(void)
1258 {
1259     if (m_initialized) {
1260         m_helper_agent.candidate_hide();
1261     }
1262 }
1263
1264 void CSCLConnectionISF::set_keyboard_ise_by_uuid(const sclchar *uuid)
1265 {
1266     if (m_initialized) {
1267         m_helper_agent.set_keyboard_ise_by_uuid(uuid);
1268     }
1269 }
1270
1271 void CSCLConnectionISF::get_keyboard_ise(const sclchar *uuid)
1272 {
1273     if (m_initialized) {
1274         m_helper_agent.get_keyboard_ise(uuid);
1275     }
1276 }
1277
1278 void CSCLConnectionISF::set_selection(sclint start, sclint end)
1279 {
1280     if (m_initialized) {
1281         m_helper_agent.set_selection(start, end);
1282     }
1283 }
1284
1285 void CSCLConnectionISF::send_private_command(const sclchar *command)
1286 {
1287     Eina_Bool tc_command = EINA_FALSE;
1288     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
1289     ISCLCoreEventCallback *callback = NULL;
1290     if (impl) {
1291         callback = impl->get_core_event_callback();
1292     }
1293     if (command && callback) {
1294         if (strcmp(command, "tizen::tc::test") == 0) {
1295             static Ise_Context context;
1296             static SclCandidateTable table;
1297             static scim::KeyEvent key;
1298             static sclu32 type;
1299             static size_t len;
1300
1301             callback->on_attach_input_context(0, "");
1302             callback->on_detach_input_context(0, "");
1303             callback->on_reload_config(0, "");
1304             callback->on_update_spot_location(0, "", 0, 0);
1305             callback->on_update_cursor_position(0, "", 0);
1306             callback->on_update_surrounding_text(0, NULL, 0);
1307             callback->on_focus_out(0, "");
1308             callback->on_focus_in(0, "");
1309             callback->on_ise_show(0, 0, context);
1310             callback->on_ise_hide(0, "");
1311             callback->on_get_geometry(NULL, NULL, NULL, NULL);
1312             callback->on_set_mode(0);
1313             callback->on_set_language(0);
1314             callback->on_set_imdata(NULL, 0);
1315             callback->on_get_imdata(NULL, NULL);
1316             callback->on_get_language_locale(0, NULL);
1317             callback->on_set_return_key_type(0);
1318             callback->on_get_return_key_type(NULL);
1319             callback->on_set_return_key_disable(0);
1320             callback->on_get_return_key_disable(NULL);
1321             callback->on_set_layout(0);
1322             callback->on_get_layout(NULL);
1323             callback->on_set_caps_mode(0);
1324             callback->on_reset_input_context(0, NULL);
1325             callback->on_update_candidate_geometry(0, NULL, 0, 0, 0, 0);
1326             callback->on_update_keyboard_ise(0, NULL, NULL, NULL);
1327             callback->on_candidate_more_window_show(0, NULL);
1328             callback->on_candidate_more_window_hide(0, NULL);
1329             callback->on_select_aux(0, NULL, 0);
1330             callback->on_select_candidate(0, NULL, 0);
1331             callback->on_candidate_table_page_up(0, NULL);
1332             callback->on_candidate_table_page_down(0, NULL);
1333             callback->on_update_lookup_table(table);
1334             callback->on_update_candidate_table_page_size(0, NULL, 0);
1335             callback->on_select_associate(0, NULL, 0);
1336             callback->on_associate_table_page_up(0, NULL);
1337             callback->on_associate_table_page_down(0, NULL);
1338             callback->on_update_associate_table_page_size(0, NULL, 0);
1339             callback->on_process_key_event(key, NULL);
1340             callback->on_process_key_event_with_keycode(key, NULL, 0);
1341             callback->on_process_key_event_with_imengine(key, NULL);
1342
1343             callback->on_set_display_language(NULL);
1344             callback->on_set_rotation_degree(0);
1345             callback->on_set_accessibility_state(FALSE);
1346
1347             callback->on_create_option_window(SCLWINDOW_INVALID, OPTION_WINDOW_TYPE_NORMAL);
1348             callback->on_destroy_option_window(SCLWINDOW_INVALID);
1349             callback->on_check_option_window_availability(NULL);
1350
1351             callback->on_candidate_show(0, "");
1352             callback->on_candidate_hide(0, "");
1353
1354             callback->on_process_input_device_event(type, NULL, len, NULL);
1355
1356             callback->on_set_prediction_hint(NULL);
1357             callback->on_set_mime_type(NULL);
1358
1359             tc_command = EINA_TRUE;
1360         }
1361     }
1362
1363     if (m_initialized && command && !tc_command) {
1364         m_helper_agent.send_private_command(command);
1365     }
1366 }
1367
1368 void CSCLConnectionISF::get_selection_text(sclchar **text)
1369 {
1370     if (m_initialized) {
1371         scim::String selection_text;
1372         m_helper_agent.get_selection_text(selection_text);
1373
1374         if (text)
1375             *text = strdup(selection_text.c_str());
1376     }
1377 }
1378
1379 void CSCLConnectionISF::request_ise_hide()
1380 {
1381     if (m_initialized) {
1382         m_helper_agent.request_ise_hide();
1383     }
1384 }
1385
1386 void CSCLConnectionISF::commit_content(const sclchar *content, const sclchar *description, const sclchar *mime_types)
1387 {
1388     if (m_initialized) {
1389         m_helper_agent.commit_content(content, description, mime_types);
1390     }
1391 }
1392
1393 void CSCLConnectionISF::update_preedit_string_with_commit(const sclchar *preedit, const sclchar *commit, const scim::AttributeList &attrs, sclint caret)
1394 {
1395     if (m_initialized) {
1396         m_helper_agent.update_preedit_string(-1, "", scim::utf8_mbstowcs(scim::String(preedit)), scim::utf8_mbstowcs(scim::String(commit)), attrs, caret);
1397     }
1398 }
1399
1400 void CSCLConnectionISF::recapture_string(sclint offset, sclint len, const sclchar *preedit, const sclchar *commit, const scim::AttributeList &attrs)
1401 {
1402     if (m_initialized) {
1403         m_helper_agent.recapture_string(-1, "", offset, len, scim::utf8_mbstowcs(scim::String(preedit)), scim::utf8_mbstowcs(scim::String(commit)), attrs);
1404     }
1405 }
1406
1407 void CSCLConnectionISF::update_lookup_table(const scim::LookupTable &table)
1408 {
1409     if (m_initialized) {
1410         m_helper_agent.update_candidate_string(table);
1411     }
1412 }
1413
1414 void CSCLConnectionISF::register_properties(const scim::PropertyList &properties)
1415 {
1416     if (m_initialized) {
1417         m_helper_agent.register_properties(properties);
1418     }
1419 }
1420
1421 void CSCLConnectionISF::update_property(const scim::Property &property)
1422 {
1423     if (m_initialized) {
1424         m_helper_agent.update_property(property);
1425     }
1426 }
1427
1428 void CSCLConnectionISF::expand_candidate(void)
1429 {
1430     if (m_initialized) {
1431         m_helper_agent.expand_candidate();
1432     }
1433 }
1434
1435 void CSCLConnectionISF::contract_candidate(void)
1436 {
1437     if (m_initialized) {
1438         m_helper_agent.contract_candidate();
1439     }
1440 }
1441
1442 void CSCLConnectionISF::set_candidate_style(scim::ISF_CANDIDATE_PORTRAIT_LINE_T portrait_line, scim::ISF_CANDIDATE_MODE_T mode)
1443 {
1444     if (m_initialized) {
1445         m_helper_agent.set_candidate_style(portrait_line, mode);
1446     }
1447 }
1448
1449 void CSCLConnectionISF::set_engine_loader_flag(sclboolean flag)
1450 {
1451     if (m_initialized) {
1452         m_helper_agent.set_engine_loader_flag(flag);
1453     }
1454 }
1455
1456 extern "C"
1457 {
1458     EXAPI void scim_module_init(void) {
1459     }
1460
1461     EXAPI void scim_module_exit(void) {
1462     }
1463
1464     EXAPI void scim_helper_module_run_helper(const scim::String &uuid, const scim::ConfigPointer &config, const scim::String &display) {
1465         _scim_config = config;
1466         CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
1467         if (impl) {
1468             impl->on_run(uuid.c_str(), display.c_str());
1469         }
1470     }
1471 }