1ac4e06439f42621f81cf7f47ac36c265066cd2b
[platform/core/uifw/isf.git] / ism / src / scim_helper.cpp
1 /** @file scim_helper.cpp
2  *  @brief Implementation of class HelperAgent.
3  */
4
5 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
6
7 /*
8  * Smart Common Input Method
9  *
10  * Copyright (c) 2004-2005 James Su <suzhe@tsinghua.org.cn>
11  * Copyright (c) 2012-2015 Samsung Electronics Co., Ltd.
12  *
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this program; if not, write to the
26  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
27  * Boston, MA  02111-1307  USA
28  *
29  * Modifications by Samsung Electronics Co., Ltd.
30  * 1. Add new interface APIs for keyboard ISE
31  *    a. expand_candidate (), contract_candidate () and set_candidate_style ()
32  *    b. set_keyboard_ise_by_uuid () and reset_keyboard_ise ()
33  *    c. get_surrounding_text () and delete_surrounding_text ()
34  *    d. show_preedit_string (), hide_preedit_string (), update_preedit_string () and update_preedit_caret ()
35  *    e. show_candidate_string (), hide_candidate_string () and update_candidate_string ()
36  *
37  * $Id: scim_helper.cpp,v 1.13 2005/05/24 12:22:51 suzhe Exp $
38  *
39  */
40
41 #define Uses_SCIM_TRANSACTION
42 #define Uses_SCIM_TRANS_COMMANDS
43 #define Uses_SCIM_HELPER
44 #define Uses_SCIM_SOCKET
45 #define Uses_SCIM_EVENT
46 #define Uses_SCIM_BACKEND
47 #define Uses_SCIM_IMENGINE_MODULE
48
49 #include <string.h>
50 #include <unistd.h>
51 #include <sys/time.h>
52 #include <Ecore_IMF.h>
53
54 #include "scim_private.h"
55 #include "scim.h"
56 #include <scim_panel_common.h>
57 #include "isf_query_utility.h"
58 #include <dlog.h>
59 #include "isf_debug.h"
60 #include "isf_message_queue.h"
61 #include "tizen_profile.h"
62 #ifdef HAVE_PKGMGR_INFO
63 #include <pkgmgr-info.h>
64 #endif // HAVE_PKGMGR_INFO
65 #include "isf_device_event.h"
66
67 #ifdef LOG_TAG
68 # undef LOG_TAG
69 #endif
70 #define LOG_TAG             "SCIM_HELPER"
71
72
73 //FIXME: remove this definitions
74 #define SHIFT_MODE_OFF  0xffe1
75 #define SHIFT_MODE_ON   0xffe2
76 #define SHIFT_MODE_LOCK 0xffe6
77 #define SHIFT_MODE_ENABLE 0x9fe7
78 #define SHIFT_MODE_DISABLE 0x9fe8
79
80 namespace scim {
81
82 typedef Signal3<void, const HelperAgent *, int, const String &>
83         HelperAgentSignalVoid;
84
85 typedef Signal4<void, const HelperAgent *, int, const String &, const String &>
86         HelperAgentSignalString;
87
88 typedef Signal4<void, const HelperAgent *, int, const String &, const std::vector<String> &>
89         HelperAgentSignalStringVector;
90
91 typedef Signal5<void, const HelperAgent *, int, const String &, const String &, const String &>
92         HelperAgentSignalString2;
93
94 typedef Signal4<void, const HelperAgent *, int, const String &, int>
95         HelperAgentSignalInt;
96
97 typedef Signal5<void, const HelperAgent *, int, const String &, int, int>
98         HelperAgentSignalIntInt;
99
100 typedef Signal4<void, const HelperAgent *, int, const String &, const Transaction &>
101         HelperAgentSignalTransaction;
102
103 typedef Signal4<void, const HelperAgent *, int, const String &, const rectinfo &>
104         HelperAgentSignalRect;
105
106 typedef Signal2<void, const HelperAgent *, struct rectinfo &>
107         HelperAgentSignalSize;
108
109 typedef Signal2<void, const HelperAgent *, uint32 &>
110         HelperAgentSignalUintVoid;
111
112 typedef Signal3<void, const HelperAgent *, int, uint32 &>
113         HelperAgentSignalIntUint;
114
115 typedef Signal3 <void, const HelperAgent *, char *, size_t &>
116         HelperAgentSignalRawVoid;
117
118 typedef Signal3 <void, const HelperAgent *, char **, size_t &>
119         HelperAgentSignalGetRawVoid;
120
121 typedef Signal4 <void, const HelperAgent *, int, char *, size_t &>
122         HelperAgentSignalIntRawVoid;
123
124 typedef Signal3 <void, const HelperAgent *, int, char **>
125         HelperAgentSignalIntGetStringVoid;
126
127 typedef Signal2<void, const HelperAgent *, const std::vector<uint32> &>
128         HelperAgentSignalUintVector;
129
130 typedef Signal2<void, const HelperAgent *, LookupTable &>
131         HelperAgentSignalLookupTable;
132
133 typedef Signal3<void, const HelperAgent *, KeyEvent &, uint32 &>
134         HelperAgentSignalKeyEventUint;
135
136 typedef Signal3<void, const HelperAgent *, KeyEvent &, uint32>
137         HelperAgentSignalKeyEventUint2;
138
139 typedef Signal4<void, const HelperAgent *, KeyEvent &, uint32 &, uint32>
140         HelperAgentSignalKeyEventUintUint;
141
142 typedef Signal5<void, const HelperAgent *, uint32 &, char *, size_t &, uint32 &>
143         HelperAgentSignalUintCharSizeUint;
144
145 typedef Signal2<void, const HelperAgent *, const String &>
146         HelperAgentSignalStringVoid;
147
148 class HelperAgent::HelperAgentImpl
149 {
150 public:
151     SocketClient socket;
152     SocketClient socket_active;
153     Transaction  recv;
154     Transaction  send;
155     uint32       magic;
156     uint32       magic_active;
157     int          timeout;
158     uint32       focused_ic;
159
160     HelperAgent* thiz;
161     IMEngineInstancePointer si;
162     ConfigPointer m_config;
163     IMEngineModule engine_module;
164
165     char* surrounding_text;
166     char* selection_text;
167     uint32 cursor_pos;
168     int need_update_surrounding_text;
169     int need_update_selection_text;
170     uint32 layout;
171     bool ise_show_flag;
172     bool hw_keyboard_mode;
173     bool need_update_entry_metadata;
174     bool ise_focus_flag;
175     char* finalized_text;
176     uint32 finalized_cursor_pos;
177     bool engine_loader_flag;
178
179     HelperAgentSignalVoid           signal_exit;
180     HelperAgentSignalVoid           signal_attach_input_context;
181     HelperAgentSignalVoid           signal_detach_input_context;
182     HelperAgentSignalVoid           signal_reload_config;
183     HelperAgentSignalInt            signal_update_screen;
184     HelperAgentSignalIntInt         signal_update_spot_location;
185     HelperAgentSignalInt            signal_update_cursor_position;
186     HelperAgentSignalInt            signal_update_surrounding_text;
187     HelperAgentSignalVoid           signal_update_selection;
188     HelperAgentSignalString         signal_trigger_property;
189     HelperAgentSignalTransaction    signal_process_imengine_event;
190     HelperAgentSignalVoid           signal_focus_out;
191     HelperAgentSignalVoid           signal_focus_in;
192     HelperAgentSignalIntRawVoid     signal_ise_show;
193     HelperAgentSignalVoid           signal_ise_hide;
194     HelperAgentSignalVoid           signal_candidate_show;
195     HelperAgentSignalVoid           signal_candidate_hide;
196     HelperAgentSignalSize           signal_get_geometry;
197     HelperAgentSignalUintVoid       signal_set_mode;
198     HelperAgentSignalUintVoid       signal_set_language;
199     HelperAgentSignalRawVoid        signal_set_imdata;
200     HelperAgentSignalGetRawVoid     signal_get_imdata;
201     HelperAgentSignalIntGetStringVoid   signal_get_language_locale;
202     HelperAgentSignalUintVoid           signal_set_return_key_type;
203     HelperAgentSignalUintVoid           signal_get_return_key_type;
204     HelperAgentSignalUintVoid           signal_set_return_key_disable;
205     HelperAgentSignalUintVoid           signal_get_return_key_disable;
206     HelperAgentSignalUintVoid           signal_set_layout;
207     HelperAgentSignalUintVoid           signal_get_layout;
208     HelperAgentSignalUintVoid           signal_set_caps_mode;
209     HelperAgentSignalVoid               signal_reset_input_context;
210     HelperAgentSignalIntInt             signal_update_candidate_ui;
211     HelperAgentSignalRect               signal_update_candidate_geometry;
212     HelperAgentSignalString2            signal_update_keyboard_ise;
213     HelperAgentSignalStringVector       signal_update_keyboard_ise_list;
214     HelperAgentSignalVoid               signal_candidate_more_window_show;
215     HelperAgentSignalVoid               signal_candidate_more_window_hide;
216     HelperAgentSignalLookupTable        signal_update_lookup_table;
217     HelperAgentSignalInt                signal_select_aux;
218     HelperAgentSignalInt                signal_select_candidate;
219     HelperAgentSignalVoid               signal_candidate_table_page_up;
220     HelperAgentSignalVoid               signal_candidate_table_page_down;
221     HelperAgentSignalInt                signal_update_candidate_table_page_size;
222     HelperAgentSignalUintVector         signal_update_candidate_item_layout;
223     HelperAgentSignalInt                signal_select_associate;
224     HelperAgentSignalVoid               signal_associate_table_page_up;
225     HelperAgentSignalVoid               signal_associate_table_page_down;
226     HelperAgentSignalInt                signal_update_associate_table_page_size;
227     HelperAgentSignalVoid               signal_reset_ise_context;
228     HelperAgentSignalUintVoid           signal_turn_on_log;
229     HelperAgentSignalInt                signal_update_displayed_candidate_number;
230     HelperAgentSignalInt                signal_longpress_candidate;
231     HelperAgentSignalKeyEventUint       signal_process_key_event;
232     HelperAgentSignalKeyEventUintUint   signal_process_key_event_with_keycode;
233     HelperAgentSignalUintVoid           signal_set_input_mode;
234     HelperAgentSignalUintVoid           signal_set_input_hint;
235     HelperAgentSignalUintVoid           signal_update_bidi_direction;
236     HelperAgentSignalVoid               signal_show_option_window;
237     HelperAgentSignalVoid               signal_resume_option_window;
238     HelperAgentSignalUintVoid           signal_check_option_window;
239     HelperAgentSignalUintCharSizeUint   signal_process_input_device_event;
240     HelperAgentSignalStringVoid         signal_set_prediction_hint;
241     HelperAgentSignalStringVoid         signal_set_mime_type;
242     HelperAgentSignalString             signal_set_prediction_hint_data;
243     HelperAgentSignalUintVoid           signal_set_optimization_hint;
244     HelperAgentSignalKeyEventUint2      signal_process_key_event_with_imengine;
245     HelperAgentSignalUintVoid           signal_set_autocapital_type;
246     HelperAgentSignalUintVoid           signal_set_prediction_allow;
247
248 public:
249     HelperAgentImpl (HelperAgent* thiz) : magic(0), magic_active(0), timeout(-1), focused_ic ((uint32) -1), thiz (thiz),
250         surrounding_text (NULL), selection_text (NULL), cursor_pos (0),
251         need_update_surrounding_text (0), need_update_selection_text (0),
252         layout (0), ise_show_flag (false), hw_keyboard_mode (false), need_update_entry_metadata (false), ise_focus_flag (false),
253         finalized_text(NULL), finalized_cursor_pos(0), engine_loader_flag(false) {
254     }
255
256     ~HelperAgentImpl () {
257         if (!si.null ()) {
258             si.reset ();
259         }
260
261         if (surrounding_text != NULL)
262             free (surrounding_text);
263
264         if (finalized_text != NULL)
265             free(finalized_text);
266
267         if (selection_text != NULL)
268             free (selection_text);
269
270         if (engine_module.valid ()) {
271             engine_module.unload ();
272         }
273     }
274
275     // Implementation of slot functions
276     void
277     slot_show_preedit_string (IMEngineInstanceBase *si)
278     {
279         thiz->show_preedit_string (focused_ic, "");
280     }
281
282     void
283     slot_show_aux_string (IMEngineInstanceBase *si)
284     {
285         thiz->show_aux_string ();
286     }
287
288     void
289     slot_show_lookup_table (IMEngineInstanceBase *si)
290     {
291         thiz->show_candidate_string ();
292     }
293
294     void
295     slot_hide_preedit_string (IMEngineInstanceBase *si)
296     {
297         thiz->hide_preedit_string (focused_ic, "");
298     }
299
300     void
301     slot_hide_aux_string (IMEngineInstanceBase *si)
302     {
303         thiz->hide_aux_string ();
304     }
305
306     void
307     slot_hide_lookup_table (IMEngineInstanceBase *si)
308     {
309         thiz->hide_candidate_string ();
310     }
311
312     void
313     slot_update_preedit_caret (IMEngineInstanceBase *si, int caret)
314     {
315         thiz->update_preedit_caret (caret);
316     }
317
318     void
319     slot_update_preedit_string (IMEngineInstanceBase *si,
320                                 const WideString & str,
321                                 const AttributeList & attrs,
322                                 int caret)
323     {
324         thiz->update_preedit_string (-1, "", str, attrs, caret);
325     }
326
327     void
328     slot_update_preedit_string_with_commit (IMEngineInstanceBase *si,
329                                             const WideString & preedit,
330                                             const WideString & commit,
331                                             const AttributeList & attrs,
332                                             int caret)
333     {
334         thiz->update_preedit_string (-1, "", preedit, commit, attrs, caret);
335     }
336
337     void
338     slot_update_aux_string (IMEngineInstanceBase *si,
339                             const WideString & str,
340                             const AttributeList & attrs)
341     {
342         thiz->update_aux_string (utf8_wcstombs(str), attrs);
343     }
344
345     void
346     slot_commit_string (IMEngineInstanceBase *si,
347                         const WideString & str)
348     {
349         thiz->commit_string (-1, "", str);
350     }
351
352     void
353     slot_recapture_string (IMEngineInstanceBase *si,
354                            int                   offset,
355                            int                   len,
356                            const WideString & preedit,
357                            const WideString & commit,
358                            const AttributeList & attrs)
359     {
360         thiz->recapture_string (-1, "", offset, len, preedit, commit, attrs);
361     }
362
363     void
364     slot_forward_key_event (IMEngineInstanceBase *si,
365                             const KeyEvent & key)
366     {
367         thiz->forward_key_event (-1, "", key);
368     }
369
370     void
371     slot_update_lookup_table (IMEngineInstanceBase *si,
372                               const LookupTable & table)
373     {
374         thiz->update_candidate_string (table);
375     }
376
377     void
378     slot_register_properties (IMEngineInstanceBase *si,
379                               const PropertyList & properties)
380     {
381         thiz->register_properties (properties);
382     }
383
384     void
385     slot_update_property (IMEngineInstanceBase *si,
386                           const Property & property)
387     {
388         thiz->update_property (property);
389     }
390
391     void
392     slot_beep (IMEngineInstanceBase *si)
393     {
394         //FIXME
395     }
396
397     void
398     slot_start_helper (IMEngineInstanceBase *si,
399                        const String &helper_uuid)
400     {
401         LOGW ("deprecated function");
402     }
403
404     void
405     slot_stop_helper (IMEngineInstanceBase *si,
406                       const String &helper_uuid)
407     {
408         LOGW ("deprecated function");
409     }
410
411     void
412     slot_send_helper_event (IMEngineInstanceBase *si,
413                             const String      &helper_uuid,
414                             const Transaction &trans)
415     {
416         signal_process_imengine_event (thiz, focused_ic, helper_uuid, trans);
417     }
418
419     bool
420     slot_get_surrounding_text (IMEngineInstanceBase *si,
421                                WideString            &text,
422                                int                   &cursor,
423                                int                    maxlen_before,
424                                int                    maxlen_after)
425     {
426         String _text;
427         thiz->get_surrounding_text (maxlen_before, maxlen_after, _text, cursor);
428         text = utf8_mbstowcs(_text);
429         return true;
430     }
431
432     bool
433     slot_delete_surrounding_text (IMEngineInstanceBase *si,
434                                   int                   offset,
435                                   int                   len)
436     {
437
438         thiz->delete_surrounding_text (offset, len);
439         return true;
440     }
441
442     bool
443     slot_get_selection (IMEngineInstanceBase *si,
444                         WideString            &text)
445     {
446         String _text;
447         thiz->get_selection_text (_text);
448         text = utf8_mbstowcs (_text);
449         return true;
450     }
451
452     bool
453     slot_set_selection (IMEngineInstanceBase *si,
454                         int              start,
455                         int              end)
456     {
457         thiz->set_selection (start, end);
458         return true;
459     }
460
461     void
462     slot_expand_candidate (IMEngineInstanceBase *si)
463     {
464         thiz->expand_candidate ();
465     }
466
467     void
468     slot_contract_candidate (IMEngineInstanceBase *si)
469     {
470         thiz->contract_candidate ();
471     }
472
473     void
474     slot_set_candidate_style (IMEngineInstanceBase *si, ISF_CANDIDATE_PORTRAIT_LINE_T portrait_line, ISF_CANDIDATE_MODE_T mode)
475     {
476         thiz->set_candidate_style (portrait_line, mode);
477     }
478
479     void
480     slot_send_private_command (IMEngineInstanceBase *si,
481                                const String &command)
482     {
483         thiz->send_private_command (command);
484     }
485
486     void
487     slot_commit_content (IMEngineInstanceBase *si,
488                          const String &content,
489                          const String &description,
490                          const String &mime_types)
491     {
492         LOGD ("");
493         thiz->commit_content (content, description, mime_types);
494     }
495
496     void
497     attach_instance ()
498     {
499         si->signal_connect_show_preedit_string (
500             slot (this, &HelperAgent::HelperAgentImpl::slot_show_preedit_string));
501         si->signal_connect_show_aux_string (
502             slot (this, &HelperAgent::HelperAgentImpl::slot_show_aux_string));
503         si->signal_connect_show_lookup_table (
504             slot (this, &HelperAgent::HelperAgentImpl::slot_show_lookup_table));
505
506         si->signal_connect_hide_preedit_string (
507             slot (this, &HelperAgent::HelperAgentImpl::slot_hide_preedit_string));
508         si->signal_connect_hide_aux_string (
509             slot (this, &HelperAgent::HelperAgentImpl::slot_hide_aux_string));
510         si->signal_connect_hide_lookup_table (
511             slot (this, &HelperAgent::HelperAgentImpl::slot_hide_lookup_table));
512
513         si->signal_connect_update_preedit_caret (
514             slot (this, &HelperAgent::HelperAgentImpl::slot_update_preedit_caret));
515         si->signal_connect_update_preedit_string (
516             slot (this, &HelperAgent::HelperAgentImpl::slot_update_preedit_string));
517         si->signal_connect_update_preedit_string_with_commit (
518             slot (this, &HelperAgent::HelperAgentImpl::slot_update_preedit_string_with_commit));
519         si->signal_connect_recapture_string (
520             slot (this, &HelperAgent::HelperAgentImpl::slot_recapture_string));
521
522         si->signal_connect_update_aux_string (
523             slot (this, &HelperAgent::HelperAgentImpl::slot_update_aux_string));
524         si->signal_connect_update_lookup_table (
525             slot (this, &HelperAgent::HelperAgentImpl::slot_update_lookup_table));
526
527         si->signal_connect_commit_string (
528             slot (this, &HelperAgent::HelperAgentImpl::slot_commit_string));
529
530         si->signal_connect_forward_key_event (
531             slot (this, &HelperAgent::HelperAgentImpl::slot_forward_key_event));
532
533         si->signal_connect_register_properties (
534             slot (this, &HelperAgent::HelperAgentImpl::slot_register_properties));
535
536         si->signal_connect_update_property (
537             slot (this, &HelperAgent::HelperAgentImpl::slot_update_property));
538
539         si->signal_connect_beep (
540             slot (this, &HelperAgent::HelperAgentImpl::slot_beep));
541
542         si->signal_connect_start_helper (
543             slot (this, &HelperAgent::HelperAgentImpl::slot_start_helper));
544
545         si->signal_connect_stop_helper (
546             slot (this, &HelperAgent::HelperAgentImpl::slot_stop_helper));
547
548         si->signal_connect_send_helper_event (
549             slot (this, &HelperAgent::HelperAgentImpl::slot_send_helper_event));
550
551         si->signal_connect_get_surrounding_text (
552             slot (this, &HelperAgent::HelperAgentImpl::slot_get_surrounding_text));
553
554         si->signal_connect_delete_surrounding_text (
555             slot (this, &HelperAgent::HelperAgentImpl::slot_delete_surrounding_text));
556
557         si->signal_connect_get_selection (
558             slot (this, &HelperAgent::HelperAgentImpl::slot_get_selection));
559
560         si->signal_connect_set_selection (
561             slot (this, &HelperAgent::HelperAgentImpl::slot_set_selection));
562
563         si->signal_connect_expand_candidate (
564             slot (this, &HelperAgent::HelperAgentImpl::slot_expand_candidate));
565         si->signal_connect_contract_candidate (
566             slot (this, &HelperAgent::HelperAgentImpl::slot_contract_candidate));
567
568         si->signal_connect_set_candidate_style (
569             slot (this, &HelperAgent::HelperAgentImpl::slot_set_candidate_style));
570
571         si->signal_connect_send_private_command (
572             slot (this, &HelperAgent::HelperAgentImpl::slot_send_private_command));
573     }
574 public:
575     void process_key_event_done (KeyEvent &key, uint32 ret, uint32 serial) {
576         LOGD ("ret: %d, serial: %d", ret, serial);
577         if (socket_active.is_connected ()) {
578             send.clear ();
579             send.put_command (SCIM_TRANS_CMD_REQUEST);
580             send.put_data (magic_active);
581             send.put_command (ISM_TRANS_CMD_PROCESS_KEY_EVENT_DONE);
582             send.put_data (key);
583             send.put_data (ret);
584             send.put_data (serial);
585             send.write_to_socket (socket_active, magic_active);
586         }
587     }
588
589     void request_ise_hide () {
590         if (socket_active.is_connected ()) {
591             send.clear ();
592             send.put_command (SCIM_TRANS_CMD_REQUEST);
593             send.put_data (magic_active);
594             send.put_command (ISM_TRANS_CMD_REQUEST_ISE_HIDE);
595             send.write_to_socket (socket_active, magic_active);
596         }
597     }
598 private:
599     HelperAgentImpl () : magic (0), magic_active (0), timeout (-1), focused_ic ((uint32) -1), thiz (NULL), surrounding_text (NULL), selection_text (NULL), cursor_pos (0), need_update_surrounding_text (0), need_update_selection_text (0), layout (0), ise_show_flag (false), hw_keyboard_mode (false), need_update_entry_metadata (false), ise_focus_flag (false), finalized_text (NULL), finalized_cursor_pos (0), engine_loader_flag (false) { }
600 };
601
602 static MessageQueue message_queue;
603
604 HelperAgent::HelperAgent ()
605     : m_impl (new HelperAgentImpl (this))
606 {
607     message_queue.create();
608 }
609
610 HelperAgent::~HelperAgent ()
611 {
612     message_queue.destroy();
613     delete m_impl;
614 }
615
616 /**
617  * @brief Open socket connection to the Panel.
618  *
619  * @param info The information of this Helper object.
620  * @param display The display which this Helper object should run on.
621  *
622  * @return The connection socket id. -1 means failed to create
623  *         the connection.
624  */
625 int
626 HelperAgent::open_connection (const HelperInfo &info,
627                               const String     &display)
628 {
629     if (m_impl->socket.is_connected ())
630         close_connection ();
631
632     SocketAddress address (scim_get_default_panel_socket_address (display));
633     int timeout = m_impl->timeout = scim_get_default_socket_timeout ();
634     uint32 magic;
635
636     if (!address.valid ())
637         return -1;
638
639     int i = 0;
640     std::cerr << " Connecting to PanelAgent server.";
641     ISF_LOG (" Connecting to PanelAgent server.\n");
642     while (!m_impl->socket.connect (address)) {
643         std::cerr << ".";
644         scim_usleep (100000);
645         if (++i == 200) {
646             std::cerr << "m_impl->socket.connect () is failed!!!\n";
647             ISF_LOG ("m_impl->socket.connect () is failed!!!\n");
648             return -1;
649         }
650     }
651     std::cerr << " Connected :" << i << "\n";
652     ISF_LOG ("  Connected :%d\n", i);
653     LOGD ("Connection to PanelAgent succeeded, %d", i);
654
655     /* Let's retry 10 times when failed */
656     int open_connection_retries = 0;
657     while (!scim_socket_open_connection (magic,
658                                       String ("Helper"),
659                                       String ("Panel"),
660                                       m_impl->socket,
661                                       timeout)) {
662         if (++open_connection_retries > 10) {
663             m_impl->socket.close ();
664             std::cerr << "scim_socket_open_connection () is failed!!!\n";
665             ISF_LOG ("scim_socket_open_connection () is failed!!!\n");
666             ISF_SAVE_LOG ("scim_socket_open_connection failed, %d", timeout);
667
668             return -1;
669         }
670
671         /* Retry after re-connecting the socket */
672         if (m_impl->socket.is_connected ())
673             close_connection ();
674
675         /* This time, just retry atmost 2 seconds */
676         i = 0;
677         while (!m_impl->socket.connect (address) && ++i < 10) {
678             scim_usleep (200000);
679         }
680     }
681
682     ISF_LOG ("scim_socket_open_connection () is successful.\n");
683     LOGD ("scim_socket_open_connection successful");
684
685     m_impl->send.clear ();
686     m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
687     m_impl->send.put_data (magic);
688     m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_REGISTER_HELPER);
689     m_impl->send.put_data (info.uuid);
690     m_impl->send.put_data (info.name);
691     m_impl->send.put_data (info.icon);
692     m_impl->send.put_data (info.description);
693     m_impl->send.put_data (info.option);
694
695     if (!m_impl->send.write_to_socket (m_impl->socket, magic)) {
696         m_impl->socket.close ();
697         return -1;
698     }
699
700     int cmd;
701     if (m_impl->recv.read_from_socket (m_impl->socket, timeout) &&
702         m_impl->recv.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
703         m_impl->recv.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {
704         m_impl->magic = magic;
705
706         while (m_impl->recv.get_command (cmd)) {
707             switch (cmd) {
708                 case SCIM_TRANS_CMD_HELPER_ATTACH_INPUT_CONTEXT:
709                 {
710                     uint32 ic;
711                     String ic_uuid;
712                     while (m_impl->recv.get_data (ic) && m_impl->recv.get_data (ic_uuid))
713                         m_impl->signal_attach_input_context (this, ic, ic_uuid);
714                     break;
715                 }
716                 case SCIM_TRANS_CMD_UPDATE_SCREEN:
717                 {
718                     uint32 screen;
719                     if (m_impl->recv.get_data (screen))
720                         m_impl->signal_update_screen (this, (uint32) -1, String (""), (int) screen);
721                     break;
722                 }
723                 default:
724                     break;
725             }
726         }
727     } else {
728         //FIXME: Attaching input context is needed for desktop environment
729         LOGW ("Attach input context and update screen failed");
730     }
731
732     ISF_SAVE_LOG ("Trying connect() with Helper_Active");
733
734     /* connect to the panel agent as the active helper client */
735     if (!m_impl->socket_active.connect (address)) return -1;
736     open_connection_retries = 0;
737     while (!scim_socket_open_connection (magic,
738                                       String ("Helper_Active"),
739                                       String ("Panel"),
740                                       m_impl->socket_active,
741                                       timeout)) {
742         if (++open_connection_retries > 10) {
743             m_impl->socket_active.close ();
744             std::cerr << "Helper_Active scim_socket_open_connection () is failed!!!\n";
745             ISF_LOG ("Helper_Active scim_socket_open_connection () is failed!!!\n");
746             ISF_SAVE_LOG ("Helper_Active scim_socket_open_connection failed, %d", timeout);
747
748             return -1;
749         }
750
751         /* Retry after re-connecting the socket */
752         if (m_impl->socket_active.is_connected ())
753             m_impl->socket_active.close ();
754
755         /* This time, just retry atmost 2 seconds */
756         i = 0;
757         while (!m_impl->socket_active.connect (address) && ++i < 10) {
758             scim_usleep (200000);
759         }
760     }
761
762     m_impl->magic_active = magic;
763
764     m_impl->send.clear ();
765     m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
766     m_impl->send.put_data (magic);
767     m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_REGISTER_ACTIVE_HELPER);
768     m_impl->send.put_data (info.uuid);
769     m_impl->send.put_data (info.name);
770     m_impl->send.put_data (info.icon);
771     m_impl->send.put_data (info.description);
772     m_impl->send.put_data (info.option);
773
774     if (!m_impl->send.write_to_socket (m_impl->socket_active, magic)) {
775         ISF_SAVE_LOG ("Helper_Active write_to_socket() failed");
776         m_impl->socket_active.close ();
777         return -1;
778     }
779     m_impl->m_config = ConfigBase::get (false, "socket");
780
781     return m_impl->socket.get_id ();
782 }
783
784 /**
785  * @brief Close the socket connection to Panel.
786  */
787 void
788 HelperAgent::close_connection ()
789 {
790     m_impl->socket.close ();
791     m_impl->socket_active.close ();
792     m_impl->send.clear ();
793     m_impl->recv.clear ();
794     m_impl->magic        = 0;
795     m_impl->magic_active = 0;
796     m_impl->timeout      = 0;
797 }
798
799 /**
800  * @brief Get the connection id previously returned by open_connection().
801  *
802  * @return the connection id
803  */
804 int
805 HelperAgent::get_connection_number () const
806 {
807     if (m_impl->socket.is_connected ())
808         return m_impl->socket.get_id ();
809     return -1;
810 }
811
812 /**
813  * @brief Check whether this HelperAgent has been connected to a Panel.
814  *
815  * Return true when it is connected to panel, otherwise return false.
816  */
817 bool
818 HelperAgent::is_connected () const
819 {
820     return m_impl->socket.is_connected ();
821 }
822
823 /**
824  * @brief Check if there are any events available to be processed.
825  *
826  * If it returns true then Helper object should call
827  * HelperAgent::filter_event() to process them.
828  *
829  * @return true if there are any events available.
830  */
831 bool
832 HelperAgent::has_pending_event () const
833 {
834     if (m_impl->socket.is_connected () && m_impl->socket.wait_for_data (0) > 0)
835         return true;
836
837     if (message_queue.has_pending_message())
838         return true;
839
840     return false;
841 }
842
843 /**
844  * @brief Process the pending events.
845  *
846  * This function will emit the corresponding signals according
847  * to the events.
848  *
849  * @return false if the connection is broken, otherwise return true.
850  */
851 bool
852 HelperAgent::filter_event ()
853 {
854     if (!m_impl->socket.is_connected ()) {
855         LOGW("Connection lost, returning false");
856         return false;
857     }
858
859     if (m_impl->recv.read_from_socket (m_impl->socket, m_impl->timeout)) {
860         message_queue.read_from_transaction(m_impl->recv);
861
862         while (message_queue.has_pending_message()) {
863             MessageItem *message = message_queue.get_pending_message();
864             handle_message(message);
865             message_queue.remove_message(message);
866         }
867     } else {
868         LOGD("read_from_socket() failed but continuing");
869     }
870
871     return true;
872 }
873
874
875 /**
876  * @brief Read messages from socket buffer, and see if there is a message with the given cmd.
877  *
878  * @return false if the connection is broken, or no message available with given cmd. Otherwise return true.
879  */
880 bool
881 HelperAgent::wait_for_message(int cmd, int timeout)
882 {
883     struct timeval t0 = { 0, 0 };
884     struct timeval t1 = { 0, 0 };
885     struct timeval t2 = { 0, 0 };
886
887     gettimeofday(&t0, NULL);
888
889     do {
890         if (!m_impl->socket.is_connected() || !m_impl->recv.read_from_socket(m_impl->socket, timeout))
891             return false;
892
893         message_queue.read_from_transaction(m_impl->recv);
894         if (message_queue.has_pending_message_by_cmd(cmd)) {
895             return true;
896         }
897
898         gettimeofday(&t1, NULL);
899         timersub(&t1, &t0, &t2);
900     } while (t2.tv_sec < timeout);
901
902     return false;
903 }
904
905 /**
906  * @brief Process one message that is in our message queue.
907  *
908  * This function will emit the corresponding signals according
909  * to the events.
910  *
911  * @param message The message that needs to be handled.
912  *
913  * @return false if the connection is broken, otherwise return true.
914  */
915 bool
916 HelperAgent::handle_message (MessageItem *message)
917 {
918     if (!message)
919         return false;
920
921     int cmd = message->get_command_ref();
922     LOGD ("HelperAgent::cmd = %d", cmd);
923     switch (cmd) {
924         case SCIM_TRANS_CMD_EXIT:
925         {
926             MessageItemExit *subclass = static_cast<MessageItemExit*>(message);
927             ISF_SAVE_LOG ("Helper ISE received SCIM_TRANS_CMD_EXIT message");
928             m_impl->signal_exit(this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
929             break;
930         }
931         case SCIM_TRANS_CMD_RELOAD_CONFIG:
932         {
933             MessageItemReloadConfig *subclass = static_cast<MessageItemReloadConfig*>(message);
934             m_impl->signal_reload_config (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
935             if (!m_impl->m_config.null())
936                 m_impl->m_config->ConfigBase::reload();
937             break;
938         }
939         case SCIM_TRANS_CMD_UPDATE_SCREEN:
940         {
941             MessageItemUpdateScreen *subclass = static_cast<MessageItemUpdateScreen*>(message);
942             m_impl->signal_update_screen (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
943                 subclass->get_screen_ref());
944             break;
945         }
946         case SCIM_TRANS_CMD_UPDATE_SPOT_LOCATION:
947         {
948             MessageItemUpdateSpotLocation *subclass = static_cast<MessageItemUpdateSpotLocation*>(message);
949             m_impl->signal_update_spot_location (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
950                 subclass->get_x_ref(), subclass->get_y_ref());
951             break;
952         }
953         case ISM_TRANS_CMD_UPDATE_CURSOR_POSITION:
954         {
955             MessageItemUpdateCursorPosition *subclass = static_cast<MessageItemUpdateCursorPosition*>(message);
956             m_impl->cursor_pos = subclass->get_cursor_pos_ref();
957             LOGD ("update cursor position %d", subclass->get_cursor_pos_ref());
958             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
959                 m_impl->signal_update_cursor_position (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
960                     subclass->get_cursor_pos_ref());
961             }
962             if (!m_impl->si.null ()) m_impl->si->update_cursor_position(subclass->get_cursor_pos_ref());
963             break;
964         }
965         case ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT:
966         {
967             MessageItemUpdateSurroundingText *subclass = static_cast<MessageItemUpdateSurroundingText*>(message);
968             if (m_impl->surrounding_text != NULL)
969                 free (m_impl->surrounding_text);
970             m_impl->surrounding_text = strdup (subclass->get_text_ref().c_str ());
971             m_impl->cursor_pos = subclass->get_cursor_ref();
972             SECURE_LOGD ("surrounding text: %s, %d", m_impl->surrounding_text, subclass->get_cursor_ref());
973             while (m_impl->need_update_surrounding_text > 0) {
974                 m_impl->need_update_surrounding_text--;
975                 m_impl->signal_update_surrounding_text (this, subclass->get_ic_ref(),
976                     subclass->get_text_ref(), subclass->get_cursor_ref());
977             }
978             break;
979         }
980         case ISM_TRANS_CMD_UPDATE_SELECTION:
981         {
982             MessageItemUpdateSelection *subclass = static_cast<MessageItemUpdateSelection*>(message);
983             if (m_impl->selection_text != NULL)
984                 free (m_impl->selection_text);
985
986             m_impl->selection_text = strdup (subclass->get_text_ref().c_str ());
987             SECURE_LOGD ("selection text: %s", m_impl->selection_text);
988
989             while (m_impl->need_update_selection_text > 0) {
990                 m_impl->need_update_selection_text--;
991                 m_impl->signal_update_selection (this, subclass->get_ic_ref(), subclass->get_text_ref());
992             }
993             break;
994         }
995         case SCIM_TRANS_CMD_TRIGGER_PROPERTY:
996         {
997             MessageItemTriggerProperty *subclass = static_cast<MessageItemTriggerProperty*>(message);
998             m_impl->signal_trigger_property (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
999                 subclass->get_property_ref());
1000             if (!m_impl->si.null ()) m_impl->si->trigger_property(subclass->get_property_ref());
1001             break;
1002         }
1003         case SCIM_TRANS_CMD_HELPER_PROCESS_IMENGINE_EVENT:
1004         {
1005             MessageItemHelperProcessImengineEvent *subclass = static_cast<MessageItemHelperProcessImengineEvent*>(message);
1006             m_impl->signal_process_imengine_event (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1007                 subclass->get_transaction_ref());
1008             break;
1009         }
1010         case SCIM_TRANS_CMD_HELPER_ATTACH_INPUT_CONTEXT:
1011         {
1012             MessageItemHelperAttachInputContext *subclass = static_cast<MessageItemHelperAttachInputContext*>(message);
1013             m_impl->signal_attach_input_context (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1014             break;
1015         }
1016         case SCIM_TRANS_CMD_HELPER_DETACH_INPUT_CONTEXT:
1017         {
1018             MessageItemHelperDetachInputContext *subclass = static_cast<MessageItemHelperDetachInputContext*>(message);
1019             m_impl->signal_detach_input_context (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1020             break;
1021         }
1022         case SCIM_TRANS_CMD_FOCUS_OUT:
1023         {
1024             MessageItemFocusOut *subclass = static_cast<MessageItemFocusOut*>(message);
1025             m_impl->ise_focus_flag = false;
1026             m_impl->signal_focus_out (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1027             m_impl->focused_ic = (uint32) -1;
1028             if (!m_impl->si.null ()) m_impl->si->focus_out();
1029             m_impl->need_update_entry_metadata = false;
1030             break;
1031         }
1032         case SCIM_TRANS_CMD_FOCUS_IN:
1033         {
1034             MessageItemFocusIn *subclass = static_cast<MessageItemFocusIn*>(message);
1035             m_impl->ise_focus_flag = true;
1036             if (_WEARABLE)
1037                 m_impl->need_update_entry_metadata = false;
1038             m_impl->signal_focus_in (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1039             m_impl->focused_ic = subclass->get_ic_ref();
1040             if (m_impl->finalized_text != NULL)
1041                 free(m_impl->finalized_text);
1042             m_impl->finalized_text = NULL;
1043             m_impl->finalized_cursor_pos = 0;
1044             if (!m_impl->si.null ()) m_impl->si->focus_in();
1045             break;
1046         }
1047         case ISM_TRANS_CMD_SHOW_ISE_PANEL:
1048         {
1049             MessageItemShowISEPanel *subclass = static_cast<MessageItemShowISEPanel*>(message);
1050             LOGD ("Helper ISE received ISM_TRANS_CMD_SHOW_ISE_PANEL message");
1051
1052             m_impl->signal_ise_show (this, subclass->get_ic_ref(), *(subclass->get_data_ptr()),
1053                 subclass->get_len_ref());
1054             m_impl->ise_show_flag = true;
1055             break;
1056         }
1057         case ISM_TRANS_CMD_HIDE_ISE_PANEL:
1058         {
1059             MessageItemHideISEPanel *subclass = static_cast<MessageItemHideISEPanel*>(message);
1060             LOGD ("Helper ISE received ISM_TRANS_CMD_HIDE_ISE_PANEL message");
1061             if (m_impl->ise_show_flag)
1062                 m_impl->signal_ise_hide (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1063             m_impl->ise_show_flag = false;
1064             break;
1065         }
1066         case ISM_TRANS_CMD_GET_ACTIVE_ISE_GEOMETRY:
1067         {
1068             struct rectinfo info = {0, 0, 0, 0};
1069             m_impl->signal_get_geometry (this, info);
1070             m_impl->send.clear ();
1071             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1072             m_impl->send.put_data (info.pos_x);
1073             m_impl->send.put_data (info.pos_y);
1074             m_impl->send.put_data (info.width);
1075             m_impl->send.put_data (info.height);
1076             m_impl->send.write_to_socket (m_impl->socket);
1077             break;
1078         }
1079         case ISM_TRANS_CMD_SET_ISE_MODE:
1080         {
1081             MessageItemSetISEMode *subclass = static_cast<MessageItemSetISEMode*>(message);
1082             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1083                 m_impl->signal_set_mode (this, subclass->get_mode_ref());
1084             }
1085             break;
1086         }
1087         case ISM_TRANS_CMD_SET_ISE_LANGUAGE:
1088         {
1089             MessageItemSetISELanguage *subclass = static_cast<MessageItemSetISELanguage*>(message);
1090             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1091                 m_impl->signal_set_language (this, subclass->get_language_ref());
1092             }
1093             break;
1094         }
1095         case ISM_TRANS_CMD_SET_ISE_IMDATA:
1096         {
1097             MessageItemSetISEImData *subclass = static_cast<MessageItemSetISEImData*>(message);
1098             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode) {
1099                 m_impl->signal_set_imdata (this, *(subclass->get_imdata_ptr()), subclass->get_len_ref());
1100             }
1101             if (!m_impl->si.null ()) m_impl->si->set_imdata(*(subclass->get_imdata_ptr()),
1102                 subclass->get_len_ref());
1103             break;
1104         }
1105         case ISM_TRANS_CMD_GET_ISE_IMDATA:
1106         {
1107             char   *buf = NULL;
1108             size_t  len = 0;
1109
1110             m_impl->signal_get_imdata (this, &buf, len);
1111             LOGD ("send ise imdata len = %zu", len);
1112             m_impl->send.clear ();
1113             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1114             m_impl->send.put_data (buf, len);
1115             m_impl->send.write_to_socket (m_impl->socket);
1116             if (NULL != buf)
1117                 free(buf);
1118             break;
1119         }
1120         case ISM_TRANS_CMD_GET_ISE_LANGUAGE_LOCALE:
1121         {
1122             MessageItemGetISELanguageLocale *subclass = static_cast<MessageItemGetISELanguageLocale*>(message);
1123             char *buf = NULL;
1124             m_impl->signal_get_language_locale (this, subclass->get_ic_ref(), &buf);
1125             m_impl->send.clear ();
1126             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1127             if (buf != NULL)
1128                 m_impl->send.put_data (buf, strlen (buf));
1129             m_impl->send.write_to_socket (m_impl->socket);
1130             if (NULL != buf)
1131                 free(buf);
1132             break;
1133         }
1134         case ISM_TRANS_CMD_SET_RETURN_KEY_TYPE:
1135         {
1136             MessageItemSetReturnKeyType *subclass = static_cast<MessageItemSetReturnKeyType*>(message);
1137             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1138                 m_impl->signal_set_return_key_type (this, subclass->get_type_ref());
1139             }
1140             break;
1141         }
1142         case ISM_TRANS_CMD_GET_RETURN_KEY_TYPE:
1143         {
1144             uint32 type = 0;
1145             m_impl->signal_get_return_key_type (this, type);
1146             m_impl->send.clear ();
1147             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1148             m_impl->send.put_data (type);
1149             m_impl->send.write_to_socket (m_impl->socket);
1150             break;
1151         }
1152         case ISM_TRANS_CMD_SET_RETURN_KEY_DISABLE:
1153         {
1154             MessageItemSetReturnKeyDisable *subclass = static_cast<MessageItemSetReturnKeyDisable*>(message);
1155             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1156                 m_impl->signal_set_return_key_disable (this, subclass->get_disabled_ref());
1157             }
1158             break;
1159         }
1160         case ISM_TRANS_CMD_GET_RETURN_KEY_DISABLE:
1161         {
1162             uint32 disabled = 0;
1163             m_impl->signal_get_return_key_type (this, disabled);
1164             m_impl->send.clear ();
1165             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1166             m_impl->send.put_data (disabled);
1167             m_impl->send.write_to_socket (m_impl->socket);
1168             break;
1169         }
1170         case SCIM_TRANS_CMD_PROCESS_KEY_EVENT:
1171         {
1172             MessageItemProcessKeyEvent *subclass = static_cast<MessageItemProcessKeyEvent*>(message);
1173             uint32 ret = 0;
1174             uint32 keycode_ret = 0;
1175             m_impl->signal_process_key_event(this, subclass->get_key_ref(), ret);
1176             m_impl->signal_process_key_event_with_keycode(this, subclass->get_key_ref(), keycode_ret, subclass->get_keycode_ref());
1177
1178             if (ret != 0 || keycode_ret != 0) {
1179                 ret = 1;
1180                 m_impl->process_key_event_done (subclass->get_key_ref(), ret, subclass->get_serial_ref());
1181                 break;
1182             }
1183
1184             if (!(subclass->get_key_ref().get_key_string().compare("KeyRelease+XF86Back") == 0 ||
1185                   subclass->get_key_ref().get_key_string().compare("XF86Back") == 0)) {
1186                 if (m_impl->engine_loader_flag) {
1187                     m_impl->signal_process_key_event_with_imengine(this, subclass->get_key_ref(), subclass->get_serial_ref());
1188                     SECURE_LOGD ("imengine process key %d", subclass->get_key_ref().code);
1189                 } else {
1190                     if (!m_impl->si.null ()) {
1191                         ret = m_impl->si->process_key_event (subclass->get_key_ref());
1192                         SECURE_LOGD ("imengine(%s) process key %d return %d", m_impl->si->get_factory_uuid().c_str(),
1193                             subclass->get_key_ref().code, ret);
1194                     }
1195                     m_impl->process_key_event_done (subclass->get_key_ref(), ret, subclass->get_serial_ref());
1196                 }
1197             } else
1198                 m_impl->process_key_event_done (subclass->get_key_ref(), ret, subclass->get_serial_ref());
1199             break;
1200         }
1201         case ISM_TRANS_CMD_SET_LAYOUT:
1202         {
1203             MessageItemSetLayout *subclass = static_cast<MessageItemSetLayout*>(message);
1204             m_impl->layout = subclass->get_layout_ref();
1205             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1206                 m_impl->signal_set_layout (this, subclass->get_layout_ref());
1207             }
1208             if (!m_impl->si.null ()) m_impl->si->set_layout(subclass->get_layout_ref());
1209             break;
1210         }
1211         case ISM_TRANS_CMD_GET_LAYOUT:
1212         {
1213             uint32 layout = 0;
1214
1215             m_impl->signal_get_layout (this, layout);
1216             m_impl->send.clear ();
1217             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1218             m_impl->send.put_data (layout);
1219             m_impl->send.write_to_socket (m_impl->socket);
1220             break;
1221         }
1222         case ISM_TRANS_CMD_SET_INPUT_MODE:
1223         {
1224             MessageItemSetInputMode *subclass = static_cast<MessageItemSetInputMode*>(message);
1225             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1226                 m_impl->signal_set_input_mode (this, subclass->get_input_mode_ref());
1227             }
1228             break;
1229         }
1230         case ISM_TRANS_CMD_SET_CAPS_MODE:
1231         {
1232             MessageItemSetCapsMode *subclass = static_cast<MessageItemSetCapsMode*>(message);
1233             m_impl->signal_set_caps_mode (this, subclass->get_mode_ref());
1234             break;
1235         }
1236         case SCIM_TRANS_CMD_PANEL_RESET_INPUT_CONTEXT:
1237         {
1238             MessageItemPanelResetInputContext *subclass = static_cast<MessageItemPanelResetInputContext*>(message);
1239             m_impl->signal_reset_input_context (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1240             if (!m_impl->si.null ()) m_impl->si->reset();
1241             break;
1242         }
1243         case ISM_TRANS_CMD_UPDATE_CANDIDATE_UI:
1244         {
1245             MessageItemUpdateCandidateUI *subclass = static_cast<MessageItemUpdateCandidateUI*>(message);
1246             m_impl->signal_update_candidate_ui (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1247                 subclass->get_style_ref(), subclass->get_mode_ref());
1248             break;
1249         }
1250         case ISM_TRANS_CMD_UPDATE_CANDIDATE_GEOMETRY:
1251         {
1252             MessageItemUpdateCandidateGeometry *subclass = static_cast<MessageItemUpdateCandidateGeometry*>(message);
1253             m_impl->signal_update_candidate_geometry (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1254                 subclass->get_rectinfo_ref());
1255             break;
1256         }
1257         case ISM_TRANS_CMD_UPDATE_KEYBOARD_ISE:
1258         {
1259             MessageItemUpdateKeyboardISE *subclass = static_cast<MessageItemUpdateKeyboardISE*>(message);
1260             m_impl->signal_update_keyboard_ise (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1261                 subclass->get_name_ref(), subclass->get_uuid_ref());
1262             break;
1263         }
1264         case ISM_TRANS_CMD_UPDATE_KEYBOARD_ISE_LIST:
1265         {
1266             MessageItemUpdateKeyboardISEList *subclass = static_cast<MessageItemUpdateKeyboardISEList*>(message);
1267             m_impl->signal_update_keyboard_ise_list (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1268                 subclass->get_list_ref());
1269             break;
1270         }
1271         case ISM_TRANS_CMD_CANDIDATE_MORE_WINDOW_SHOW:
1272         {
1273             MessageItemCandidateMoreWindowShow *subclass = static_cast<MessageItemCandidateMoreWindowShow*>(message);
1274             m_impl->signal_candidate_more_window_show (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1275             if (!m_impl->si.null ()) m_impl->si->candidate_more_window_show();
1276             break;
1277         }
1278         case ISM_TRANS_CMD_CANDIDATE_MORE_WINDOW_HIDE:
1279         {
1280             MessageItemCandidateMoreWindowHide *subclass = static_cast<MessageItemCandidateMoreWindowHide*>(message);
1281             m_impl->signal_candidate_more_window_hide (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1282             if (!m_impl->si.null ()) m_impl->si->candidate_more_window_hide();
1283             break;
1284         }
1285         case ISM_TRANS_CMD_SELECT_AUX:
1286         {
1287             MessageItemSelectAux *subclass = static_cast<MessageItemSelectAux*>(message);
1288             m_impl->signal_select_aux (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1289                 subclass->get_item_ref());
1290             if (!m_impl->si.null ()) m_impl->si->select_aux(subclass->get_item_ref());
1291             break;
1292         }
1293         case SCIM_TRANS_CMD_SELECT_CANDIDATE: //FIXME:remove if useless
1294         {
1295             MessageItemSelectCandidate *subclass = static_cast<MessageItemSelectCandidate*>(message);
1296             m_impl->signal_select_candidate (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1297                 subclass->get_item_ref());
1298             if (!m_impl->si.null ()) m_impl->si->select_candidate(subclass->get_item_ref());
1299             break;
1300         }
1301         case SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_UP: //FIXME:remove if useless
1302         {
1303             MessageItemLookupTablePageUp *subclass = static_cast<MessageItemLookupTablePageUp*>(message);
1304             m_impl->signal_candidate_table_page_up (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1305             if (!m_impl->si.null ()) m_impl->si->lookup_table_page_up();
1306             break;
1307         }
1308         case SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_DOWN: //FIXME:remove if useless
1309         {
1310             MessageItemLookupTablePageDown *subclass = static_cast<MessageItemLookupTablePageDown*>(message);
1311             m_impl->signal_candidate_table_page_down (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1312             if (!m_impl->si.null ()) m_impl->si->lookup_table_page_down();
1313             break;
1314         }
1315         case SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE_PAGE_SIZE:
1316         {
1317             MessageItemUpdateLookupTablePageSize *subclass = static_cast<MessageItemUpdateLookupTablePageSize*>(message);
1318             m_impl->signal_update_candidate_table_page_size (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1319                 subclass->get_size_ref());
1320             if (!m_impl->si.null ()) m_impl->si->update_lookup_table_page_size(subclass->get_size_ref());
1321             break;
1322         }
1323         case ISM_TRANS_CMD_CANDIDATE_SHOW: //FIXME:remove if useless
1324         {
1325             MessageItemCandidateShow *subclass = static_cast<MessageItemCandidateShow*>(message);
1326             m_impl->signal_candidate_show (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1327             break;
1328         }
1329         case ISM_TRANS_CMD_CANDIDATE_HIDE: //FIXME:remove if useless
1330         {
1331             MessageItemCandidateHide *subclass = static_cast<MessageItemCandidateHide*>(message);
1332             m_impl->signal_candidate_hide (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1333             break;
1334         }
1335         case ISM_TRANS_CMD_UPDATE_LOOKUP_TABLE: //FIXME:remove if useless
1336         {
1337             MessageItemUpdateLookupTable *subclass = static_cast<MessageItemUpdateLookupTable*>(message);
1338             m_impl->signal_update_lookup_table (this, subclass->get_candidate_table_ref());
1339             break;
1340         }
1341         case ISM_TRANS_CMD_UPDATE_CANDIDATE_ITEM_LAYOUT:
1342         {
1343             MessageItemUpdateCandidateItemLayout *subclass = static_cast<MessageItemUpdateCandidateItemLayout*>(message);
1344             m_impl->signal_update_candidate_item_layout (this, subclass->get_row_items_ref());
1345             if (!m_impl->si.null ()) m_impl->si->update_candidate_item_layout(subclass->get_row_items_ref());
1346             break;
1347         }
1348         case ISM_TRANS_CMD_SELECT_ASSOCIATE:
1349         {
1350             MessageItemSelectAssociate *subclass = static_cast<MessageItemSelectAssociate*>(message);
1351             m_impl->signal_select_associate (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1352                 subclass->get_item_ref());
1353             break;
1354         }
1355         case ISM_TRANS_CMD_ASSOCIATE_TABLE_PAGE_UP:
1356         {
1357             MessageItemAssociateTablePageUp *subclass = static_cast<MessageItemAssociateTablePageUp*>(message);
1358             m_impl->signal_associate_table_page_up (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1359             break;
1360         }
1361         case ISM_TRANS_CMD_ASSOCIATE_TABLE_PAGE_DOWN:
1362         {
1363             MessageItemAssociateTablePageDown *subclass = static_cast<MessageItemAssociateTablePageDown*>(message);
1364             m_impl->signal_associate_table_page_down (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1365             break;
1366         }
1367         case ISM_TRANS_CMD_UPDATE_ASSOCIATE_TABLE_PAGE_SIZE:
1368         {
1369             MessageItemUpdateAssociateTablePageSize *subclass = static_cast<MessageItemUpdateAssociateTablePageSize*>(message);
1370             m_impl->signal_update_associate_table_page_size (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1371                 subclass->get_size_ref());
1372             break;
1373         }
1374         case ISM_TRANS_CMD_RESET_ISE_CONTEXT:
1375         {
1376             MessageItemResetISEContext *subclass = static_cast<MessageItemResetISEContext*>(message);
1377             m_impl->signal_reset_ise_context (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1378             m_impl->signal_reset_input_context (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1379             if (!m_impl->si.null ()) m_impl->si->reset();
1380             break;
1381         }
1382         case ISM_TRANS_CMD_TURN_ON_LOG:
1383         {
1384             MessageItemTurnOnLog *subclass = static_cast<MessageItemTurnOnLog*>(message);
1385             m_impl->signal_turn_on_log (this, subclass->get_state_ref());
1386             break;
1387         }
1388         case ISM_TRANS_CMD_UPDATE_DISPLAYED_CANDIDATE:
1389         {
1390             MessageItemUpdateDisplayedCandidate *subclass = static_cast<MessageItemUpdateDisplayedCandidate*>(message);
1391             m_impl->signal_update_displayed_candidate_number (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1392                 subclass->get_size_ref());
1393             if (!m_impl->si.null ()) m_impl->si->update_displayed_candidate_number(subclass->get_size_ref());
1394             break;
1395         }
1396         case ISM_TRANS_CMD_LONGPRESS_CANDIDATE:
1397         {
1398             MessageItemLongpressCandidate *subclass = static_cast<MessageItemLongpressCandidate*>(message);
1399             m_impl->signal_longpress_candidate (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1400                 subclass->get_index_ref());
1401             if (!m_impl->si.null ()) m_impl->si->longpress_candidate(subclass->get_index_ref());
1402             break;
1403         }
1404         case ISM_TRANS_CMD_SET_INPUT_HINT:
1405         {
1406             MessageItemSetInputHint *subclass = static_cast<MessageItemSetInputHint*>(message);
1407             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1408                 m_impl->signal_set_input_hint (this, subclass->get_input_hint_ref());
1409             }
1410             if (!m_impl->si.null ()) m_impl->si->set_input_hint(subclass->get_input_hint_ref());
1411             break;
1412         }
1413         case ISM_TRANS_CMD_UPDATE_BIDI_DIRECTION:
1414         {
1415             MessageItemUpdateBidiDirection *subclass = static_cast<MessageItemUpdateBidiDirection*>(message);
1416             m_impl->signal_update_bidi_direction (this, subclass->get_bidi_direction());
1417             if (!m_impl->si.null ()) m_impl->si->update_bidi_direction(subclass->get_bidi_direction());
1418             break;
1419         }
1420         case ISM_TRANS_CMD_SHOW_ISE_OPTION_WINDOW:
1421         {
1422             MessageItemShowISEOptionWindow *subclass = static_cast<MessageItemShowISEOptionWindow*>(message);
1423             m_impl->signal_show_option_window (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1424             break;
1425         }
1426         case ISM_TRANS_CMD_RESUME_ISE_OPTION_WINDOW:
1427         {
1428             MessageItemResumeISEOptionWindow *subclass = static_cast<MessageItemResumeISEOptionWindow*>(message);
1429             m_impl->signal_resume_option_window (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1430             break;
1431         }
1432         case ISM_TRANS_CMD_CHECK_OPTION_WINDOW:
1433         {
1434             uint32 avail = 0;
1435             m_impl->signal_check_option_window (this, avail);
1436             m_impl->send.clear ();
1437             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1438             m_impl->send.put_data (avail);
1439             m_impl->send.write_to_socket (m_impl->socket);
1440             break;
1441         }
1442         case ISM_TRANS_CMD_PROCESS_INPUT_DEVICE_EVENT:
1443         {
1444             MessageItemProcessInputDeviceEvent *subclass = static_cast<MessageItemProcessInputDeviceEvent*>(message);
1445             uint32 ret = 0;
1446             unsigned int ecore_event_id = find_ecore_event_from_device_type((isf_device_type_e)(subclass->get_type_ref()));
1447             char *decoded = (char*)malloc(subclass->get_len_ref());
1448             size_t decoded_size = subclass->get_len_ref();
1449             if (decoded) {
1450                 if(device_buffer_decode((const char*)*(subclass->get_data_ptr()),
1451                     subclass->get_len_ref(), (char*)(decoded), &decoded_size)) {
1452                     m_impl->signal_process_input_device_event(this, ecore_event_id, decoded, decoded_size, ret);
1453                 }
1454                 free(decoded);
1455             }
1456             break;
1457         }
1458         case SCIM_TRANS_CMD_SET_AUTOCAPITAL_TYPE:
1459         {
1460             MessageItemSetAutocapitalType *subclass = static_cast<MessageItemSetAutocapitalType*>(message);
1461             if (!m_impl->si.null ()) m_impl->si->set_autocapital_type(subclass->get_auto_capital_type_ref());
1462             m_impl->signal_set_autocapital_type(this, subclass->get_auto_capital_type_ref());
1463             break;
1464         }
1465         case ISM_TRANS_CMD_SET_PREDICTION_ALLOW:
1466         {
1467             MessageItemSetPredictionAllow *subclass = static_cast<MessageItemSetPredictionAllow*>(message);
1468             if (!m_impl->si.null ()) m_impl->si->set_prediction_allow(subclass->get_prediction_allow_ref() == 0 ? false : true);
1469             m_impl->signal_set_prediction_allow(this, subclass->get_prediction_allow_ref());
1470             break;
1471         }
1472         case ISM_TRANS_CMD_SET_KEYBOARD_MODE:
1473         {
1474             MessageItemSetKeyboardMode *subclass = static_cast<MessageItemSetKeyboardMode*>(message);
1475             if (subclass->get_mode_ref())
1476                 m_impl->hw_keyboard_mode = false;
1477             else
1478                 m_impl->hw_keyboard_mode = true;
1479             break;
1480         }
1481         case ISM_TRANS_CMD_SET_PREDICTION_HINT:
1482         {
1483             MessageItemSetPredictionHint *subclass = static_cast<MessageItemSetPredictionHint*>(message);
1484             m_impl->signal_set_prediction_hint (this, subclass->get_message_ref());
1485             break;
1486         }
1487         case ISM_TRANS_CMD_SET_MIME_TYPE:
1488         {
1489             MessageItemSetMimeType *subclass = static_cast<MessageItemSetMimeType*>(message);
1490             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1491                 m_impl->signal_set_mime_type (this, subclass->get_mime_type_ref());
1492             }
1493             break;
1494         }
1495         case ISM_TRANS_CMD_FINALIZE_CONTENT:
1496         {
1497             MessageItemFinalizeContent *subclass = static_cast<MessageItemFinalizeContent*>(message);
1498             if (m_impl) {
1499                 if (m_impl->finalized_text != NULL)
1500                     free(m_impl->finalized_text);
1501                 m_impl->finalized_text = strdup(subclass->get_text_ref().c_str());
1502                 m_impl->finalized_cursor_pos = subclass->get_cursor_pos_ref();
1503             }
1504             break;
1505         }
1506         case ISM_TRANS_CMD_SET_PREDICTION_HINT_DATA:
1507         {
1508             MessageItemSetPredictionHintData *subclass = static_cast<MessageItemSetPredictionHintData*>(message);
1509             m_impl->signal_set_prediction_hint_data (this, 0, subclass->get_key_ref(), subclass->get_value_ref());
1510             break;
1511         }
1512         case ISM_TRANS_CMD_SET_OPTIMIZATION_HINT:
1513         {
1514             MessageItemSetOptimizationHint *subclass = static_cast<MessageItemSetOptimizationHint*>(message);
1515             m_impl->signal_set_optimization_hint(this, subclass->get_hint_ref());
1516             break;
1517         }
1518         default:
1519             break;
1520     }
1521     return true;
1522 }
1523
1524 /**
1525  * @brief Request SCIM to reload all configuration.
1526  *
1527  * This function should only by used by Setup Helper to request
1528  * scim's reloading the configuration.
1529  * Deprecated: reload config message only send by socketconfig client
1530  * using socketconfig::reload instead.
1531  */
1532 void
1533 HelperAgent::reload_config () const
1534 {
1535     LOGD ("send reload config message to isf");
1536     if (!m_impl->m_config.null())
1537         m_impl->m_config->reload();
1538 }
1539
1540 /**
1541  * @brief Register some properties into Panel.
1542  *
1543  * This function send the request to Panel to register a list
1544  * of Properties.
1545  *
1546  * @param properties The list of Properties to be registered into Panel.
1547  *
1548  * @sa scim::Property.
1549  */
1550 void
1551 HelperAgent::register_properties (const PropertyList &properties) const
1552 {
1553     if (m_impl->socket_active.is_connected ()) {
1554         m_impl->send.clear ();
1555         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1556         m_impl->send.put_data (m_impl->magic_active);
1557         m_impl->send.put_command (SCIM_TRANS_CMD_REGISTER_PROPERTIES);
1558         m_impl->send.put_data (properties);
1559         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1560     }
1561 }
1562
1563 /**
1564  * @brief Update a registered property.
1565  *
1566  * @param property The property to be updated.
1567  */
1568 void
1569 HelperAgent::update_property (const Property &property) const
1570 {
1571     if (m_impl->socket_active.is_connected ()) {
1572         m_impl->send.clear ();
1573         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1574         m_impl->send.put_data (m_impl->magic_active);
1575         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_PROPERTY);
1576         m_impl->send.put_data (property);
1577         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1578     }
1579 }
1580
1581 /**
1582  * @brief Send a set of events to an IMEngineInstance.
1583  *
1584  * All events should be put into a Transaction.
1585  * And the events can only be received by one IMEngineInstance object.
1586  *
1587  * @param ic The handle of the Input Context to receive the events.
1588  * @param ic_uuid The UUID of the Input Context.
1589  * @param trans The Transaction object holds the events.
1590  */
1591 void
1592 HelperAgent::send_imengine_event (int                ic,
1593                                   const String      &ic_uuid,
1594                                   const Transaction &trans) const
1595 {
1596 //remove if not necessary
1597 #if 0
1598     if (m_impl->socket_active.is_connected ()) {
1599         m_impl->send.clear ();
1600         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1601         m_impl->send.put_data (m_impl->magic_active);
1602         m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_SEND_IMENGINE_EVENT);
1603         m_impl->send.put_data ((uint32)ic);
1604         m_impl->send.put_data (ic_uuid);
1605         m_impl->send.put_data (trans);
1606         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1607     }
1608 #endif
1609     if (!m_impl->si.null ()) m_impl->si->process_helper_event (ic_uuid, trans);
1610 }
1611
1612 /**
1613  * @brief Send a KeyEvent to an IMEngineInstance.
1614  *
1615  * @param ic The handle of the IMEngineInstance to receive the event.
1616  *        -1 means the currently focused IMEngineInstance.
1617  * @param ic_uuid The UUID of the IMEngineInstance. Empty means don't match.
1618  * @param key The KeyEvent to be sent.
1619  */
1620 void
1621 HelperAgent::send_key_event (int            ic,
1622                              const String   &ic_uuid,
1623                              const KeyEvent &key) const
1624 {
1625
1626     //FIXME: remove shift_mode_off, shift_mode_on, shift_mode_lock from ISE side
1627     if (key.code == SHIFT_MODE_OFF ||
1628         key.code == SHIFT_MODE_ON ||
1629         key.code == SHIFT_MODE_LOCK ||
1630         key.code == SHIFT_MODE_ENABLE ||
1631         key.code == SHIFT_MODE_DISABLE) {
1632         LOGW("FIXME ignore shift codes");
1633         return;
1634     }
1635
1636     if (m_impl->socket_active.is_connected ()) {
1637         m_impl->send.clear ();
1638         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1639         m_impl->send.put_data (m_impl->magic_active);
1640         m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_SEND_KEY_EVENT);
1641         if (ic == -1) {
1642             m_impl->send.put_data (m_impl->focused_ic);
1643         } else {
1644             m_impl->send.put_data ((uint32)ic);
1645         }
1646         m_impl->send.put_data (ic_uuid);
1647         m_impl->send.put_data (key);
1648         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1649     }
1650 }
1651
1652 /**
1653  * @brief Forward a KeyEvent to client application directly.
1654  *
1655  * @param ic The handle of the client Input Context to receive the event.
1656  *        -1 means the currently focused Input Context.
1657  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1658  *        Empty means don't match.
1659  * @param key The KeyEvent to be forwarded.
1660  */
1661 void
1662 HelperAgent::forward_key_event (int            ic,
1663                                 const String   &ic_uuid,
1664                                 const KeyEvent &key) const
1665 {
1666     if (m_impl->socket_active.is_connected ()) {
1667         m_impl->send.clear ();
1668         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1669         m_impl->send.put_data (m_impl->magic_active);
1670         m_impl->send.put_command (SCIM_TRANS_CMD_FORWARD_KEY_EVENT);
1671         if (ic == -1) {
1672             m_impl->send.put_data (m_impl->focused_ic);
1673         } else {
1674             m_impl->send.put_data ((uint32)ic);
1675         }
1676         m_impl->send.put_data (ic_uuid);
1677         m_impl->send.put_data (key);
1678         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1679     }
1680 }
1681
1682 /**
1683  * @brief Commit a WideString to client application directly.
1684  *
1685  * @param ic The handle of the client Input Context to receive the WideString.
1686  *        -1 means the currently focused Input Context.
1687  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1688  *        Empty means don't match.
1689  * @param wstr The WideString to be committed.
1690  */
1691 void
1692 HelperAgent::commit_string (int               ic,
1693                             const String     &ic_uuid,
1694                             const WideString &wstr) const
1695 {
1696     if (m_impl->socket_active.is_connected ()) {
1697         m_impl->send.clear ();
1698         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1699         m_impl->send.put_data (m_impl->magic_active);
1700         m_impl->send.put_command (SCIM_TRANS_CMD_COMMIT_STRING);
1701         if (ic == -1) {
1702             m_impl->send.put_data (m_impl->focused_ic);
1703         } else {
1704             m_impl->send.put_data ((uint32)ic);
1705         }
1706         m_impl->send.put_data (ic_uuid);
1707         m_impl->send.put_data (wstr);
1708         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1709     }
1710 }
1711
1712 void
1713 HelperAgent::commit_string (int               ic,
1714                             const String     &ic_uuid,
1715                             const  char      *buf,
1716                             int               buflen) const
1717 {
1718     if (m_impl->socket_active.is_connected ()) {
1719         m_impl->send.clear ();
1720         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1721         m_impl->send.put_data (m_impl->magic_active);
1722         m_impl->send.put_command (SCIM_TRANS_CMD_COMMIT_STRING);
1723         if (ic == -1) {
1724             m_impl->send.put_data (m_impl->focused_ic);
1725         } else {
1726             m_impl->send.put_data ((uint32)ic);
1727         }
1728         m_impl->send.put_data (ic_uuid);
1729         m_impl->send.put_dataw (buf, buflen);
1730         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1731     }
1732 }
1733
1734 /**
1735  * @brief Request to show preedit string.
1736  *
1737  * @param ic The handle of the client Input Context to receive the request.
1738  *        -1 means the currently focused Input Context.
1739  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1740  *        Empty means don't match.
1741  */
1742 void
1743 HelperAgent::show_preedit_string (int               ic,
1744                                   const String     &ic_uuid) const
1745 {
1746
1747     if (m_impl->socket_active.is_connected ()) {
1748         m_impl->send.clear ();
1749         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1750         m_impl->send.put_data (m_impl->magic_active);
1751         m_impl->send.put_command (SCIM_TRANS_CMD_SHOW_PREEDIT_STRING);
1752         m_impl->send.put_data ((uint32)ic);
1753         m_impl->send.put_data (ic_uuid);
1754         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1755     }
1756 }
1757
1758 /**
1759  * @brief Request to show aux string.
1760  */
1761 void
1762 HelperAgent::show_aux_string (void) const
1763 {
1764
1765     if (m_impl->socket_active.is_connected ()) {
1766         m_impl->send.clear ();
1767         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1768         m_impl->send.put_data (m_impl->magic_active);
1769         m_impl->send.put_command (SCIM_TRANS_CMD_SHOW_AUX_STRING);
1770         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1771     }
1772 }
1773
1774 /**
1775  * @brief Request to show candidate string.
1776  */
1777 void
1778 HelperAgent::show_candidate_string (void) const
1779 {
1780
1781     if (m_impl->socket_active.is_connected ()) {
1782         m_impl->send.clear ();
1783         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1784         m_impl->send.put_data (m_impl->magic_active);
1785         m_impl->send.put_command (SCIM_TRANS_CMD_SHOW_LOOKUP_TABLE);
1786         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1787     }
1788 }
1789
1790 /**
1791  * @brief Request to show associate string.
1792  */
1793 void
1794 HelperAgent::show_associate_string (void) const
1795 {
1796     if (m_impl->socket_active.is_connected ()) {
1797         m_impl->send.clear ();
1798         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1799         m_impl->send.put_data (m_impl->magic_active);
1800         m_impl->send.put_command (ISM_TRANS_CMD_SHOW_ASSOCIATE_TABLE);
1801         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1802     }
1803 }
1804
1805 /**
1806  * @brief Request to hide preedit string.
1807  *
1808  * @param ic The handle of the client Input Context to receive the request.
1809  *        -1 means the currently focused Input Context.
1810  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1811  *        Empty means don't match.
1812  */
1813 void
1814 HelperAgent::hide_preedit_string (int               ic,
1815                                   const String     &ic_uuid) const
1816 {
1817
1818     if (m_impl->socket_active.is_connected ()) {
1819         m_impl->send.clear ();
1820         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1821         m_impl->send.put_data (m_impl->magic_active);
1822         m_impl->send.put_command (SCIM_TRANS_CMD_HIDE_PREEDIT_STRING);
1823         m_impl->send.put_data ((uint32)ic);
1824         m_impl->send.put_data (ic_uuid);
1825         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1826     }
1827 }
1828
1829 /**
1830  * @brief Request to hide aux string.
1831  */
1832 void
1833 HelperAgent::hide_aux_string (void) const
1834 {
1835     if (m_impl->socket_active.is_connected ()) {
1836         m_impl->send.clear ();
1837         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1838         m_impl->send.put_data (m_impl->magic_active);
1839         m_impl->send.put_command (SCIM_TRANS_CMD_HIDE_AUX_STRING);
1840         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1841     }
1842 }
1843
1844 /**
1845  * @brief Request to hide candidate string.
1846  */
1847 void
1848 HelperAgent::hide_candidate_string (void) const
1849 {
1850     if (m_impl->socket_active.is_connected ()) {
1851         m_impl->send.clear ();
1852         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1853         m_impl->send.put_data (m_impl->magic_active);
1854         m_impl->send.put_command (SCIM_TRANS_CMD_HIDE_LOOKUP_TABLE);
1855         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1856     }
1857 }
1858
1859 /**
1860  * @brief Request to hide associate string.
1861  */
1862 void
1863 HelperAgent::hide_associate_string (void) const
1864 {
1865     if (m_impl->socket_active.is_connected ()) {
1866         m_impl->send.clear ();
1867         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1868         m_impl->send.put_data (m_impl->magic_active);
1869         m_impl->send.put_command (ISM_TRANS_CMD_HIDE_ASSOCIATE_TABLE);
1870         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1871     }
1872 }
1873
1874 /**
1875  * @brief Update a new WideString for preedit.
1876  *
1877  * @param ic The handle of the client Input Context to receive the WideString.
1878  *        -1 means the currently focused Input Context.
1879  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1880  *        Empty means don't match.
1881  * @param str The WideString to be updated.
1882  * @param attrs The attribute list for preedit string.
1883  */
1884 void
1885 HelperAgent::update_preedit_string (int                  ic,
1886                                     const String        &ic_uuid,
1887                                     const WideString    &str,
1888                                     const AttributeList &attrs) const
1889 {
1890     update_preedit_string (ic, ic_uuid, str, str, attrs, -1);
1891 }
1892
1893 void
1894 HelperAgent::update_preedit_string (int                  ic,
1895                                     const String        &ic_uuid,
1896                                     const char         *buf,
1897                                     int                 buflen,
1898                                     const AttributeList &attrs) const
1899 {
1900     update_preedit_string (ic, ic_uuid, buf, buflen, attrs, -1);
1901 }
1902
1903 /**
1904  * @brief Update a new WideString for preedit.
1905  *
1906  * @param ic The handle of the client Input Context to receive the WideString.
1907  *        -1 means the currently focused Input Context.
1908  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1909  *        Empty means don't match.
1910  * @param str The WideString to be updated.
1911  * @param attrs The attribute list for preedit string.
1912  * @param caret The caret position in preedit string.
1913  */
1914 void
1915 HelperAgent::update_preedit_string (int                  ic,
1916                                     const String        &ic_uuid,
1917                                     const WideString    &wstr,
1918                                     const AttributeList &attrs,
1919                                     int            caret) const
1920 {
1921     update_preedit_string (ic, ic_uuid, wstr, wstr, attrs, caret);
1922 }
1923
1924 void
1925 HelperAgent::update_preedit_string (int                 ic,
1926                                     const String       &ic_uuid,
1927                                     const char         *buf,
1928                                     int                 buflen,
1929                                     const AttributeList &attrs,
1930                                     int            caret) const
1931 {
1932
1933     if (m_impl->socket_active.is_connected ()) {
1934         m_impl->send.clear ();
1935         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1936         m_impl->send.put_data (m_impl->magic_active);
1937         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING);
1938         m_impl->send.put_data ((uint32)ic);
1939         m_impl->send.put_data (ic_uuid);
1940         m_impl->send.put_dataw (buf, buflen);
1941         m_impl->send.put_dataw (buf, buflen);
1942         m_impl->send.put_data (attrs);
1943         m_impl->send.put_data (caret);
1944         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1945     }
1946 }
1947
1948 void
1949 HelperAgent::update_preedit_string (int                  ic,
1950                                     const String        &ic_uuid,
1951                                     const WideString    &preedit,
1952                                     const WideString    &commit,
1953                                     const AttributeList &attrs,
1954                                     int                  caret) const
1955 {
1956     if (m_impl->socket_active.is_connected ()) {
1957         m_impl->send.clear ();
1958         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1959         m_impl->send.put_data (m_impl->magic_active);
1960         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING);
1961         m_impl->send.put_data ((uint32)ic);
1962         m_impl->send.put_data (ic_uuid);
1963         m_impl->send.put_data (preedit);
1964         m_impl->send.put_data (commit);
1965         m_impl->send.put_data (attrs);
1966         m_impl->send.put_data (caret);
1967         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1968     }
1969 }
1970
1971 /**
1972  * @brief Update the preedit caret position in the preedit string.
1973  *
1974  * @param caret - the new position of the preedit caret.
1975  */
1976 void
1977 HelperAgent::update_preedit_caret (int caret) const
1978 {
1979
1980     if (m_impl->socket_active.is_connected ()) {
1981         m_impl->send.clear ();
1982         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1983         m_impl->send.put_data (m_impl->magic_active);
1984         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET);
1985         m_impl->send.put_data ((uint32)caret);
1986         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1987     }
1988 }
1989
1990 /**
1991  * @brief Update a new string for aux.
1992  *
1993  * @param str The string to be updated.
1994  * @param attrs The attribute list for aux string.
1995  */
1996 void
1997 HelperAgent::update_aux_string (const String        &str,
1998                                 const AttributeList &attrs) const
1999 {
2000     if (m_impl->socket_active.is_connected ()) {
2001         m_impl->send.clear ();
2002         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2003         m_impl->send.put_data (m_impl->magic_active);
2004         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_AUX_STRING);
2005         m_impl->send.put_data (str);
2006         m_impl->send.put_data (attrs);
2007         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2008     }
2009 }
2010
2011 /**
2012  * @brief Request to update candidate.
2013  *
2014  * @param table The lookup table for candidate.
2015  */
2016 void
2017 HelperAgent::update_candidate_string (const LookupTable &table) const
2018 {
2019     if (m_impl->socket_active.is_connected ()) {
2020         m_impl->send.clear ();
2021         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2022         m_impl->send.put_data (m_impl->magic_active);
2023         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE);
2024         m_impl->send.put_data (table);
2025         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2026     }
2027 }
2028
2029 /**
2030  * @brief Request to update associate.
2031  *
2032  * @param table The lookup table for associate.
2033  */
2034 void
2035 HelperAgent::update_associate_string (const LookupTable &table) const
2036 {
2037     if (m_impl->socket_active.is_connected ()) {
2038         m_impl->send.clear ();
2039         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2040         m_impl->send.put_data (m_impl->magic_active);
2041         m_impl->send.put_command (ISM_TRANS_CMD_UPDATE_ASSOCIATE_TABLE);
2042         m_impl->send.put_data (table);
2043         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2044     }
2045 }
2046
2047 /**
2048  * @brief When the input context of ISE is changed,
2049  *         ISE can call this function to notify application
2050  *
2051  * @param type  type of event.
2052  * @param value value of event.
2053  */
2054 void
2055 HelperAgent::update_input_context (uint32 type, uint32 value) const
2056 {
2057     if (type == ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT) {
2058         /* Update all state variables that could be queried by the client application */
2059         char *buf = NULL;
2060         m_impl->signal_get_language_locale(this, -1, &buf);
2061
2062         if (buf != NULL) {
2063             if (m_impl->socket_active.is_connected()) {
2064                 m_impl->send.clear();
2065                 m_impl->send.put_command(SCIM_TRANS_CMD_REQUEST);
2066                 m_impl->send.put_data(m_impl->magic_active);
2067                 m_impl->send.put_command(ISM_TRANS_CMD_UPDATE_ISE_LANGUAGE_LOCALE);
2068                 m_impl->send.put_data(buf, strlen(buf));
2069                 m_impl->send.write_to_socket(m_impl->socket_active, m_impl->magic_active);
2070             }
2071             free(buf);
2072             buf = NULL;
2073         }
2074     }
2075
2076     if (m_impl->socket_active.is_connected ()) {
2077         m_impl->send.clear ();
2078         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2079         m_impl->send.put_data (m_impl->magic_active);
2080         m_impl->send.put_command (ISM_TRANS_CMD_UPDATE_ISE_INPUT_CONTEXT);
2081         m_impl->send.put_data (type);
2082         m_impl->send.put_data (value);
2083         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2084     }
2085 }
2086
2087 /**
2088  * @brief Request to get surrounding text asynchronously.
2089  *
2090  * @param uuid The helper ISE UUID.
2091  * @param maxlen_before The max length of before.
2092  * @param maxlen_after The max length of after.
2093  */
2094 void
2095 HelperAgent::get_surrounding_text (const String &uuid, int maxlen_before, int maxlen_after) const
2096 {
2097     if (m_impl->socket_active.is_connected () && (m_impl->need_update_surrounding_text == 0)) {
2098         m_impl->send.clear ();
2099         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2100         m_impl->send.put_data (m_impl->magic_active);
2101         m_impl->send.put_command (SCIM_TRANS_CMD_GET_SURROUNDING_TEXT);
2102         m_impl->send.put_data (uuid);
2103         m_impl->send.put_data (maxlen_before);
2104         m_impl->send.put_data (maxlen_after);
2105         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2106     }
2107     m_impl->need_update_surrounding_text++;
2108 }
2109
2110 /**
2111  * @brief Request to get surrounding text synchronously.
2112  *
2113  * @param uuid The helper ISE UUID.
2114  * @param maxlen_before The max length of before.
2115  * @param maxlen_after The max length of after.
2116  * @param text The surrounding text.
2117  * @param cursor The cursor position.
2118  */
2119 void
2120 HelperAgent::get_surrounding_text (int maxlen_before, int maxlen_after, String &text, int &cursor)
2121 {
2122     if (!m_impl->socket_active.is_connected ())
2123         return;
2124
2125     if (!m_impl->ise_focus_flag) {
2126         if (m_impl->finalized_text) {
2127             String buffer = m_impl->finalized_text;
2128             cursor = m_impl->finalized_cursor_pos;
2129             int pos = cursor - maxlen_before;
2130             if (maxlen_before < 0) pos = 0;
2131             if (pos > (int)buffer.length()) pos = (int)buffer.length();
2132             if (pos < 0) pos = 0;
2133             size_t len = maxlen_after + (cursor - pos);
2134             if (maxlen_after < 0) len = String::npos;
2135             text = buffer.substr (pos, len);
2136         } else {
2137             text.clear ();
2138             cursor = 0;
2139         }
2140     } else {
2141         m_impl->send.clear();
2142         m_impl->send.put_command(SCIM_TRANS_CMD_REQUEST);
2143         m_impl->send.put_data(m_impl->magic_active);
2144         m_impl->send.put_command(SCIM_TRANS_CMD_GET_SURROUNDING_TEXT);
2145         m_impl->send.put_data("");
2146         m_impl->send.put_data(maxlen_before);
2147         m_impl->send.put_data(maxlen_after);
2148         m_impl->send.write_to_socket(m_impl->socket_active, m_impl->magic_active);
2149         if (m_impl->surrounding_text) {
2150             free(m_impl->surrounding_text);
2151             m_impl->surrounding_text = NULL;
2152         }
2153
2154         const int WAIT_FOR_SYNC_RESPONSE_TIMEOUT = 1000;
2155         /* Now we are waiting for the ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT message */
2156         if (wait_for_message(ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT, WAIT_FOR_SYNC_RESPONSE_TIMEOUT)) {
2157             MessageItem *message = message_queue.get_pending_message_by_cmd(ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT);
2158             handle_message(message);
2159             message_queue.remove_message(message);
2160
2161             if (m_impl->surrounding_text) {
2162                 text = m_impl->surrounding_text;
2163                 cursor = m_impl->cursor_pos;
2164             }
2165         }
2166
2167         if (m_impl->surrounding_text) {
2168             free(m_impl->surrounding_text);
2169             m_impl->surrounding_text = NULL;
2170         }
2171
2172         LOGD("message_queue size : %d", message_queue.get_message_size());
2173
2174         m_impl->send.clear ();
2175         m_impl->send.put_command(SCIM_TRANS_CMD_REQUEST);
2176         m_impl->send.put_data(m_impl->magic_active);
2177         m_impl->send.put_command(SCIM_TRANS_CMD_PING);
2178         m_impl->send.write_to_socket(m_impl->socket_active, m_impl->magic_active);
2179     }
2180 }
2181
2182 /**
2183  * @brief Request to delete surrounding text.
2184  *
2185  * @param offset The offset for cursor position.
2186  * @param len The length for delete text.
2187  */
2188 void
2189 HelperAgent::delete_surrounding_text (int offset, int len) const
2190 {
2191     LOGD ("offset = %d, len = %d", offset, len);
2192
2193     if (m_impl->socket_active.is_connected ()) {
2194         m_impl->send.clear ();
2195         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2196         m_impl->send.put_data (m_impl->magic_active);
2197         m_impl->send.put_command (SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT);
2198         m_impl->send.put_data (offset);
2199         m_impl->send.put_data (len);
2200         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2201     }
2202 }
2203
2204 /**
2205  * @brief Request to get selection text asynchronously.
2206  *
2207  * @param uuid The helper ISE UUID.
2208  */
2209 void
2210 HelperAgent::get_selection (const String &uuid) const
2211 {
2212     if (m_impl->socket_active.is_connected () && (m_impl->need_update_selection_text == 0)) {
2213         m_impl->send.clear ();
2214         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2215         m_impl->send.put_data (m_impl->magic_active);
2216         m_impl->send.put_command (SCIM_TRANS_CMD_GET_SELECTION);
2217         m_impl->send.put_data (uuid);
2218         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2219     }
2220     m_impl->need_update_selection_text++;
2221 }
2222
2223 /**
2224  * @brief Request to get selection text synchronously.
2225  *
2226  * @param text The selection text.
2227  */
2228 void
2229 HelperAgent::get_selection_text (String &text)
2230 {
2231
2232     if (!m_impl->socket_active.is_connected ())
2233         return;
2234
2235     m_impl->send.clear ();
2236     m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2237     m_impl->send.put_data (m_impl->magic_active);
2238     m_impl->send.put_command (SCIM_TRANS_CMD_GET_SELECTION);
2239     m_impl->send.put_data ("");
2240     m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2241     if (m_impl->selection_text) {
2242         free (m_impl->selection_text);
2243         m_impl->selection_text = NULL;
2244     }
2245
2246     const int WAIT_FOR_SYNC_RESPONSE_TIMEOUT = 1000;
2247     /* Now we are waiting for the ISM_TRANS_CMD_UPDATE_SELECTION message */
2248     if (wait_for_message(ISM_TRANS_CMD_UPDATE_SELECTION, WAIT_FOR_SYNC_RESPONSE_TIMEOUT)) {
2249         MessageItem *message = message_queue.get_pending_message_by_cmd(ISM_TRANS_CMD_UPDATE_SELECTION);
2250         handle_message(message);
2251         message_queue.remove_message(message);
2252         if (m_impl->selection_text) {
2253             text = m_impl->selection_text;
2254         }
2255     }
2256
2257     if (m_impl->selection_text) {
2258         free (m_impl->selection_text);
2259         m_impl->selection_text = NULL;
2260     }
2261
2262     LOGD("message_queue size : %d", message_queue.get_message_size());
2263
2264     m_impl->send.clear ();
2265     m_impl->send.put_command(SCIM_TRANS_CMD_REQUEST);
2266     m_impl->send.put_data(m_impl->magic_active);
2267     m_impl->send.put_command(SCIM_TRANS_CMD_PING);
2268     m_impl->send.write_to_socket(m_impl->socket_active, m_impl->magic_active);
2269 }
2270
2271 /**
2272  * @brief Request to select text.
2273  *
2274  * @param start The start position in text.
2275  * @param end The end position in text.
2276  */
2277 void
2278 HelperAgent::set_selection (int start, int end) const
2279 {
2280     if (m_impl->socket_active.is_connected ()) {
2281         m_impl->send.clear ();
2282         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2283         m_impl->send.put_data (m_impl->magic_active);
2284         m_impl->send.put_command (SCIM_TRANS_CMD_SET_SELECTION);
2285         m_impl->send.put_data (start);
2286         m_impl->send.put_data (end);
2287         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2288     }
2289 }
2290
2291 /**
2292  * @brief Send a private command to an application.
2293  *
2294  * @param command The private command sent from IME.
2295  */
2296 void
2297 HelperAgent::send_private_command (const String &command) const
2298 {
2299     if (m_impl->socket_active.is_connected ()) {
2300         m_impl->send.clear ();
2301         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2302         m_impl->send.put_data (m_impl->magic_active);
2303         m_impl->send.put_command (SCIM_TRANS_CMD_SEND_PRIVATE_COMMAND);
2304         m_impl->send.put_data (command);
2305         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2306     }
2307 }
2308
2309 /**
2310  * @brief Commit content to an application.
2311  *
2312  * @param content The content sent from IME.
2313  */
2314 void
2315 HelperAgent::commit_content (const String &content, const String &description, const String &mime_types) const
2316 {
2317     LOGD ("");
2318     if (m_impl->socket_active.is_connected ()) {
2319         m_impl->send.clear ();
2320         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2321         m_impl->send.put_data (m_impl->magic_active);
2322         m_impl->send.put_command (SCIM_TRANS_CMD_COMMIT_CONTENT);
2323         m_impl->send.put_data (content);
2324         m_impl->send.put_data (description);
2325         m_impl->send.put_data (mime_types);
2326         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2327     }
2328 }
2329
2330 /**
2331  * @brief Request to get uuid list of all keyboard ISEs.
2332  *
2333  * @param uuid The helper ISE UUID.
2334  */
2335 void
2336 HelperAgent::get_keyboard_ise_list (const String &uuid) const
2337 {
2338     if (m_impl->socket_active.is_connected ()) {
2339         m_impl->send.clear ();
2340         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2341         m_impl->send.put_data (m_impl->magic_active);
2342         m_impl->send.put_command (ISM_TRANS_CMD_GET_KEYBOARD_ISE_LIST);
2343         m_impl->send.put_data (uuid);
2344         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2345     }
2346 }
2347
2348 /**
2349  * @brief Set candidate position in screen.
2350  *
2351  * @param left The x position in screen.
2352  * @param top The y position in screen.
2353  */
2354 void
2355 HelperAgent::set_candidate_position (int left, int top) const
2356 {
2357     if (m_impl->socket_active.is_connected ()) {
2358         m_impl->send.clear ();
2359         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2360         m_impl->send.put_data (m_impl->magic_active);
2361         m_impl->send.put_command (ISM_TRANS_CMD_SET_CANDIDATE_POSITION);
2362         m_impl->send.put_data (left);
2363         m_impl->send.put_data (top);
2364         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2365     }
2366 }
2367
2368 /**
2369  * @brief Set candidate style.
2370  *
2371  * @param portrait_line - the displayed line number for portrait mode.
2372  * @param mode          - candidate window mode.
2373  */
2374 void
2375 HelperAgent::set_candidate_style (ISF_CANDIDATE_PORTRAIT_LINE_T portrait_line,
2376                                   ISF_CANDIDATE_MODE_T          mode) const
2377 {
2378     if (m_impl->socket_active.is_connected ()) {
2379         m_impl->send.clear ();
2380         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2381         m_impl->send.put_data (m_impl->magic_active);
2382         m_impl->send.put_command (ISM_TRANS_CMD_SET_CANDIDATE_UI);
2383         m_impl->send.put_data (portrait_line);
2384         m_impl->send.put_data (mode);
2385         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2386     }
2387 }
2388
2389 /**
2390  * @brief Request to hide candidate window.
2391  */
2392 void
2393 HelperAgent::candidate_hide (void) const
2394 {
2395     if (m_impl->socket_active.is_connected ()) {
2396         m_impl->send.clear ();
2397         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2398         m_impl->send.put_data (m_impl->magic_active);
2399         m_impl->send.put_command (ISM_TRANS_CMD_HIDE_CANDIDATE);
2400         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2401     }
2402 }
2403
2404 /**
2405  * @brief Request to get candidate window size and position.
2406  *
2407  * @param uuid The helper ISE UUID.
2408  */
2409 void
2410 HelperAgent::get_candidate_window_geometry (const String &uuid) const
2411 {
2412     if (m_impl->socket_active.is_connected ()) {
2413         m_impl->send.clear ();
2414         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2415         m_impl->send.put_data (m_impl->magic_active);
2416         m_impl->send.put_command (ISM_TRANS_CMD_GET_CANDIDATE_GEOMETRY);
2417         m_impl->send.put_data (uuid);
2418         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2419     }
2420 }
2421
2422 /**
2423  * @brief Set current keyboard ISE.
2424  *
2425  * @param uuid The keyboard ISE UUID.
2426  */
2427 void
2428 HelperAgent::set_keyboard_ise_by_uuid (const String &uuid) const
2429 {
2430     ImeInfoDB imeInfo;
2431     IMEngineFactoryPointer factory;
2432     IMEngineModule *engine_module = NULL;
2433     static int instance_count = 1;
2434
2435     if ((!m_impl->si.null ()) && m_impl->si->get_factory_uuid () == uuid) {
2436         ISF_SAVE_LOG ("Already in UUID: %s", uuid.c_str());
2437         return;
2438     }
2439
2440     if (!m_impl->si.null()) {
2441         m_impl->si->focus_out();
2442         m_impl->si.reset();
2443     }
2444
2445     if (m_impl->m_config.null ()) {
2446         ISF_SAVE_LOG ("config is not working");
2447         return;
2448     }
2449
2450 #ifdef HAVE_PKGMGR_INFO
2451     int ret = 0;
2452     char *pkgid = NULL;
2453     pkgmgrinfo_appinfo_h handle;
2454     ret = pkgmgrinfo_appinfo_get_appinfo(uuid.c_str(), &handle);
2455     if (ret != PMINFO_R_OK) {
2456         ISF_SAVE_LOG ("Retrieve app info failed : %s", uuid.c_str ());
2457         return;
2458     }
2459
2460     ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
2461     if (ret != PMINFO_R_OK) {
2462         ISF_SAVE_LOG ("Retrieve pkgid failed : %s, %p", uuid.c_str(), handle);
2463         pkgmgrinfo_appinfo_destroy_appinfo(handle);
2464         return;
2465     }
2466
2467     imeInfo.module_name = pkgid;
2468     pkgmgrinfo_appinfo_destroy_appinfo(handle);
2469 #else
2470     if (isf_db_select_ime_info_by_appid(uuid.c_str(), &imeInfo) < 1) {
2471         ISF_SAVE_LOG ("ime_info row is not available for %s", uuid.c_str());
2472         return;
2473     }
2474 #endif
2475
2476     engine_module = &m_impl->engine_module;
2477
2478     if (engine_module->valid() && imeInfo.module_name != engine_module->get_module_name()) {
2479         ISF_SAVE_LOG ("imengine module %s unloaded", engine_module->get_module_name().c_str());
2480         engine_module->unload();
2481     }
2482
2483     if (!engine_module->valid()) {
2484         if (engine_module->load (imeInfo.module_name, m_impl->m_config) == false) {
2485             ISF_SAVE_LOG ("load module %s failed", imeInfo.module_name.c_str());
2486             return;
2487         }
2488         ISF_SAVE_LOG ("imengine module %s loaded", imeInfo.module_name.c_str());
2489     }
2490
2491     for (size_t j = 0; j < engine_module->number_of_factories (); ++j) {
2492         try {
2493             factory = engine_module->create_factory (j);
2494             if (factory.null () == false && factory->get_uuid () == uuid)
2495                 break;
2496         } catch (...) {
2497             factory.reset ();
2498             return;
2499         }
2500     }
2501
2502     if (factory.null()) {
2503         ISF_SAVE_LOG ("imengine uuid %s is not found", uuid.c_str());
2504         return;
2505     }
2506
2507     m_impl->si = factory->create_instance ("UTF-8", instance_count++);
2508     if (m_impl->si.null ()) {
2509         ISF_SAVE_LOG ("create_instance %s failed", uuid.c_str ());
2510         return;
2511     }
2512
2513     m_impl->attach_instance ();
2514     ISF_SAVE_LOG ("Require UUID: %s Current UUID: %s", uuid.c_str (), m_impl->si->get_factory_uuid ().c_str ());
2515     m_impl->si->set_layout (m_impl->layout);
2516     if (m_impl->focused_ic != (uint32)-1)
2517         m_impl->si->focus_in ();
2518 }
2519
2520 /**
2521  * @brief Request to get current keyboard ISE information.
2522  *
2523  * @param uuid The helper ISE UUID.
2524  */
2525 void
2526 HelperAgent::get_keyboard_ise (const String &uuid) const
2527 {
2528     //FIXME: maybe useless
2529 #if 0
2530     if (m_impl->socket_active.is_connected ()) {
2531         m_impl->send.clear ();
2532         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2533         m_impl->send.put_data (m_impl->magic_active);
2534         m_impl->send.put_command (ISM_TRANS_CMD_GET_KEYBOARD_ISE);
2535         m_impl->send.put_data (uuid);
2536         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2537     }
2538 #endif
2539 }
2540
2541 /**
2542  * @brief Update ISE window geometry.
2543  *
2544  * @param x      The x position in screen.
2545  * @param y      The y position in screen.
2546  * @param width  The ISE window width.
2547  * @param height The ISE window height.
2548  */
2549 void
2550 HelperAgent::update_geometry (int x, int y, int width, int height) const
2551 {
2552     if (m_impl->socket_active.is_connected ()) {
2553         m_impl->send.clear ();
2554         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2555         m_impl->send.put_data (m_impl->magic_active);
2556         m_impl->send.put_command (ISM_TRANS_CMD_UPDATE_ISE_GEOMETRY);
2557         m_impl->send.put_data (x);
2558         m_impl->send.put_data (y);
2559         m_impl->send.put_data (width);
2560         m_impl->send.put_data (height);
2561         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2562     }
2563 }
2564
2565 /**
2566  * @brief Request to expand candidate window.
2567  */
2568 void
2569 HelperAgent::expand_candidate (void) const
2570 {
2571     if (m_impl->socket_active.is_connected ()) {
2572         m_impl->send.clear ();
2573         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2574         m_impl->send.put_data (m_impl->magic_active);
2575         m_impl->send.put_command (ISM_TRANS_CMD_EXPAND_CANDIDATE);
2576         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2577     }
2578 }
2579
2580 /**
2581  * @brief Request to contract candidate window.
2582  */
2583 void
2584 HelperAgent::contract_candidate (void) const
2585 {
2586     if (m_impl->socket_active.is_connected ()) {
2587         m_impl->send.clear ();
2588         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2589         m_impl->send.put_data (m_impl->magic_active);
2590         m_impl->send.put_command (ISM_TRANS_CMD_CONTRACT_CANDIDATE);
2591         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2592     }
2593 }
2594
2595 /**
2596  * @brief Send selected candidate string index number.
2597  */
2598 void
2599 HelperAgent::select_candidate (int index) const
2600 {
2601     if (!m_impl->si.null ())
2602         m_impl->si->select_candidate (index);
2603     //FIXME: maybe useless
2604 #if 0
2605
2606     if (m_impl->socket_active.is_connected ()) {
2607         m_impl->send.clear ();
2608         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2609         m_impl->send.put_data (m_impl->magic_active);
2610         m_impl->send.put_command (ISM_TRANS_CMD_SELECT_CANDIDATE);
2611         m_impl->send.put_data (index);
2612         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2613     }
2614 #endif
2615 }
2616
2617 /**
2618  * @brief Update our ISE is exiting.
2619  *
2620  * The IME must call this function before terminating IME itself in On-demand mode.
2621  * If this function isn't called, IME will automatically restart.
2622  * This function only works in On-demand mode.
2623  *
2624  */
2625 void
2626 HelperAgent::update_ise_exit (void) const
2627 {
2628     if (m_impl->socket_active.is_connected ()) {
2629         m_impl->send.clear ();
2630         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2631         m_impl->send.put_data (m_impl->magic_active);
2632         m_impl->send.put_command (ISM_TRANS_CMD_UPDATE_ISE_EXIT);
2633         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2634
2635         // The update_ise_exit must be delivered before del_client of isf_info_manager was called.
2636         sync();
2637     }
2638 }
2639
2640 /**
2641  * @brief Request to reset keyboard ISE.
2642  */
2643 void
2644 HelperAgent::reset_keyboard_ise (void) const
2645 {
2646 //FIXME: maybe useless
2647 #if 0
2648     if (m_impl->socket_active.is_connected ()) {
2649         m_impl->send.clear ();
2650         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2651         m_impl->send.put_data (m_impl->magic_active);
2652         m_impl->send.put_command (ISM_TRANS_CMD_PANEL_RESET_KEYBOARD_ISE);
2653         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2654     }
2655 #endif
2656     if (!m_impl->si.null ()) {
2657         m_impl->si->reset ();
2658     }
2659 }
2660
2661 /**
2662  * @brief Request to flush keyboard ISE.
2663  */
2664 void
2665 HelperAgent::flush_keyboard_ise (void) const
2666 {
2667     if (!m_impl->si.null ()) {
2668         m_impl->si->flush ();
2669     }
2670 }
2671
2672 /**
2673  * @brief Request panel to hide ISE.
2674  */
2675 void
2676 HelperAgent::request_ise_hide (void) const
2677 {
2678     if (m_impl->socket_active.is_connected ()) {
2679         m_impl->send.clear ();
2680         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2681         m_impl->send.put_data (m_impl->magic_active);
2682         m_impl->send.put_command (ISM_TRANS_CMD_REQUEST_ISE_HIDE);
2683         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2684     }
2685 }
2686
2687 /**
2688  * @brief Recapture
2689  */
2690 void
2691 HelperAgent::recapture_string (int                  ic,
2692                                const String        &ic_uuid,
2693                                int                  offset,
2694                                int                  len,
2695                                const WideString    &preedit_str,
2696                                const WideString    &commit_str,
2697                                const AttributeList &attrs) const
2698 {
2699     LOGD ("offset = %d, len = %d", offset, len);
2700
2701     if (m_impl->socket_active.is_connected ()) {
2702         m_impl->send.clear ();
2703         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2704         m_impl->send.put_data (m_impl->magic_active);
2705         m_impl->send.put_command (ISM_TRANS_CMD_RECAPTURE_STRING);
2706
2707         m_impl->send.put_data ((uint32)ic);
2708         m_impl->send.put_data (ic_uuid);
2709
2710         // Deleting surrounding text
2711         m_impl->send.put_data (offset);
2712         m_impl->send.put_data (len);
2713
2714         // Update preedit text
2715         m_impl->send.put_data (preedit_str);
2716
2717         // Commit
2718         m_impl->send.put_data (commit_str);
2719
2720         // preedit attributes
2721         m_impl->send.put_data (attrs);
2722
2723         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2724     }
2725 }
2726
2727 void
2728 HelperAgent::set_engine_loader_flag (bool flag)
2729 {
2730     m_impl->engine_loader_flag = flag;
2731 }
2732
2733 void
2734 HelperAgent::send_key_event_processing_result (KeyEvent &key,
2735                                                uint32          serial,
2736                                                bool            is_success) const
2737 {
2738     int ret = is_success ? 1 : 0;
2739     m_impl->process_key_event_done (key, ret, serial);
2740 }
2741
2742 /**
2743  * @brief Connect a slot to Helper exit signal.
2744  *
2745  * This signal is used to let the Helper exit.
2746  *
2747  * The prototype of the slot is:
2748  *
2749  * void exit (const HelperAgent *agent, int ic, const String &ic_uuid);
2750  *
2751  * Parameters:
2752  * - agent    The pointer to the HelperAgent object which emits this signal.
2753  * - ic       An opaque handle of the currently focused input context.
2754  * - ic_uuid  The UUID of the IMEngineInstance associated with the focused input context.
2755  */
2756 Connection
2757 HelperAgent::signal_connect_exit (HelperAgentSlotVoid *slot)
2758 {
2759     return m_impl->signal_exit.connect (slot);
2760 }
2761
2762 /**
2763  * @brief Connect a slot to Helper attach input context signal.
2764  *
2765  * This signal is used to attach an input context to this helper.
2766  *
2767  * When an input context requst to start this helper, then this
2768  * signal will be emitted as soon as the helper is started.
2769  *
2770  * When an input context want to start an already started helper,
2771  * this signal will also be emitted.
2772  *
2773  * Helper can send some events back to the IMEngineInstance in this
2774  * signal-slot, to inform that it has been started sccessfully.
2775  *
2776  * The prototype of the slot is:
2777  *
2778  * void attach_input_context (const HelperAgent *agent, int ic, const String &ic_uuid);
2779  */
2780 Connection
2781 HelperAgent::signal_connect_attach_input_context (HelperAgentSlotVoid *slot)
2782 {
2783     return m_impl->signal_attach_input_context.connect (slot);
2784 }
2785
2786 /**
2787  * @brief Connect a slot to Helper detach input context signal.
2788  *
2789  * This signal is used to detach an input context from this helper.
2790  *
2791  * When an input context requst to stop this helper, then this
2792  * signal will be emitted.
2793  *
2794  * Helper shouldn't send any event back to the IMEngineInstance, because
2795  * the IMEngineInstance attached to the ic should have been destroyed.
2796  *
2797  * The prototype of the slot is:
2798  *
2799  * void detach_input_context (const HelperAgent *agent, int ic, const String &ic_uuid);
2800  */
2801 Connection
2802 HelperAgent::signal_connect_detach_input_context (HelperAgentSlotVoid *slot)
2803 {
2804     return m_impl->signal_detach_input_context.connect (slot);
2805 }
2806
2807 /**
2808  * @brief Connect a slot to Helper reload config signal.
2809  *
2810  * This signal is used to let the Helper reload configuration.
2811  *
2812  * The prototype of the slot is:
2813  *
2814  * void reload_config (const HelperAgent *agent, int ic, const String &ic_uuid);
2815  */
2816 Connection
2817 HelperAgent::signal_connect_reload_config (HelperAgentSlotVoid *slot)
2818 {
2819     return m_impl->signal_reload_config.connect (slot);
2820 }
2821
2822 /**
2823  * @brief Connect a slot to Helper update screen signal.
2824  *
2825  * This signal is used to let the Helper move its GUI to another screen.
2826  * It can only be emitted when SCIM_HELPER_NEED_SCREEN_INFO is set in HelperInfo.option.
2827  *
2828  * The prototype of the slot is:
2829  *
2830  * void update_screen (const HelperAgent *agent, int ic, const String &ic_uuid, int screen_number);
2831  */
2832 Connection
2833 HelperAgent::signal_connect_update_screen (HelperAgentSlotInt *slot)
2834 {
2835     return m_impl->signal_update_screen.connect (slot);
2836 }
2837
2838 /**
2839  * @brief Connect a slot to Helper update spot location signal.
2840  *
2841  * This signal is used to let the Helper move its GUI according to the current spot location.
2842  * It can only be emitted when SCIM_HELPER_NEED_SPOT_LOCATION_INFO is set in HelperInfo.option.
2843  *
2844  * The prototype of the slot is:
2845  * void update_spot_location (const HelperAgent *agent, int ic, const String &ic_uuid, int x, int y);
2846  */
2847 Connection
2848 HelperAgent::signal_connect_update_spot_location (HelperAgentSlotIntInt *slot)
2849 {
2850     return m_impl->signal_update_spot_location.connect (slot);
2851 }
2852
2853 /**
2854  * @brief Connect a slot to Helper update cursor position signal.
2855  *
2856  * This signal is used to let the Helper get the cursor position information.
2857  *
2858  * The prototype of the slot is:
2859  * void update_cursor_position (const HelperAgent *agent, int ic, const String &ic_uuid, int cursor_pos);
2860  */
2861 Connection
2862 HelperAgent::signal_connect_update_cursor_position (HelperAgentSlotInt *slot)
2863 {
2864     return m_impl->signal_update_cursor_position.connect (slot);
2865 }
2866
2867 /**
2868  * @brief Connect a slot to Helper update surrounding text signal.
2869  *
2870  * This signal is used to let the Helper get the surrounding text.
2871  *
2872  * The prototype of the slot is:
2873  * void update_surrounding_text (const HelperAgent *agent, int ic, const String &text, int cursor);
2874  */
2875 Connection
2876 HelperAgent::signal_connect_update_surrounding_text (HelperAgentSlotInt *slot)
2877 {
2878     return m_impl->signal_update_surrounding_text.connect (slot);
2879 }
2880
2881 /**
2882  * @brief Connect a slot to Helper update selection signal.
2883  *
2884  * This signal is used to let the Helper get the selection.
2885  *
2886  * The prototype of the slot is:
2887  * void update_selection (const HelperAgent *agent, int ic, const String &text);
2888  */
2889 Connection
2890 HelperAgent::signal_connect_update_selection (HelperAgentSlotVoid *slot)
2891 {
2892     return m_impl->signal_update_selection.connect (slot);
2893 }
2894
2895 /**
2896  * @brief Connect a slot to Helper trigger property signal.
2897  *
2898  * This signal is used to trigger a property registered by this Helper.
2899  * A property will be triggered when user clicks on it.
2900  *
2901  * The prototype of the slot is:
2902  * void trigger_property (const HelperAgent *agent, int ic, const String &ic_uuid, const String &property);
2903  */
2904 Connection
2905 HelperAgent::signal_connect_trigger_property (HelperAgentSlotString *slot)
2906 {
2907     return m_impl->signal_trigger_property.connect (slot);
2908 }
2909
2910 /**
2911  * @brief Connect a slot to Helper process imengine event signal.
2912  *
2913  * This signal is used to deliver the events sent from IMEngine to Helper.
2914  *
2915  * The prototype of the slot is:
2916  * void process_imengine_event (const HelperAgent *agent, int ic, const String &ic_uuid, const Transaction &transaction);
2917  */
2918 Connection
2919 HelperAgent::signal_connect_process_imengine_event (HelperAgentSlotTransaction *slot)
2920 {
2921     return m_impl->signal_process_imengine_event.connect (slot);
2922 }
2923
2924 /**
2925  * @brief Connect a slot to Helper focus out signal.
2926  *
2927  * This signal is used to do something when input context is focus out.
2928  *
2929  * The prototype of the slot is:
2930  * void focus_out (const HelperAgent *agent, int ic, const String &ic_uuid);
2931  */
2932 Connection
2933 HelperAgent::signal_connect_focus_out (HelperAgentSlotVoid *slot)
2934 {
2935     return m_impl->signal_focus_out.connect (slot);
2936 }
2937
2938 /**
2939  * @brief Connect a slot to Helper focus in signal.
2940  *
2941  * This signal is used to do something when input context is focus in.
2942  *
2943  * The prototype of the slot is:
2944  * void focus_in (const HelperAgent *agent, int ic, const String &ic_uuid);
2945  */
2946 Connection
2947 HelperAgent::signal_connect_focus_in (HelperAgentSlotVoid *slot)
2948 {
2949     return m_impl->signal_focus_in.connect (slot);
2950 }
2951
2952 /**
2953  * @brief Connect a slot to Helper show signal.
2954  *
2955  * This signal is used to show Helper ISE window.
2956  *
2957  * The prototype of the slot is:
2958  * void ise_show (const HelperAgent *agent, int ic, char *buf, size_t &len);
2959  */
2960 Connection
2961 HelperAgent::signal_connect_ise_show (HelperAgentSlotIntRawVoid *slot)
2962 {
2963     return m_impl->signal_ise_show.connect (slot);
2964 }
2965
2966 /**
2967  * @brief Connect a slot to Helper hide signal.
2968  *
2969  * This signal is used to hide Helper ISE window.
2970  *
2971  * The prototype of the slot is:
2972  * void ise_hide (const HelperAgent *agent, int ic, const String &ic_uuid);
2973  */
2974 Connection
2975 HelperAgent::signal_connect_ise_hide (HelperAgentSlotVoid *slot)
2976 {
2977     return m_impl->signal_ise_hide.connect (slot);
2978 }
2979
2980 /**
2981  * @brief Connect a slot to Helper get ISE window geometry signal.
2982  *
2983  * This signal is used to get Helper ISE window size and position.
2984  *
2985  * The prototype of the slot is:
2986  * void get_geometry (const HelperAgent *agent, struct rectinfo &info);
2987  */
2988 Connection
2989 HelperAgent::signal_connect_get_geometry (HelperAgentSlotSize *slot)
2990 {
2991     return m_impl->signal_get_geometry.connect (slot);
2992 }
2993
2994 /**
2995  * @brief Connect a slot to Helper set mode signal.
2996  *
2997  * This signal is used to set Helper ISE mode.
2998  *
2999  * The prototype of the slot is:
3000  * void set_mode (const HelperAgent *agent, uint32 &mode);
3001  */
3002 Connection
3003 HelperAgent::signal_connect_set_mode (HelperAgentSlotUintVoid *slot)
3004 {
3005     return m_impl->signal_set_mode.connect (slot);
3006 }
3007
3008 /**
3009  * @brief Connect a slot to Helper set language signal.
3010  *
3011  * This signal is used to set Helper ISE language.
3012  *
3013  * The prototype of the slot is:
3014  * void set_language (const HelperAgent *agent, uint32 &language);
3015  */
3016 Connection
3017 HelperAgent::signal_connect_set_language (HelperAgentSlotUintVoid *slot)
3018 {
3019     return m_impl->signal_set_language.connect (slot);
3020 }
3021
3022 /**
3023  * @brief Connect a slot to Helper set im data signal.
3024  *
3025  * This signal is used to send im data to Helper ISE.
3026  *
3027  * The prototype of the slot is:
3028  * void set_imdata (const HelperAgent *agent, char *buf, size_t &len);
3029  */
3030 Connection
3031 HelperAgent::signal_connect_set_imdata (HelperAgentSlotRawVoid *slot)
3032 {
3033     return m_impl->signal_set_imdata.connect (slot);
3034 }
3035
3036 /**
3037  * @brief Connect a slot to Helper get im data signal.
3038  *
3039  * This signal is used to get im data from Helper ISE.
3040  *
3041  * The prototype of the slot is:
3042  * void get_imdata (const HelperAgent *, char **buf, size_t &len);
3043  */
3044 Connection
3045 HelperAgent::signal_connect_get_imdata (HelperAgentSlotGetRawVoid *slot)
3046 {
3047     return m_impl->signal_get_imdata.connect (slot);
3048 }
3049
3050 /**
3051  * @brief Connect a slot to Helper get language locale signal.
3052  *
3053  * This signal is used to get language locale from Helper ISE.
3054  *
3055  * The prototype of the slot is:
3056  * void get_language_locale (const HelperAgent *, int ic, char **locale);
3057  */
3058 Connection
3059 HelperAgent::signal_connect_get_language_locale (HelperAgentSlotIntGetStringVoid *slot)
3060 {
3061     return m_impl->signal_get_language_locale.connect (slot);
3062 }
3063
3064 /**
3065  * @brief Connect a slot to Helper set return key type signal.
3066  *
3067  * This signal is used to send return key type to Helper ISE.
3068  *
3069  * The prototype of the slot is:
3070  * void set_return_key_type (const HelperAgent *agent, uint32 &type);
3071  */
3072 Connection
3073 HelperAgent::signal_connect_set_return_key_type (HelperAgentSlotUintVoid *slot)
3074 {
3075     return m_impl->signal_set_return_key_type.connect (slot);
3076 }
3077
3078 /**
3079  * @brief Connect a slot to Helper get return key type signal.
3080  *
3081  * This signal is used to get return key type from Helper ISE.
3082  *
3083  * The prototype of the slot is:
3084  * void get_return_key_type (const HelperAgent *agent, uint32 &type);
3085  */
3086 Connection
3087 HelperAgent::signal_connect_get_return_key_type (HelperAgentSlotUintVoid *slot)
3088 {
3089     return m_impl->signal_get_return_key_type.connect (slot);
3090 }
3091
3092 /**
3093  * @brief Connect a slot to Helper set return key disable signal.
3094  *
3095  * This signal is used to send return key disable to Helper ISE.
3096  *
3097  * The prototype of the slot is:
3098  * void set_return_key_disable (const HelperAgent *agent, uint32 &disabled);
3099  */
3100 Connection
3101 HelperAgent::signal_connect_set_return_key_disable (HelperAgentSlotUintVoid *slot)
3102 {
3103     return m_impl->signal_set_return_key_disable.connect (slot);
3104 }
3105
3106 /**
3107  * @brief Connect a slot to Helper process key event signal.
3108  *
3109  * This signal is used to send keyboard key event to Helper ISE.
3110  *
3111  * The prototype of the slot is:
3112  * void process_key_event (const HelperAgent *agent, KeyEvent &key, uint32 &ret);
3113  */
3114 Connection
3115 HelperAgent::signal_connect_process_key_event (HelperAgentSlotKeyEventUint *slot)
3116 {
3117     return m_impl->signal_process_key_event.connect (slot);
3118 }
3119
3120 /**
3121  * @brief Connect a slot to Helper process key event with keycode signal.
3122  *
3123  * This signal is used to send keyboard key event with keycode to Helper ISE.
3124  *
3125  * The prototype of the slot is:
3126  * void process_key_event_with_keycode (const HelperAgent *agent, KeyEvent &key, uint32 &ret, uint32 keycode);
3127  */
3128 Connection
3129 HelperAgent::signal_connect_process_key_event_with_keycode (HelperAgentSlotKeyEventUintUint *slot)
3130 {
3131     return m_impl->signal_process_key_event_with_keycode.connect (slot);
3132 }
3133
3134 /**
3135  * @brief Connect a slot to Helper get return key disable signal.
3136  *
3137  * This signal is used to get return key disable from Helper ISE.
3138  *
3139  * The prototype of the slot is:
3140  * void get_return_key_disable (const HelperAgent *agent, uint32 &disabled);
3141  */
3142 Connection
3143 HelperAgent::signal_connect_get_return_key_disable (HelperAgentSlotUintVoid *slot)
3144 {
3145     return m_impl->signal_get_return_key_disable.connect (slot);
3146 }
3147
3148 /**
3149  * @brief Connect a slot to Helper set layout signal.
3150  *
3151  * This signal is used to set Helper ISE layout.
3152  *
3153  * The prototype of the slot is:
3154  * void set_layout (const HelperAgent *agent, uint32 &layout);
3155  */
3156 Connection
3157 HelperAgent::signal_connect_set_layout (HelperAgentSlotUintVoid *slot)
3158 {
3159     return m_impl->signal_set_layout.connect (slot);
3160 }
3161
3162 /**
3163  * @brief Connect a slot to Helper get layout signal.
3164  *
3165  * This signal is used to get Helper ISE layout.
3166  *
3167  * The prototype of the slot is:
3168  * void get_layout (const HelperAgent *agent, uint32 &layout);
3169  */
3170 Connection
3171 HelperAgent::signal_connect_get_layout (HelperAgentSlotUintVoid *slot)
3172 {
3173     return m_impl->signal_get_layout.connect (slot);
3174 }
3175
3176 /**
3177  * @brief Connect a slot to Helper set input mode signal.
3178  *
3179  * This signal is used to set Helper ISE input mode.
3180  *
3181  * The prototype of the slot is:
3182  * void set_input_mode (const HelperAgent *agent, uint32 &input_mode);
3183  */
3184 Connection
3185 HelperAgent::signal_connect_set_input_mode (HelperAgentSlotUintVoid *slot)
3186 {
3187     return m_impl->signal_set_input_mode.connect (slot);
3188 }
3189
3190 /**
3191  * @brief Connect a slot to Helper set input hint signal.
3192  *
3193  * This signal is used to set Helper ISE input hint.
3194  *
3195  * The prototype of the slot is:
3196  * void set_input_hint (const HelperAgent *agent, uint32 &input_hint);
3197  */
3198 Connection
3199 HelperAgent::signal_connect_set_input_hint (HelperAgentSlotUintVoid *slot)
3200 {
3201     return m_impl->signal_set_input_hint.connect (slot);
3202 }
3203
3204 /**
3205  * @brief Connect a slot to Helper set BiDi direction signal.
3206  *
3207  * This signal is used to set Helper ISE BiDi direction.
3208  *
3209  * The prototype of the slot is:
3210  * void update_bidi_direction (const HelperAgent *agent, uint32 &bidi_direction);
3211  */
3212 Connection
3213 HelperAgent::signal_connect_update_bidi_direction (HelperAgentSlotUintVoid *slot)
3214 {
3215     return m_impl->signal_update_bidi_direction.connect (slot);
3216 }
3217
3218 /**
3219  * @brief Connect a slot to Helper set shift mode signal.
3220  *
3221  * This signal is used to set Helper shift mode.
3222  *
3223  * The prototype of the slot is:
3224  * void set_caps_mode (const HelperAgent *agent, uint32 &mode);
3225  */
3226 Connection
3227 HelperAgent::signal_connect_set_caps_mode (HelperAgentSlotUintVoid *slot)
3228 {
3229     return m_impl->signal_set_caps_mode.connect (slot);
3230 }
3231
3232 /**
3233  * @brief Connect a slot to Helper reset input context signal.
3234  *
3235  * This signal is used to reset Helper ISE input context.
3236  *
3237  * The prototype of the slot is:
3238  * void reset_input_context (const HelperAgent *agent, int ic, const String &uuid);
3239  */
3240 Connection
3241 HelperAgent::signal_connect_reset_input_context (HelperAgentSlotVoid *slot)
3242 {
3243     return m_impl->signal_reset_input_context.connect (slot);
3244 }
3245
3246 /**
3247  * @brief Connect a slot to Helper update candidate window geometry signal.
3248  *
3249  * This signal is used to get candidate window size and position.
3250  *
3251  * The prototype of the slot is:
3252  * void update_candidate_geometry (const HelperAgent *agent, int ic, const String &uuid, const rectinfo &info);
3253  */
3254 Connection
3255 HelperAgent::signal_connect_update_candidate_geometry (HelperAgentSlotRect *slot)
3256 {
3257     return m_impl->signal_update_candidate_geometry.connect (slot);
3258 }
3259
3260 /**
3261  * @brief Connect a slot to Helper update keyboard ISE signal.
3262  *
3263  * This signal is used to get current keyboard ISE name and uuid.
3264  *
3265  * The prototype of the slot is:
3266  * void update_keyboard_ise (const HelperAgent *agent, int ic, const String &uuid,
3267  *                           const String &ise_name, const String &ise_uuid);
3268  */
3269 Connection
3270 HelperAgent::signal_connect_update_keyboard_ise (HelperAgentSlotString2 *slot)
3271 {
3272     return m_impl->signal_update_keyboard_ise.connect (slot);
3273 }
3274
3275 /**
3276  * @brief Connect a slot to Helper update keyboard ISE list signal.
3277  *
3278  * This signal is used to get uuid list of all keyboard ISEs.
3279  *
3280  * The prototype of the slot is:
3281  * void update_keyboard_ise_list (const HelperAgent *agent, int ic, const String &uuid,
3282  *                                const std::vector<String> &ise_list);
3283  */
3284 Connection
3285 HelperAgent::signal_connect_update_keyboard_ise_list (HelperAgentSlotStringVector *slot)
3286 {
3287     return m_impl->signal_update_keyboard_ise_list.connect (slot);
3288 }
3289
3290 /**
3291  * @brief Connect a slot to Helper candidate more window show signal.
3292  *
3293  * This signal is used to do someting when candidate more window is showed.
3294  *
3295  * The prototype of the slot is:
3296  * void candidate_more_window_show (const HelperAgent *agent, int ic, const String &uuid);
3297  */
3298 Connection
3299 HelperAgent::signal_connect_candidate_more_window_show (HelperAgentSlotVoid *slot)
3300 {
3301     return m_impl->signal_candidate_more_window_show.connect (slot);
3302 }
3303
3304 /**
3305  * @brief Connect a slot to Helper candidate more window hide signal.
3306  *
3307  * This signal is used to do someting when candidate more window is hidden.
3308  *
3309  * The prototype of the slot is:
3310  * void candidate_more_window_hide (const HelperAgent *agent, int ic, const String &uuid);
3311  */
3312 Connection
3313 HelperAgent::signal_connect_candidate_more_window_hide (HelperAgentSlotVoid *slot)
3314 {
3315     return m_impl->signal_candidate_more_window_hide.connect (slot);
3316 }
3317
3318 /**
3319  * @brief Connect a slot to Helper candidate show signal.
3320  *
3321  * This signal is used to do candidate show.
3322  *
3323  * The prototype of the slot is:
3324  * void candidate_show (const HelperAgent *agent, int ic, const String &uuid);
3325  */
3326 Connection
3327 HelperAgent::signal_connect_candidate_show (HelperAgentSlotVoid *slot)
3328 {
3329     return m_impl->signal_candidate_show.connect (slot);
3330 }
3331
3332 /**
3333  * @brief Connect a slot to Helper candidate hide signal.
3334  *
3335  * This signal is used to do candidate hide.
3336  *
3337  * The prototype of the slot is:
3338  * void candidate_hide (const HelperAgent *agent, int ic, const String &uuid);
3339  */
3340 Connection
3341 HelperAgent::signal_connect_candidate_hide (HelperAgentSlotVoid *slot)
3342 {
3343     return m_impl->signal_candidate_hide.connect (slot);
3344 }
3345
3346 /**
3347  * @brief Connect a slot to Helper update lookup table signal.
3348  *
3349  * This signal is used to do someting when update lookup table.
3350  *
3351  * The prototype of the slot is:
3352  * void update_lookup_table (const HelperAgent *agent, int ic, const String &uuid ,LookupTable &table);
3353  */
3354 Connection
3355 HelperAgent::signal_connect_update_lookup_table (HelperAgentSlotLookupTable *slot)
3356 {
3357     return m_impl->signal_update_lookup_table.connect (slot);
3358 }
3359
3360 /**
3361  * @brief Connect a slot to Helper select aux signal.
3362  *
3363  * This signal is used to do something when aux is selected.
3364  *
3365  * The prototype of the slot is:
3366  * void select_aux (const HelperAgent *agent, int ic, const String &uuid, int index);
3367  */
3368 Connection
3369 HelperAgent::signal_connect_select_aux (HelperAgentSlotInt *slot)
3370 {
3371     return m_impl->signal_select_aux.connect (slot);
3372 }
3373
3374 /**
3375  * @brief Connect a slot to Helper select candidate signal.
3376  *
3377  * This signal is used to do something when candidate is selected.
3378  *
3379  * The prototype of the slot is:
3380  * void select_candidate (const HelperAgent *agent, int ic, const String &uuid, int index);
3381  */
3382 Connection
3383 HelperAgent::signal_connect_select_candidate (HelperAgentSlotInt *slot)
3384 {
3385     return m_impl->signal_select_candidate.connect (slot);
3386 }
3387
3388 /**
3389  * @brief Connect a slot to Helper candidate table page up signal.
3390  *
3391  * This signal is used to do something when candidate table is paged up.
3392  *
3393  * The prototype of the slot is:
3394  * void candidate_table_page_up (const HelperAgent *agent, int ic, const String &uuid);
3395  */
3396 Connection
3397 HelperAgent::signal_connect_candidate_table_page_up (HelperAgentSlotVoid *slot)
3398 {
3399     return m_impl->signal_candidate_table_page_up.connect (slot);
3400 }
3401
3402 /**
3403  * @brief Connect a slot to Helper candidate table page down signal.
3404  *
3405  * This signal is used to do something when candidate table is paged down.
3406  *
3407  * The prototype of the slot is:
3408  * void candidate_table_page_down (const HelperAgent *agent, int ic, const String &uuid);
3409  */
3410 Connection
3411 HelperAgent::signal_connect_candidate_table_page_down (HelperAgentSlotVoid *slot)
3412 {
3413     return m_impl->signal_candidate_table_page_down.connect (slot);
3414 }
3415
3416 /**
3417  * @brief Connect a slot to Helper update candidate table page size signal.
3418  *
3419  * This signal is used to do something when candidate table page size is changed.
3420  *
3421  * The prototype of the slot is:
3422  * void update_candidate_table_page_size (const HelperAgent *, int ic, const String &uuid, int page_size);
3423  */
3424 Connection
3425 HelperAgent::signal_connect_update_candidate_table_page_size (HelperAgentSlotInt *slot)
3426 {
3427     return m_impl->signal_update_candidate_table_page_size.connect (slot);
3428 }
3429
3430 /**
3431  * @brief Connect a slot to Helper update candidate item layout signal.
3432  *
3433  * The prototype of the slot is:
3434  * void update_candidate_item_layout (const HelperAgent *, const std::vector<uint32> &row_items);
3435  */
3436 Connection
3437 HelperAgent::signal_connect_update_candidate_item_layout (HelperAgentSlotUintVector *slot)
3438 {
3439     return m_impl->signal_update_candidate_item_layout.connect (slot);
3440 }
3441
3442 /**
3443  * @brief Connect a slot to Helper select associate signal.
3444  *
3445  * This signal is used to do something when associate is selected.
3446  *
3447  * The prototype of the slot is:
3448  * void select_associate (const HelperAgent *agent, int ic, const String &uuid, int index);
3449  */
3450 Connection
3451 HelperAgent::signal_connect_select_associate (HelperAgentSlotInt *slot)
3452 {
3453     return m_impl->signal_select_associate.connect (slot);
3454 }
3455
3456 /**
3457  * @brief Connect a slot to Helper associate table page up signal.
3458  *
3459  * This signal is used to do something when associate table is paged up.
3460  *
3461  * The prototype of the slot is:
3462  * void associate_table_page_up (const HelperAgent *agent, int ic, const String &uuid);
3463  */
3464 Connection
3465 HelperAgent::signal_connect_associate_table_page_up (HelperAgentSlotVoid *slot)
3466 {
3467     return m_impl->signal_associate_table_page_up.connect (slot);
3468 }
3469
3470 /**
3471  * @brief Connect a slot to Helper associate table page down signal.
3472  *
3473  * This signal is used to do something when associate table is paged down.
3474  *
3475  * The prototype of the slot is:
3476  * void associate_table_page_down (const HelperAgent *agent, int ic, const String &uuid);
3477  */
3478 Connection
3479 HelperAgent::signal_connect_associate_table_page_down (HelperAgentSlotVoid *slot)
3480 {
3481     return m_impl->signal_associate_table_page_down.connect (slot);
3482 }
3483
3484 /**
3485  * @brief Connect a slot to Helper update associate table page size signal.
3486  *
3487  * This signal is used to do something when associate table page size is changed.
3488  *
3489  * The prototype of the slot is:
3490  * void update_associate_table_page_size (const HelperAgent *, int ic, const String &uuid, int page_size);
3491  */
3492 Connection
3493 HelperAgent::signal_connect_update_associate_table_page_size (HelperAgentSlotInt *slot)
3494 {
3495     return m_impl->signal_update_associate_table_page_size.connect (slot);
3496 }
3497
3498 /**
3499  * @brief Connect a slot to Helper turn on log signal.
3500  *
3501  * This signal is used to turn on Helper ISE debug information.
3502  *
3503  * The prototype of the slot is:
3504  * void turn_on_log (const HelperAgent *agent, uint32 &on);
3505  */
3506 Connection
3507 HelperAgent::signal_connect_turn_on_log (HelperAgentSlotUintVoid *slot)
3508 {
3509     return m_impl->signal_turn_on_log.connect (slot);
3510 }
3511
3512 /**
3513  * @brief Connect a slot to Helper update displayed candidate number signal.
3514  *
3515  * This signal is used to inform helper ISE displayed candidate number.
3516  *
3517  * The prototype of the slot is:
3518  * void update_displayed_candidate_number (const HelperAgent *, int ic, const String &uuid, int number);
3519  */
3520 Connection
3521 HelperAgent::signal_connect_update_displayed_candidate_number (HelperAgentSlotInt *slot)
3522 {
3523     return m_impl->signal_update_displayed_candidate_number.connect (slot);
3524 }
3525
3526 /**
3527  * @brief Connect a slot to Helper longpress candidate signal.
3528  *
3529  * This signal is used to do something when candidate is longpress.
3530  *
3531  * The prototype of the slot is:
3532  * void longpress_candidate (const HelperAgent *agent, int ic, const String &uuid, int index);
3533  */
3534 Connection
3535 HelperAgent::signal_connect_longpress_candidate (HelperAgentSlotInt *slot)
3536 {
3537     return m_impl->signal_longpress_candidate.connect (slot);
3538 }
3539
3540 /**
3541  * @brief Connect a slot to Helper show option window.
3542  *
3543  * This signal is used to do request the ISE to show option window.
3544  *
3545  * The prototype of the slot is:
3546  * void show_option_window (const HelperAgent *agent, int ic, const String &uuid);
3547  */
3548 Connection
3549 HelperAgent::signal_connect_show_option_window (HelperAgentSlotVoid *slot)
3550 {
3551     return m_impl->signal_show_option_window.connect (slot);
3552 }
3553
3554 /**
3555  * @brief Connect a slot to Helper resume option window.
3556  *
3557  * This signal is used to do request the ISE to resume option window.
3558  *
3559  * The prototype of the slot is:
3560  * void resume_option_window (const HelperAgent *agent, int ic, const String &uuid);
3561  */
3562 Connection
3563 HelperAgent::signal_connect_resume_option_window (HelperAgentSlotVoid *slot)
3564 {
3565     return m_impl->signal_resume_option_window.connect (slot);
3566 }
3567
3568 /**
3569  * @brief Connect a slot to Helper check if the option is available.
3570  *
3571  * This signal is used to check if the option (setting) is available from Helper ISE.
3572  *
3573  * The prototype of the slot is:
3574  * void check_option_window (const HelperAgent *agent, uint32 &avail);
3575  */
3576 Connection
3577 HelperAgent::signal_connect_check_option_window (HelperAgentSlotUintVoid *slot)
3578 {
3579     return m_impl->signal_check_option_window.connect (slot);
3580 }
3581
3582 /**
3583  * @brief Connect a slot to Helper process unconventional input device event signal.
3584  *
3585  * This signal is used to send unconventional input device event to Helper ISE.
3586  *
3587  * The prototype of the slot is:
3588  * void process_input_device_event (const HelperAgent *, uint32 &type, char *data, size_t &size, uint32 &ret);
3589  */
3590 Connection
3591 HelperAgent::signal_connect_process_input_device_event (HelperAgentSlotUintCharSizeUint *slot)
3592 {
3593     return m_impl->signal_process_input_device_event.connect (slot);
3594 }
3595
3596 /**
3597  * @brief Connect a slot to Helper set prediction hint signal.
3598  *
3599  * This signal is used to send prediction hint to Helper ISE.
3600  *
3601  * The prototype of the slot is:
3602  * void set_prediction_hint (const HelperAgent *agent, char *prediction_hint);
3603  */
3604 Connection
3605 HelperAgent::signal_connect_set_prediction_hint (HelperAgentSlotStringVoid *slot)
3606 {
3607     return m_impl->signal_set_prediction_hint.connect (slot);
3608 }
3609
3610 /**
3611  * @brief Connect a slot to Helper set mime type signal.
3612  *
3613  * This signal is used to send mime type to Helper ISE.
3614  *
3615  * The prototype of the slot is:
3616  * void set_mime_type (const HelperAgent *agent, char *mime_type);
3617  */
3618 Connection
3619 HelperAgent::signal_connect_set_mime_type (HelperAgentSlotStringVoid *slot)
3620 {
3621     return m_impl->signal_set_mime_type.connect (slot);
3622 }
3623
3624 /**
3625  * @brief Connect a slot to Helper set prediction hint data signal.
3626  *
3627  * This signal is used to send prediction hint data to Helper ISE.
3628  *
3629  * The prototype of the slot is:
3630  * void set_prediction_hint_data (const HelperAgent *agent, char *key, char *value);
3631  */
3632 Connection
3633 HelperAgent::signal_connect_set_prediction_hint_data (HelperAgentSlotString *slot)
3634 {
3635     return m_impl->signal_set_prediction_hint_data.connect (slot);
3636 }
3637
3638 /**
3639  * @brief Connect a slot to Helper set optimization hint signal.
3640  *
3641  * This signal is used to send optimization hint to Helper ISE.
3642  *
3643  * The prototype of the slot is:
3644  * void set_optimization_hint (const HelperAgent *agent, uint32 &hint);
3645  */
3646 Connection
3647 HelperAgent::signal_connect_set_optimization_hint (HelperAgentSlotUintVoid *slot)
3648 {
3649     return m_impl->signal_set_optimization_hint.connect (slot);
3650 }
3651
3652 /**
3653  * @brief Connect a slot to Helper process key event with imengine signal.
3654  *
3655  * This signal is used to deliver the key event to Helper ISE.
3656  *
3657  * The prototype of the slot is:
3658  * void process_key_event_with_imengine (const HelperAgent *agent, KeyEvent &key, uint32 serial);
3659  */
3660 Connection
3661 HelperAgent::signal_connect_process_key_event_with_imengine (HelperAgentSlotKeyEventUint2 *slot)
3662 {
3663     return m_impl->signal_process_key_event_with_imengine.connect (slot);
3664 }
3665
3666 /**
3667  * @brief Connect a slot to Helper set autocapital type signal.
3668  *
3669  * This signal is used to send autocapital type to imengine.
3670  *
3671  * The prototype of the slot is:
3672  * void set_autocapital_type (const HelperAgent *agent, uint32 &type);
3673  */
3674 Connection
3675 HelperAgent::signal_connect_set_autocapital_type (HelperAgentSlotUintVoid *slot)
3676 {
3677     return m_impl->signal_set_autocapital_type.connect (slot);
3678 }
3679
3680 /**
3681  * @brief Connect a slot to Helper set prediction allow signal.
3682  *
3683  * This signal is used to send prediction allow to imengine.
3684  *
3685  * The prototype of the slot is:
3686  * void set_prediction_allow (const HelperAgent *agent, uint32 &prediction_allow);
3687  */
3688 Connection
3689 HelperAgent::signal_connect_set_prediction_allow (HelperAgentSlotUintVoid *slot)
3690 {
3691     return m_impl->signal_set_prediction_allow.connect (slot);
3692 }
3693
3694 } /* namespace scim */
3695
3696 /*
3697 vi:ts=4:nowrap:ai:expandtab
3698 */
3699