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