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