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