Modified to call key_event_done() last when processing key event from engine-loader
[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             if (!_TV)
1030                 m_impl->ise_show_flag = false;
1031             m_impl->need_update_entry_metadata = false;
1032             break;
1033         }
1034         case SCIM_TRANS_CMD_FOCUS_IN:
1035         {
1036             MessageItemFocusIn *subclass = static_cast<MessageItemFocusIn*>(message);
1037             m_impl->ise_focus_flag = true;
1038             if (_WEARABLE)
1039                 m_impl->need_update_entry_metadata = false;
1040             m_impl->signal_focus_in (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1041             m_impl->focused_ic = subclass->get_ic_ref();
1042             if (m_impl->finalized_text != NULL)
1043                 free(m_impl->finalized_text);
1044             m_impl->finalized_text = NULL;
1045             m_impl->finalized_cursor_pos = 0;
1046             if (!m_impl->si.null ()) m_impl->si->focus_in();
1047             break;
1048         }
1049         case ISM_TRANS_CMD_SHOW_ISE_PANEL:
1050         {
1051             MessageItemShowISEPanel *subclass = static_cast<MessageItemShowISEPanel*>(message);
1052             LOGD ("Helper ISE received ISM_TRANS_CMD_SHOW_ISE_PANEL message");
1053
1054             m_impl->signal_ise_show (this, subclass->get_ic_ref(), *(subclass->get_data_ptr()),
1055                 subclass->get_len_ref());
1056             m_impl->ise_show_flag = true;
1057             break;
1058         }
1059         case ISM_TRANS_CMD_HIDE_ISE_PANEL:
1060         {
1061             MessageItemHideISEPanel *subclass = static_cast<MessageItemHideISEPanel*>(message);
1062             LOGD ("Helper ISE received ISM_TRANS_CMD_HIDE_ISE_PANEL message");
1063             if (m_impl->ise_show_flag)
1064                 m_impl->signal_ise_hide (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1065             m_impl->ise_show_flag = false;
1066             break;
1067         }
1068         case ISM_TRANS_CMD_GET_ACTIVE_ISE_GEOMETRY:
1069         {
1070             struct rectinfo info = {0, 0, 0, 0};
1071             m_impl->signal_get_geometry (this, info);
1072             m_impl->send.clear ();
1073             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1074             m_impl->send.put_data (info.pos_x);
1075             m_impl->send.put_data (info.pos_y);
1076             m_impl->send.put_data (info.width);
1077             m_impl->send.put_data (info.height);
1078             m_impl->send.write_to_socket (m_impl->socket);
1079             break;
1080         }
1081         case ISM_TRANS_CMD_SET_ISE_MODE:
1082         {
1083             MessageItemSetISEMode *subclass = static_cast<MessageItemSetISEMode*>(message);
1084             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1085                 m_impl->signal_set_mode (this, subclass->get_mode_ref());
1086             }
1087             break;
1088         }
1089         case ISM_TRANS_CMD_SET_ISE_LANGUAGE:
1090         {
1091             MessageItemSetISELanguage *subclass = static_cast<MessageItemSetISELanguage*>(message);
1092             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1093                 m_impl->signal_set_language (this, subclass->get_language_ref());
1094             }
1095             break;
1096         }
1097         case ISM_TRANS_CMD_SET_ISE_IMDATA:
1098         {
1099             MessageItemSetISEImData *subclass = static_cast<MessageItemSetISEImData*>(message);
1100             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode) {
1101                 m_impl->signal_set_imdata (this, *(subclass->get_imdata_ptr()), subclass->get_len_ref());
1102             }
1103             if (!m_impl->si.null ()) m_impl->si->set_imdata(*(subclass->get_imdata_ptr()),
1104                 subclass->get_len_ref());
1105             break;
1106         }
1107         case ISM_TRANS_CMD_GET_ISE_IMDATA:
1108         {
1109             char   *buf = NULL;
1110             size_t  len = 0;
1111
1112             m_impl->signal_get_imdata (this, &buf, len);
1113             LOGD ("send ise imdata len = %zu", len);
1114             m_impl->send.clear ();
1115             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1116             m_impl->send.put_data (buf, len);
1117             m_impl->send.write_to_socket (m_impl->socket);
1118             if (NULL != buf)
1119                 free(buf);
1120             break;
1121         }
1122         case ISM_TRANS_CMD_GET_ISE_LANGUAGE_LOCALE:
1123         {
1124             MessageItemGetISELanguageLocale *subclass = static_cast<MessageItemGetISELanguageLocale*>(message);
1125             char *buf = NULL;
1126             m_impl->signal_get_language_locale (this, subclass->get_ic_ref(), &buf);
1127             m_impl->send.clear ();
1128             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1129             if (buf != NULL)
1130                 m_impl->send.put_data (buf, strlen (buf));
1131             m_impl->send.write_to_socket (m_impl->socket);
1132             if (NULL != buf)
1133                 free(buf);
1134             break;
1135         }
1136         case ISM_TRANS_CMD_SET_RETURN_KEY_TYPE:
1137         {
1138             MessageItemSetReturnKeyType *subclass = static_cast<MessageItemSetReturnKeyType*>(message);
1139             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1140                 m_impl->signal_set_return_key_type (this, subclass->get_type_ref());
1141             }
1142             break;
1143         }
1144         case ISM_TRANS_CMD_GET_RETURN_KEY_TYPE:
1145         {
1146             uint32 type = 0;
1147             m_impl->signal_get_return_key_type (this, type);
1148             m_impl->send.clear ();
1149             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1150             m_impl->send.put_data (type);
1151             m_impl->send.write_to_socket (m_impl->socket);
1152             break;
1153         }
1154         case ISM_TRANS_CMD_SET_RETURN_KEY_DISABLE:
1155         {
1156             MessageItemSetReturnKeyDisable *subclass = static_cast<MessageItemSetReturnKeyDisable*>(message);
1157             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1158                 m_impl->signal_set_return_key_disable (this, subclass->get_disabled_ref());
1159             }
1160             break;
1161         }
1162         case ISM_TRANS_CMD_GET_RETURN_KEY_DISABLE:
1163         {
1164             uint32 disabled = 0;
1165             m_impl->signal_get_return_key_type (this, disabled);
1166             m_impl->send.clear ();
1167             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1168             m_impl->send.put_data (disabled);
1169             m_impl->send.write_to_socket (m_impl->socket);
1170             break;
1171         }
1172         case SCIM_TRANS_CMD_PROCESS_KEY_EVENT:
1173         {
1174             MessageItemProcessKeyEvent *subclass = static_cast<MessageItemProcessKeyEvent*>(message);
1175             uint32 ret = 0;
1176             uint32 keycode_ret = 0;
1177             m_impl->signal_process_key_event(this, subclass->get_key_ref(), ret);
1178             m_impl->signal_process_key_event_with_keycode(this, subclass->get_key_ref(), keycode_ret, subclass->get_keycode_ref());
1179
1180             if (ret != 0 && keycode_ret != 0) {
1181                 ret = 1;
1182                 m_impl->process_key_event_done (subclass->get_key_ref(), ret, subclass->get_serial_ref());
1183             } else {
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             }
1200             break;
1201         }
1202         case ISM_TRANS_CMD_SET_LAYOUT:
1203         {
1204             MessageItemSetLayout *subclass = static_cast<MessageItemSetLayout*>(message);
1205             m_impl->layout = subclass->get_layout_ref();
1206             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1207                 m_impl->signal_set_layout (this, subclass->get_layout_ref());
1208             }
1209             if (!m_impl->si.null ()) m_impl->si->set_layout(subclass->get_layout_ref());
1210             break;
1211         }
1212         case ISM_TRANS_CMD_GET_LAYOUT:
1213         {
1214             uint32 layout = 0;
1215
1216             m_impl->signal_get_layout (this, layout);
1217             m_impl->send.clear ();
1218             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1219             m_impl->send.put_data (layout);
1220             m_impl->send.write_to_socket (m_impl->socket);
1221             break;
1222         }
1223         case ISM_TRANS_CMD_SET_INPUT_MODE:
1224         {
1225             MessageItemSetInputMode *subclass = static_cast<MessageItemSetInputMode*>(message);
1226             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1227                 m_impl->signal_set_input_mode (this, subclass->get_input_mode_ref());
1228             }
1229             break;
1230         }
1231         case ISM_TRANS_CMD_SET_CAPS_MODE:
1232         {
1233             MessageItemSetCapsMode *subclass = static_cast<MessageItemSetCapsMode*>(message);
1234             m_impl->signal_set_caps_mode (this, subclass->get_mode_ref());
1235             break;
1236         }
1237         case SCIM_TRANS_CMD_PANEL_RESET_INPUT_CONTEXT:
1238         {
1239             MessageItemPanelResetInputContext *subclass = static_cast<MessageItemPanelResetInputContext*>(message);
1240             m_impl->signal_reset_input_context (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1241             if (!m_impl->si.null ()) m_impl->si->reset();
1242             break;
1243         }
1244         case ISM_TRANS_CMD_UPDATE_CANDIDATE_UI:
1245         {
1246             MessageItemUpdateCandidateUI *subclass = static_cast<MessageItemUpdateCandidateUI*>(message);
1247             m_impl->signal_update_candidate_ui (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1248                 subclass->get_style_ref(), subclass->get_mode_ref());
1249             break;
1250         }
1251         case ISM_TRANS_CMD_UPDATE_CANDIDATE_GEOMETRY:
1252         {
1253             MessageItemUpdateCandidateGeometry *subclass = static_cast<MessageItemUpdateCandidateGeometry*>(message);
1254             m_impl->signal_update_candidate_geometry (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1255                 subclass->get_rectinfo_ref());
1256             break;
1257         }
1258         case ISM_TRANS_CMD_UPDATE_KEYBOARD_ISE:
1259         {
1260             MessageItemUpdateKeyboardISE *subclass = static_cast<MessageItemUpdateKeyboardISE*>(message);
1261             m_impl->signal_update_keyboard_ise (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1262                 subclass->get_name_ref(), subclass->get_uuid_ref());
1263             break;
1264         }
1265         case ISM_TRANS_CMD_UPDATE_KEYBOARD_ISE_LIST:
1266         {
1267             MessageItemUpdateKeyboardISEList *subclass = static_cast<MessageItemUpdateKeyboardISEList*>(message);
1268             m_impl->signal_update_keyboard_ise_list (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1269                 subclass->get_list_ref());
1270             break;
1271         }
1272         case ISM_TRANS_CMD_CANDIDATE_MORE_WINDOW_SHOW:
1273         {
1274             MessageItemCandidateMoreWindowShow *subclass = static_cast<MessageItemCandidateMoreWindowShow*>(message);
1275             m_impl->signal_candidate_more_window_show (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1276             if (!m_impl->si.null ()) m_impl->si->candidate_more_window_show();
1277             break;
1278         }
1279         case ISM_TRANS_CMD_CANDIDATE_MORE_WINDOW_HIDE:
1280         {
1281             MessageItemCandidateMoreWindowHide *subclass = static_cast<MessageItemCandidateMoreWindowHide*>(message);
1282             m_impl->signal_candidate_more_window_hide (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1283             if (!m_impl->si.null ()) m_impl->si->candidate_more_window_hide();
1284             break;
1285         }
1286         case ISM_TRANS_CMD_SELECT_AUX:
1287         {
1288             MessageItemSelectAux *subclass = static_cast<MessageItemSelectAux*>(message);
1289             m_impl->signal_select_aux (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1290                 subclass->get_item_ref());
1291             if (!m_impl->si.null ()) m_impl->si->select_aux(subclass->get_item_ref());
1292             break;
1293         }
1294         case SCIM_TRANS_CMD_SELECT_CANDIDATE: //FIXME:remove if useless
1295         {
1296             MessageItemSelectCandidate *subclass = static_cast<MessageItemSelectCandidate*>(message);
1297             m_impl->signal_select_candidate (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1298                 subclass->get_item_ref());
1299             if (!m_impl->si.null ()) m_impl->si->select_candidate(subclass->get_item_ref());
1300             break;
1301         }
1302         case SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_UP: //FIXME:remove if useless
1303         {
1304             MessageItemLookupTablePageUp *subclass = static_cast<MessageItemLookupTablePageUp*>(message);
1305             m_impl->signal_candidate_table_page_up (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1306             if (!m_impl->si.null ()) m_impl->si->lookup_table_page_up();
1307             break;
1308         }
1309         case SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_DOWN: //FIXME:remove if useless
1310         {
1311             MessageItemLookupTablePageDown *subclass = static_cast<MessageItemLookupTablePageDown*>(message);
1312             m_impl->signal_candidate_table_page_down (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1313             if (!m_impl->si.null ()) m_impl->si->lookup_table_page_down();
1314             break;
1315         }
1316         case SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE_PAGE_SIZE:
1317         {
1318             MessageItemUpdateLookupTablePageSize *subclass = static_cast<MessageItemUpdateLookupTablePageSize*>(message);
1319             m_impl->signal_update_candidate_table_page_size (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1320                 subclass->get_size_ref());
1321             if (!m_impl->si.null ()) m_impl->si->update_lookup_table_page_size(subclass->get_size_ref());
1322             break;
1323         }
1324         case ISM_TRANS_CMD_CANDIDATE_SHOW: //FIXME:remove if useless
1325         {
1326             MessageItemCandidateShow *subclass = static_cast<MessageItemCandidateShow*>(message);
1327             m_impl->signal_candidate_show (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1328             break;
1329         }
1330         case ISM_TRANS_CMD_CANDIDATE_HIDE: //FIXME:remove if useless
1331         {
1332             MessageItemCandidateHide *subclass = static_cast<MessageItemCandidateHide*>(message);
1333             m_impl->signal_candidate_hide (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1334             break;
1335         }
1336         case ISM_TRANS_CMD_UPDATE_LOOKUP_TABLE: //FIXME:remove if useless
1337         {
1338             MessageItemUpdateLookupTable *subclass = static_cast<MessageItemUpdateLookupTable*>(message);
1339             m_impl->signal_update_lookup_table (this, subclass->get_candidate_table_ref());
1340             break;
1341         }
1342         case ISM_TRANS_CMD_UPDATE_CANDIDATE_ITEM_LAYOUT:
1343         {
1344             MessageItemUpdateCandidateItemLayout *subclass = static_cast<MessageItemUpdateCandidateItemLayout*>(message);
1345             m_impl->signal_update_candidate_item_layout (this, subclass->get_row_items_ref());
1346             if (!m_impl->si.null ()) m_impl->si->update_candidate_item_layout(subclass->get_row_items_ref());
1347             break;
1348         }
1349         case ISM_TRANS_CMD_SELECT_ASSOCIATE:
1350         {
1351             MessageItemSelectAssociate *subclass = static_cast<MessageItemSelectAssociate*>(message);
1352             m_impl->signal_select_associate (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1353                 subclass->get_item_ref());
1354             break;
1355         }
1356         case ISM_TRANS_CMD_ASSOCIATE_TABLE_PAGE_UP:
1357         {
1358             MessageItemAssociateTablePageUp *subclass = static_cast<MessageItemAssociateTablePageUp*>(message);
1359             m_impl->signal_associate_table_page_up (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1360             break;
1361         }
1362         case ISM_TRANS_CMD_ASSOCIATE_TABLE_PAGE_DOWN:
1363         {
1364             MessageItemAssociateTablePageDown *subclass = static_cast<MessageItemAssociateTablePageDown*>(message);
1365             m_impl->signal_associate_table_page_down (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1366             break;
1367         }
1368         case ISM_TRANS_CMD_UPDATE_ASSOCIATE_TABLE_PAGE_SIZE:
1369         {
1370             MessageItemUpdateAssociateTablePageSize *subclass = static_cast<MessageItemUpdateAssociateTablePageSize*>(message);
1371             m_impl->signal_update_associate_table_page_size (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1372                 subclass->get_size_ref());
1373             break;
1374         }
1375         case ISM_TRANS_CMD_RESET_ISE_CONTEXT:
1376         {
1377             MessageItemResetISEContext *subclass = static_cast<MessageItemResetISEContext*>(message);
1378             m_impl->signal_reset_ise_context (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1379             m_impl->signal_reset_input_context (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1380             if (!m_impl->si.null ()) m_impl->si->reset();
1381             break;
1382         }
1383         case ISM_TRANS_CMD_TURN_ON_LOG:
1384         {
1385             MessageItemTurnOnLog *subclass = static_cast<MessageItemTurnOnLog*>(message);
1386             m_impl->signal_turn_on_log (this, subclass->get_state_ref());
1387             break;
1388         }
1389         case ISM_TRANS_CMD_UPDATE_DISPLAYED_CANDIDATE:
1390         {
1391             MessageItemUpdateDisplayedCandidate *subclass = static_cast<MessageItemUpdateDisplayedCandidate*>(message);
1392             m_impl->signal_update_displayed_candidate_number (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1393                 subclass->get_size_ref());
1394             if (!m_impl->si.null ()) m_impl->si->update_displayed_candidate_number(subclass->get_size_ref());
1395             break;
1396         }
1397         case ISM_TRANS_CMD_LONGPRESS_CANDIDATE:
1398         {
1399             MessageItemLongpressCandidate *subclass = static_cast<MessageItemLongpressCandidate*>(message);
1400             m_impl->signal_longpress_candidate (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref(),
1401                 subclass->get_index_ref());
1402             if (!m_impl->si.null ()) m_impl->si->longpress_candidate(subclass->get_index_ref());
1403             break;
1404         }
1405         case ISM_TRANS_CMD_SET_INPUT_HINT:
1406         {
1407             MessageItemSetInputHint *subclass = static_cast<MessageItemSetInputHint*>(message);
1408             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1409                 m_impl->signal_set_input_hint (this, subclass->get_input_hint_ref());
1410             }
1411             if (!m_impl->si.null ()) m_impl->si->set_input_hint(subclass->get_input_hint_ref());
1412             break;
1413         }
1414         case ISM_TRANS_CMD_UPDATE_BIDI_DIRECTION:
1415         {
1416             MessageItemUpdateBidiDirection *subclass = static_cast<MessageItemUpdateBidiDirection*>(message);
1417             m_impl->signal_update_bidi_direction (this, subclass->get_bidi_direction());
1418             if (!m_impl->si.null ()) m_impl->si->update_bidi_direction(subclass->get_bidi_direction());
1419             break;
1420         }
1421         case ISM_TRANS_CMD_SHOW_ISE_OPTION_WINDOW:
1422         {
1423             MessageItemShowISEOptionWindow *subclass = static_cast<MessageItemShowISEOptionWindow*>(message);
1424             m_impl->signal_show_option_window (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1425             break;
1426         }
1427         case ISM_TRANS_CMD_RESUME_ISE_OPTION_WINDOW:
1428         {
1429             MessageItemResumeISEOptionWindow *subclass = static_cast<MessageItemResumeISEOptionWindow*>(message);
1430             m_impl->signal_resume_option_window (this, subclass->get_ic_ref(), subclass->get_ic_uuid_ref());
1431             break;
1432         }
1433         case ISM_TRANS_CMD_CHECK_OPTION_WINDOW:
1434         {
1435             uint32 avail = 0;
1436             m_impl->signal_check_option_window (this, avail);
1437             m_impl->send.clear ();
1438             m_impl->send.put_command (SCIM_TRANS_CMD_REPLY);
1439             m_impl->send.put_data (avail);
1440             m_impl->send.write_to_socket (m_impl->socket);
1441             break;
1442         }
1443         case ISM_TRANS_CMD_PROCESS_INPUT_DEVICE_EVENT:
1444         {
1445             MessageItemProcessInputDeviceEvent *subclass = static_cast<MessageItemProcessInputDeviceEvent*>(message);
1446             uint32 ret = 0;
1447             unsigned int ecore_event_id = find_ecore_event_from_device_type((isf_device_type_e)(subclass->get_type_ref()));
1448             char *decoded = (char*)malloc(subclass->get_len_ref());
1449             size_t decoded_size = subclass->get_len_ref();
1450             if (decoded) {
1451                 if(device_buffer_decode((const char*)*(subclass->get_data_ptr()),
1452                     subclass->get_len_ref(), (char*)(decoded), &decoded_size)) {
1453                     m_impl->signal_process_input_device_event(this, ecore_event_id, decoded, decoded_size, ret);
1454                 }
1455                 free(decoded);
1456             }
1457             break;
1458         }
1459         case SCIM_TRANS_CMD_SET_AUTOCAPITAL_TYPE:
1460         {
1461             MessageItemSetAutocapitalType *subclass = static_cast<MessageItemSetAutocapitalType*>(message);
1462             if (!m_impl->si.null ()) m_impl->si->set_autocapital_type(subclass->get_auto_capital_type_ref());
1463             m_impl->signal_set_autocapital_type(this, subclass->get_auto_capital_type_ref());
1464             break;
1465         }
1466         case ISM_TRANS_CMD_SET_PREDICTION_ALLOW:
1467         {
1468             MessageItemSetPredictionAllow *subclass = static_cast<MessageItemSetPredictionAllow*>(message);
1469             if (!m_impl->si.null ()) m_impl->si->set_prediction_allow(subclass->get_prediction_allow_ref() == 0 ? false : true);
1470             m_impl->signal_set_prediction_allow(this, subclass->get_prediction_allow_ref());
1471             break;
1472         }
1473         case ISM_TRANS_CMD_SET_KEYBOARD_MODE:
1474         {
1475             MessageItemSetKeyboardMode *subclass = static_cast<MessageItemSetKeyboardMode*>(message);
1476             if (subclass->get_mode_ref())
1477                 m_impl->hw_keyboard_mode = false;
1478             else
1479                 m_impl->hw_keyboard_mode = true;
1480             break;
1481         }
1482         case ISM_TRANS_CMD_SET_PREDICTION_HINT:
1483         {
1484             MessageItemSetPredictionHint *subclass = static_cast<MessageItemSetPredictionHint*>(message);
1485             m_impl->signal_set_prediction_hint (this, subclass->get_message_ref());
1486             break;
1487         }
1488         case ISM_TRANS_CMD_SET_MIME_TYPE:
1489         {
1490             MessageItemSetMimeType *subclass = static_cast<MessageItemSetMimeType*>(message);
1491             if (m_impl->ise_show_flag || m_impl->hw_keyboard_mode || m_impl->need_update_entry_metadata) {
1492                 m_impl->signal_set_mime_type (this, subclass->get_mime_type_ref());
1493             }
1494             break;
1495         }
1496         case ISM_TRANS_CMD_FINALIZE_CONTENT:
1497         {
1498             MessageItemFinalizeContent *subclass = static_cast<MessageItemFinalizeContent*>(message);
1499             if (m_impl) {
1500                 if (m_impl->finalized_text != NULL)
1501                     free(m_impl->finalized_text);
1502                 m_impl->finalized_text = strdup(subclass->get_text_ref().c_str());
1503                 m_impl->finalized_cursor_pos = subclass->get_cursor_pos_ref();
1504             }
1505             break;
1506         }
1507         case ISM_TRANS_CMD_SET_PREDICTION_HINT_DATA:
1508         {
1509             MessageItemSetPredictionHintData *subclass = static_cast<MessageItemSetPredictionHintData*>(message);
1510             m_impl->signal_set_prediction_hint_data (this, 0, subclass->get_key_ref(), subclass->get_value_ref());
1511             break;
1512         }
1513         case ISM_TRANS_CMD_SET_OPTIMIZATION_HINT:
1514         {
1515             MessageItemSetOptimizationHint *subclass = static_cast<MessageItemSetOptimizationHint*>(message);
1516             m_impl->signal_set_optimization_hint(this, subclass->get_hint_ref());
1517             break;
1518         }
1519         default:
1520             break;
1521     }
1522     return true;
1523 }
1524
1525 /**
1526  * @brief Request SCIM to reload all configuration.
1527  *
1528  * This function should only by used by Setup Helper to request
1529  * scim's reloading the configuration.
1530  * Deprecated: reload config message only send by socketconfig client
1531  * using socketconfig::reload instead.
1532  */
1533 void
1534 HelperAgent::reload_config () const
1535 {
1536     LOGD ("send reload config message to isf");
1537     if (!m_impl->m_config.null())
1538         m_impl->m_config->reload();
1539 }
1540
1541 /**
1542  * @brief Register some properties into Panel.
1543  *
1544  * This function send the request to Panel to register a list
1545  * of Properties.
1546  *
1547  * @param properties The list of Properties to be registered into Panel.
1548  *
1549  * @sa scim::Property.
1550  */
1551 void
1552 HelperAgent::register_properties (const PropertyList &properties) const
1553 {
1554     if (m_impl->socket_active.is_connected ()) {
1555         m_impl->send.clear ();
1556         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1557         m_impl->send.put_data (m_impl->magic_active);
1558         m_impl->send.put_command (SCIM_TRANS_CMD_REGISTER_PROPERTIES);
1559         m_impl->send.put_data (properties);
1560         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1561     }
1562 }
1563
1564 /**
1565  * @brief Update a registered property.
1566  *
1567  * @param property The property to be updated.
1568  */
1569 void
1570 HelperAgent::update_property (const Property &property) const
1571 {
1572     if (m_impl->socket_active.is_connected ()) {
1573         m_impl->send.clear ();
1574         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1575         m_impl->send.put_data (m_impl->magic_active);
1576         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_PROPERTY);
1577         m_impl->send.put_data (property);
1578         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1579     }
1580 }
1581
1582 /**
1583  * @brief Send a set of events to an IMEngineInstance.
1584  *
1585  * All events should be put into a Transaction.
1586  * And the events can only be received by one IMEngineInstance object.
1587  *
1588  * @param ic The handle of the Input Context to receive the events.
1589  * @param ic_uuid The UUID of the Input Context.
1590  * @param trans The Transaction object holds the events.
1591  */
1592 void
1593 HelperAgent::send_imengine_event (int                ic,
1594                                   const String      &ic_uuid,
1595                                   const Transaction &trans) const
1596 {
1597 //remove if not necessary
1598 #if 0
1599     if (m_impl->socket_active.is_connected ()) {
1600         m_impl->send.clear ();
1601         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1602         m_impl->send.put_data (m_impl->magic_active);
1603         m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_SEND_IMENGINE_EVENT);
1604         m_impl->send.put_data ((uint32)ic);
1605         m_impl->send.put_data (ic_uuid);
1606         m_impl->send.put_data (trans);
1607         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1608     }
1609 #endif
1610     if (!m_impl->si.null ()) m_impl->si->process_helper_event (ic_uuid, trans);
1611 }
1612
1613 /**
1614  * @brief Send a KeyEvent to an IMEngineInstance.
1615  *
1616  * @param ic The handle of the IMEngineInstance to receive the event.
1617  *        -1 means the currently focused IMEngineInstance.
1618  * @param ic_uuid The UUID of the IMEngineInstance. Empty means don't match.
1619  * @param key The KeyEvent to be sent.
1620  */
1621 void
1622 HelperAgent::send_key_event (int            ic,
1623                              const String   &ic_uuid,
1624                              const KeyEvent &key) const
1625 {
1626
1627     //FIXME: remove shift_mode_off, shift_mode_on, shift_mode_lock from ISE side
1628     if (key.code == SHIFT_MODE_OFF ||
1629         key.code == SHIFT_MODE_ON ||
1630         key.code == SHIFT_MODE_LOCK ||
1631         key.code == SHIFT_MODE_ENABLE ||
1632         key.code == SHIFT_MODE_DISABLE) {
1633         LOGW("FIXME ignore shift codes");
1634         return;
1635     }
1636
1637     if (m_impl->socket_active.is_connected ()) {
1638         m_impl->send.clear ();
1639         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1640         m_impl->send.put_data (m_impl->magic_active);
1641         m_impl->send.put_command (SCIM_TRANS_CMD_PANEL_SEND_KEY_EVENT);
1642         if (ic == -1) {
1643             m_impl->send.put_data (m_impl->focused_ic);
1644         } else {
1645             m_impl->send.put_data ((uint32)ic);
1646         }
1647         m_impl->send.put_data (ic_uuid);
1648         m_impl->send.put_data (key);
1649         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1650     }
1651 }
1652
1653 /**
1654  * @brief Forward a KeyEvent to client application directly.
1655  *
1656  * @param ic The handle of the client Input Context to receive the event.
1657  *        -1 means the currently focused Input Context.
1658  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1659  *        Empty means don't match.
1660  * @param key The KeyEvent to be forwarded.
1661  */
1662 void
1663 HelperAgent::forward_key_event (int            ic,
1664                                 const String   &ic_uuid,
1665                                 const KeyEvent &key) const
1666 {
1667     if (m_impl->socket_active.is_connected ()) {
1668         m_impl->send.clear ();
1669         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1670         m_impl->send.put_data (m_impl->magic_active);
1671         m_impl->send.put_command (SCIM_TRANS_CMD_FORWARD_KEY_EVENT);
1672         if (ic == -1) {
1673             m_impl->send.put_data (m_impl->focused_ic);
1674         } else {
1675             m_impl->send.put_data ((uint32)ic);
1676         }
1677         m_impl->send.put_data (ic_uuid);
1678         m_impl->send.put_data (key);
1679         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1680     }
1681 }
1682
1683 /**
1684  * @brief Commit a WideString to client application directly.
1685  *
1686  * @param ic The handle of the client Input Context to receive the WideString.
1687  *        -1 means the currently focused Input Context.
1688  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1689  *        Empty means don't match.
1690  * @param wstr The WideString to be committed.
1691  */
1692 void
1693 HelperAgent::commit_string (int               ic,
1694                             const String     &ic_uuid,
1695                             const WideString &wstr) const
1696 {
1697     if (m_impl->socket_active.is_connected ()) {
1698         m_impl->send.clear ();
1699         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1700         m_impl->send.put_data (m_impl->magic_active);
1701         m_impl->send.put_command (SCIM_TRANS_CMD_COMMIT_STRING);
1702         if (ic == -1) {
1703             m_impl->send.put_data (m_impl->focused_ic);
1704         } else {
1705             m_impl->send.put_data ((uint32)ic);
1706         }
1707         m_impl->send.put_data (ic_uuid);
1708         m_impl->send.put_data (wstr);
1709         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1710     }
1711 }
1712
1713 void
1714 HelperAgent::commit_string (int               ic,
1715                             const String     &ic_uuid,
1716                             const  char      *buf,
1717                             int               buflen) const
1718 {
1719     if (m_impl->socket_active.is_connected ()) {
1720         m_impl->send.clear ();
1721         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1722         m_impl->send.put_data (m_impl->magic_active);
1723         m_impl->send.put_command (SCIM_TRANS_CMD_COMMIT_STRING);
1724         if (ic == -1) {
1725             m_impl->send.put_data (m_impl->focused_ic);
1726         } else {
1727             m_impl->send.put_data ((uint32)ic);
1728         }
1729         m_impl->send.put_data (ic_uuid);
1730         m_impl->send.put_dataw (buf, buflen);
1731         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1732     }
1733 }
1734
1735 /**
1736  * @brief Request to show preedit string.
1737  *
1738  * @param ic The handle of the client Input Context to receive the request.
1739  *        -1 means the currently focused Input Context.
1740  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1741  *        Empty means don't match.
1742  */
1743 void
1744 HelperAgent::show_preedit_string (int               ic,
1745                                   const String     &ic_uuid) const
1746 {
1747
1748     if (m_impl->socket_active.is_connected ()) {
1749         m_impl->send.clear ();
1750         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1751         m_impl->send.put_data (m_impl->magic_active);
1752         m_impl->send.put_command (SCIM_TRANS_CMD_SHOW_PREEDIT_STRING);
1753         m_impl->send.put_data ((uint32)ic);
1754         m_impl->send.put_data (ic_uuid);
1755         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1756     }
1757 }
1758
1759 /**
1760  * @brief Request to show aux string.
1761  */
1762 void
1763 HelperAgent::show_aux_string (void) const
1764 {
1765
1766     if (m_impl->socket_active.is_connected ()) {
1767         m_impl->send.clear ();
1768         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1769         m_impl->send.put_data (m_impl->magic_active);
1770         m_impl->send.put_command (SCIM_TRANS_CMD_SHOW_AUX_STRING);
1771         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1772     }
1773 }
1774
1775 /**
1776  * @brief Request to show candidate string.
1777  */
1778 void
1779 HelperAgent::show_candidate_string (void) const
1780 {
1781
1782     if (m_impl->socket_active.is_connected ()) {
1783         m_impl->send.clear ();
1784         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1785         m_impl->send.put_data (m_impl->magic_active);
1786         m_impl->send.put_command (SCIM_TRANS_CMD_SHOW_LOOKUP_TABLE);
1787         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1788     }
1789 }
1790
1791 /**
1792  * @brief Request to show associate string.
1793  */
1794 void
1795 HelperAgent::show_associate_string (void) const
1796 {
1797     if (m_impl->socket_active.is_connected ()) {
1798         m_impl->send.clear ();
1799         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1800         m_impl->send.put_data (m_impl->magic_active);
1801         m_impl->send.put_command (ISM_TRANS_CMD_SHOW_ASSOCIATE_TABLE);
1802         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1803     }
1804 }
1805
1806 /**
1807  * @brief Request to hide preedit string.
1808  *
1809  * @param ic The handle of the client Input Context to receive the request.
1810  *        -1 means the currently focused Input Context.
1811  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1812  *        Empty means don't match.
1813  */
1814 void
1815 HelperAgent::hide_preedit_string (int               ic,
1816                                   const String     &ic_uuid) const
1817 {
1818
1819     if (m_impl->socket_active.is_connected ()) {
1820         m_impl->send.clear ();
1821         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1822         m_impl->send.put_data (m_impl->magic_active);
1823         m_impl->send.put_command (SCIM_TRANS_CMD_HIDE_PREEDIT_STRING);
1824         m_impl->send.put_data ((uint32)ic);
1825         m_impl->send.put_data (ic_uuid);
1826         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1827     }
1828 }
1829
1830 /**
1831  * @brief Request to hide aux string.
1832  */
1833 void
1834 HelperAgent::hide_aux_string (void) const
1835 {
1836     if (m_impl->socket_active.is_connected ()) {
1837         m_impl->send.clear ();
1838         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1839         m_impl->send.put_data (m_impl->magic_active);
1840         m_impl->send.put_command (SCIM_TRANS_CMD_HIDE_AUX_STRING);
1841         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1842     }
1843 }
1844
1845 /**
1846  * @brief Request to hide candidate string.
1847  */
1848 void
1849 HelperAgent::hide_candidate_string (void) const
1850 {
1851     if (m_impl->socket_active.is_connected ()) {
1852         m_impl->send.clear ();
1853         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1854         m_impl->send.put_data (m_impl->magic_active);
1855         m_impl->send.put_command (SCIM_TRANS_CMD_HIDE_LOOKUP_TABLE);
1856         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1857     }
1858 }
1859
1860 /**
1861  * @brief Request to hide associate string.
1862  */
1863 void
1864 HelperAgent::hide_associate_string (void) const
1865 {
1866     if (m_impl->socket_active.is_connected ()) {
1867         m_impl->send.clear ();
1868         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1869         m_impl->send.put_data (m_impl->magic_active);
1870         m_impl->send.put_command (ISM_TRANS_CMD_HIDE_ASSOCIATE_TABLE);
1871         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1872     }
1873 }
1874
1875 /**
1876  * @brief Update a new WideString for preedit.
1877  *
1878  * @param ic The handle of the client Input Context to receive the WideString.
1879  *        -1 means the currently focused Input Context.
1880  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1881  *        Empty means don't match.
1882  * @param str The WideString to be updated.
1883  * @param attrs The attribute list for preedit string.
1884  */
1885 void
1886 HelperAgent::update_preedit_string (int                  ic,
1887                                     const String        &ic_uuid,
1888                                     const WideString    &str,
1889                                     const AttributeList &attrs) const
1890 {
1891     update_preedit_string (ic, ic_uuid, str, str, attrs, -1);
1892 }
1893
1894 void
1895 HelperAgent::update_preedit_string (int                  ic,
1896                                     const String        &ic_uuid,
1897                                     const char         *buf,
1898                                     int                 buflen,
1899                                     const AttributeList &attrs) const
1900 {
1901     update_preedit_string (ic, ic_uuid, buf, buflen, attrs, -1);
1902 }
1903
1904 /**
1905  * @brief Update a new WideString for preedit.
1906  *
1907  * @param ic The handle of the client Input Context to receive the WideString.
1908  *        -1 means the currently focused Input Context.
1909  * @param ic_uuid The UUID of the IMEngine used by the Input Context.
1910  *        Empty means don't match.
1911  * @param str The WideString to be updated.
1912  * @param attrs The attribute list for preedit string.
1913  * @param caret The caret position in preedit string.
1914  */
1915 void
1916 HelperAgent::update_preedit_string (int                  ic,
1917                                     const String        &ic_uuid,
1918                                     const WideString    &wstr,
1919                                     const AttributeList &attrs,
1920                                     int            caret) const
1921 {
1922     update_preedit_string (ic, ic_uuid, wstr, wstr, attrs, caret);
1923 }
1924
1925 void
1926 HelperAgent::update_preedit_string (int                 ic,
1927                                     const String       &ic_uuid,
1928                                     const char         *buf,
1929                                     int                 buflen,
1930                                     const AttributeList &attrs,
1931                                     int            caret) const
1932 {
1933
1934     if (m_impl->socket_active.is_connected ()) {
1935         m_impl->send.clear ();
1936         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1937         m_impl->send.put_data (m_impl->magic_active);
1938         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING);
1939         m_impl->send.put_data ((uint32)ic);
1940         m_impl->send.put_data (ic_uuid);
1941         m_impl->send.put_dataw (buf, buflen);
1942         m_impl->send.put_dataw (buf, buflen);
1943         m_impl->send.put_data (attrs);
1944         m_impl->send.put_data (caret);
1945         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1946     }
1947 }
1948
1949 void
1950 HelperAgent::update_preedit_string (int                  ic,
1951                                     const String        &ic_uuid,
1952                                     const WideString    &preedit,
1953                                     const WideString    &commit,
1954                                     const AttributeList &attrs,
1955                                     int                  caret) const
1956 {
1957     if (m_impl->socket_active.is_connected ()) {
1958         m_impl->send.clear ();
1959         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1960         m_impl->send.put_data (m_impl->magic_active);
1961         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING);
1962         m_impl->send.put_data ((uint32)ic);
1963         m_impl->send.put_data (ic_uuid);
1964         m_impl->send.put_data (preedit);
1965         m_impl->send.put_data (commit);
1966         m_impl->send.put_data (attrs);
1967         m_impl->send.put_data (caret);
1968         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1969     }
1970 }
1971
1972 /**
1973  * @brief Update the preedit caret position in the preedit string.
1974  *
1975  * @param caret - the new position of the preedit caret.
1976  */
1977 void
1978 HelperAgent::update_preedit_caret (int caret) const
1979 {
1980
1981     if (m_impl->socket_active.is_connected ()) {
1982         m_impl->send.clear ();
1983         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
1984         m_impl->send.put_data (m_impl->magic_active);
1985         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET);
1986         m_impl->send.put_data ((uint32)caret);
1987         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
1988     }
1989 }
1990
1991 /**
1992  * @brief Update a new string for aux.
1993  *
1994  * @param str The string to be updated.
1995  * @param attrs The attribute list for aux string.
1996  */
1997 void
1998 HelperAgent::update_aux_string (const String        &str,
1999                                 const AttributeList &attrs) const
2000 {
2001     if (m_impl->socket_active.is_connected ()) {
2002         m_impl->send.clear ();
2003         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2004         m_impl->send.put_data (m_impl->magic_active);
2005         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_AUX_STRING);
2006         m_impl->send.put_data (str);
2007         m_impl->send.put_data (attrs);
2008         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2009     }
2010 }
2011
2012 /**
2013  * @brief Request to update candidate.
2014  *
2015  * @param table The lookup table for candidate.
2016  */
2017 void
2018 HelperAgent::update_candidate_string (const LookupTable &table) const
2019 {
2020     if (m_impl->socket_active.is_connected ()) {
2021         m_impl->send.clear ();
2022         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2023         m_impl->send.put_data (m_impl->magic_active);
2024         m_impl->send.put_command (SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE);
2025         m_impl->send.put_data (table);
2026         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2027     }
2028 }
2029
2030 /**
2031  * @brief Request to update associate.
2032  *
2033  * @param table The lookup table for associate.
2034  */
2035 void
2036 HelperAgent::update_associate_string (const LookupTable &table) const
2037 {
2038     if (m_impl->socket_active.is_connected ()) {
2039         m_impl->send.clear ();
2040         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2041         m_impl->send.put_data (m_impl->magic_active);
2042         m_impl->send.put_command (ISM_TRANS_CMD_UPDATE_ASSOCIATE_TABLE);
2043         m_impl->send.put_data (table);
2044         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2045     }
2046 }
2047
2048 /**
2049  * @brief When the input context of ISE is changed,
2050  *         ISE can call this function to notify application
2051  *
2052  * @param type  type of event.
2053  * @param value value of event.
2054  */
2055 void
2056 HelperAgent::update_input_context (uint32 type, uint32 value) const
2057 {
2058     if (type == ECORE_IMF_INPUT_PANEL_LANGUAGE_EVENT) {
2059         /* Update all state variables that could be queried by the client application */
2060         char *buf = NULL;
2061         m_impl->signal_get_language_locale(this, -1, &buf);
2062
2063         if (buf != NULL) {
2064             if (m_impl->socket_active.is_connected()) {
2065                 m_impl->send.clear();
2066                 m_impl->send.put_command(SCIM_TRANS_CMD_REQUEST);
2067                 m_impl->send.put_data(m_impl->magic_active);
2068                 m_impl->send.put_command(ISM_TRANS_CMD_UPDATE_ISE_LANGUAGE_LOCALE);
2069                 m_impl->send.put_data(buf, strlen(buf));
2070                 m_impl->send.write_to_socket(m_impl->socket_active, m_impl->magic_active);
2071             }
2072             free(buf);
2073             buf = NULL;
2074         }
2075     }
2076
2077     if (m_impl->socket_active.is_connected ()) {
2078         m_impl->send.clear ();
2079         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2080         m_impl->send.put_data (m_impl->magic_active);
2081         m_impl->send.put_command (ISM_TRANS_CMD_UPDATE_ISE_INPUT_CONTEXT);
2082         m_impl->send.put_data (type);
2083         m_impl->send.put_data (value);
2084         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2085     }
2086 }
2087
2088 /**
2089  * @brief Request to get surrounding text asynchronously.
2090  *
2091  * @param uuid The helper ISE UUID.
2092  * @param maxlen_before The max length of before.
2093  * @param maxlen_after The max length of after.
2094  */
2095 void
2096 HelperAgent::get_surrounding_text (const String &uuid, int maxlen_before, int maxlen_after) const
2097 {
2098     if (m_impl->socket_active.is_connected () && (m_impl->need_update_surrounding_text == 0)) {
2099         m_impl->send.clear ();
2100         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2101         m_impl->send.put_data (m_impl->magic_active);
2102         m_impl->send.put_command (SCIM_TRANS_CMD_GET_SURROUNDING_TEXT);
2103         m_impl->send.put_data (uuid);
2104         m_impl->send.put_data (maxlen_before);
2105         m_impl->send.put_data (maxlen_after);
2106         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2107     }
2108     m_impl->need_update_surrounding_text++;
2109 }
2110
2111 /**
2112  * @brief Request to get surrounding text synchronously.
2113  *
2114  * @param uuid The helper ISE UUID.
2115  * @param maxlen_before The max length of before.
2116  * @param maxlen_after The max length of after.
2117  * @param text The surrounding text.
2118  * @param cursor The cursor position.
2119  */
2120 void
2121 HelperAgent::get_surrounding_text (int maxlen_before, int maxlen_after, String &text, int &cursor)
2122 {
2123     if (!m_impl->socket_active.is_connected ())
2124         return;
2125
2126     if (!m_impl->ise_focus_flag) {
2127         if (m_impl->finalized_text) {
2128             String buffer = m_impl->finalized_text;
2129             cursor = m_impl->finalized_cursor_pos;
2130             int pos = cursor - maxlen_before;
2131             if (maxlen_before < 0) pos = 0;
2132             if (pos > (int)buffer.length()) pos = (int)buffer.length();
2133             if (pos < 0) pos = 0;
2134             size_t len = maxlen_after + (cursor - pos);
2135             if (maxlen_after < 0) len = String::npos;
2136             text = buffer.substr (pos, len);
2137         } else {
2138             text.clear ();
2139             cursor = 0;
2140         }
2141     } else {
2142         m_impl->send.clear();
2143         m_impl->send.put_command(SCIM_TRANS_CMD_REQUEST);
2144         m_impl->send.put_data(m_impl->magic_active);
2145         m_impl->send.put_command(SCIM_TRANS_CMD_GET_SURROUNDING_TEXT);
2146         m_impl->send.put_data("");
2147         m_impl->send.put_data(maxlen_before);
2148         m_impl->send.put_data(maxlen_after);
2149         m_impl->send.write_to_socket(m_impl->socket_active, m_impl->magic_active);
2150         if (m_impl->surrounding_text) {
2151             free(m_impl->surrounding_text);
2152             m_impl->surrounding_text = NULL;
2153         }
2154
2155         const int WAIT_FOR_SYNC_RESPONSE_TIMEOUT = 1000;
2156         /* Now we are waiting for the ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT message */
2157         if (wait_for_message(ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT, WAIT_FOR_SYNC_RESPONSE_TIMEOUT)) {
2158             MessageItem *message = message_queue.get_pending_message_by_cmd(ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT);
2159             handle_message(message);
2160             message_queue.remove_message(message);
2161
2162             if (m_impl->surrounding_text) {
2163                 text = m_impl->surrounding_text;
2164                 cursor = m_impl->cursor_pos;
2165             }
2166         }
2167
2168         if (m_impl->surrounding_text) {
2169             free(m_impl->surrounding_text);
2170             m_impl->surrounding_text = NULL;
2171         }
2172
2173         LOGD("message_queue size : %d", message_queue.get_message_size());
2174
2175         m_impl->send.clear ();
2176         m_impl->send.put_command(SCIM_TRANS_CMD_REQUEST);
2177         m_impl->send.put_data(m_impl->magic_active);
2178         m_impl->send.put_command(SCIM_TRANS_CMD_PING);
2179         m_impl->send.write_to_socket(m_impl->socket_active, m_impl->magic_active);
2180     }
2181 }
2182
2183 /**
2184  * @brief Request to delete surrounding text.
2185  *
2186  * @param offset The offset for cursor position.
2187  * @param len The length for delete text.
2188  */
2189 void
2190 HelperAgent::delete_surrounding_text (int offset, int len) const
2191 {
2192     LOGD ("offset = %d, len = %d", offset, len);
2193
2194     if (m_impl->socket_active.is_connected ()) {
2195         m_impl->send.clear ();
2196         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2197         m_impl->send.put_data (m_impl->magic_active);
2198         m_impl->send.put_command (SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT);
2199         m_impl->send.put_data (offset);
2200         m_impl->send.put_data (len);
2201         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2202     }
2203 }
2204
2205 /**
2206  * @brief Request to get selection text asynchronously.
2207  *
2208  * @param uuid The helper ISE UUID.
2209  */
2210 void
2211 HelperAgent::get_selection (const String &uuid) const
2212 {
2213     if (m_impl->socket_active.is_connected () && (m_impl->need_update_selection_text == 0)) {
2214         m_impl->send.clear ();
2215         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2216         m_impl->send.put_data (m_impl->magic_active);
2217         m_impl->send.put_command (SCIM_TRANS_CMD_GET_SELECTION);
2218         m_impl->send.put_data (uuid);
2219         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2220     }
2221     m_impl->need_update_selection_text++;
2222 }
2223
2224 /**
2225  * @brief Request to get selection text synchronously.
2226  *
2227  * @param text The selection text.
2228  */
2229 void
2230 HelperAgent::get_selection_text (String &text)
2231 {
2232
2233     if (!m_impl->socket_active.is_connected ())
2234         return;
2235
2236     m_impl->send.clear ();
2237     m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2238     m_impl->send.put_data (m_impl->magic_active);
2239     m_impl->send.put_command (SCIM_TRANS_CMD_GET_SELECTION);
2240     m_impl->send.put_data ("");
2241     m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2242     if (m_impl->selection_text) {
2243         free (m_impl->selection_text);
2244         m_impl->selection_text = NULL;
2245     }
2246
2247     const int WAIT_FOR_SYNC_RESPONSE_TIMEOUT = 1000;
2248     /* Now we are waiting for the ISM_TRANS_CMD_UPDATE_SELECTION message */
2249     if (wait_for_message(ISM_TRANS_CMD_UPDATE_SELECTION, WAIT_FOR_SYNC_RESPONSE_TIMEOUT)) {
2250         MessageItem *message = message_queue.get_pending_message_by_cmd(ISM_TRANS_CMD_UPDATE_SELECTION);
2251         handle_message(message);
2252         message_queue.remove_message(message);
2253         if (m_impl->selection_text) {
2254             text = m_impl->selection_text;
2255         }
2256     }
2257
2258     if (m_impl->selection_text) {
2259         free (m_impl->selection_text);
2260         m_impl->selection_text = NULL;
2261     }
2262
2263     LOGD("message_queue size : %d", message_queue.get_message_size());
2264
2265     m_impl->send.clear ();
2266     m_impl->send.put_command(SCIM_TRANS_CMD_REQUEST);
2267     m_impl->send.put_data(m_impl->magic_active);
2268     m_impl->send.put_command(SCIM_TRANS_CMD_PING);
2269     m_impl->send.write_to_socket(m_impl->socket_active, m_impl->magic_active);
2270 }
2271
2272 /**
2273  * @brief Request to select text.
2274  *
2275  * @param start The start position in text.
2276  * @param end The end position in text.
2277  */
2278 void
2279 HelperAgent::set_selection (int start, int end) const
2280 {
2281     if (m_impl->socket_active.is_connected ()) {
2282         m_impl->send.clear ();
2283         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2284         m_impl->send.put_data (m_impl->magic_active);
2285         m_impl->send.put_command (SCIM_TRANS_CMD_SET_SELECTION);
2286         m_impl->send.put_data (start);
2287         m_impl->send.put_data (end);
2288         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2289     }
2290 }
2291
2292 /**
2293  * @brief Send a private command to an application.
2294  *
2295  * @param command The private command sent from IME.
2296  */
2297 void
2298 HelperAgent::send_private_command (const String &command) const
2299 {
2300     if (m_impl->socket_active.is_connected ()) {
2301         m_impl->send.clear ();
2302         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2303         m_impl->send.put_data (m_impl->magic_active);
2304         m_impl->send.put_command (SCIM_TRANS_CMD_SEND_PRIVATE_COMMAND);
2305         m_impl->send.put_data (command);
2306         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2307     }
2308 }
2309
2310 /**
2311  * @brief Commit content to an application.
2312  *
2313  * @param content The content sent from IME.
2314  */
2315 void
2316 HelperAgent::commit_content (const String &content, const String &description, const String &mime_types) const
2317 {
2318     LOGD ("");
2319     if (m_impl->socket_active.is_connected ()) {
2320         m_impl->send.clear ();
2321         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2322         m_impl->send.put_data (m_impl->magic_active);
2323         m_impl->send.put_command (SCIM_TRANS_CMD_COMMIT_CONTENT);
2324         m_impl->send.put_data (content);
2325         m_impl->send.put_data (description);
2326         m_impl->send.put_data (mime_types);
2327         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2328     }
2329 }
2330
2331 /**
2332  * @brief Request to get uuid list of all keyboard ISEs.
2333  *
2334  * @param uuid The helper ISE UUID.
2335  */
2336 void
2337 HelperAgent::get_keyboard_ise_list (const String &uuid) const
2338 {
2339     if (m_impl->socket_active.is_connected ()) {
2340         m_impl->send.clear ();
2341         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2342         m_impl->send.put_data (m_impl->magic_active);
2343         m_impl->send.put_command (ISM_TRANS_CMD_GET_KEYBOARD_ISE_LIST);
2344         m_impl->send.put_data (uuid);
2345         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2346     }
2347 }
2348
2349 /**
2350  * @brief Set candidate position in screen.
2351  *
2352  * @param left The x position in screen.
2353  * @param top The y position in screen.
2354  */
2355 void
2356 HelperAgent::set_candidate_position (int left, int top) const
2357 {
2358     if (m_impl->socket_active.is_connected ()) {
2359         m_impl->send.clear ();
2360         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2361         m_impl->send.put_data (m_impl->magic_active);
2362         m_impl->send.put_command (ISM_TRANS_CMD_SET_CANDIDATE_POSITION);
2363         m_impl->send.put_data (left);
2364         m_impl->send.put_data (top);
2365         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2366     }
2367 }
2368
2369 /**
2370  * @brief Set candidate style.
2371  *
2372  * @param portrait_line - the displayed line number for portrait mode.
2373  * @param mode          - candidate window mode.
2374  */
2375 void
2376 HelperAgent::set_candidate_style (ISF_CANDIDATE_PORTRAIT_LINE_T portrait_line,
2377                                   ISF_CANDIDATE_MODE_T          mode) const
2378 {
2379     if (m_impl->socket_active.is_connected ()) {
2380         m_impl->send.clear ();
2381         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2382         m_impl->send.put_data (m_impl->magic_active);
2383         m_impl->send.put_command (ISM_TRANS_CMD_SET_CANDIDATE_UI);
2384         m_impl->send.put_data (portrait_line);
2385         m_impl->send.put_data (mode);
2386         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2387     }
2388 }
2389
2390 /**
2391  * @brief Request to hide candidate window.
2392  */
2393 void
2394 HelperAgent::candidate_hide (void) const
2395 {
2396     if (m_impl->socket_active.is_connected ()) {
2397         m_impl->send.clear ();
2398         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2399         m_impl->send.put_data (m_impl->magic_active);
2400         m_impl->send.put_command (ISM_TRANS_CMD_HIDE_CANDIDATE);
2401         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2402     }
2403 }
2404
2405 /**
2406  * @brief Request to get candidate window size and position.
2407  *
2408  * @param uuid The helper ISE UUID.
2409  */
2410 void
2411 HelperAgent::get_candidate_window_geometry (const String &uuid) const
2412 {
2413     if (m_impl->socket_active.is_connected ()) {
2414         m_impl->send.clear ();
2415         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2416         m_impl->send.put_data (m_impl->magic_active);
2417         m_impl->send.put_command (ISM_TRANS_CMD_GET_CANDIDATE_GEOMETRY);
2418         m_impl->send.put_data (uuid);
2419         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2420     }
2421 }
2422
2423 /**
2424  * @brief Set current keyboard ISE.
2425  *
2426  * @param uuid The keyboard ISE UUID.
2427  */
2428 void
2429 HelperAgent::set_keyboard_ise_by_uuid (const String &uuid) const
2430 {
2431     ImeInfoDB imeInfo;
2432     IMEngineFactoryPointer factory;
2433     IMEngineModule *engine_module = NULL;
2434     static int instance_count = 1;
2435
2436     if ((!m_impl->si.null ()) && m_impl->si->get_factory_uuid () == uuid) {
2437         ISF_SAVE_LOG ("Already in UUID: %s", uuid.c_str());
2438         return;
2439     }
2440
2441     if (!m_impl->si.null()) {
2442         m_impl->si->focus_out();
2443         m_impl->si.reset();
2444     }
2445
2446     if (m_impl->m_config.null ()) {
2447         ISF_SAVE_LOG ("config is not working");
2448         return;
2449     }
2450
2451 #ifdef HAVE_PKGMGR_INFO
2452     int ret = 0;
2453     char *pkgid = NULL;
2454     pkgmgrinfo_appinfo_h handle;
2455     ret = pkgmgrinfo_appinfo_get_appinfo(uuid.c_str(), &handle);
2456     if (ret != PMINFO_R_OK) {
2457         ISF_SAVE_LOG ("Retrieve app info failed : %s", uuid.c_str ());
2458         return;
2459     }
2460
2461     ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgid);
2462     if (ret != PMINFO_R_OK) {
2463         ISF_SAVE_LOG ("Retrieve pkgid failed : %s, %p", uuid.c_str(), handle);
2464         pkgmgrinfo_appinfo_destroy_appinfo(handle);
2465         return;
2466     }
2467
2468     imeInfo.module_name = pkgid;
2469     pkgmgrinfo_appinfo_destroy_appinfo(handle);
2470 #else
2471     if (isf_db_select_ime_info_by_appid(uuid.c_str(), &imeInfo) < 1) {
2472         ISF_SAVE_LOG ("ime_info row is not available for %s", uuid.c_str());
2473         return;
2474     }
2475 #endif
2476
2477     engine_module = &m_impl->engine_module;
2478
2479     if (engine_module->valid() && imeInfo.module_name != engine_module->get_module_name()) {
2480         ISF_SAVE_LOG ("imengine module %s unloaded", engine_module->get_module_name().c_str());
2481         engine_module->unload();
2482     }
2483
2484     if (!engine_module->valid()) {
2485         if (engine_module->load (imeInfo.module_name, m_impl->m_config) == false) {
2486             ISF_SAVE_LOG ("load module %s failed", imeInfo.module_name.c_str());
2487             return;
2488         }
2489         ISF_SAVE_LOG ("imengine module %s loaded", imeInfo.module_name.c_str());
2490     }
2491
2492     for (size_t j = 0; j < engine_module->number_of_factories (); ++j) {
2493         try {
2494             factory = engine_module->create_factory (j);
2495             if (factory.null () == false && factory->get_uuid () == uuid)
2496                 break;
2497         } catch (...) {
2498             factory.reset ();
2499             return;
2500         }
2501     }
2502
2503     if (factory.null()) {
2504         ISF_SAVE_LOG ("imengine uuid %s is not found", uuid.c_str());
2505         return;
2506     }
2507
2508     m_impl->si = factory->create_instance ("UTF-8", instance_count++);
2509     if (m_impl->si.null ()) {
2510         ISF_SAVE_LOG ("create_instance %s failed", uuid.c_str ());
2511         return;
2512     }
2513
2514     m_impl->attach_instance ();
2515     ISF_SAVE_LOG ("Require UUID: %s Current UUID: %s", uuid.c_str (), m_impl->si->get_factory_uuid ().c_str ());
2516     m_impl->si->set_layout (m_impl->layout);
2517     if (m_impl->focused_ic != (uint32)-1)
2518         m_impl->si->focus_in ();
2519 }
2520
2521 /**
2522  * @brief Request to get current keyboard ISE information.
2523  *
2524  * @param uuid The helper ISE UUID.
2525  */
2526 void
2527 HelperAgent::get_keyboard_ise (const String &uuid) const
2528 {
2529     //FIXME: maybe useless
2530 #if 0
2531     if (m_impl->socket_active.is_connected ()) {
2532         m_impl->send.clear ();
2533         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2534         m_impl->send.put_data (m_impl->magic_active);
2535         m_impl->send.put_command (ISM_TRANS_CMD_GET_KEYBOARD_ISE);
2536         m_impl->send.put_data (uuid);
2537         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2538     }
2539 #endif
2540 }
2541
2542 /**
2543  * @brief Update ISE window geometry.
2544  *
2545  * @param x      The x position in screen.
2546  * @param y      The y position in screen.
2547  * @param width  The ISE window width.
2548  * @param height The ISE window height.
2549  */
2550 void
2551 HelperAgent::update_geometry (int x, int y, int width, int height) const
2552 {
2553     if (m_impl->socket_active.is_connected ()) {
2554         m_impl->send.clear ();
2555         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2556         m_impl->send.put_data (m_impl->magic_active);
2557         m_impl->send.put_command (ISM_TRANS_CMD_UPDATE_ISE_GEOMETRY);
2558         m_impl->send.put_data (x);
2559         m_impl->send.put_data (y);
2560         m_impl->send.put_data (width);
2561         m_impl->send.put_data (height);
2562         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2563     }
2564 }
2565
2566 /**
2567  * @brief Request to expand candidate window.
2568  */
2569 void
2570 HelperAgent::expand_candidate (void) const
2571 {
2572     if (m_impl->socket_active.is_connected ()) {
2573         m_impl->send.clear ();
2574         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2575         m_impl->send.put_data (m_impl->magic_active);
2576         m_impl->send.put_command (ISM_TRANS_CMD_EXPAND_CANDIDATE);
2577         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2578     }
2579 }
2580
2581 /**
2582  * @brief Request to contract candidate window.
2583  */
2584 void
2585 HelperAgent::contract_candidate (void) const
2586 {
2587     if (m_impl->socket_active.is_connected ()) {
2588         m_impl->send.clear ();
2589         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2590         m_impl->send.put_data (m_impl->magic_active);
2591         m_impl->send.put_command (ISM_TRANS_CMD_CONTRACT_CANDIDATE);
2592         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2593     }
2594 }
2595
2596 /**
2597  * @brief Send selected candidate string index number.
2598  */
2599 void
2600 HelperAgent::select_candidate (int index) const
2601 {
2602     if (!m_impl->si.null ())
2603         m_impl->si->select_candidate (index);
2604     //FIXME: maybe useless
2605 #if 0
2606
2607     if (m_impl->socket_active.is_connected ()) {
2608         m_impl->send.clear ();
2609         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2610         m_impl->send.put_data (m_impl->magic_active);
2611         m_impl->send.put_command (ISM_TRANS_CMD_SELECT_CANDIDATE);
2612         m_impl->send.put_data (index);
2613         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2614     }
2615 #endif
2616 }
2617
2618 /**
2619  * @brief Update our ISE is exiting.
2620  *
2621  * The IME must call this function before terminating IME itself in On-demand mode.
2622  * If this function isn't called, IME will automatically restart.
2623  * This function only works in On-demand mode.
2624  *
2625  */
2626 void
2627 HelperAgent::update_ise_exit (void) const
2628 {
2629     if (m_impl->socket_active.is_connected ()) {
2630         m_impl->send.clear ();
2631         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2632         m_impl->send.put_data (m_impl->magic_active);
2633         m_impl->send.put_command (ISM_TRANS_CMD_UPDATE_ISE_EXIT);
2634         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2635
2636         // The update_ise_exit must be delivered before del_client of isf_info_manager was called.
2637         sync();
2638     }
2639 }
2640
2641 /**
2642  * @brief Request to reset keyboard ISE.
2643  */
2644 void
2645 HelperAgent::reset_keyboard_ise (void) const
2646 {
2647 //FIXME: maybe useless
2648 #if 0
2649     if (m_impl->socket_active.is_connected ()) {
2650         m_impl->send.clear ();
2651         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2652         m_impl->send.put_data (m_impl->magic_active);
2653         m_impl->send.put_command (ISM_TRANS_CMD_PANEL_RESET_KEYBOARD_ISE);
2654         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2655     }
2656 #endif
2657     if (!m_impl->si.null ()) {
2658         m_impl->si->reset ();
2659     }
2660 }
2661
2662 /**
2663  * @brief Request to flush keyboard ISE.
2664  */
2665 void
2666 HelperAgent::flush_keyboard_ise (void) const
2667 {
2668     if (!m_impl->si.null ()) {
2669         m_impl->si->flush ();
2670     }
2671 }
2672
2673 /**
2674  * @brief Request panel to hide ISE.
2675  */
2676 void
2677 HelperAgent::request_ise_hide (void) const
2678 {
2679     if (m_impl->socket_active.is_connected ()) {
2680         m_impl->send.clear ();
2681         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2682         m_impl->send.put_data (m_impl->magic_active);
2683         m_impl->send.put_command (ISM_TRANS_CMD_REQUEST_ISE_HIDE);
2684         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2685     }
2686 }
2687
2688 /**
2689  * @brief Recapture
2690  */
2691 void
2692 HelperAgent::recapture_string (int                  ic,
2693                                const String        &ic_uuid,
2694                                int                  offset,
2695                                int                  len,
2696                                const WideString    &preedit_str,
2697                                const WideString    &commit_str,
2698                                const AttributeList &attrs) const
2699 {
2700     LOGD ("offset = %d, len = %d", offset, len);
2701
2702     if (m_impl->socket_active.is_connected ()) {
2703         m_impl->send.clear ();
2704         m_impl->send.put_command (SCIM_TRANS_CMD_REQUEST);
2705         m_impl->send.put_data (m_impl->magic_active);
2706         m_impl->send.put_command (ISM_TRANS_CMD_RECAPTURE_STRING);
2707
2708         m_impl->send.put_data ((uint32)ic);
2709         m_impl->send.put_data (ic_uuid);
2710
2711         // Deleting surrounding text
2712         m_impl->send.put_data (offset);
2713         m_impl->send.put_data (len);
2714
2715         // Update preedit text
2716         m_impl->send.put_data (preedit_str);
2717
2718         // Commit
2719         m_impl->send.put_data (commit_str);
2720
2721         // preedit attributes
2722         m_impl->send.put_data (attrs);
2723
2724         m_impl->send.write_to_socket (m_impl->socket_active, m_impl->magic_active);
2725     }
2726 }
2727
2728 void
2729 HelperAgent::set_engine_loader_flag (bool flag)
2730 {
2731     m_impl->engine_loader_flag = flag;
2732 }
2733
2734 void
2735 HelperAgent::send_key_event_processing_result (KeyEvent &key,
2736                                                uint32          serial,
2737                                                bool            is_success) const
2738 {
2739     int ret = is_success ? 1 : 0;
2740     m_impl->process_key_event_done (key, ret, serial);
2741 }
2742
2743 /**
2744  * @brief Connect a slot to Helper exit signal.
2745  *
2746  * This signal is used to let the Helper exit.
2747  *
2748  * The prototype of the slot is:
2749  *
2750  * void exit (const HelperAgent *agent, int ic, const String &ic_uuid);
2751  *
2752  * Parameters:
2753  * - agent    The pointer to the HelperAgent object which emits this signal.
2754  * - ic       An opaque handle of the currently focused input context.
2755  * - ic_uuid  The UUID of the IMEngineInstance associated with the focused input context.
2756  */
2757 Connection
2758 HelperAgent::signal_connect_exit (HelperAgentSlotVoid *slot)
2759 {
2760     return m_impl->signal_exit.connect (slot);
2761 }
2762
2763 /**
2764  * @brief Connect a slot to Helper attach input context signal.
2765  *
2766  * This signal is used to attach an input context to this helper.
2767  *
2768  * When an input context requst to start this helper, then this
2769  * signal will be emitted as soon as the helper is started.
2770  *
2771  * When an input context want to start an already started helper,
2772  * this signal will also be emitted.
2773  *
2774  * Helper can send some events back to the IMEngineInstance in this
2775  * signal-slot, to inform that it has been started sccessfully.
2776  *
2777  * The prototype of the slot is:
2778  *
2779  * void attach_input_context (const HelperAgent *agent, int ic, const String &ic_uuid);
2780  */
2781 Connection
2782 HelperAgent::signal_connect_attach_input_context (HelperAgentSlotVoid *slot)
2783 {
2784     return m_impl->signal_attach_input_context.connect (slot);
2785 }
2786
2787 /**
2788  * @brief Connect a slot to Helper detach input context signal.
2789  *
2790  * This signal is used to detach an input context from this helper.
2791  *
2792  * When an input context requst to stop this helper, then this
2793  * signal will be emitted.
2794  *
2795  * Helper shouldn't send any event back to the IMEngineInstance, because
2796  * the IMEngineInstance attached to the ic should have been destroyed.
2797  *
2798  * The prototype of the slot is:
2799  *
2800  * void detach_input_context (const HelperAgent *agent, int ic, const String &ic_uuid);
2801  */
2802 Connection
2803 HelperAgent::signal_connect_detach_input_context (HelperAgentSlotVoid *slot)
2804 {
2805     return m_impl->signal_detach_input_context.connect (slot);
2806 }
2807
2808 /**
2809  * @brief Connect a slot to Helper reload config signal.
2810  *
2811  * This signal is used to let the Helper reload configuration.
2812  *
2813  * The prototype of the slot is:
2814  *
2815  * void reload_config (const HelperAgent *agent, int ic, const String &ic_uuid);
2816  */
2817 Connection
2818 HelperAgent::signal_connect_reload_config (HelperAgentSlotVoid *slot)
2819 {
2820     return m_impl->signal_reload_config.connect (slot);
2821 }
2822
2823 /**
2824  * @brief Connect a slot to Helper update screen signal.
2825  *
2826  * This signal is used to let the Helper move its GUI to another screen.
2827  * It can only be emitted when SCIM_HELPER_NEED_SCREEN_INFO is set in HelperInfo.option.
2828  *
2829  * The prototype of the slot is:
2830  *
2831  * void update_screen (const HelperAgent *agent, int ic, const String &ic_uuid, int screen_number);
2832  */
2833 Connection
2834 HelperAgent::signal_connect_update_screen (HelperAgentSlotInt *slot)
2835 {
2836     return m_impl->signal_update_screen.connect (slot);
2837 }
2838
2839 /**
2840  * @brief Connect a slot to Helper update spot location signal.
2841  *
2842  * This signal is used to let the Helper move its GUI according to the current spot location.
2843  * It can only be emitted when SCIM_HELPER_NEED_SPOT_LOCATION_INFO is set in HelperInfo.option.
2844  *
2845  * The prototype of the slot is:
2846  * void update_spot_location (const HelperAgent *agent, int ic, const String &ic_uuid, int x, int y);
2847  */
2848 Connection
2849 HelperAgent::signal_connect_update_spot_location (HelperAgentSlotIntInt *slot)
2850 {
2851     return m_impl->signal_update_spot_location.connect (slot);
2852 }
2853
2854 /**
2855  * @brief Connect a slot to Helper update cursor position signal.
2856  *
2857  * This signal is used to let the Helper get the cursor position information.
2858  *
2859  * The prototype of the slot is:
2860  * void update_cursor_position (const HelperAgent *agent, int ic, const String &ic_uuid, int cursor_pos);
2861  */
2862 Connection
2863 HelperAgent::signal_connect_update_cursor_position (HelperAgentSlotInt *slot)
2864 {
2865     return m_impl->signal_update_cursor_position.connect (slot);
2866 }
2867
2868 /**
2869  * @brief Connect a slot to Helper update surrounding text signal.
2870  *
2871  * This signal is used to let the Helper get the surrounding text.
2872  *
2873  * The prototype of the slot is:
2874  * void update_surrounding_text (const HelperAgent *agent, int ic, const String &text, int cursor);
2875  */
2876 Connection
2877 HelperAgent::signal_connect_update_surrounding_text (HelperAgentSlotInt *slot)
2878 {
2879     return m_impl->signal_update_surrounding_text.connect (slot);
2880 }
2881
2882 /**
2883  * @brief Connect a slot to Helper update selection signal.
2884  *
2885  * This signal is used to let the Helper get the selection.
2886  *
2887  * The prototype of the slot is:
2888  * void update_selection (const HelperAgent *agent, int ic, const String &text);
2889  */
2890 Connection
2891 HelperAgent::signal_connect_update_selection (HelperAgentSlotVoid *slot)
2892 {
2893     return m_impl->signal_update_selection.connect (slot);
2894 }
2895
2896 /**
2897  * @brief Connect a slot to Helper trigger property signal.
2898  *
2899  * This signal is used to trigger a property registered by this Helper.
2900  * A property will be triggered when user clicks on it.
2901  *
2902  * The prototype of the slot is:
2903  * void trigger_property (const HelperAgent *agent, int ic, const String &ic_uuid, const String &property);
2904  */
2905 Connection
2906 HelperAgent::signal_connect_trigger_property (HelperAgentSlotString *slot)
2907 {
2908     return m_impl->signal_trigger_property.connect (slot);
2909 }
2910
2911 /**
2912  * @brief Connect a slot to Helper process imengine event signal.
2913  *
2914  * This signal is used to deliver the events sent from IMEngine to Helper.
2915  *
2916  * The prototype of the slot is:
2917  * void process_imengine_event (const HelperAgent *agent, int ic, const String &ic_uuid, const Transaction &transaction);
2918  */
2919 Connection
2920 HelperAgent::signal_connect_process_imengine_event (HelperAgentSlotTransaction *slot)
2921 {
2922     return m_impl->signal_process_imengine_event.connect (slot);
2923 }
2924
2925 /**
2926  * @brief Connect a slot to Helper focus out signal.
2927  *
2928  * This signal is used to do something when input context is focus out.
2929  *
2930  * The prototype of the slot is:
2931  * void focus_out (const HelperAgent *agent, int ic, const String &ic_uuid);
2932  */
2933 Connection
2934 HelperAgent::signal_connect_focus_out (HelperAgentSlotVoid *slot)
2935 {
2936     return m_impl->signal_focus_out.connect (slot);
2937 }
2938
2939 /**
2940  * @brief Connect a slot to Helper focus in signal.
2941  *
2942  * This signal is used to do something when input context is focus in.
2943  *
2944  * The prototype of the slot is:
2945  * void focus_in (const HelperAgent *agent, int ic, const String &ic_uuid);
2946  */
2947 Connection
2948 HelperAgent::signal_connect_focus_in (HelperAgentSlotVoid *slot)
2949 {
2950     return m_impl->signal_focus_in.connect (slot);
2951 }
2952
2953 /**
2954  * @brief Connect a slot to Helper show signal.
2955  *
2956  * This signal is used to show Helper ISE window.
2957  *
2958  * The prototype of the slot is:
2959  * void ise_show (const HelperAgent *agent, int ic, char *buf, size_t &len);
2960  */
2961 Connection
2962 HelperAgent::signal_connect_ise_show (HelperAgentSlotIntRawVoid *slot)
2963 {
2964     return m_impl->signal_ise_show.connect (slot);
2965 }
2966
2967 /**
2968  * @brief Connect a slot to Helper hide signal.
2969  *
2970  * This signal is used to hide Helper ISE window.
2971  *
2972  * The prototype of the slot is:
2973  * void ise_hide (const HelperAgent *agent, int ic, const String &ic_uuid);
2974  */
2975 Connection
2976 HelperAgent::signal_connect_ise_hide (HelperAgentSlotVoid *slot)
2977 {
2978     return m_impl->signal_ise_hide.connect (slot);
2979 }
2980
2981 /**
2982  * @brief Connect a slot to Helper get ISE window geometry signal.
2983  *
2984  * This signal is used to get Helper ISE window size and position.
2985  *
2986  * The prototype of the slot is:
2987  * void get_geometry (const HelperAgent *agent, struct rectinfo &info);
2988  */
2989 Connection
2990 HelperAgent::signal_connect_get_geometry (HelperAgentSlotSize *slot)
2991 {
2992     return m_impl->signal_get_geometry.connect (slot);
2993 }
2994
2995 /**
2996  * @brief Connect a slot to Helper set mode signal.
2997  *
2998  * This signal is used to set Helper ISE mode.
2999  *
3000  * The prototype of the slot is:
3001  * void set_mode (const HelperAgent *agent, uint32 &mode);
3002  */
3003 Connection
3004 HelperAgent::signal_connect_set_mode (HelperAgentSlotUintVoid *slot)
3005 {
3006     return m_impl->signal_set_mode.connect (slot);
3007 }
3008
3009 /**
3010  * @brief Connect a slot to Helper set language signal.
3011  *
3012  * This signal is used to set Helper ISE language.
3013  *
3014  * The prototype of the slot is:
3015  * void set_language (const HelperAgent *agent, uint32 &language);
3016  */
3017 Connection
3018 HelperAgent::signal_connect_set_language (HelperAgentSlotUintVoid *slot)
3019 {
3020     return m_impl->signal_set_language.connect (slot);
3021 }
3022
3023 /**
3024  * @brief Connect a slot to Helper set im data signal.
3025  *
3026  * This signal is used to send im data to Helper ISE.
3027  *
3028  * The prototype of the slot is:
3029  * void set_imdata (const HelperAgent *agent, char *buf, size_t &len);
3030  */
3031 Connection
3032 HelperAgent::signal_connect_set_imdata (HelperAgentSlotRawVoid *slot)
3033 {
3034     return m_impl->signal_set_imdata.connect (slot);
3035 }
3036
3037 /**
3038  * @brief Connect a slot to Helper get im data signal.
3039  *
3040  * This signal is used to get im data from Helper ISE.
3041  *
3042  * The prototype of the slot is:
3043  * void get_imdata (const HelperAgent *, char **buf, size_t &len);
3044  */
3045 Connection
3046 HelperAgent::signal_connect_get_imdata (HelperAgentSlotGetRawVoid *slot)
3047 {
3048     return m_impl->signal_get_imdata.connect (slot);
3049 }
3050
3051 /**
3052  * @brief Connect a slot to Helper get language locale signal.
3053  *
3054  * This signal is used to get language locale from Helper ISE.
3055  *
3056  * The prototype of the slot is:
3057  * void get_language_locale (const HelperAgent *, int ic, char **locale);
3058  */
3059 Connection
3060 HelperAgent::signal_connect_get_language_locale (HelperAgentSlotIntGetStringVoid *slot)
3061 {
3062     return m_impl->signal_get_language_locale.connect (slot);
3063 }
3064
3065 /**
3066  * @brief Connect a slot to Helper set return key type signal.
3067  *
3068  * This signal is used to send return key type to Helper ISE.
3069  *
3070  * The prototype of the slot is:
3071  * void set_return_key_type (const HelperAgent *agent, uint32 &type);
3072  */
3073 Connection
3074 HelperAgent::signal_connect_set_return_key_type (HelperAgentSlotUintVoid *slot)
3075 {
3076     return m_impl->signal_set_return_key_type.connect (slot);
3077 }
3078
3079 /**
3080  * @brief Connect a slot to Helper get return key type signal.
3081  *
3082  * This signal is used to get return key type from Helper ISE.
3083  *
3084  * The prototype of the slot is:
3085  * void get_return_key_type (const HelperAgent *agent, uint32 &type);
3086  */
3087 Connection
3088 HelperAgent::signal_connect_get_return_key_type (HelperAgentSlotUintVoid *slot)
3089 {
3090     return m_impl->signal_get_return_key_type.connect (slot);
3091 }
3092
3093 /**
3094  * @brief Connect a slot to Helper set return key disable signal.
3095  *
3096  * This signal is used to send return key disable to Helper ISE.
3097  *
3098  * The prototype of the slot is:
3099  * void set_return_key_disable (const HelperAgent *agent, uint32 &disabled);
3100  */
3101 Connection
3102 HelperAgent::signal_connect_set_return_key_disable (HelperAgentSlotUintVoid *slot)
3103 {
3104     return m_impl->signal_set_return_key_disable.connect (slot);
3105 }
3106
3107 /**
3108  * @brief Connect a slot to Helper process key event signal.
3109  *
3110  * This signal is used to send keyboard key event to Helper ISE.
3111  *
3112  * The prototype of the slot is:
3113  * void process_key_event (const HelperAgent *agent, KeyEvent &key, uint32 &ret);
3114  */
3115 Connection
3116 HelperAgent::signal_connect_process_key_event (HelperAgentSlotKeyEventUint *slot)
3117 {
3118     return m_impl->signal_process_key_event.connect (slot);
3119 }
3120
3121 /**
3122  * @brief Connect a slot to Helper process key event with keycode signal.
3123  *
3124  * This signal is used to send keyboard key event with keycode to Helper ISE.
3125  *
3126  * The prototype of the slot is:
3127  * void process_key_event_with_keycode (const HelperAgent *agent, KeyEvent &key, uint32 &ret, uint32 keycode);
3128  */
3129 Connection
3130 HelperAgent::signal_connect_process_key_event_with_keycode (HelperAgentSlotKeyEventUintUint *slot)
3131 {
3132     return m_impl->signal_process_key_event_with_keycode.connect (slot);
3133 }
3134
3135 /**
3136  * @brief Connect a slot to Helper get return key disable signal.
3137  *
3138  * This signal is used to get return key disable from Helper ISE.
3139  *
3140  * The prototype of the slot is:
3141  * void get_return_key_disable (const HelperAgent *agent, uint32 &disabled);
3142  */
3143 Connection
3144 HelperAgent::signal_connect_get_return_key_disable (HelperAgentSlotUintVoid *slot)
3145 {
3146     return m_impl->signal_get_return_key_disable.connect (slot);
3147 }
3148
3149 /**
3150  * @brief Connect a slot to Helper set layout signal.
3151  *
3152  * This signal is used to set Helper ISE layout.
3153  *
3154  * The prototype of the slot is:
3155  * void set_layout (const HelperAgent *agent, uint32 &layout);
3156  */
3157 Connection
3158 HelperAgent::signal_connect_set_layout (HelperAgentSlotUintVoid *slot)
3159 {
3160     return m_impl->signal_set_layout.connect (slot);
3161 }
3162
3163 /**
3164  * @brief Connect a slot to Helper get layout signal.
3165  *
3166  * This signal is used to get Helper ISE layout.
3167  *
3168  * The prototype of the slot is:
3169  * void get_layout (const HelperAgent *agent, uint32 &layout);
3170  */
3171 Connection
3172 HelperAgent::signal_connect_get_layout (HelperAgentSlotUintVoid *slot)
3173 {
3174     return m_impl->signal_get_layout.connect (slot);
3175 }
3176
3177 /**
3178  * @brief Connect a slot to Helper set input mode signal.
3179  *
3180  * This signal is used to set Helper ISE input mode.
3181  *
3182  * The prototype of the slot is:
3183  * void set_input_mode (const HelperAgent *agent, uint32 &input_mode);
3184  */
3185 Connection
3186 HelperAgent::signal_connect_set_input_mode (HelperAgentSlotUintVoid *slot)
3187 {
3188     return m_impl->signal_set_input_mode.connect (slot);
3189 }
3190
3191 /**
3192  * @brief Connect a slot to Helper set input hint signal.
3193  *
3194  * This signal is used to set Helper ISE input hint.
3195  *
3196  * The prototype of the slot is:
3197  * void set_input_hint (const HelperAgent *agent, uint32 &input_hint);
3198  */
3199 Connection
3200 HelperAgent::signal_connect_set_input_hint (HelperAgentSlotUintVoid *slot)
3201 {
3202     return m_impl->signal_set_input_hint.connect (slot);
3203 }
3204
3205 /**
3206  * @brief Connect a slot to Helper set BiDi direction signal.
3207  *
3208  * This signal is used to set Helper ISE BiDi direction.
3209  *
3210  * The prototype of the slot is:
3211  * void update_bidi_direction (const HelperAgent *agent, uint32 &bidi_direction);
3212  */
3213 Connection
3214 HelperAgent::signal_connect_update_bidi_direction (HelperAgentSlotUintVoid *slot)
3215 {
3216     return m_impl->signal_update_bidi_direction.connect (slot);
3217 }
3218
3219 /**
3220  * @brief Connect a slot to Helper set shift mode signal.
3221  *
3222  * This signal is used to set Helper shift mode.
3223  *
3224  * The prototype of the slot is:
3225  * void set_caps_mode (const HelperAgent *agent, uint32 &mode);
3226  */
3227 Connection
3228 HelperAgent::signal_connect_set_caps_mode (HelperAgentSlotUintVoid *slot)
3229 {
3230     return m_impl->signal_set_caps_mode.connect (slot);
3231 }
3232
3233 /**
3234  * @brief Connect a slot to Helper reset input context signal.
3235  *
3236  * This signal is used to reset Helper ISE input context.
3237  *
3238  * The prototype of the slot is:
3239  * void reset_input_context (const HelperAgent *agent, int ic, const String &uuid);
3240  */
3241 Connection
3242 HelperAgent::signal_connect_reset_input_context (HelperAgentSlotVoid *slot)
3243 {
3244     return m_impl->signal_reset_input_context.connect (slot);
3245 }
3246
3247 /**
3248  * @brief Connect a slot to Helper update candidate window geometry signal.
3249  *
3250  * This signal is used to get candidate window size and position.
3251  *
3252  * The prototype of the slot is:
3253  * void update_candidate_geometry (const HelperAgent *agent, int ic, const String &uuid, const rectinfo &info);
3254  */
3255 Connection
3256 HelperAgent::signal_connect_update_candidate_geometry (HelperAgentSlotRect *slot)
3257 {
3258     return m_impl->signal_update_candidate_geometry.connect (slot);
3259 }
3260
3261 /**
3262  * @brief Connect a slot to Helper update keyboard ISE signal.
3263  *
3264  * This signal is used to get current keyboard ISE name and uuid.
3265  *
3266  * The prototype of the slot is:
3267  * void update_keyboard_ise (const HelperAgent *agent, int ic, const String &uuid,
3268  *                           const String &ise_name, const String &ise_uuid);
3269  */
3270 Connection
3271 HelperAgent::signal_connect_update_keyboard_ise (HelperAgentSlotString2 *slot)
3272 {
3273     return m_impl->signal_update_keyboard_ise.connect (slot);
3274 }
3275
3276 /**
3277  * @brief Connect a slot to Helper update keyboard ISE list signal.
3278  *
3279  * This signal is used to get uuid list of all keyboard ISEs.
3280  *
3281  * The prototype of the slot is:
3282  * void update_keyboard_ise_list (const HelperAgent *agent, int ic, const String &uuid,
3283  *                                const std::vector<String> &ise_list);
3284  */
3285 Connection
3286 HelperAgent::signal_connect_update_keyboard_ise_list (HelperAgentSlotStringVector *slot)
3287 {
3288     return m_impl->signal_update_keyboard_ise_list.connect (slot);
3289 }
3290
3291 /**
3292  * @brief Connect a slot to Helper candidate more window show signal.
3293  *
3294  * This signal is used to do someting when candidate more window is showed.
3295  *
3296  * The prototype of the slot is:
3297  * void candidate_more_window_show (const HelperAgent *agent, int ic, const String &uuid);
3298  */
3299 Connection
3300 HelperAgent::signal_connect_candidate_more_window_show (HelperAgentSlotVoid *slot)
3301 {
3302     return m_impl->signal_candidate_more_window_show.connect (slot);
3303 }
3304
3305 /**
3306  * @brief Connect a slot to Helper candidate more window hide signal.
3307  *
3308  * This signal is used to do someting when candidate more window is hidden.
3309  *
3310  * The prototype of the slot is:
3311  * void candidate_more_window_hide (const HelperAgent *agent, int ic, const String &uuid);
3312  */
3313 Connection
3314 HelperAgent::signal_connect_candidate_more_window_hide (HelperAgentSlotVoid *slot)
3315 {
3316     return m_impl->signal_candidate_more_window_hide.connect (slot);
3317 }
3318
3319 /**
3320  * @brief Connect a slot to Helper candidate show signal.
3321  *
3322  * This signal is used to do candidate show.
3323  *
3324  * The prototype of the slot is:
3325  * void candidate_show (const HelperAgent *agent, int ic, const String &uuid);
3326  */
3327 Connection
3328 HelperAgent::signal_connect_candidate_show (HelperAgentSlotVoid *slot)
3329 {
3330     return m_impl->signal_candidate_show.connect (slot);
3331 }
3332
3333 /**
3334  * @brief Connect a slot to Helper candidate hide signal.
3335  *
3336  * This signal is used to do candidate hide.
3337  *
3338  * The prototype of the slot is:
3339  * void candidate_hide (const HelperAgent *agent, int ic, const String &uuid);
3340  */
3341 Connection
3342 HelperAgent::signal_connect_candidate_hide (HelperAgentSlotVoid *slot)
3343 {
3344     return m_impl->signal_candidate_hide.connect (slot);
3345 }
3346
3347 /**
3348  * @brief Connect a slot to Helper update lookup table signal.
3349  *
3350  * This signal is used to do someting when update lookup table.
3351  *
3352  * The prototype of the slot is:
3353  * void update_lookup_table (const HelperAgent *agent, int ic, const String &uuid ,LookupTable &table);
3354  */
3355 Connection
3356 HelperAgent::signal_connect_update_lookup_table (HelperAgentSlotLookupTable *slot)
3357 {
3358     return m_impl->signal_update_lookup_table.connect (slot);
3359 }
3360
3361 /**
3362  * @brief Connect a slot to Helper select aux signal.
3363  *
3364  * This signal is used to do something when aux is selected.
3365  *
3366  * The prototype of the slot is:
3367  * void select_aux (const HelperAgent *agent, int ic, const String &uuid, int index);
3368  */
3369 Connection
3370 HelperAgent::signal_connect_select_aux (HelperAgentSlotInt *slot)
3371 {
3372     return m_impl->signal_select_aux.connect (slot);
3373 }
3374
3375 /**
3376  * @brief Connect a slot to Helper select candidate signal.
3377  *
3378  * This signal is used to do something when candidate is selected.
3379  *
3380  * The prototype of the slot is:
3381  * void select_candidate (const HelperAgent *agent, int ic, const String &uuid, int index);
3382  */
3383 Connection
3384 HelperAgent::signal_connect_select_candidate (HelperAgentSlotInt *slot)
3385 {
3386     return m_impl->signal_select_candidate.connect (slot);
3387 }
3388
3389 /**
3390  * @brief Connect a slot to Helper candidate table page up signal.
3391  *
3392  * This signal is used to do something when candidate table is paged up.
3393  *
3394  * The prototype of the slot is:
3395  * void candidate_table_page_up (const HelperAgent *agent, int ic, const String &uuid);
3396  */
3397 Connection
3398 HelperAgent::signal_connect_candidate_table_page_up (HelperAgentSlotVoid *slot)
3399 {
3400     return m_impl->signal_candidate_table_page_up.connect (slot);
3401 }
3402
3403 /**
3404  * @brief Connect a slot to Helper candidate table page down signal.
3405  *
3406  * This signal is used to do something when candidate table is paged down.
3407  *
3408  * The prototype of the slot is:
3409  * void candidate_table_page_down (const HelperAgent *agent, int ic, const String &uuid);
3410  */
3411 Connection
3412 HelperAgent::signal_connect_candidate_table_page_down (HelperAgentSlotVoid *slot)
3413 {
3414     return m_impl->signal_candidate_table_page_down.connect (slot);
3415 }
3416
3417 /**
3418  * @brief Connect a slot to Helper update candidate table page size signal.
3419  *
3420  * This signal is used to do something when candidate table page size is changed.
3421  *
3422  * The prototype of the slot is:
3423  * void update_candidate_table_page_size (const HelperAgent *, int ic, const String &uuid, int page_size);
3424  */
3425 Connection
3426 HelperAgent::signal_connect_update_candidate_table_page_size (HelperAgentSlotInt *slot)
3427 {
3428     return m_impl->signal_update_candidate_table_page_size.connect (slot);
3429 }
3430
3431 /**
3432  * @brief Connect a slot to Helper update candidate item layout signal.
3433  *
3434  * The prototype of the slot is:
3435  * void update_candidate_item_layout (const HelperAgent *, const std::vector<uint32> &row_items);
3436  */
3437 Connection
3438 HelperAgent::signal_connect_update_candidate_item_layout (HelperAgentSlotUintVector *slot)
3439 {
3440     return m_impl->signal_update_candidate_item_layout.connect (slot);
3441 }
3442
3443 /**
3444  * @brief Connect a slot to Helper select associate signal.
3445  *
3446  * This signal is used to do something when associate is selected.
3447  *
3448  * The prototype of the slot is:
3449  * void select_associate (const HelperAgent *agent, int ic, const String &uuid, int index);
3450  */
3451 Connection
3452 HelperAgent::signal_connect_select_associate (HelperAgentSlotInt *slot)
3453 {
3454     return m_impl->signal_select_associate.connect (slot);
3455 }
3456
3457 /**
3458  * @brief Connect a slot to Helper associate table page up signal.
3459  *
3460  * This signal is used to do something when associate table is paged up.
3461  *
3462  * The prototype of the slot is:
3463  * void associate_table_page_up (const HelperAgent *agent, int ic, const String &uuid);
3464  */
3465 Connection
3466 HelperAgent::signal_connect_associate_table_page_up (HelperAgentSlotVoid *slot)
3467 {
3468     return m_impl->signal_associate_table_page_up.connect (slot);
3469 }
3470
3471 /**
3472  * @brief Connect a slot to Helper associate table page down signal.
3473  *
3474  * This signal is used to do something when associate table is paged down.
3475  *
3476  * The prototype of the slot is:
3477  * void associate_table_page_down (const HelperAgent *agent, int ic, const String &uuid);
3478  */
3479 Connection
3480 HelperAgent::signal_connect_associate_table_page_down (HelperAgentSlotVoid *slot)
3481 {
3482     return m_impl->signal_associate_table_page_down.connect (slot);
3483 }
3484
3485 /**
3486  * @brief Connect a slot to Helper update associate table page size signal.
3487  *
3488  * This signal is used to do something when associate table page size is changed.
3489  *
3490  * The prototype of the slot is:
3491  * void update_associate_table_page_size (const HelperAgent *, int ic, const String &uuid, int page_size);
3492  */
3493 Connection
3494 HelperAgent::signal_connect_update_associate_table_page_size (HelperAgentSlotInt *slot)
3495 {
3496     return m_impl->signal_update_associate_table_page_size.connect (slot);
3497 }
3498
3499 /**
3500  * @brief Connect a slot to Helper turn on log signal.
3501  *
3502  * This signal is used to turn on Helper ISE debug information.
3503  *
3504  * The prototype of the slot is:
3505  * void turn_on_log (const HelperAgent *agent, uint32 &on);
3506  */
3507 Connection
3508 HelperAgent::signal_connect_turn_on_log (HelperAgentSlotUintVoid *slot)
3509 {
3510     return m_impl->signal_turn_on_log.connect (slot);
3511 }
3512
3513 /**
3514  * @brief Connect a slot to Helper update displayed candidate number signal.
3515  *
3516  * This signal is used to inform helper ISE displayed candidate number.
3517  *
3518  * The prototype of the slot is:
3519  * void update_displayed_candidate_number (const HelperAgent *, int ic, const String &uuid, int number);
3520  */
3521 Connection
3522 HelperAgent::signal_connect_update_displayed_candidate_number (HelperAgentSlotInt *slot)
3523 {
3524     return m_impl->signal_update_displayed_candidate_number.connect (slot);
3525 }
3526
3527 /**
3528  * @brief Connect a slot to Helper longpress candidate signal.
3529  *
3530  * This signal is used to do something when candidate is longpress.
3531  *
3532  * The prototype of the slot is:
3533  * void longpress_candidate (const HelperAgent *agent, int ic, const String &uuid, int index);
3534  */
3535 Connection
3536 HelperAgent::signal_connect_longpress_candidate (HelperAgentSlotInt *slot)
3537 {
3538     return m_impl->signal_longpress_candidate.connect (slot);
3539 }
3540
3541 /**
3542  * @brief Connect a slot to Helper show option window.
3543  *
3544  * This signal is used to do request the ISE to show option window.
3545  *
3546  * The prototype of the slot is:
3547  * void show_option_window (const HelperAgent *agent, int ic, const String &uuid);
3548  */
3549 Connection
3550 HelperAgent::signal_connect_show_option_window (HelperAgentSlotVoid *slot)
3551 {
3552     return m_impl->signal_show_option_window.connect (slot);
3553 }
3554
3555 /**
3556  * @brief Connect a slot to Helper resume option window.
3557  *
3558  * This signal is used to do request the ISE to resume option window.
3559  *
3560  * The prototype of the slot is:
3561  * void resume_option_window (const HelperAgent *agent, int ic, const String &uuid);
3562  */
3563 Connection
3564 HelperAgent::signal_connect_resume_option_window (HelperAgentSlotVoid *slot)
3565 {
3566     return m_impl->signal_resume_option_window.connect (slot);
3567 }
3568
3569 /**
3570  * @brief Connect a slot to Helper check if the option is available.
3571  *
3572  * This signal is used to check if the option (setting) is available from Helper ISE.
3573  *
3574  * The prototype of the slot is:
3575  * void check_option_window (const HelperAgent *agent, uint32 &avail);
3576  */
3577 Connection
3578 HelperAgent::signal_connect_check_option_window (HelperAgentSlotUintVoid *slot)
3579 {
3580     return m_impl->signal_check_option_window.connect (slot);
3581 }
3582
3583 /**
3584  * @brief Connect a slot to Helper process unconventional input device event signal.
3585  *
3586  * This signal is used to send unconventional input device event to Helper ISE.
3587  *
3588  * The prototype of the slot is:
3589  * void process_input_device_event (const HelperAgent *, uint32 &type, char *data, size_t &size, uint32 &ret);
3590  */
3591 Connection
3592 HelperAgent::signal_connect_process_input_device_event (HelperAgentSlotUintCharSizeUint *slot)
3593 {
3594     return m_impl->signal_process_input_device_event.connect (slot);
3595 }
3596
3597 /**
3598  * @brief Connect a slot to Helper set prediction hint signal.
3599  *
3600  * This signal is used to send prediction hint to Helper ISE.
3601  *
3602  * The prototype of the slot is:
3603  * void set_prediction_hint (const HelperAgent *agent, char *prediction_hint);
3604  */
3605 Connection
3606 HelperAgent::signal_connect_set_prediction_hint (HelperAgentSlotStringVoid *slot)
3607 {
3608     return m_impl->signal_set_prediction_hint.connect (slot);
3609 }
3610
3611 /**
3612  * @brief Connect a slot to Helper set mime type signal.
3613  *
3614  * This signal is used to send mime type to Helper ISE.
3615  *
3616  * The prototype of the slot is:
3617  * void set_mime_type (const HelperAgent *agent, char *mime_type);
3618  */
3619 Connection
3620 HelperAgent::signal_connect_set_mime_type (HelperAgentSlotStringVoid *slot)
3621 {
3622     return m_impl->signal_set_mime_type.connect (slot);
3623 }
3624
3625 /**
3626  * @brief Connect a slot to Helper set prediction hint data signal.
3627  *
3628  * This signal is used to send prediction hint data to Helper ISE.
3629  *
3630  * The prototype of the slot is:
3631  * void set_prediction_hint_data (const HelperAgent *agent, char *key, char *value);
3632  */
3633 Connection
3634 HelperAgent::signal_connect_set_prediction_hint_data (HelperAgentSlotString *slot)
3635 {
3636     return m_impl->signal_set_prediction_hint_data.connect (slot);
3637 }
3638
3639 /**
3640  * @brief Connect a slot to Helper set optimization hint signal.
3641  *
3642  * This signal is used to send optimization hint to Helper ISE.
3643  *
3644  * The prototype of the slot is:
3645  * void set_optimization_hint (const HelperAgent *agent, uint32 &hint);
3646  */
3647 Connection
3648 HelperAgent::signal_connect_set_optimization_hint (HelperAgentSlotUintVoid *slot)
3649 {
3650     return m_impl->signal_set_optimization_hint.connect (slot);
3651 }
3652
3653 /**
3654  * @brief Connect a slot to Helper process key event with imengine signal.
3655  *
3656  * This signal is used to deliver the key event to Helper ISE.
3657  *
3658  * The prototype of the slot is:
3659  * void process_key_event_with_imengine (const HelperAgent *agent, KeyEvent &key, uint32 serial);
3660  */
3661 Connection
3662 HelperAgent::signal_connect_process_key_event_with_imengine (HelperAgentSlotKeyEventUint2 *slot)
3663 {
3664     return m_impl->signal_process_key_event_with_imengine.connect (slot);
3665 }
3666
3667 /**
3668  * @brief Connect a slot to Helper set autocapital type signal.
3669  *
3670  * This signal is used to send autocapital type to imengine.
3671  *
3672  * The prototype of the slot is:
3673  * void set_autocapital_type (const HelperAgent *agent, uint32 &type);
3674  */
3675 Connection
3676 HelperAgent::signal_connect_set_autocapital_type (HelperAgentSlotUintVoid *slot)
3677 {
3678     return m_impl->signal_set_autocapital_type.connect (slot);
3679 }
3680
3681 /**
3682  * @brief Connect a slot to Helper set prediction allow signal.
3683  *
3684  * This signal is used to send prediction allow to imengine.
3685  *
3686  * The prototype of the slot is:
3687  * void set_prediction_allow (const HelperAgent *agent, uint32 &prediction_allow);
3688  */
3689 Connection
3690 HelperAgent::signal_connect_set_prediction_allow (HelperAgentSlotUintVoid *slot)
3691 {
3692     return m_impl->signal_set_prediction_allow.connect (slot);
3693 }
3694
3695 } /* namespace scim */
3696
3697 /*
3698 vi:ts=4:nowrap:ai:expandtab
3699 */
3700