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