54d0e5b01346b84cee5ee3ba2b9d50a6fed3e5a4
[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 using namespace scl;
24
25 static scim::ConfigPointer _scim_config(0);
26
27 /* Slot functions for calling appropriate callback functions */
28 static void slot_exit(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
29     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
30     if (impl) {
31         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
32         if (callback) {
33             callback->on_ise_hide(ic, ic_uuid.c_str());
34             callback->on_exit();
35         }
36         if (agent) {
37             agent->update_ise_exit();
38         }
39     }
40     elm_exit();
41 }
42
43 static void slot_attach_input_context(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
44     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
45     if (impl) {
46         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
47         if (callback) {
48             callback->on_attach_input_context(ic, ic_uuid.c_str());
49         }
50     }
51 }
52
53 static void slot_detach_input_context(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
54     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
55     if (impl) {
56         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
57         if (callback) {
58             callback->on_detach_input_context(ic, ic_uuid.c_str());
59         }
60     }
61 }
62
63 static void slot_reload_config(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
64     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
65     if (impl) {
66         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
67         if (callback) {
68             callback->on_reload_config(ic, ic_uuid.c_str());
69         }
70     }
71 }
72
73 static void slot_update_screen(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int screen_number) {
74     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
75     if (impl) {
76         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
77         if (callback) {
78             //callback->on_update_screen(ic, ic_uuid.c_str(), screen_number);
79         }
80     }
81 }
82
83 static void slot_update_spot_location(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int x, int y) {
84     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
85     if (impl) {
86         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
87         if (callback) {
88             callback->on_update_spot_location(ic, ic_uuid.c_str(), x, y);
89         }
90     }
91 }
92
93 static void slot_update_cursor_position(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, int cursor_pos) {
94     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
95     if (impl) {
96         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
97         if (callback) {
98             callback->on_update_cursor_position(ic, ic_uuid.c_str(), cursor_pos);
99         }
100     }
101 }
102
103 static void slot_update_surrounding_text(const scim::HelperAgent *agent, int ic, const scim::String &text, int cursor) {
104     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
105     if (impl) {
106         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
107         if (callback) {
108             callback->on_update_surrounding_text(ic, text.c_str(), cursor);
109         }
110     }
111 }
112
113 static void slot_trigger_property(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid, const scim::String &property) {
114     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
115     if (impl) {
116         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
117         if (callback) {
118             //callback->on_trigger_property(ic, ic_uuid.c_str(), property.c_str());
119         }
120     }
121 }
122
123 static void slot_focus_out(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
124     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
125     if (impl) {
126         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
127         if (callback) {
128             callback->on_focus_out(ic, ic_uuid.c_str());
129         }
130     }
131 }
132
133 static void slot_focus_in(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
134     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
135     if (impl) {
136         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
137         if (callback) {
138             callback->on_focus_in(ic, ic_uuid.c_str());
139         }
140     }
141 }
142
143 static void slot_ise_show(const scim::HelperAgent *agent, int ic, char *buf, size_t &len) {
144     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
145     if (impl) {
146         /* Make sure the appropriate keyboard ise was selected -> is this really necessary? */
147         //impl->set_keyboard_ise_by_uuid(impl->get_keyboard_ise_uuid().c_str());
148
149         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
150         if (callback) {
151             /* Check if effect is enabled */
152             Ise_Context ise_context;
153             memset(&ise_context, 0x00, sizeof(ise_context));
154
155             if (len >= sizeof(Ise_Context)) {
156                 memcpy(&ise_context, buf, sizeof(ise_context));
157
158                 if (ise_context.imdata_size > 0) {
159                     callback->on_set_imdata(buf + sizeof(ise_context), ise_context.imdata_size);
160                 }
161             } else {
162                 LOGD("\n-=-= WARNING - buf %p len %d size %d \n", buf, len, sizeof(ise_context));
163             }
164             callback->on_ise_show(ic, impl->get_screen_rotation_degree(), ise_context);
165         }
166     }
167 }
168
169 static void slot_ise_hide(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
170     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
171     if (impl) {
172         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
173         if (callback) {
174             callback->on_ise_hide(ic, ic_uuid.c_str());
175         }
176     }
177 }
178
179 static void slot_get_geometry(const scim::HelperAgent *agent, struct scim::rectinfo &info) {
180     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
181     if (impl) {
182         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
183         if (callback) {
184             callback->on_get_geometry(&(info.pos_x), &(info.pos_y), &(info.width), &(info.height));
185         }
186     }
187 }
188
189 static void slot_set_mode(const scim::HelperAgent *agent, scim::uint32 &mode) {
190     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
191     if (impl) {
192         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
193         if (callback) {
194             callback->on_set_mode(mode);
195         }
196     }
197 }
198
199 static void slot_set_language(const scim::HelperAgent *agent, scim::uint32 &language) {
200     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
201     if (impl) {
202         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
203         if (callback) {
204             callback->on_set_language(language);
205         }
206     }
207 }
208
209 static void slot_set_imdata(const scim::HelperAgent *agent, char *buf, size_t &len) {
210     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
211     if (impl) {
212         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
213         if (callback) {
214             scl32 _len = static_cast<scl32>(reinterpret_cast<size_t>(len) & 0xffffffff);
215             callback->on_set_imdata(buf, _len);
216         }
217     }
218 }
219
220 static void slot_get_imdata(const scim::HelperAgent *, char **buf, size_t &len) {
221     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
222     if (impl) {
223         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
224         if (callback) {
225             sclu32 _len = 0;
226             callback->on_get_imdata(buf, &_len);
227             len = _len;
228         }
229     }
230 }
231
232 static void slot_get_language_locale(const scim::HelperAgent *, int ic, char **locale) {
233     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
234     if (impl) {
235         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
236         if (callback) {
237             callback->on_get_language_locale(ic, locale);
238         }
239     }
240 }
241
242 static void slot_set_return_key_type(const scim::HelperAgent *agent, scim::uint32 &type) {
243     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
244     if (impl) {
245         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
246         if (callback) {
247             callback->on_set_return_key_type(type);
248         }
249     }
250 }
251
252 static void slot_get_return_key_type(const scim::HelperAgent *agent, scim::uint32 &type) {
253     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
254     if (impl) {
255         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
256         if (callback) {
257             callback->on_get_return_key_type(&type);
258         }
259     }
260 }
261
262 static void slot_set_return_key_disable(const scim::HelperAgent *agent, scim::uint32 &disabled) {
263     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
264     if (impl) {
265         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
266         if (callback) {
267             callback->on_set_return_key_disable(disabled);
268         }
269     }
270 }
271
272 static void slot_get_return_key_disable(const scim::HelperAgent *agent, scim::uint32 &disabled) {
273     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
274     if (impl) {
275         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
276         if (callback) {
277             callback->on_get_return_key_disable(&disabled);
278         }
279     }
280 }
281
282 static void slot_set_layout(const scim::HelperAgent *agent, scim::uint32 &layout) {
283     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
284     if (impl) {
285         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
286         if (callback) {
287             callback->on_set_layout(layout);
288         }
289     }
290 }
291
292 static void slot_get_layout(const scim::HelperAgent *agent, scim::uint32 &layout) {
293     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
294     if (impl) {
295         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
296         if (callback) {
297             callback->on_get_layout(&layout);
298         }
299     }
300 }
301
302 static void slot_set_caps_mode(const scim::HelperAgent *agent, scim::uint32 &mode) {
303     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
304     if (impl) {
305         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
306         if (callback) {
307             callback->on_set_caps_mode(mode);
308         }
309     }
310 }
311
312 static void slot_reset_input_context(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
313     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
314     if (impl) {
315         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
316         if (callback) {
317             callback->on_reset_input_context(ic, uuid.c_str());
318         }
319     }
320 }
321
322 static void slot_update_candidate_geometry(const scim::HelperAgent *agent, int ic, const scim::String &uuid, const scim::rectinfo &info) {
323     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
324     if (impl) {
325         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
326         if (callback) {
327             callback->on_update_candidate_geometry(ic, uuid.c_str(), info.pos_x, info.pos_y, info.width, info.height);
328         }
329     }
330 }
331 static void slot_update_keyboard_ise(const scim::HelperAgent *agent, int ic, const scim::String &uuid,
332                                                   const scim::String &ise_name, const scim::String &ise_uuid) {
333     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
334     if (impl) {
335         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
336         if (callback) {
337             callback->on_update_keyboard_ise(ic, uuid.c_str(), ise_name.c_str(), ise_uuid.c_str());
338         }
339     }
340 }
341
342 static void slot_candidate_more_window_show(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
343     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
344     if (impl) {
345         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
346         if (callback) {
347             callback->on_candidate_more_window_show(ic, uuid.c_str());
348         }
349     }
350 }
351
352 static void slot_candidate_more_window_hide(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
353     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
354     if (impl) {
355         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
356         if (callback) {
357             callback->on_candidate_more_window_hide(ic, uuid.c_str());
358         }
359     }
360 }
361
362 static void slot_select_aux(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
363     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
364     if (impl) {
365         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
366         if (callback) {
367             callback->on_select_aux(ic, uuid.c_str(), index);
368         }
369     }
370 }
371
372 static void slot_select_candidate(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
373     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
374     if (impl) {
375         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
376         if (callback) {
377             callback->on_select_candidate(ic, uuid.c_str(), index);
378         }
379     }
380 }
381
382 static void slot_candidate_table_page_up(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
383     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
384     if (impl) {
385         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
386         if (callback) {
387             callback->on_candidate_table_page_up(ic, uuid.c_str());
388         }
389     }
390 }
391
392 static void slot_candidate_table_page_down(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
393     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
394     if (impl) {
395         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
396         if (callback) {
397             callback->on_candidate_table_page_down(ic, uuid.c_str());
398         }
399     }
400 }
401
402 static void slot_update_candidate_table_page_size(const scim::HelperAgent *, int ic, const scim::String &uuid, int page_size) {
403     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
404     if (impl) {
405         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
406         if (callback) {
407             callback->on_update_candidate_table_page_size(ic, uuid.c_str(), page_size);
408         }
409     }
410 }
411
412 static void slot_update_lookup_table(const scim::HelperAgent *, scim::LookupTable &table) {
413     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
414     if (impl) {
415         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
416         if (callback) {
417             SclCandidateTable lookup_table;
418             lookup_table.page_size = table.get_page_size();
419             lookup_table.current_page_start = table.get_current_page_start();
420             lookup_table.cursor_pos = table.get_cursor_pos();
421             lookup_table.cursor_visible = table.is_cursor_visible();
422             lookup_table.page_size_fixed = table.is_page_size_fixed();
423             lookup_table.candidate_labels.clear();
424             for (int page_index = 0;page_index < lookup_table.page_size;page_index++) {
425                 scim::WideString label = table.get_candidate_label(page_index);
426                 lookup_table.candidate_labels.push_back(scim::utf8_wcstombs(label).c_str());
427             }
428
429             int nCandidateSize = table.get_current_page_size();
430             for (int index = 0; index < nCandidateSize; ++index) {
431                 scim::WideString candidate_str = table.get_candidate_in_current_page(index);
432                 lookup_table.candidate.push_back(scim::utf8_wcstombs(candidate_str).c_str());
433             }
434
435             callback->on_update_lookup_table(lookup_table);
436
437             std::vector<scim::WideString> labels;
438             for (unsigned int loop = 0;loop < lookup_table.candidate_labels.size();loop++) {
439                 labels.push_back(scim::utf8_mbstowcs(lookup_table.candidate_labels.at(loop).c_str()));
440             }
441             table.set_candidate_labels(labels);
442         }
443     }
444 }
445
446 static void slot_select_associate(const scim::HelperAgent *agent, int ic, const scim::String &uuid, int index) {
447     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
448     if (impl) {
449         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
450         if (callback) {
451             callback->on_select_associate(ic, uuid.c_str(), index);
452         }
453     }
454 }
455
456 static void slot_associate_table_page_up(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
457     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
458     if (impl) {
459         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
460         if (callback) {
461             callback->on_associate_table_page_up(ic, uuid.c_str());
462         }
463     }
464 }
465
466 static void slot_associate_table_page_down(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
467     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
468     if (impl) {
469         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
470         if (callback) {
471             callback->on_associate_table_page_down(ic, uuid.c_str());
472         }
473     }
474 }
475
476 static void slot_update_associate_table_page_size(const scim::HelperAgent *, int ic, const scim::String &uuid, int page_size) {
477     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
478     if (impl) {
479         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
480         if (callback) {
481             callback->on_update_associate_table_page_size(ic, uuid.c_str(), page_size);
482         }
483     }
484 }
485
486 static void slot_show_ise_option_window(const scim::HelperAgent *agent, int ic, const scim::String &uuid) {
487     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
488     if (impl) {
489         CSCLCoreUI *core_ui = impl->get_core_ui();
490         if (core_ui) {
491             LOGD("slot_show_ise_option_window() called!!!\n");
492             core_ui->create_option_window(OPTION_WINDOW_TYPE_SETTING_APPLICATION);
493         }
494     }
495 }
496
497 static void slot_check_ise_option_window(const scim::HelperAgent *agent, sclu32 &avail) {
498     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
499     if (impl) {
500         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
501         if (callback) {
502             callback->on_check_option_window_availability(reinterpret_cast<sclboolean *>(&avail));
503         }
504     }
505 }
506
507 static void slot_process_key_event(const scim::HelperAgent *agent, scim::KeyEvent &key, scim::uint32 &ret) {
508     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
509     if (impl) {
510         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
511         if (callback) {
512             callback->on_process_key_event(key, &ret);
513         }
514     }
515 }
516
517 static void slot_candidate_show(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
518     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
519     if (impl) {
520         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
521         if (callback) {
522             callback->on_candidate_show(ic, ic_uuid.c_str());
523         }
524     }
525 }
526
527 static void slot_candidate_hide(const scim::HelperAgent *agent, int ic, const scim::String &ic_uuid) {
528     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
529     if (impl) {
530         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
531         if (callback) {
532             callback->on_candidate_hide(ic, ic_uuid.c_str());
533         }
534     }
535 }
536
537 static void slot_process_input_device_event(const scim::HelperAgent *agent, scim::uint32 &type, char *data, size_t &len, scim::uint32 &ret) {
538     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
539     if (impl) {
540         ISCLCoreEventCallback *callback = impl->get_core_event_callback();
541         if (callback) {
542             /* Input Device Event callback is available in versions after 1.1 */
543             if (check_interface_version(callback, 1, 1)) {
544                 callback->on_process_input_device_event(type, data, len, &ret);
545             }
546         }
547     }
548 }
549
550 /* Internal input handler function */
551 Eina_Bool input_handler(void *data, Ecore_Fd_Handler *fd_handler)
552 {
553     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
554     if (impl) {
555         scim::HelperAgent *agent = static_cast<scim::HelperAgent*>(data);
556         if (agent) {
557             if (agent->has_pending_event()) {
558                 if (!(agent->filter_event())) {
559                     LOGD("helper_agent.filter_event() failed!!!\n");
560                     impl->fini();
561                     elm_exit();
562                 }
563             } else {
564                 LOGD("helper_agent.has_pending_event() failed!!!\n");
565                 impl->fini();
566                 elm_exit();
567             }
568         }
569     }
570
571     return ECORE_CALLBACK_RENEW;
572 }
573
574 CSCLConnectionISF::CSCLConnectionISF()
575 {
576     m_initialized = FALSE;
577     m_fd_handler = NULL;
578
579     m_backend_identifier = "ISF";
580 }
581
582 CSCLConnectionISF::~CSCLConnectionISF()
583 {
584 }
585
586 sclboolean CSCLConnectionISF::init()
587 {
588     LOGD("Enter\n");
589
590     CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
591     if (impl) {
592         sclchar *uuid = impl->get_uuid();
593         if (uuid) {
594             m_helper_info.uuid = uuid;
595         }
596     }
597
598     if (!m_initialized) {
599         m_helper_agent.signal_connect_exit(scim::slot(slot_exit));
600         m_helper_agent.signal_connect_attach_input_context(scim::slot(slot_attach_input_context));
601         m_helper_agent.signal_connect_detach_input_context(scim::slot(slot_detach_input_context));
602         m_helper_agent.signal_connect_reload_config(scim::slot(slot_reload_config));
603         m_helper_agent.signal_connect_update_screen(scim::slot(slot_update_screen));
604         m_helper_agent.signal_connect_update_spot_location(scim::slot(slot_update_spot_location));
605         m_helper_agent.signal_connect_update_cursor_position(scim::slot(slot_update_cursor_position));
606         m_helper_agent.signal_connect_update_surrounding_text(scim::slot(slot_update_surrounding_text));
607         m_helper_agent.signal_connect_trigger_property(scim::slot(slot_trigger_property));
608         //m_helper_agent.signal_connect_process_imengine_event (slot (slot_process_imengine_event));
609         m_helper_agent.signal_connect_focus_out(scim::slot(slot_focus_out));
610         m_helper_agent.signal_connect_focus_in(scim::slot(slot_focus_in));
611         m_helper_agent.signal_connect_ise_show(scim::slot(slot_ise_show));
612         m_helper_agent.signal_connect_ise_hide(scim::slot(slot_ise_hide));
613         m_helper_agent.signal_connect_get_geometry(scim::slot(slot_get_geometry));
614         m_helper_agent.signal_connect_set_mode(scim::slot(slot_set_mode));
615         m_helper_agent.signal_connect_set_language(scim::slot(slot_set_language));
616         m_helper_agent.signal_connect_set_imdata(scim::slot(slot_set_imdata));
617         m_helper_agent.signal_connect_get_imdata(scim::slot(slot_get_imdata));
618         m_helper_agent.signal_connect_get_language_locale(scim::slot(slot_get_language_locale));
619         m_helper_agent.signal_connect_set_return_key_type(scim::slot(slot_set_return_key_type));
620         m_helper_agent.signal_connect_get_return_key_type(scim::slot(slot_get_return_key_type));
621         m_helper_agent.signal_connect_set_return_key_disable(scim::slot(slot_set_return_key_disable));
622         m_helper_agent.signal_connect_get_return_key_disable(scim::slot(slot_get_return_key_disable));
623         m_helper_agent.signal_connect_get_layout(scim::slot(slot_get_layout));
624         m_helper_agent.signal_connect_set_layout(scim::slot(slot_set_layout));
625         m_helper_agent.signal_connect_set_caps_mode(scim::slot(slot_set_caps_mode));
626         m_helper_agent.signal_connect_reset_input_context(scim::slot(slot_reset_input_context));
627         m_helper_agent.signal_connect_update_candidate_geometry(scim::slot(slot_update_candidate_geometry));
628         m_helper_agent.signal_connect_update_keyboard_ise(scim::slot(slot_update_keyboard_ise));
629         //m_helper_agent.signal_connect_update_keyboard_ise_list (slot (slot_update_keyboard_ise_list));
630         m_helper_agent.signal_connect_candidate_more_window_show(scim::slot(slot_candidate_more_window_show));
631         m_helper_agent.signal_connect_candidate_more_window_hide(scim::slot(slot_candidate_more_window_hide));
632         m_helper_agent.signal_connect_select_aux(scim::slot(slot_select_aux));
633         m_helper_agent.signal_connect_select_candidate(scim::slot(slot_select_candidate));
634         m_helper_agent.signal_connect_candidate_table_page_up(scim::slot(slot_candidate_table_page_up));
635         m_helper_agent.signal_connect_candidate_table_page_down(scim::slot(slot_candidate_table_page_down));
636         m_helper_agent.signal_connect_update_candidate_table_page_size(scim::slot(slot_update_candidate_table_page_size));
637         m_helper_agent.signal_connect_update_lookup_table(scim::slot(slot_update_lookup_table));
638         m_helper_agent.signal_connect_select_associate(scim::slot(slot_select_associate));
639         m_helper_agent.signal_connect_associate_table_page_up(scim::slot(slot_associate_table_page_up));
640         m_helper_agent.signal_connect_associate_table_page_down(scim::slot(slot_associate_table_page_down));
641         m_helper_agent.signal_connect_update_associate_table_page_size(scim::slot(slot_update_associate_table_page_size));
642         m_helper_agent.signal_connect_show_option_window(scim::slot(slot_show_ise_option_window));
643         m_helper_agent.signal_connect_check_option_window(scim::slot(slot_check_ise_option_window));
644         m_helper_agent.signal_connect_process_key_event(scim::slot(slot_process_key_event));
645         m_helper_agent.signal_connect_candidate_show(scim::slot(slot_candidate_show));
646         m_helper_agent.signal_connect_candidate_hide(scim::slot(slot_candidate_hide));
647         m_helper_agent.signal_connect_process_input_device_event(scim::slot(slot_process_input_device_event));
648
649         m_initialized = TRUE;
650     }
651
652     return TRUE;
653 }
654
655 void CSCLConnectionISF::fini()
656 {
657     close_connection();
658     m_initialized = FALSE;
659 }
660
661 void CSCLConnectionISF::open_connection(const sclchar *display)
662 {
663     if (m_initialized) {
664         m_helper_agent.open_connection(m_helper_info, display);
665         int fd = m_helper_agent.get_connection_number();
666
667         if (fd >= 0) {
668 #ifndef WAYLAND
669             Evas_Object *main_window = NULL;
670             CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
671             if (impl) {
672                 main_window = NATIVE_WINDOW_CAST(impl->get_main_window());
673             }
674
675             Ecore_X_Window xwindow = elm_win_xwindow_get(main_window);
676             char xid[255];
677             snprintf(xid, 255, "%d", xwindow);
678             scim::Property prop(xid, "XID", "", "");
679             scim::PropertyList props;
680             props.push_back(prop);
681             m_helper_agent.register_properties(props);
682 #endif
683
684             m_fd_handler = ecore_main_fd_handler_add(fd, ECORE_FD_READ, input_handler, &m_helper_agent, NULL, NULL);
685         }
686     }
687 }
688 void CSCLConnectionISF::close_connection()
689 {
690     if (m_initialized) {
691         if (m_fd_handler) {
692             ecore_main_fd_handler_del(m_fd_handler);
693             m_fd_handler = NULL;
694         }
695         m_helper_agent.update_ise_exit();
696         m_helper_agent.close_connection();
697     }
698 }
699
700 void CSCLConnectionISF::config_reload()
701 {
702     if (m_initialized) {
703         m_helper_agent.reload_config();
704     }
705 }
706
707 sclboolean CSCLConnectionISF::config_read_int(const sclchar *name, sclint &value)
708 {
709     sclboolean ret = FALSE;
710     if (m_initialized && _scim_config) {
711         value = _scim_config->read(name, value);
712         ret = TRUE;
713     }
714     return ret;
715 }
716
717 sclboolean CSCLConnectionISF::config_read_string(const sclchar *name, std::string &value)
718 {
719     sclboolean ret = FALSE;
720     if (m_initialized && _scim_config) {
721         value = _scim_config->read(name, value);
722         ret = TRUE;
723     }
724     return ret;
725 }
726
727 sclboolean CSCLConnectionISF::config_write_int(const sclchar *name, sclint value)
728 {
729     sclboolean ret = FALSE;
730     if (m_initialized && _scim_config) {
731         _scim_config->write(name, value);
732         ret = TRUE;
733     }
734     return ret;
735 }
736
737 sclboolean CSCLConnectionISF::config_write_string(const sclchar *name, const std::string value)
738 {
739     sclboolean ret = FALSE;
740     if (m_initialized && _scim_config) {
741         _scim_config->write(name, value);
742         ret = TRUE;
743     }
744     return ret;
745 }
746
747 sclboolean CSCLConnectionISF::config_erase(const sclchar *name)
748 {
749     sclboolean ret = FALSE;
750     if (m_initialized && _scim_config) {
751         _scim_config->erase(name);
752         ret = TRUE;
753     }
754     return ret;
755 }
756
757 sclboolean CSCLConnectionISF::config_flush(void)
758 {
759     sclboolean ret = FALSE;
760     if (m_initialized && _scim_config) {
761         _scim_config->flush();
762         ret = TRUE;
763     }
764     return ret;
765 }
766
767 void CSCLConnectionISF::send_imengine_event(sclint ic, const sclchar *ic_uuid, const sclint command, const sclu32 value)
768 {
769     if (m_initialized) {
770         scim::String uuid;
771         if (ic_uuid) {
772             uuid = scim::String(ic_uuid);
773         }
774         scim::Transaction trans;
775         trans.put_command(command);
776         trans.put_data(value);
777         m_helper_agent.send_imengine_event(ic, uuid, trans);
778     }
779 }
780
781 void CSCLConnectionISF::reset_keyboard_ise()
782 {
783     if (m_initialized) {
784         m_helper_agent.reset_keyboard_ise();
785     }
786 }
787
788 void CSCLConnectionISF::send_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
789 {
790     if (m_initialized) {
791         scim::String uuid;
792         if (ic_uuid) {
793             uuid = scim::String(ic_uuid);
794         }
795         scim::KeyEvent event;
796         event.code = keycode;
797         event.mask = keymask;
798         m_helper_agent.send_key_event(ic, uuid, event);
799     }
800 }
801
802 void CSCLConnectionISF::forward_key_event(sclint ic, const sclchar *ic_uuid, sclu32 keycode, sclu16 keymask)
803 {
804     if (m_initialized) {
805         scim::String uuid;
806         if (ic_uuid) {
807             uuid = scim::String(ic_uuid);
808         }
809         scim::KeyEvent event;
810         event.code = keycode;
811         event.mask = keymask;
812         m_helper_agent.forward_key_event(ic, uuid, event);
813     }
814 }
815
816 void CSCLConnectionISF::commit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
817 {
818     if (m_initialized) {
819         scim::String uuid;
820         if (ic_uuid) {
821             uuid = scim::String(ic_uuid);
822         }
823         m_helper_agent.commit_string(ic, uuid, scim::utf8_mbstowcs(str));
824     }
825 }
826
827 void CSCLConnectionISF::select_candidate(int index)
828 {
829     if (m_initialized) {
830         m_helper_agent.select_candidate(index);
831     }
832 }
833
834 void CSCLConnectionISF::show_preedit_string(sclint ic, const sclchar *ic_uuid)
835 {
836     if (m_initialized) {
837         scim::String uuid;
838         if (ic_uuid) {
839             uuid = scim::String(ic_uuid);
840         }
841         m_helper_agent.show_preedit_string(ic, uuid);
842     }
843 }
844
845 void CSCLConnectionISF::show_aux_string(void)
846 {
847     if (m_initialized) {
848         m_helper_agent.show_aux_string();
849     }
850 }
851
852 void CSCLConnectionISF::show_candidate_string(void)
853 {
854     if (m_initialized) {
855         m_helper_agent.show_candidate_string();
856     }
857 }
858
859 void CSCLConnectionISF::show_associate_string(void)
860 {
861     if (m_initialized) {
862         m_helper_agent.show_associate_string();
863     }
864 }
865
866 void CSCLConnectionISF::hide_preedit_string(sclint ic, const sclchar *ic_uuid)
867 {
868     if (m_initialized) {
869         scim::String uuid;
870         if (ic_uuid) {
871             uuid = scim::String(ic_uuid);
872         }
873         m_helper_agent.hide_preedit_string(ic, uuid);
874     }
875 }
876
877 void CSCLConnectionISF::hide_aux_string(void)
878 {
879     if (m_initialized) {
880         m_helper_agent.hide_aux_string();
881     }
882 }
883
884 void CSCLConnectionISF::hide_candidate_string(void)
885 {
886     if (m_initialized) {
887         m_helper_agent.hide_candidate_string();
888     }
889 }
890
891 void CSCLConnectionISF::hide_associate_string(void)
892 {
893     if (m_initialized) {
894         m_helper_agent.hide_associate_string();
895     }
896 }
897
898 void CSCLConnectionISF::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str)
899 {
900     if (m_initialized) {
901         scim::AttributeList list;
902         scim::String uuid;
903         if (ic_uuid) {
904             uuid = scim::String(ic_uuid);
905         }
906         m_helper_agent.update_preedit_string(ic, uuid, scim::utf8_mbstowcs(str), list);
907
908         if (str && strlen(str) > 0) {
909             show_preedit_string(ic, ic_uuid);
910         } else {
911             hide_preedit_string(ic, ic_uuid);
912         }
913     }
914 }
915
916 void CSCLConnectionISF::update_preedit_string(sclint ic, const sclchar *ic_uuid, const sclchar *str, const scim::AttributeList &attrs)
917 {
918     if (m_initialized) {
919         scim::String uuid;
920         if (ic_uuid) {
921             uuid = scim::String(ic_uuid);
922         }
923         m_helper_agent.update_preedit_string(ic, uuid, scim::utf8_mbstowcs(str), attrs);
924
925         if (str && strlen(str) > 0) {
926             show_preedit_string(ic, ic_uuid);
927         } else {
928             hide_preedit_string(ic, ic_uuid);
929         }
930     }
931 }
932
933 void CSCLConnectionISF::update_aux_string(const sclchar *str)
934 {
935     if (m_initialized) {
936         scim::AttributeList list;
937         m_helper_agent.update_aux_string(scim::String(str), list);
938     }
939 }
940
941 void CSCLConnectionISF::update_input_context(sclu32 type, sclu32 value)
942 {
943     if (m_initialized) {
944         m_helper_agent.update_input_context(type, value);
945     }
946 }
947
948 void CSCLConnectionISF::update_geometry(sclint x, sclint y, sclint width, sclint height)
949 {
950     if (m_initialized) {
951         m_helper_agent.update_geometry(x, y, width, height);
952     }
953 }
954
955 void CSCLConnectionISF::get_surrounding_text(const sclchar *ic_uuid, sclint maxlen_before, sclint maxlen_after) const
956 {
957     if (m_initialized) {
958         scim::String uuid;
959         if (ic_uuid) {
960             uuid = scim::String(ic_uuid);
961         }
962         m_helper_agent.get_surrounding_text(uuid, maxlen_before, maxlen_after);
963     }
964 }
965
966 sclint CSCLConnectionISF::get_surrounding_text(sclint maxlen_before, sclint maxlen_after, sclchar **text, int &cursor)
967 {
968     if (m_initialized) {
969         scim::String surrounding_text;
970         m_helper_agent.get_surrounding_text(maxlen_before, maxlen_after, surrounding_text, cursor);
971
972         if (text) {
973             *text = strdup(surrounding_text.c_str());
974             if (*text == NULL) {
975                 return -1;
976             }
977         }
978     }
979     return 0;
980 }
981
982 void CSCLConnectionISF::delete_surrounding_text(sclint offset, sclint len) const
983 {
984     if (m_initialized) {
985         m_helper_agent.delete_surrounding_text(offset, len);
986     }
987 }
988
989 void CSCLConnectionISF::set_candidate_position(sclint left, sclint top)
990 {
991     if (m_initialized) {
992         m_helper_agent.set_candidate_position(left, top);
993     }
994 }
995
996 void CSCLConnectionISF::enable_soft_candidate(sclboolean enable)
997 {
998     if (m_initialized) {
999         if (enable)
1000             m_helper_agent.set_candidate_style(scim::ONE_LINE_CANDIDATE, scim::SOFT_CANDIDATE_WINDOW);
1001         else
1002             m_helper_agent.set_candidate_style(scim::ONE_LINE_CANDIDATE, scim::FIXED_CANDIDATE_WINDOW);
1003     }
1004 }
1005
1006 void CSCLConnectionISF::candidate_hide(void)
1007 {
1008     if (m_initialized) {
1009         m_helper_agent.candidate_hide();
1010     }
1011 }
1012
1013 void CSCLConnectionISF::set_keyboard_ise_by_uuid(const sclchar *uuid)
1014 {
1015     if (m_initialized) {
1016         m_helper_agent.set_keyboard_ise_by_uuid(uuid);
1017     }
1018 }
1019
1020 void CSCLConnectionISF::get_keyboard_ise(const sclchar *uuid)
1021 {
1022     if (m_initialized) {
1023         m_helper_agent.get_keyboard_ise(uuid);
1024     }
1025 }
1026
1027 void CSCLConnectionISF::set_selection(sclint start, sclint end)
1028 {
1029     if (m_initialized) {
1030         m_helper_agent.set_selection(start, end);
1031     }
1032 }
1033
1034 void CSCLConnectionISF::send_private_command(const sclchar *command)
1035 {
1036     if (m_initialized) {
1037         m_helper_agent.send_private_command(command);
1038     }
1039 }
1040
1041 void CSCLConnectionISF::get_selection_text(sclchar **text)
1042 {
1043     if (m_initialized) {
1044         scim::String selection_text;
1045         m_helper_agent.get_selection_text(selection_text);
1046
1047         if (text)
1048             *text = strdup(selection_text.c_str());
1049     }
1050 }
1051
1052 extern "C"
1053 {
1054     void scim_module_init(void) {
1055     }
1056
1057     void scim_module_exit(void) {
1058     }
1059
1060     void scim_helper_module_run_helper(const scim::String &uuid, const scim::ConfigPointer &config, const scim::String &display) {
1061         _scim_config = config;
1062         CSCLCoreImpl *impl = CSCLCoreImpl::get_instance();
1063         if (impl) {
1064             impl->on_run(uuid.c_str(), display.c_str());
1065         }
1066     }
1067 }