Revert manifest to default one
[framework/uifw/isf.git] / ism / src / scim_panel_agent.cpp
1 /** @file scim_panel.cpp
2  *  @brief Implementation of class PanelAgent.
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) 2005 James Su <suzhe@tsinghua.org.cn>
11  *
12  *
13  * This library is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU Lesser General Public
15  * License as published by the Free Software Foundation; either
16  * version 2 of the License, or (at your option) any later version.
17  *
18  * This library is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU Lesser General Public License for more details.
22  *
23  * You should have received a copy of the GNU Lesser General Public
24  * License along with this program; if not, write to the
25  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
26  * Boston, MA  02111-1307  USA
27  *
28  * $Id: scim_panel_agent.cpp,v 1.8.2.1 2006/01/09 14:32:18 suzhe Exp $
29  *
30  */
31
32 #define Uses_SCIM_TRANSACTION
33 #define Uses_SCIM_TRANS_COMMANDS
34 #define Uses_SCIM_PANEL_AGENT
35 #define Uses_SCIM_HELPER
36 #define Uses_SCIM_SOCKET
37 #define Uses_SCIM_EVENT
38 #define Uses_SCIM_CONFIG
39 #define Uses_SCIM_CONFIG_MODULE
40 #define Uses_SCIM_CONFIG_PATH
41 #define Uses_SCIM_UTILITY
42
43 #include <string.h>
44 #include <sys/types.h>
45 #include <unistd.h>
46 #include "scim_private.h"
47 #include "scim.h"
48 #include "scim_stl_map.h"
49
50
51 scim::CommonLookupTable g_isf_candidate_table;
52
53
54 namespace scim {
55
56 typedef Signal0<void>
57         PanelAgentSignalVoid;
58
59 typedef Signal1<void, int>
60         PanelAgentSignalInt;
61
62 typedef Signal1<void, const String &>
63         PanelAgentSignalString;
64
65 typedef Signal2<void, const String &, bool>
66         PanelAgentSignalStringBool;
67
68 typedef Signal2<void, String &, String &>
69         PanelAgentSignalString2;
70
71 typedef Signal2<void, int, const String &>
72         PanelAgentSignalIntString;
73
74 typedef Signal1<void, const PanelFactoryInfo &>
75         PanelAgentSignalFactoryInfo;
76
77 typedef Signal1<void, const std::vector <PanelFactoryInfo> &>
78         PanelAgentSignalFactoryInfoVector;
79
80 typedef Signal1<void, const LookupTable &>
81         PanelAgentSignalLookupTable;
82
83 typedef Signal1<void, const Property &>
84         PanelAgentSignalProperty;
85
86 typedef Signal1<void, const PropertyList &>
87         PanelAgentSignalPropertyList;
88
89 typedef Signal2<void, int, int>
90         PanelAgentSignalIntInt;
91
92 typedef Signal2<void, int &, int &>
93         PanelAgentSignalIntInt2;
94
95 typedef Signal3<void, int, int, int>
96         PanelAgentSignalIntIntInt;
97
98 typedef Signal4<void, int, int, int, int>
99         PanelAgentSignalIntIntIntInt;
100
101 typedef Signal2<void, int, const Property &>
102         PanelAgentSignalIntProperty;
103
104 typedef Signal2<void, int, const PropertyList &>
105         PanelAgentSignalIntPropertyList;
106
107 typedef Signal2<void, int, const HelperInfo &>
108         PanelAgentSignalIntHelperInfo;
109
110 typedef Signal2<void, const String &, const AttributeList &>
111         PanelAgentSignalAttributeString;
112
113 typedef Signal1<void, std::vector <String> &>
114         PanelAgentSignalStringVector;
115
116 typedef Signal1<bool, std::vector <String> &>
117         PanelAgentSignalBoolStringVector;
118
119 typedef Signal2<void, char *, std::vector <String> &>
120         PanelAgentSignalStrStringVector;
121
122 typedef Signal2<bool, const String &, ISE_INFO &>
123         PanelAgentSignalStringISEINFO;
124
125 typedef Signal1<void, const KeyEvent &>
126         PanelAgentSignalKeyEvent;
127
128 typedef Signal1<void, struct rectinfo &>
129         PanelAgentSignalRect;
130
131 enum ClientType {
132     UNKNOWN_CLIENT,
133     FRONTEND_CLIENT,
134     HELPER_CLIENT,
135     HELPER_ACT_CLIENT,
136     IMCONTROL_ACT_CLIENT,
137     IMCONTROL_CLIENT
138 };
139
140 struct ClientInfo {
141     uint32       key;
142     ClientType   type;
143 };
144
145 struct HelperClientStub {
146     int id;
147     int ref;
148
149     HelperClientStub (int i = 0, int r = 0) : id (i), ref (r) { }
150 };
151
152 struct IMControlStub {
153     std::vector<ISE_INFO> info;
154     std::vector<int> count;
155 };
156
157 static  int _id_count = -4;
158
159 #define DEFAULT_CONTEXT_VALUE 0xfff
160
161 #if SCIM_USE_STL_EXT_HASH_MAP
162 typedef __gnu_cxx::hash_map <int, ClientInfo, __gnu_cxx::hash <int> >       ClientRepository;
163 typedef __gnu_cxx::hash_map <int, HelperInfo, __gnu_cxx::hash <int> >       HelperInfoRepository;
164 typedef __gnu_cxx::hash_map <uint32, String, __gnu_cxx::hash <unsigned int> > ClientContextUUIDRepository;
165 typedef __gnu_cxx::hash_map <String, HelperClientStub, scim_hash_string>    HelperClientIndex;
166 typedef __gnu_cxx::hash_map <String, std::vector < std::pair <uint32, String> >, scim_hash_string>    StartHelperICIndex;
167 #elif SCIM_USE_STL_HASH_MAP
168 typedef std::hash_map <int, ClientInfo, std::hash <int> >                   ClientRepository;
169 typedef std::hash_map <int, HelperInfo, std::hash <int> >                   HelperInfoRepository;
170 typedef std::hash_map <uint32, String, std::hash <unsigned int> >           ClientContextUUIDRepository;
171 typedef std::hash_map <String, HelperClientStub, scim_hash_string>          HelperClientIndex;
172 typedef std::hash_map <String, std::vector < std::pair <uint32, String> >, scim_hash_string>          StartHelperICIndex;
173 #else
174 typedef std::map <int, ClientInfo>                                          ClientRepository;
175 typedef std::map <int, HelperInfo>                                          HelperInfoRepository;
176 typedef std::map <uint32, String>                                           ClientContextUUIDRepository;
177 typedef std::map <String, HelperClientStub>                                 HelperClientIndex;
178 typedef std::map <String, std::vector < std::pair <uint32, String> > >                                StartHelperICIndex;
179 #endif
180
181 typedef std::map <String, uint32>              UUIDCountRepository;
182 typedef std::map <String, enum HelperState>    UUIDStateRepository;
183 typedef std::map <String, int>                 StringIntRepository;
184 typedef std::map <int, struct IMControlStub>   IMControlRepository;
185 typedef std::map <int, int>                    IntIntRepository;
186
187 static uint32
188 get_helper_ic (int client, uint32 context)
189 {
190     return (uint32) (client & 0xFFFF) | ((context & 0x7FFF) << 16);
191 }
192
193 static void
194 get_imengine_client_context (uint32 helper_ic, int &client, uint32 &context)
195 {
196     client   = (int) (helper_ic & 0xFFFF);
197     context  = ((helper_ic >> 16) & 0x7FFF);
198 }
199
200 //==================================== PanelAgent ===========================
201 class PanelAgent::PanelAgentImpl
202 {
203     bool                                m_should_exit;
204     bool                                m_should_resident;
205
206     int                                 m_current_screen;
207
208     String                              m_config_name;
209     String                              m_display_name;
210
211     int                                 m_socket_timeout;
212     String                              m_socket_address;
213     SocketServer                        m_socket_server;
214
215     Transaction                         m_send_trans;
216     Transaction                         m_recv_trans;
217     Transaction                         m_nest_trans;
218
219     int                                 m_current_socket_client;
220     uint32                              m_current_client_context;
221     String                              m_current_context_uuid;
222     TOOLBAR_MODE_T                      m_current_toolbar_mode;
223     String                              m_current_factory_icon;
224     String                              m_current_helper_uuid;
225     String                              m_last_helper_uuid;
226     String                              m_current_ise_name;
227     uint32                              m_current_ise_style;
228     int                                 m_current_active_imcontrol_id;
229     int                                 m_pending_active_imcontrol_id;
230     IntIntRepository                    m_imcontrol_map;
231     DEFAULT_ISE_T                       m_default_ise;
232     bool                                m_should_shared_ise;
233     char *                              m_ise_settings;
234     size_t                              m_ise_settings_len;
235     bool                                m_ise_changing;
236     bool                                m_ise_exiting;
237
238     int                                 m_last_socket_client;
239     uint32                              m_last_client_context;
240     String                              m_last_context_uuid;
241
242     ClientRepository                    m_client_repository;
243     /*
244     * Each Helper ISE has two socket connect between PanelAgent and HelperAgent.
245     * m_helper_info_repository records the active connection.
246     * m_helper_active_info_repository records the passive connection.
247     */
248     HelperInfoRepository                m_helper_info_repository;
249     HelperInfoRepository                m_helper_active_info_repository;
250     HelperClientIndex                   m_helper_client_index;
251
252     /* when helper register, notify imcontrol client */
253     StringIntRepository                 m_ise_pending_repository;
254     IMControlRepository                 m_imcontrol_repository;
255
256     StartHelperICIndex                  m_start_helper_ic_index;
257
258     /* Keyboard ISE */
259     ClientContextUUIDRepository         m_client_context_uuids;
260
261     /* Helper ISE */
262     ClientContextUUIDRepository         m_client_context_helper;
263     UUIDCountRepository                 m_helper_uuid_count;
264     UUIDStateRepository                 m_helper_uuid_state;
265
266     HelperManager                       m_helper_manager;
267
268     PanelAgentSignalVoid                m_signal_reload_config;
269     PanelAgentSignalVoid                m_signal_turn_on;
270     PanelAgentSignalVoid                m_signal_turn_off;
271     PanelAgentSignalVoid                m_signal_show_panel;
272     PanelAgentSignalVoid                m_signal_hide_panel;
273     PanelAgentSignalInt                 m_signal_update_screen;
274     PanelAgentSignalIntIntInt           m_signal_update_spot_location;
275     PanelAgentSignalFactoryInfo         m_signal_update_factory_info;
276     PanelAgentSignalVoid                m_signal_start_default_ise;
277     PanelAgentSignalIntInt              m_signal_update_input_context;
278     PanelAgentSignalIntInt              m_signal_set_candidate_ui;
279     PanelAgentSignalIntInt2             m_signal_get_candidate_ui;
280     PanelAgentSignalIntInt              m_signal_set_candidate_position;
281     PanelAgentSignalRect                m_signal_get_candidate_geometry;
282     PanelAgentSignalRect                m_signal_get_input_panel_geometry;
283     PanelAgentSignalIntString           m_signal_set_keyboard_ise;
284     PanelAgentSignalString2             m_signal_get_keyboard_ise;
285     PanelAgentSignalString              m_signal_show_help;
286     PanelAgentSignalFactoryInfoVector   m_signal_show_factory_menu;
287     PanelAgentSignalVoid                m_signal_show_preedit_string;
288     PanelAgentSignalVoid                m_signal_show_aux_string;
289     PanelAgentSignalVoid                m_signal_show_lookup_table;
290     PanelAgentSignalVoid                m_signal_show_associate_table;
291     PanelAgentSignalVoid                m_signal_hide_preedit_string;
292     PanelAgentSignalVoid                m_signal_hide_aux_string;
293     PanelAgentSignalVoid                m_signal_hide_lookup_table;
294     PanelAgentSignalVoid                m_signal_hide_associate_table;
295     PanelAgentSignalAttributeString     m_signal_update_preedit_string;
296     PanelAgentSignalInt                 m_signal_update_preedit_caret;
297     PanelAgentSignalAttributeString     m_signal_update_aux_string;
298     PanelAgentSignalLookupTable         m_signal_update_lookup_table;
299     PanelAgentSignalLookupTable         m_signal_update_associate_table;
300     PanelAgentSignalPropertyList        m_signal_register_properties;
301     PanelAgentSignalProperty            m_signal_update_property;
302     PanelAgentSignalIntPropertyList     m_signal_register_helper_properties;
303     PanelAgentSignalIntProperty         m_signal_update_helper_property;
304     PanelAgentSignalIntHelperInfo       m_signal_register_helper;
305     PanelAgentSignalInt                 m_signal_remove_helper;
306     PanelAgentSignalStringBool          m_signal_set_active_ise_by_uuid;
307     PanelAgentSignalString              m_signal_set_active_ise_by_name;
308     PanelAgentSignalVoid                m_signal_focus_in;
309     PanelAgentSignalVoid                m_signal_focus_out;
310     PanelAgentSignalVoid                m_signal_expand_candidate;
311     PanelAgentSignalVoid                m_signal_contract_candidate;
312     PanelAgentSignalBoolStringVector    m_signal_get_ise_list;
313     PanelAgentSignalBoolStringVector    m_signal_get_keyboard_ise_list;
314     PanelAgentSignalIntIntIntInt        m_signal_update_ise_geometry;
315     PanelAgentSignalStringVector        m_signal_get_language_list;
316     PanelAgentSignalStringVector        m_signal_get_all_language;
317     PanelAgentSignalStrStringVector     m_signal_get_ise_language;
318     PanelAgentSignalString              m_signal_set_isf_language;
319     PanelAgentSignalStringISEINFO       m_signal_get_ise_info_by_uuid;
320     PanelAgentSignalStringISEINFO       m_signal_get_ise_info_by_name;
321     PanelAgentSignalKeyEvent            m_signal_send_key_event;
322
323     PanelAgentSignalInt                 m_signal_accept_connection;
324     PanelAgentSignalInt                 m_signal_close_connection;
325     PanelAgentSignalVoid                m_signal_exit;
326
327     PanelAgentSignalVoid                m_signal_transaction_start;
328     PanelAgentSignalVoid                m_signal_transaction_end;
329
330     PanelAgentSignalVoid                m_signal_lock;
331     PanelAgentSignalVoid                m_signal_unlock;
332
333 public:
334     PanelAgentImpl ()
335         : m_should_exit (false),
336           m_should_resident (false),
337           m_current_screen (0),
338           m_socket_timeout (scim_get_default_socket_timeout ()),
339           m_current_socket_client (-1), m_current_client_context (0),
340           m_current_toolbar_mode (TOOLBAR_KEYBOARD_MODE),
341           m_current_ise_style (0),
342           m_current_active_imcontrol_id (-1), m_pending_active_imcontrol_id (-1),
343           m_should_shared_ise (false),
344           m_ise_settings (NULL), m_ise_settings_len (0),
345           m_ise_changing (false), m_ise_exiting (false),
346           m_last_socket_client (-1), m_last_client_context (0)
347     {
348         m_current_ise_name = String (_("English/Keyboard"));
349         m_imcontrol_repository.clear ();
350         m_imcontrol_map.clear ();
351         m_socket_server.signal_connect_accept (slot (this, &PanelAgentImpl::socket_accept_callback));
352         m_socket_server.signal_connect_receive (slot (this, &PanelAgentImpl::socket_receive_callback));
353         m_socket_server.signal_connect_exception (slot (this, &PanelAgentImpl::socket_exception_callback));
354     }
355
356     bool initialize (const String &config, const String &display, bool resident)
357     {
358         m_config_name = config;
359         m_display_name = display;
360         m_should_resident = resident;
361
362         m_socket_address = scim_get_default_panel_socket_address (display);
363
364         m_socket_server.shutdown ();
365
366         return m_socket_server.create (SocketAddress (m_socket_address));
367     }
368
369     bool valid (void) const
370     {
371         return m_socket_server.valid ();
372     }
373
374 public:
375     bool run (void)
376     {
377         SCIM_DEBUG_MAIN (1) << "PanelAgent::run ()\n";
378
379         return m_socket_server.run ();
380     }
381
382     void stop (void)
383     {
384         SCIM_DEBUG_MAIN(1) << "PanelAgent::stop ()\n";
385
386         lock ();
387         m_should_exit = true;
388         unlock ();
389
390         SocketClient  client;
391
392         if (client.connect (SocketAddress (m_socket_address))) {
393             client.close ();
394         }
395
396         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode) {
397             String helper_uuid = get_current_helper_uuid ();
398             hide_helper (helper_uuid);
399             stop_helper (helper_uuid, -2, 0);
400         }
401     }
402
403     int get_helper_list (std::vector <HelperInfo> & helpers) const
404     {
405         SCIM_DEBUG_MAIN (1) << "PanelAgent::get_helper_list ()\n";
406
407         helpers.clear ();
408
409         m_helper_manager.get_helper_list ();
410         unsigned int num = m_helper_manager.number_of_helpers ();
411         HelperInfo info;
412
413         SCIM_DEBUG_MAIN (2) << "Found " << num << " Helper objects\n";
414
415         for (unsigned int i = 0; i < num; ++i) {
416             if (m_helper_manager.get_helper_info (i, info) && info.uuid.length ()
417                 && (info.option & SCIM_HELPER_STAND_ALONE))
418                 helpers.push_back (info);
419
420             SCIM_DEBUG_MAIN (3) << "Helper " << i << " : " << info.uuid << " : " << info.name << " : "
421                                 << ((info.option & SCIM_HELPER_STAND_ALONE) ? "SA " : "")
422                                 << ((info.option & SCIM_HELPER_AUTO_START) ? "AS " : "")
423                                 << ((info.option & SCIM_HELPER_AUTO_RESTART) ? "AR " : "") << "\n";
424         }
425
426         return (int)(helpers.size ());
427     }
428
429     TOOLBAR_MODE_T get_current_toolbar_mode () const
430     {
431         return m_current_toolbar_mode;
432     }
433
434     String get_current_ise_name () const
435     {
436         return m_current_ise_name;
437     }
438
439     String get_current_factory_icon () const
440     {
441         return m_current_factory_icon;
442     }
443
444     String get_current_helper_uuid () const
445     {
446         return m_current_helper_uuid;
447     }
448
449     String get_current_helper_name () const
450     {
451         std::vector<HelperInfo> helpers;
452
453         get_helper_list (helpers);
454
455         std::vector<HelperInfo>::iterator iter;
456
457         for (iter = helpers.begin (); iter != helpers.end (); iter++) {
458             if (iter->uuid == m_current_helper_uuid)
459                 return iter->name;
460         }
461
462         return String ("");
463     }
464
465     void set_current_ise_name (String &name)
466     {
467         m_current_ise_name = name;
468     }
469
470     void set_current_ise_style (uint32 &style)
471     {
472         m_current_ise_style = style;
473     }
474
475     void set_current_toolbar_mode (TOOLBAR_MODE_T mode)
476     {
477         m_current_toolbar_mode = mode;
478     }
479
480     void update_ise_name (String &name)
481     {
482         ClientRepository::iterator iter = m_client_repository.begin ();
483
484         for (; iter != m_client_repository.end (); iter++)
485         {
486             if (IMCONTROL_CLIENT == iter->second.type
487                 && iter->first == m_imcontrol_map[m_current_active_imcontrol_id])
488             {
489                 Socket client_socket (iter->first);
490                 Transaction trans;
491
492                 trans.clear ();
493                 trans.put_command (SCIM_TRANS_CMD_REQUEST);
494                 trans.put_command (ISM_TRANS_CMD_ISE_CHANGED);
495                 trans.put_data (name);
496
497                 trans.write_to_socket (client_socket);
498                 break;
499             }
500         }
501     }
502
503     void update_ise_style (uint32 &style)
504     {
505         ClientRepository::iterator iter = m_client_repository.begin ();
506
507         for (; iter != m_client_repository.end (); iter++)
508         {
509             if (IMCONTROL_CLIENT == iter->second.type &&
510                 iter->first == m_imcontrol_map[m_current_active_imcontrol_id])
511             {
512                 Socket client_socket (iter->first);
513                 Transaction trans;
514
515                 trans.clear ();
516                 trans.put_command (SCIM_TRANS_CMD_REQUEST);
517                 trans.put_command (ISM_TRANS_CMD_UPDATE_ISE_STYLE);
518                 trans.put_data (style);
519
520                 trans.write_to_socket (client_socket);
521                 break;
522             }
523         }
524     }
525
526     void update_panel_event (int cmd, uint32 nType, uint32 nValue)
527     {
528         SCIM_DEBUG_MAIN(1) << __func__ << " (" << nType << ", " << nValue << ")\n";
529         ClientRepository::iterator iter = m_client_repository.begin ();
530
531         for (; iter != m_client_repository.end (); iter++)
532         {
533             if (IMCONTROL_CLIENT == iter->second.type &&
534                 iter->first == m_imcontrol_map[m_current_active_imcontrol_id])
535             {
536                 Socket client_socket (iter->first);
537                 Transaction trans;
538
539                 trans.clear ();
540                 trans.put_command (SCIM_TRANS_CMD_REQUEST);
541                 trans.put_command (cmd);
542                 trans.put_data (nType);
543                 trans.put_data (nValue);
544
545                 trans.write_to_socket (client_socket);
546                 break;
547             }
548         }
549     }
550
551     void set_current_factory_icon (String &icon)
552     {
553         m_current_factory_icon = icon;
554     }
555
556     bool move_preedit_caret (uint32 position)
557     {
558         SCIM_DEBUG_MAIN(1) << "PanelAgent::move_preedit_caret (" << position << ")\n";
559
560         int client;
561         uint32 context;
562
563         lock ();
564
565         get_focused_context (client, context);
566
567         if (client >= 0) {
568             Socket client_socket (client);
569             m_send_trans.clear ();
570             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
571             m_send_trans.put_data ((uint32) context);
572             m_send_trans.put_command (SCIM_TRANS_CMD_MOVE_PREEDIT_CARET);
573             m_send_trans.put_data ((uint32) position);
574             m_send_trans.write_to_socket (client_socket);
575         }
576
577         unlock ();
578
579         return client >= 0;
580     }
581
582     bool request_help (void)
583     {
584         SCIM_DEBUG_MAIN(1) << "PanelAgent::request_help ()\n";
585
586         int client;
587         uint32 context;
588
589         lock ();
590
591         get_focused_context (client, context);
592
593         if (client >= 0) {
594             Socket client_socket (client);
595             m_send_trans.clear ();
596             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
597             m_send_trans.put_data ((uint32) context);
598             m_send_trans.put_command (SCIM_TRANS_CMD_PANEL_REQUEST_HELP);
599             m_send_trans.write_to_socket (client_socket);
600         }
601
602         unlock ();
603
604         return client >= 0;
605     }
606
607     bool request_factory_menu (void)
608     {
609         SCIM_DEBUG_MAIN(1) << "PanelAgent::request_factory_menu ()\n";
610
611         int client;
612         uint32 context;
613
614         lock ();
615
616         get_focused_context (client, context);
617
618         if (client >= 0) {
619             Socket client_socket (client);
620             m_send_trans.clear ();
621             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
622             m_send_trans.put_data ((uint32) context);
623             m_send_trans.put_command (SCIM_TRANS_CMD_PANEL_REQUEST_FACTORY_MENU);
624             m_send_trans.write_to_socket (client_socket);
625         }
626
627         unlock ();
628
629         return client >= 0;
630     }
631
632     bool reset_keyboard_ise (void)
633     {
634         SCIM_DEBUG_MAIN(1) << "PanelAgent::reset_keyboard_ise ()\n";
635         int    client = -1;
636         uint32 context = 0;
637
638         lock ();
639
640         get_focused_context (client, context);
641         if (client >= 0) {
642             Socket client_socket (client);
643             m_send_trans.clear ();
644             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
645             m_send_trans.put_data ((uint32) context);
646             m_send_trans.put_command (ISM_TRANS_CMD_PANEL_REQUEST_RESET_ISE);
647             m_send_trans.write_to_socket (client_socket);
648         }
649
650         unlock ();
651
652         return client >= 0;
653     }
654
655     bool update_keyboard_ise_list (void)
656     {
657         SCIM_DEBUG_MAIN(1) << "PanelAgent::update_keyboard_ise_list ()\n";
658         int    client = -1;
659         uint32 context = 0;
660
661         lock ();
662
663         get_focused_context (client, context);
664         if (client >= 0) {
665             Socket client_socket (client);
666             m_send_trans.clear ();
667             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
668             m_send_trans.put_data ((uint32) context);
669             m_send_trans.put_command (ISM_TRANS_CMD_PANEL_UPDATE_KEYBOARD_ISE);
670             m_send_trans.write_to_socket (client_socket);
671         }
672
673         unlock ();
674
675         return client >= 0;
676     }
677
678     bool change_factory (const String  &uuid)
679     {
680         SCIM_DEBUG_MAIN(1) << "PanelAgent::change_factory (" << uuid << ")\n";
681
682         int client;
683         uint32 context;
684
685         lock ();
686
687         get_focused_context (client, context);
688
689         if (client >= 0) {
690             Socket client_socket (client);
691             m_send_trans.clear ();
692             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
693             m_send_trans.put_data ((uint32) context);
694             m_send_trans.put_command (SCIM_TRANS_CMD_PANEL_CHANGE_FACTORY);
695             m_send_trans.put_data (uuid);
696             m_send_trans.write_to_socket (client_socket);
697         }
698
699         unlock ();
700
701         return client >= 0;
702     }
703
704     bool candidate_more_window_show (void)
705     {
706         SCIM_DEBUG_MAIN(4) << __FUNCTION__ << "...\n";
707
708         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
709         {
710             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
711
712             if (it != m_helper_client_index.end ())
713             {
714                 int    client;
715                 uint32 context;
716                 Socket client_socket (it->second.id);
717                 uint32 ctx;
718
719                 get_focused_context (client, context);
720                 ctx = get_helper_ic (client, context);
721
722                 m_send_trans.clear ();
723                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
724                 m_send_trans.put_data (ctx);
725                 m_send_trans.put_data (m_current_helper_uuid);
726                 m_send_trans.put_command (ISM_TRANS_CMD_CANDIDATE_MORE_WINDOW_SHOW);
727                 m_send_trans.write_to_socket (client_socket);
728
729                 return true;
730             }
731         }
732
733         return false;
734     }
735
736     bool candidate_more_window_hide (void)
737     {
738         SCIM_DEBUG_MAIN(4) << __FUNCTION__ << "...\n";
739
740         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
741         {
742             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
743
744             if (it != m_helper_client_index.end ())
745             {
746                 int    client;
747                 uint32 context;
748                 Socket client_socket (it->second.id);
749                 uint32 ctx;
750
751                 get_focused_context (client, context);
752                 ctx = get_helper_ic (client, context);
753
754                 m_send_trans.clear ();
755                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
756                 m_send_trans.put_data (ctx);
757                 m_send_trans.put_data (m_current_helper_uuid);
758                 m_send_trans.put_command (ISM_TRANS_CMD_CANDIDATE_MORE_WINDOW_HIDE);
759                 m_send_trans.write_to_socket (client_socket);
760
761                 return true;
762             }
763         }
764
765         return false;
766     }
767
768     bool select_aux (uint32 item)
769     {
770         SCIM_DEBUG_MAIN(1) << "PanelAgent::select_aux (" << item << ")\n";
771
772         int client;
773         uint32 context;
774
775         lock ();
776
777         get_focused_context (client, context);
778
779         if (client >= 0) {
780             Socket client_socket (client);
781             m_send_trans.clear ();
782             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
783             m_send_trans.put_data ((uint32) context);
784             m_send_trans.put_command (ISM_TRANS_CMD_SELECT_AUX);
785             m_send_trans.put_data ((uint32)item);
786             m_send_trans.write_to_socket (client_socket);
787         }
788
789         unlock ();
790
791         helper_select_aux (item);
792
793         return client >= 0;
794     }
795
796     bool select_candidate (uint32 item)
797     {
798         SCIM_DEBUG_MAIN(1) << "PanelAgent::select_candidate (" << item << ")\n";
799
800         int client;
801         uint32 context;
802
803         lock ();
804
805         get_focused_context (client, context);
806
807         if (client >= 0) {
808             Socket client_socket (client);
809             m_send_trans.clear ();
810             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
811             m_send_trans.put_data ((uint32) context);
812             m_send_trans.put_command (SCIM_TRANS_CMD_SELECT_CANDIDATE);
813             m_send_trans.put_data ((uint32)item);
814             m_send_trans.write_to_socket (client_socket);
815         }
816
817         unlock ();
818
819         helper_select_candidate (item);
820
821         return client >= 0;
822     }
823
824     bool lookup_table_page_up (void)
825     {
826         SCIM_DEBUG_MAIN(1) << "PanelAgent::lookup_table_page_up ()\n";
827
828         int client;
829         uint32 context;
830
831         lock ();
832
833         get_focused_context (client, context);
834
835         if (client >= 0) {
836             Socket client_socket (client);
837             m_send_trans.clear ();
838             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
839             m_send_trans.put_data ((uint32) context);
840             m_send_trans.put_command (SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_UP);
841             m_send_trans.write_to_socket (client_socket);
842         }
843
844         unlock ();
845
846         helper_lookup_table_page_up ();
847
848         return client >= 0;
849     }
850
851     bool lookup_table_page_down (void)
852     {
853         SCIM_DEBUG_MAIN(1) << "PanelAgent::lookup_table_page_down ()\n";
854
855         int client;
856         uint32 context;
857
858         lock ();
859
860         get_focused_context (client, context);
861
862         if (client >= 0) {
863             Socket client_socket (client);
864             m_send_trans.clear ();
865             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
866             m_send_trans.put_data ((uint32) context);
867             m_send_trans.put_command (SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_DOWN);
868             m_send_trans.write_to_socket (client_socket);
869         }
870
871         unlock ();
872
873         helper_lookup_table_page_down ();
874
875         return client >= 0;
876     }
877
878     bool update_lookup_table_page_size (uint32 size)
879     {
880         SCIM_DEBUG_MAIN(1) << "PanelAgent::update_lookup_table_page_size (" << size << ")\n";
881
882         int client;
883         uint32 context;
884
885         lock ();
886
887         get_focused_context (client, context);
888
889         if (client >= 0) {
890             Socket client_socket (client);
891             m_send_trans.clear ();
892             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
893             m_send_trans.put_data ((uint32) context);
894             m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE_PAGE_SIZE);
895             m_send_trans.put_data (size);
896             m_send_trans.write_to_socket (client_socket);
897         }
898
899         unlock ();
900
901         helper_update_lookup_table_page_size (size);
902
903         return client >= 0;
904     }
905
906     bool select_associate (uint32 item)
907     {
908         SCIM_DEBUG_MAIN(1) << "PanelAgent::select_associate (" << item << ")\n";
909
910         int client;
911         uint32 context;
912
913         lock ();
914
915         get_focused_context (client, context);
916
917         if (client >= 0) {
918             Socket client_socket (client);
919             m_send_trans.clear ();
920             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
921             m_send_trans.put_data ((uint32) context);
922             m_send_trans.put_command (ISM_TRANS_CMD_SELECT_ASSOCIATE);
923             m_send_trans.put_data ((uint32)item);
924             m_send_trans.write_to_socket (client_socket);
925         }
926
927         unlock ();
928
929         helper_select_associate (item);
930
931         return client >= 0;
932     }
933
934     bool associate_table_page_up (void)
935     {
936         SCIM_DEBUG_MAIN(1) << "PanelAgent::associate_table_page_up ()\n";
937
938         int client;
939         uint32 context;
940
941         lock ();
942
943         get_focused_context (client, context);
944
945         if (client >= 0) {
946             Socket client_socket (client);
947             m_send_trans.clear ();
948             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
949             m_send_trans.put_data ((uint32) context);
950             m_send_trans.put_command (ISM_TRANS_CMD_ASSOCIATE_TABLE_PAGE_UP);
951             m_send_trans.write_to_socket (client_socket);
952         }
953
954         unlock ();
955
956         helper_associate_table_page_up ();
957
958         return client >= 0;
959     }
960
961     bool associate_table_page_down (void)
962     {
963         SCIM_DEBUG_MAIN(1) << "PanelAgent::associate_table_page_down ()\n";
964
965         int client;
966         uint32 context;
967
968         lock ();
969
970         get_focused_context (client, context);
971
972         if (client >= 0) {
973             Socket client_socket (client);
974             m_send_trans.clear ();
975             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
976             m_send_trans.put_data ((uint32) context);
977             m_send_trans.put_command (ISM_TRANS_CMD_ASSOCIATE_TABLE_PAGE_DOWN);
978             m_send_trans.write_to_socket (client_socket);
979         }
980
981         unlock ();
982
983         helper_associate_table_page_down ();
984
985         return client >= 0;
986     }
987
988     bool update_associate_table_page_size (uint32 size)
989     {
990         SCIM_DEBUG_MAIN(1) << "PanelAgent::update_associate_table_page_size (" << size << ")\n";
991
992         int client;
993         uint32 context;
994
995         lock ();
996
997         get_focused_context (client, context);
998
999         if (client >= 0) {
1000             Socket client_socket (client);
1001             m_send_trans.clear ();
1002             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1003             m_send_trans.put_data ((uint32) context);
1004             m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_ASSOCIATE_TABLE_PAGE_SIZE);
1005             m_send_trans.put_data (size);
1006             m_send_trans.write_to_socket (client_socket);
1007         }
1008
1009         unlock ();
1010
1011         helper_update_associate_table_page_size (size);
1012
1013         return client >= 0;
1014     }
1015
1016     bool update_displayed_candidate_number (uint32 size)
1017     {
1018         SCIM_DEBUG_MAIN(1) << __func__ << " (" << size << ")\n";
1019
1020         int client;
1021         uint32 context;
1022
1023         lock ();
1024         get_focused_context (client, context);
1025         unlock ();
1026
1027         helper_update_displayed_candidate_number (size);
1028
1029         return client >= 0;
1030     }
1031
1032     bool trigger_property (const String  &property)
1033     {
1034         SCIM_DEBUG_MAIN(1) << "PanelAgent::trigger_property (" << property << ")\n";
1035
1036         int client;
1037         uint32 context;
1038
1039         lock ();
1040
1041         get_focused_context (client, context);
1042
1043         if (client >= 0) {
1044             Socket client_socket (client);
1045             m_send_trans.clear ();
1046             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1047             m_send_trans.put_data ((uint32) context);
1048             m_send_trans.put_command (SCIM_TRANS_CMD_TRIGGER_PROPERTY);
1049             m_send_trans.put_data (property);
1050             m_send_trans.write_to_socket (client_socket);
1051         }
1052
1053         unlock ();
1054
1055         return client >= 0;
1056     }
1057
1058     bool trigger_helper_property (int            client,
1059                                   const String  &property)
1060     {
1061         SCIM_DEBUG_MAIN(1) << "PanelAgent::trigger_helper_property (" << client << "," << property << ")\n";
1062
1063         lock ();
1064
1065         ClientInfo info = socket_get_client_info (client);
1066
1067         if (client >= 0 && info.type == HELPER_CLIENT) {
1068             int fe_client;
1069             uint32 fe_context;
1070             String fe_uuid;
1071
1072             fe_uuid = get_focused_context (fe_client, fe_context);
1073
1074             Socket client_socket (client);
1075             m_send_trans.clear ();
1076             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1077
1078             /* FIXME: We presume that client and context are both less than 65536.
1079              * Hopefully, it should be true in any UNIXs.
1080              * So it's ok to combine client and context into one uint32.*/
1081             m_send_trans.put_data (get_helper_ic (fe_client, fe_context));
1082             m_send_trans.put_data (fe_uuid);
1083             m_send_trans.put_command (SCIM_TRANS_CMD_TRIGGER_PROPERTY);
1084             m_send_trans.put_data (property);
1085             m_send_trans.write_to_socket (client_socket);
1086         }
1087
1088         unlock ();
1089
1090         return client >= 0 && info.type == HELPER_CLIENT;
1091     }
1092
1093     bool start_helper (const String  &uuid, int client, uint32 context)
1094     {
1095         SCIM_DEBUG_MAIN(1) << "PanelAgent::start_helper (" << uuid << ")\n";
1096         if (uuid.length () <= 0)
1097             return false;
1098
1099         lock ();
1100
1101         if (m_current_toolbar_mode != TOOLBAR_HELPER_MODE || m_current_helper_uuid.compare (uuid) != 0)
1102         {
1103             SCIM_DEBUG_MAIN(1) << uuid.c_str () <<  ".....enter run_helper ..............\n";
1104             m_helper_manager.run_helper (uuid, m_config_name, m_display_name);
1105         }
1106         m_current_helper_uuid = uuid;
1107 #ifdef ONE_HELPER_ISE_PROCESS
1108         if (client == -2)
1109             get_focused_context (client, context);
1110
1111         SCIM_DEBUG_MAIN(1) << "[start helper] client : " << client << " context : " << context << "\n";
1112         uint32 ctx = get_helper_ic (client, context);
1113
1114         /*HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
1115         if (it == m_helper_client_index.end ())*/
1116         if (m_helper_uuid_count.find (uuid) == m_helper_uuid_count.end ())
1117         {
1118             m_client_context_helper[ctx] = uuid;
1119             m_current_helper_uuid        = uuid;
1120             m_helper_uuid_count[uuid]    = 1;
1121             m_helper_uuid_state[uuid]    = HELPER_HIDED;
1122
1123             m_helper_manager.run_helper (uuid, m_config_name, m_display_name);
1124             SCIM_DEBUG_MAIN(1) << "Start HelperISE " << uuid << " ...\n";
1125         }
1126         else
1127         {
1128             ClientContextUUIDRepository::iterator it2 = m_client_context_helper.find (ctx);
1129             if (it2 == m_client_context_helper.end ())
1130             {
1131                 m_client_context_helper[ctx] = uuid;
1132                 m_current_helper_uuid        = uuid;
1133                 m_helper_uuid_count[uuid]    = m_helper_uuid_count[uuid] + 1;
1134             }
1135
1136             if (m_current_active_imcontrol_id != -1
1137                 && m_ise_settings != NULL && m_ise_changing)
1138             {
1139                 show_helper (uuid, m_ise_settings, m_ise_settings_len);
1140                 m_ise_changing = false;
1141             }
1142
1143             SCIM_DEBUG_MAIN(1) << "Increment usage count of HelperISE " << uuid << " to "
1144                         << m_helper_uuid_count[uuid] << "\n";
1145         }
1146 #endif
1147         unlock ();
1148
1149         return true;
1150     }
1151
1152     bool stop_helper (const String &helper_uuid, int client, uint32 context)
1153     {
1154         String uuid = helper_uuid;
1155         SCIM_DEBUG_MAIN(1) << "PanelAgent::stop_helper (" << uuid << ")\n";
1156         if (uuid.length () <= 0)
1157             return false;
1158
1159         lock ();
1160
1161         uint32 ctx = get_helper_ic (client, context);
1162         HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
1163         if (it != m_helper_client_index.end ())
1164         {
1165             Socket client_socket (it->second.id);
1166             m_send_trans.clear ();
1167             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1168             m_send_trans.put_data (ctx);
1169             m_send_trans.put_data (uuid);
1170
1171             m_ise_exiting = true;
1172             m_send_trans.put_command (SCIM_TRANS_CMD_EXIT);
1173             m_send_trans.write_to_socket (client_socket);
1174             SCIM_DEBUG_MAIN(1) << "Stop HelperISE " << uuid << " ...\n";
1175         }
1176 #ifdef ONE_HELPER_ISE_PROCESS
1177         if (client == -2)
1178             get_focused_context (client, context);
1179
1180         SCIM_DEBUG_MAIN(1) << "[stop helper] client : " << client << " context : " << context << "\n";
1181         uint32 ctx = get_helper_ic (client, context);
1182
1183         HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
1184         /*if (it != m_helper_client_index.end ())*/
1185         if (m_helper_uuid_count.find (uuid) != m_helper_uuid_count.end ())
1186         {
1187             m_client_context_helper.erase (ctx);
1188
1189             uint32 count = m_helper_uuid_count[uuid];
1190             if (1 == count)
1191             {
1192                 m_helper_uuid_count.erase (uuid);
1193
1194                 if (it != m_helper_client_index.end ())
1195                 {
1196                     Socket client_socket (it->second.id);
1197                     m_send_trans.clear ();
1198                     m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1199                     m_send_trans.put_data (ctx);
1200                     m_send_trans.put_data (uuid);
1201                     m_send_trans.put_command (SCIM_TRANS_CMD_EXIT);
1202                     m_send_trans.write_to_socket (client_socket);
1203                     SCIM_DEBUG_MAIN(1) << "Stop HelperISE " << uuid << " ...\n";
1204                 }
1205             }
1206             else
1207             {
1208                 m_helper_uuid_count[uuid] = count - 1;
1209                 SCIM_DEBUG_MAIN(1) << "Decrement usage count of HelperISE " << uuid
1210                         << " to " << m_helper_uuid_count[uuid] << "\n";
1211             }
1212         }
1213 #endif
1214         unlock ();
1215
1216         return true;
1217     }
1218
1219     void focus_out_helper (const String &uuid, int client, uint32 context)
1220     {
1221         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1222
1223         if (it != m_helper_client_index.end ())
1224         {
1225             Socket client_socket (it->second.id);
1226             uint32 ctx = get_helper_ic (client, context);
1227
1228             m_send_trans.clear ();
1229             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1230             m_send_trans.put_data (ctx);
1231             m_send_trans.put_data (uuid);
1232             m_send_trans.put_command (SCIM_TRANS_CMD_FOCUS_OUT);
1233             m_send_trans.write_to_socket (client_socket);
1234         }
1235     }
1236
1237     void focus_in_helper (const String &uuid, int client, uint32 context)
1238     {
1239         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1240
1241         if (it != m_helper_client_index.end ())
1242         {
1243             Socket client_socket (it->second.id);
1244             uint32 ctx = get_helper_ic (client, context);
1245
1246             m_send_trans.clear ();
1247             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1248             m_send_trans.put_data (ctx);
1249             m_send_trans.put_data (uuid);
1250             m_send_trans.put_command (SCIM_TRANS_CMD_FOCUS_IN);
1251             m_send_trans.write_to_socket (client_socket);
1252         }
1253     }
1254
1255     void show_helper (const String &uuid, char *data, size_t &len)
1256     {
1257         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1258
1259         if (it != m_helper_client_index.end ())
1260         {
1261             int client;
1262             uint32 context;
1263             Socket client_socket (it->second.id);
1264             uint32 ctx;
1265
1266             m_helper_uuid_state[uuid] = HELPER_SHOWED;
1267
1268             get_focused_context (client, context);
1269             ctx = get_helper_ic (client, context);
1270
1271             m_send_trans.clear ();
1272             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1273             m_send_trans.put_data (ctx);
1274             m_send_trans.put_data (uuid);
1275             m_send_trans.put_command (ISM_TRANS_CMD_SHOW_ISE);
1276             m_send_trans.put_data (data, len);
1277             m_send_trans.write_to_socket (client_socket);
1278         }
1279         return;
1280     }
1281
1282     void hide_helper (const String &uuid)
1283     {
1284         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1285
1286         if (it != m_helper_client_index.end ())
1287         {
1288             int client;
1289             uint32 context;
1290             Socket client_socket (it->second.id);
1291             uint32 ctx;
1292
1293             m_helper_uuid_state[uuid] = HELPER_HIDED;
1294
1295             get_focused_context (client, context);
1296             ctx = get_helper_ic (client, context);
1297
1298             m_send_trans.clear ();
1299             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1300             m_send_trans.put_data (ctx);
1301             m_send_trans.put_data (uuid);
1302             m_send_trans.put_command (ISM_TRANS_CMD_HIDE_ISE);
1303             m_send_trans.write_to_socket (client_socket);
1304         }
1305     }
1306
1307     bool set_helper_mode (const String &uuid, uint32 &mode)
1308     {
1309         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1310
1311         if (it != m_helper_client_index.end ())
1312         {
1313             int client;
1314             uint32 context;
1315             Socket client_socket (it->second.id);
1316             uint32 ctx;
1317
1318             get_focused_context (client, context);
1319             ctx = get_helper_ic (client, context);
1320
1321             m_send_trans.clear ();
1322             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1323             m_send_trans.put_data (ctx);
1324             m_send_trans.put_data (uuid);
1325             m_send_trans.put_command (ISM_TRANS_CMD_SET_ISE_MODE);
1326             m_send_trans.put_data (mode);
1327             m_send_trans.write_to_socket (client_socket);
1328             return true;
1329         }
1330
1331         return false;
1332     }
1333
1334     bool set_helper_language (const String &uuid, uint32 &language)
1335     {
1336         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1337
1338         if (it != m_helper_client_index.end ())
1339         {
1340             int client     = -1;
1341             uint32 context = 0;
1342             Socket client_socket (it->second.id);
1343             uint32 ctx;
1344
1345             get_focused_context (client, context);
1346             ctx = get_helper_ic (client, context);
1347
1348             m_send_trans.clear ();
1349             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1350             m_send_trans.put_data (ctx);
1351             m_send_trans.put_data (uuid);
1352             m_send_trans.put_command (ISM_TRANS_CMD_SET_ISE_LANGUAGE);
1353             m_send_trans.put_data (language);
1354             m_send_trans.write_to_socket (client_socket);
1355             return true;
1356         }
1357         return false;
1358     }
1359
1360     bool set_helper_imdata (const String &uuid, char *imdata, size_t &len)
1361     {
1362         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1363
1364         if (it != m_helper_client_index.end ())
1365         {
1366             int client     = -1;
1367             uint32 context = 0;
1368             Socket client_socket (it->second.id);
1369             uint32 ctx;
1370
1371             get_focused_context (client, context);
1372             ctx = get_helper_ic (client, context);
1373
1374             m_send_trans.clear ();
1375             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1376             m_send_trans.put_data (ctx);
1377             m_send_trans.put_data (uuid);
1378             m_send_trans.put_command (ISM_TRANS_CMD_SET_ISE_IMDATA);
1379             m_send_trans.put_data (imdata, len);
1380             m_send_trans.write_to_socket (client_socket);
1381             return true;
1382         }
1383         return false;
1384     }
1385
1386     bool set_helper_return_key_type (const String &uuid, int type)
1387     {
1388         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1389
1390         if (it != m_helper_client_index.end ())
1391         {
1392             int client     = -1;
1393             uint32 context = 0;
1394             Socket client_socket (it->second.id);
1395             uint32 ctx;
1396
1397             get_focused_context (client, context);
1398             ctx = get_helper_ic (client, context);
1399
1400             m_send_trans.clear ();
1401             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1402             m_send_trans.put_data (ctx);
1403             m_send_trans.put_data (uuid);
1404             m_send_trans.put_command (ISM_TRANS_CMD_SET_RETURN_KEY_TYPE);
1405             m_send_trans.put_data (type);
1406             m_send_trans.write_to_socket (client_socket);
1407
1408             return true;
1409         }
1410
1411         return false;
1412     }
1413
1414     bool get_helper_return_key_type (const String &uuid, uint32 &type)
1415     {
1416         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1417
1418         if (it != m_helper_client_index.end ()) {
1419
1420             int    client;
1421             uint32 context;
1422             Socket client_socket (it->second.id);
1423             uint32 ctx;
1424             Transaction trans;
1425
1426             get_focused_context (client, context);
1427             ctx = get_helper_ic (client, context);
1428
1429             trans.clear ();
1430             trans.put_command (SCIM_TRANS_CMD_REPLY);
1431             trans.put_data (ctx);
1432             trans.put_data (uuid);
1433             trans.put_command (ISM_TRANS_CMD_GET_RETURN_KEY_TYPE);
1434
1435             int cmd;
1436             if (trans.write_to_socket (client_socket)
1437                 && trans.read_from_socket (client_socket)
1438                 && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY
1439                 && trans.get_data (type)) {
1440                 SCIM_DEBUG_MAIN (1) << __func__ << " success\n";
1441                 return true;
1442             } else {
1443                 std::cerr << __func__ << " failed\n";
1444             }
1445         }
1446         return false;
1447     }
1448
1449     bool set_helper_return_key_disable (const String &uuid, bool disabled)
1450     {
1451         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1452
1453         if (it != m_helper_client_index.end ())
1454         {
1455             int client     = -1;
1456             uint32 context = 0;
1457             Socket client_socket (it->second.id);
1458             uint32 ctx;
1459
1460             get_focused_context (client, context);
1461             ctx = get_helper_ic (client, context);
1462
1463             m_send_trans.clear ();
1464             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1465             m_send_trans.put_data (ctx);
1466             m_send_trans.put_data (uuid);
1467             m_send_trans.put_command (ISM_TRANS_CMD_SET_RETURN_KEY_DISABLE);
1468             m_send_trans.put_data (disabled);
1469             m_send_trans.write_to_socket (client_socket);
1470
1471             return true;
1472         }
1473
1474         return false;
1475     }
1476
1477     bool get_helper_return_key_disable (const String &uuid, uint32 &disabled)
1478     {
1479         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1480
1481         if (it != m_helper_client_index.end ()) {
1482
1483             int    client;
1484             uint32 context;
1485             Socket client_socket (it->second.id);
1486             uint32 ctx;
1487             Transaction trans;
1488
1489             get_focused_context (client, context);
1490             ctx = get_helper_ic (client, context);
1491
1492             trans.clear ();
1493             trans.put_command (SCIM_TRANS_CMD_REPLY);
1494             trans.put_data (ctx);
1495             trans.put_data (uuid);
1496             trans.put_command (ISM_TRANS_CMD_GET_RETURN_KEY_DISABLE);
1497
1498             int cmd;
1499             if (trans.write_to_socket (client_socket)
1500                 && trans.read_from_socket (client_socket)
1501                 && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY
1502                 && trans.get_data (disabled)) {
1503                 SCIM_DEBUG_MAIN (1) << __func__ << " success\n";
1504                 return true;
1505             } else {
1506                 std::cerr << __func__ << " failed\n";
1507             }
1508         }
1509         return false;
1510     }
1511
1512     bool set_helper_layout (const String &uuid, uint32 &layout)
1513     {
1514         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1515
1516         if (it != m_helper_client_index.end ())
1517         {
1518             int client;
1519             uint32 context;
1520             Socket client_socket (it->second.id);
1521             uint32 ctx;
1522
1523             get_focused_context (client, context);
1524             ctx = get_helper_ic (client, context);
1525
1526             m_send_trans.clear ();
1527             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1528             m_send_trans.put_data (ctx);
1529             m_send_trans.put_data (uuid);
1530             m_send_trans.put_command (ISM_TRANS_CMD_SET_LAYOUT);
1531             m_send_trans.put_data (layout);
1532             m_send_trans.write_to_socket (client_socket);
1533             return true;
1534         }
1535
1536         return false;
1537     }
1538
1539     bool set_helper_caps_mode (const String &uuid, uint32 &mode)
1540     {
1541         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1542
1543         if (it != m_helper_client_index.end ())
1544         {
1545             int client;
1546             uint32 context;
1547             Socket client_socket (it->second.id);
1548             uint32 ctx;
1549
1550             get_focused_context (client, context);
1551             ctx = get_helper_ic (client, context);
1552
1553             m_send_trans.clear ();
1554             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
1555             m_send_trans.put_data (ctx);
1556             m_send_trans.put_data (uuid);
1557             m_send_trans.put_command (ISM_TRANS_CMD_SET_CAPS_MODE);
1558             m_send_trans.put_data (mode);
1559             m_send_trans.write_to_socket (client_socket);
1560             return true;
1561         }
1562
1563         return false;
1564     }
1565
1566     void show_isf_panel (int client_id)
1567     {
1568         SCIM_DEBUG_MAIN(4) << "PanelAgent::show_isf_panel ()\n";
1569         Transaction trans;
1570         Socket client_socket (client_id);
1571
1572         m_signal_show_panel ();
1573     }
1574
1575     void hide_isf_panel (int client_id)
1576     {
1577         SCIM_DEBUG_MAIN(4) << "PanelAgent::hide_isf_panel ()\n";
1578         Transaction trans;
1579         Socket client_socket (client_id);
1580
1581         m_signal_hide_panel ();
1582     }
1583
1584     void show_ise_panel (int client_id)
1585     {
1586         SCIM_DEBUG_MAIN(4) << "PanelAgent::show_ise_panel ()\n";
1587         char   *data = NULL;
1588         size_t  len;
1589
1590         m_current_active_imcontrol_id = client_id;
1591
1592         if (m_recv_trans.get_data (&data, len))
1593         {
1594             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
1595                 show_helper (m_current_helper_uuid, data, len);
1596         }
1597
1598         if (data != NULL)
1599         {
1600             if (m_ise_settings != NULL)
1601                 delete [] m_ise_settings;
1602             m_ise_settings = data;
1603             m_ise_settings_len = len;
1604         }
1605     }
1606
1607     void hide_ise_panel (int client_id)
1608     {
1609         SCIM_DEBUG_MAIN(4) << "PanelAgent::hide_ise_panel ()\n";
1610         TOOLBAR_MODE_T mode;
1611
1612         mode = m_current_toolbar_mode;
1613
1614         if (client_id == m_current_active_imcontrol_id &&
1615             TOOLBAR_HELPER_MODE == mode)
1616         {
1617             hide_helper (m_current_helper_uuid);
1618         }
1619     }
1620
1621     void set_default_ise (const DEFAULT_ISE_T &ise)
1622     {
1623         m_default_ise.type = ise.type;
1624         m_default_ise.uuid = ise.uuid;
1625         m_default_ise.name = ise.name;
1626
1627         scim_global_config_write (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_TYPE), (int)m_default_ise.type);
1628         scim_global_config_write (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_UUID), m_default_ise.uuid);
1629         scim_global_config_write (String (SCIM_GLOBAL_CONFIG_DEFAULT_ISE_NAME), m_default_ise.name);
1630         scim_global_config_flush ();
1631     }
1632
1633     void set_should_shared_ise (const bool should_shared_ise)
1634     {
1635         m_should_shared_ise = should_shared_ise;
1636     }
1637
1638     bool get_helper_geometry (String &uuid, struct rectinfo &info)
1639     {
1640         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1641
1642         if (it != m_helper_client_index.end ()) {
1643             int    client;
1644             uint32 context;
1645             Socket client_socket (it->second.id);
1646             uint32 ctx;
1647             Transaction trans;
1648
1649             get_focused_context (client, context);
1650             ctx = get_helper_ic (client, context);
1651
1652             trans.clear ();
1653             trans.put_command (SCIM_TRANS_CMD_REPLY);
1654             trans.put_data (ctx);
1655             trans.put_data (uuid);
1656             trans.put_command (ISM_TRANS_CMD_GET_ACTIVE_ISE_GEOMETRY);
1657
1658             if (trans.write_to_socket (client_socket)) {
1659                 int cmd;
1660
1661                 trans.clear ();
1662                 if (trans.read_from_socket (client_socket)
1663                     && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY
1664                     && trans.get_data (info.pos_x)
1665                     && trans.get_data (info.pos_y)
1666                     && trans.get_data (info.width)
1667                     && trans.get_data (info.height)) {
1668                     SCIM_DEBUG_MAIN (1) << __func__ << " is successful\n";
1669                     return true;
1670                 } else {
1671                     std::cerr << __func__ << " is failed!!!\n";
1672                     return false;
1673                 }
1674             }
1675         }
1676         return false;
1677     }
1678
1679     bool get_helper_imdata (String &uuid, char **imdata, size_t &len)
1680     {
1681         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1682
1683         if (it != m_helper_client_index.end ()) {
1684
1685             int    client;
1686             uint32 context;
1687             Socket client_socket (it->second.id);
1688             uint32 ctx;
1689             Transaction trans;
1690
1691             get_focused_context (client, context);
1692             ctx = get_helper_ic (client, context);
1693
1694             trans.clear ();
1695             trans.put_command (SCIM_TRANS_CMD_REPLY);
1696             trans.put_data (ctx);
1697             trans.put_data (uuid);
1698             trans.put_command (ISM_TRANS_CMD_GET_ISE_IMDATA);
1699
1700             int cmd;
1701             if (trans.write_to_socket (client_socket)
1702                 && trans.read_from_socket (client_socket)
1703                 && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY
1704                 && trans.get_data (imdata, len))
1705             {
1706                 SCIM_DEBUG_MAIN (1) << "get_helper_imdata success\n";
1707                 return true;
1708             }
1709             else
1710             {
1711                 std::cerr << "get_helper_imdata failed\n";
1712             }
1713         }
1714         return false;
1715     }
1716
1717     bool get_helper_layout (String &uuid, uint32 &layout)
1718     {
1719         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1720
1721         if (it != m_helper_client_index.end ()) {
1722
1723             int    client;
1724             uint32 context;
1725             Socket client_socket (it->second.id);
1726             uint32 ctx;
1727             Transaction trans;
1728
1729             get_focused_context (client, context);
1730             ctx = get_helper_ic (client, context);
1731
1732             trans.clear ();
1733             trans.put_command (SCIM_TRANS_CMD_REPLY);
1734             trans.put_data (ctx);
1735             trans.put_data (uuid);
1736             trans.put_command (ISM_TRANS_CMD_GET_LAYOUT);
1737
1738             int cmd;
1739             if (trans.write_to_socket (client_socket)
1740                 && trans.read_from_socket (client_socket)
1741                 && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY
1742                 && trans.get_data (layout))
1743             {
1744                 SCIM_DEBUG_MAIN (1) << "get_helper_layout success\n";
1745                 return true;
1746             }
1747             else
1748             {
1749                 std::cerr << "get_helper_layout failed\n";
1750             }
1751         }
1752         return false;
1753     }
1754
1755     bool get_helper_layout_list (String &uuid, std::vector<uint32> &list)
1756     {
1757         HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
1758
1759         if (it != m_helper_client_index.end ()) {
1760
1761             int    client;
1762             uint32 context;
1763             Socket client_socket (it->second.id);
1764             uint32 ctx;
1765             Transaction trans;
1766
1767             get_focused_context (client, context);
1768             ctx = get_helper_ic (client, context);
1769
1770             trans.clear ();
1771             trans.put_command (SCIM_TRANS_CMD_REPLY);
1772             trans.put_data (ctx);
1773             trans.put_data (uuid);
1774             trans.put_command (ISM_TRANS_CMD_GET_LAYOUT_LIST);
1775
1776             int cmd;
1777             if (trans.write_to_socket (client_socket)
1778                 && trans.read_from_socket (client_socket, 500)
1779                 && trans.get_command(cmd) && cmd == SCIM_TRANS_CMD_REPLY
1780                 && trans.get_data (list))
1781             {
1782                 SCIM_DEBUG_MAIN (1) << "get_helper_layout_list success\n";
1783                 return true;
1784             }
1785             else
1786             {
1787                 std::cerr << "get_helper_layout_list failed\n";
1788             }
1789         }
1790         return false;
1791     }
1792
1793     void get_input_panel_geometry (int client_id)
1794     {
1795         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
1796
1797         struct rectinfo info = {0, 0, 0, 0};
1798         m_signal_get_input_panel_geometry (info);
1799
1800         Transaction trans;
1801         Socket client_socket (client_id);
1802
1803         trans.clear ();
1804         trans.put_command (SCIM_TRANS_CMD_REPLY);
1805         trans.put_command (SCIM_TRANS_CMD_OK);
1806         trans.put_data (info.pos_x);
1807         trans.put_data (info.pos_y);
1808         trans.put_data (info.width);
1809         trans.put_data (info.height);
1810         trans.write_to_socket (client_socket);
1811     }
1812
1813     void get_candidate_window_geometry (int client_id)
1814     {
1815         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
1816
1817         struct rectinfo info = {0, 0, 0, 0};
1818         m_signal_get_candidate_geometry (info);
1819
1820         Transaction trans;
1821         Socket client_socket (client_id);
1822
1823         trans.clear ();
1824         trans.put_command (SCIM_TRANS_CMD_REPLY);
1825         trans.put_command (SCIM_TRANS_CMD_OK);
1826         trans.put_data (info.pos_x);
1827         trans.put_data (info.pos_y);
1828         trans.put_data (info.width);
1829         trans.put_data (info.height);
1830         trans.write_to_socket (client_socket);
1831     }
1832
1833     void get_ise_language_locale (int client_id)
1834     {
1835         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
1836
1837         size_t  len;
1838         char   *data = NULL;
1839         bool    ret  = false;
1840         Transaction trans;
1841
1842         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode) {
1843             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
1844
1845             if (it != m_helper_client_index.end ()) {
1846                 int    client;
1847                 uint32 context;
1848                 get_focused_context (client, context);
1849
1850                 uint32 ctx = get_helper_ic (client, context);
1851
1852                 trans.clear ();
1853                 trans.put_command (SCIM_TRANS_CMD_REPLY);
1854                 trans.put_data (ctx);
1855                 trans.put_data (m_current_helper_uuid);
1856                 trans.put_command (ISM_TRANS_CMD_GET_ISE_LANGUAGE_LOCALE);
1857
1858                 int cmd;
1859                 Socket client_socket (it->second.id);
1860                 if (trans.write_to_socket (client_socket)
1861                     && trans.read_from_socket (client_socket)
1862                     && trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY
1863                     && trans.get_data (&data, len)) {
1864                     ret = true;
1865                 } else {
1866                     std::cerr << "Get ISE language locale is failed!!!\n";
1867                 }
1868             }
1869         }
1870
1871         trans.clear ();
1872         trans.put_command (SCIM_TRANS_CMD_REPLY);
1873         if (data != NULL && len > 0) {
1874             trans.put_command (SCIM_TRANS_CMD_OK);
1875             trans.put_data (data, len);
1876         } else {
1877             trans.put_command (SCIM_TRANS_CMD_FAIL);
1878         }
1879
1880         Socket client_socket (client_id);
1881         trans.write_to_socket (client_socket);
1882
1883         if (NULL != data)
1884             delete [] data;
1885     }
1886
1887     void get_current_ise_geometry (rectinfo &rect)
1888     {
1889         SCIM_DEBUG_MAIN(4) << __func__ << " \n";
1890         TOOLBAR_MODE_T mode = m_current_toolbar_mode;
1891         bool           ret  = false;
1892
1893         if (TOOLBAR_HELPER_MODE == mode)
1894             ret = get_helper_geometry (m_current_helper_uuid, rect);
1895
1896         if (!ret) {
1897             rect.pos_x  = 0;
1898             rect.pos_y  = 0;
1899             rect.width  = 0;
1900             rect.height = 0;
1901         }
1902     }
1903
1904     void set_ise_mode (int client_id)
1905     {
1906         SCIM_DEBUG_MAIN(4) << "PanelAgent::set_ise_mode ()\n";
1907         uint32 mode;
1908
1909         if (m_recv_trans.get_data (mode))
1910         {
1911             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
1912                 set_helper_mode (m_current_helper_uuid, mode);
1913         }
1914     }
1915
1916     void set_ise_layout (int client_id)
1917     {
1918         SCIM_DEBUG_MAIN(4) << "PanelAgent::set_ise_layout ()\n";
1919         uint32 layout;
1920
1921         if (m_recv_trans.get_data (layout))
1922         {
1923             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
1924                 set_helper_layout (m_current_helper_uuid, layout);
1925         }
1926     }
1927
1928     void set_ise_language (int client_id)
1929     {
1930         SCIM_DEBUG_MAIN(4) << "PanelAgent::set_ise_language ()\n";
1931         uint32 language;
1932
1933         if (m_recv_trans.get_data (language))
1934         {
1935             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
1936                 set_helper_language (m_current_helper_uuid, language);
1937         }
1938     }
1939
1940     void set_isf_language (int client_id)
1941     {
1942         SCIM_DEBUG_MAIN(4) << "PanelAgent::set_isf_language ()\n";
1943         char   *buf = NULL;
1944         size_t  len;
1945
1946         if (m_recv_trans.get_data (&buf, len))
1947         {
1948             String lang (buf);
1949             m_signal_set_isf_language (lang);
1950         }
1951
1952         if (NULL != buf)
1953             delete[] buf;
1954     }
1955
1956     void set_ise_imdata (int client_id)
1957     {
1958         SCIM_DEBUG_MAIN(4) << "PanelAgent::set_ise_imdata ()\n";
1959         char   *imdata = NULL;
1960         size_t  len;
1961
1962         if (m_recv_trans.get_data (&imdata, len))
1963         {
1964             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
1965                 set_helper_imdata (m_current_helper_uuid, imdata, len);
1966         }
1967
1968         if (NULL != imdata)
1969             delete [] imdata;
1970     }
1971
1972     void get_ise_imdata (int client_id)
1973     {
1974         SCIM_DEBUG_MAIN(4) << "PanelAgent::get_ise_imdata ()\n";
1975         char   *imdata = NULL;
1976         size_t  len;
1977         bool    ret    = false;
1978
1979         TOOLBAR_MODE_T mode;
1980
1981         mode = m_current_toolbar_mode;
1982
1983         if (TOOLBAR_HELPER_MODE == mode)
1984         {
1985             ret = get_helper_imdata (m_current_helper_uuid, &imdata, len);
1986         }
1987
1988         Transaction trans;
1989         Socket client_socket (client_id);
1990
1991         trans.clear ();
1992         trans.put_command (SCIM_TRANS_CMD_REPLY);
1993         if (ret)
1994         {
1995             trans.put_command (SCIM_TRANS_CMD_OK);
1996             trans.put_data (imdata, len);
1997         }
1998         else
1999             trans.put_command (SCIM_TRANS_CMD_FAIL);
2000
2001         trans.write_to_socket (client_socket);
2002
2003         if (NULL != imdata)
2004             delete [] imdata;
2005     }
2006
2007     void get_ise_layout (int client_id)
2008     {
2009         SCIM_DEBUG_MAIN(4) << "PanelAgent::get_ise_layout ()\n";
2010         uint32 layout;
2011         bool   ret = false;
2012
2013         TOOLBAR_MODE_T mode = m_current_toolbar_mode;
2014
2015         if (TOOLBAR_HELPER_MODE == mode)
2016             ret = get_helper_layout (m_current_helper_uuid, layout);
2017
2018         Transaction trans;
2019         Socket client_socket (client_id);
2020
2021         trans.clear ();
2022         trans.put_command (SCIM_TRANS_CMD_REPLY);
2023         if (ret) {
2024             trans.put_command (SCIM_TRANS_CMD_OK);
2025             trans.put_data (layout);
2026         } else {
2027             trans.put_command (SCIM_TRANS_CMD_FAIL);
2028         }
2029
2030         trans.write_to_socket (client_socket);
2031     }
2032
2033     bool get_ise_layout_list (std::vector<uint32> &list)
2034     {
2035         bool ret = false;
2036
2037         TOOLBAR_MODE_T mode = m_current_toolbar_mode;
2038
2039         if (TOOLBAR_HELPER_MODE == mode)
2040             ret = get_helper_layout_list (m_current_helper_uuid, list);
2041
2042         return ret;
2043     }
2044
2045     void get_active_ise_name (int client_id)
2046     {
2047         SCIM_DEBUG_MAIN(4) << "PanelAgent::get_active_ise_name ()\n";
2048         Transaction trans;
2049         Socket client_socket (client_id);
2050         char *name = const_cast<char *> (m_current_ise_name.c_str ());
2051         size_t len = strlen (name) + 1;
2052
2053         trans.clear ();
2054         trans.put_command (SCIM_TRANS_CMD_REPLY);
2055         trans.put_command (SCIM_TRANS_CMD_OK);
2056         trans.put_data (name, len);
2057         trans.write_to_socket (client_socket);
2058     }
2059
2060     void get_ise_list (int client_id)
2061     {
2062         SCIM_DEBUG_MAIN(4) << "PanelAgent::get_ise_list ()\n";
2063         std::vector<String> strlist;
2064         m_signal_get_ise_list (strlist);
2065
2066         Transaction trans;
2067         Socket client_socket (client_id);
2068         char *buf = NULL;
2069         size_t len;
2070         uint32 num;
2071
2072         trans.clear ();
2073         trans.put_command (SCIM_TRANS_CMD_REPLY);
2074         trans.put_command (SCIM_TRANS_CMD_OK);
2075
2076         num = strlist.size ();
2077         trans.put_data (num);
2078         for (unsigned int i = 0; i < num; i++)
2079         {
2080             buf = const_cast<char *>(strlist[i].c_str ());
2081             len = strlen (buf) + 1;
2082             trans.put_data (buf, len);
2083         }
2084
2085         trans.write_to_socket (client_socket);
2086     }
2087
2088     void get_language_list (int client_id)
2089     {
2090         SCIM_DEBUG_MAIN(4) << "PanelAgent::get_language_list ()\n";
2091         std::vector<String> strlist;
2092
2093         m_signal_get_language_list (strlist);
2094
2095         Transaction trans;
2096         Socket client_socket (client_id);
2097         char *buf = NULL;
2098         size_t len;
2099         uint32 num;
2100
2101         trans.clear ();
2102         trans.put_command (SCIM_TRANS_CMD_REPLY);
2103         trans.put_command (SCIM_TRANS_CMD_OK);
2104
2105         num = strlist.size ();
2106         trans.put_data (num);
2107         for (unsigned int i = 0; i < num; i++)
2108         {
2109             buf = const_cast<char *>(strlist[i].c_str ());
2110             len = strlen (buf) + 1;
2111             trans.put_data (buf, len);
2112         }
2113
2114         trans.write_to_socket (client_socket);
2115     }
2116
2117     void get_all_language (int client_id)
2118     {
2119         SCIM_DEBUG_MAIN(4) << "PanelAgent::get_all_language ()\n";
2120         std::vector<String> strlist;
2121
2122         m_signal_get_all_language (strlist);
2123
2124         Transaction trans;
2125         Socket  client_socket (client_id);
2126         char   *buf = NULL;
2127         size_t  len;
2128         uint32  num;
2129
2130         trans.clear ();
2131         trans.put_command (SCIM_TRANS_CMD_REPLY);
2132         trans.put_command (SCIM_TRANS_CMD_OK);
2133
2134         num = strlist.size ();
2135         trans.put_data (num);
2136         for (unsigned int i = 0; i < num; i++)
2137         {
2138             buf = const_cast<char *>(strlist[i].c_str ());
2139             len = strlen (buf) + 1;
2140             trans.put_data (buf, len);
2141         }
2142
2143         trans.write_to_socket (client_socket);
2144     }
2145
2146     void get_ise_language (int client_id)
2147     {
2148         SCIM_DEBUG_MAIN(4) << "PanelAgent::get_ise_language ()\n";
2149         std::vector<String> strlist;
2150         char   *buf = NULL;
2151         size_t  len;
2152         Transaction trans;
2153         Socket client_socket (client_id);
2154
2155         if (!(m_recv_trans.get_data (&buf, len)))
2156         {
2157             trans.clear ();
2158             trans.put_command (SCIM_TRANS_CMD_REPLY);
2159             trans.put_command (SCIM_TRANS_CMD_FAIL);
2160             trans.write_to_socket (client_socket);
2161             if (NULL != buf)
2162                 delete[] buf;
2163             return;
2164         }
2165
2166         m_signal_get_ise_language (buf, strlist);
2167
2168         if (buf)
2169         {
2170             delete [] buf;
2171             buf = NULL;
2172         }
2173
2174         uint32 num;
2175
2176         trans.clear ();
2177         trans.put_command (SCIM_TRANS_CMD_REPLY);
2178         trans.put_command (SCIM_TRANS_CMD_OK);
2179
2180         num = strlist.size ();
2181         trans.put_data (num);
2182         for (unsigned int i = 0; i < num; i++)
2183         {
2184             buf = const_cast<char *>(strlist[i].c_str ());
2185             len = strlen (buf) + 1;
2186             trans.put_data (buf, len);
2187         }
2188
2189         trans.write_to_socket (client_socket);
2190     }
2191
2192     bool reset_ise_option (int client_id)
2193     {
2194         SCIM_DEBUG_MAIN(1) << "PanelAgent::resect_ise_option ()\n";
2195
2196         int    client = -1;
2197         uint32 context;
2198
2199         lock ();
2200
2201         ClientContextUUIDRepository::iterator it = m_client_context_uuids.begin ();
2202         if (it != m_client_context_uuids.end ()) {
2203             get_imengine_client_context (it->first, client, context);
2204         }
2205
2206         if (client >= 0) {
2207             Socket client_socket (client);
2208             m_send_trans.clear ();
2209             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
2210             m_send_trans.put_data ((uint32) context);
2211             m_send_trans.put_command (ISM_TRANS_CMD_RESET_ISE_OPTION);
2212             m_send_trans.write_to_socket (client_socket);
2213         }
2214
2215         unlock ();
2216
2217         Transaction trans;
2218         trans.clear ();
2219         trans.put_command (SCIM_TRANS_CMD_REPLY);
2220         trans.put_command (SCIM_TRANS_CMD_OK);
2221         Socket client_socket (client_id);
2222         trans.write_to_socket (client_socket);
2223
2224         return client >= 0;
2225     }
2226
2227     bool find_active_ise_by_uuid (String uuid)
2228     {
2229         HelperInfoRepository::iterator iter = m_helper_info_repository.begin ();
2230         for (; iter != m_helper_info_repository.end (); iter++)
2231         {
2232             if (!uuid.compare (iter->second.uuid))
2233                 return true;
2234         }
2235
2236         return false;
2237     }
2238
2239     void set_active_ise_by_uuid (int client_id)
2240     {
2241         SCIM_DEBUG_MAIN(4) << "PanelAgent::set_active_ise_by_uuid ()\n";
2242         char   *buf = NULL;
2243         size_t  len;
2244         Transaction trans;
2245         Socket client_socket (client_id);
2246         m_current_active_imcontrol_id = client_id;
2247
2248         trans.clear ();
2249         trans.put_command (SCIM_TRANS_CMD_REPLY);
2250         if (!(m_recv_trans.get_data (&buf, len)))
2251         {
2252             trans.put_command (SCIM_TRANS_CMD_FAIL);
2253             trans.write_to_socket (client_socket);
2254             if (NULL != buf)
2255                 delete[] buf;
2256             return;
2257         }
2258
2259         String uuid (buf);
2260         ISE_INFO info;
2261
2262         if (!m_signal_get_ise_info_by_uuid (uuid, info))
2263         {
2264             trans.put_command (SCIM_TRANS_CMD_FAIL);
2265             trans.write_to_socket (client_socket);
2266             if (NULL != buf)
2267                 delete[] buf;
2268             return;
2269         }
2270
2271         if (info.type == TOOLBAR_KEYBOARD_MODE)
2272         {
2273             m_signal_set_active_ise_by_uuid (uuid, 1);
2274             trans.put_command (SCIM_TRANS_CMD_OK);
2275             trans.write_to_socket (client_socket);
2276             if (NULL != buf)
2277                 delete[] buf;
2278             return;
2279         }
2280         else if (info.option & ISM_ISE_HIDE_IN_CONTROL_PANEL)
2281         {
2282             int count = _id_count--;
2283             if (info.type == TOOLBAR_HELPER_MODE)
2284             {
2285                 m_current_toolbar_mode = TOOLBAR_HELPER_MODE;
2286                 if (uuid != m_current_helper_uuid)
2287                     m_last_helper_uuid = m_current_helper_uuid;
2288                 start_helper (uuid, count, DEFAULT_CONTEXT_VALUE);
2289                 IMControlRepository::iterator iter = m_imcontrol_repository.find (client_id);
2290                 if (iter == m_imcontrol_repository.end ())
2291                 {
2292                     struct IMControlStub stub;
2293                     stub.count.clear ();
2294                     stub.info.clear ();
2295                     stub.info.push_back (info);
2296                     stub.count.push_back (count);
2297                     m_imcontrol_repository[client_id] = stub;
2298                 }
2299                 else
2300                 {
2301                     iter->second.info.push_back (info);
2302                     iter->second.count.push_back (count);
2303                 }
2304             }
2305         }
2306         else
2307             m_signal_set_active_ise_by_uuid (uuid, 1);
2308
2309         if (find_active_ise_by_uuid (uuid))
2310         {
2311             trans.put_command (SCIM_TRANS_CMD_OK);
2312             trans.write_to_socket (client_socket);
2313         }
2314         else
2315             m_ise_pending_repository[uuid] = client_id;
2316
2317         if (NULL != buf)
2318             delete[] buf;
2319     }
2320
2321     bool find_active_ise_by_name (String name)
2322     {
2323         HelperInfoRepository::iterator iter = m_helper_info_repository.begin ();
2324         for (; iter != m_helper_info_repository.end (); iter++)
2325         {
2326             if (!name.compare (iter->second.name))
2327                 return true;
2328         }
2329
2330         return false;
2331     }
2332
2333     void set_active_ise_by_name (int client_id)
2334     {
2335         char   *buf = NULL;
2336         size_t  len;
2337         Transaction trans;
2338         Socket client_socket (client_id);
2339         m_current_active_imcontrol_id = client_id;
2340
2341         trans.clear ();
2342         trans.put_command (SCIM_TRANS_CMD_REPLY);
2343         if (!(m_recv_trans.get_data (&buf, len)))
2344         {
2345             trans.put_command (SCIM_TRANS_CMD_FAIL);
2346             trans.write_to_socket (client_socket);
2347             if (NULL != buf)
2348                 delete[] buf;
2349             return;
2350         }
2351
2352         String name (buf);
2353         ISE_INFO info;
2354
2355         if (!m_signal_get_ise_info_by_name (name, info))
2356         {
2357             trans.put_command (SCIM_TRANS_CMD_FAIL);
2358             trans.write_to_socket (client_socket);
2359             if (NULL != buf)
2360                 delete[] buf;
2361             return;
2362         }
2363
2364         if (info.type == TOOLBAR_KEYBOARD_MODE)
2365         {
2366             m_signal_set_keyboard_ise (ISM_TRANS_CMD_SET_KEYBOARD_ISE_BY_NAME, name);
2367             trans.put_command (SCIM_TRANS_CMD_OK);
2368             trans.write_to_socket (client_socket);
2369             if (NULL != buf)
2370                 delete[] buf;
2371             return;
2372         }
2373         else if (info.option & ISM_ISE_HIDE_IN_CONTROL_PANEL)
2374         {
2375             int count = _id_count--;
2376             if (info.type == TOOLBAR_HELPER_MODE)
2377             {
2378                 m_current_toolbar_mode = TOOLBAR_HELPER_MODE;
2379                 if (info.uuid != m_current_helper_uuid)
2380                     m_last_helper_uuid = m_current_helper_uuid;
2381                 start_helper (info.uuid, count, DEFAULT_CONTEXT_VALUE);
2382                 IMControlRepository::iterator iter = m_imcontrol_repository.find (client_id);
2383                 if (iter == m_imcontrol_repository.end ())
2384                 {
2385                     struct IMControlStub stub;
2386                     stub.count.clear ();
2387                     stub.info.clear ();
2388                     stub.info.push_back (info);
2389                     stub.count.push_back (count);
2390                     m_imcontrol_repository[client_id] = stub;
2391                 }
2392                 else
2393                 {
2394                     iter->second.info.push_back (info);
2395                     iter->second.count.push_back (count);
2396                 }
2397             }
2398         }
2399         else
2400             m_signal_set_active_ise_by_name (name);
2401
2402         if (find_active_ise_by_name (name))
2403         {
2404             trans.put_command (SCIM_TRANS_CMD_OK);
2405             trans.write_to_socket (client_socket);
2406         }
2407         else
2408             m_ise_pending_repository[name] = client_id;
2409
2410         if (NULL != buf)
2411             delete[] buf;
2412     }
2413
2414     void update_isf_control_status (const bool showed)
2415     {
2416         for (ClientRepository::iterator iter = m_client_repository.begin ();
2417              iter != m_client_repository.end (); ++iter)
2418         {
2419             if (IMCONTROL_CLIENT == iter->second.type
2420                 && iter->first == m_imcontrol_map[m_current_active_imcontrol_id])
2421             {
2422                 Socket client_socket (iter->first);
2423                 Transaction trans;
2424
2425                 trans.clear ();
2426                 trans.put_command (SCIM_TRANS_CMD_REQUEST);
2427                 if (showed)
2428                     trans.put_command (ISM_TRANS_CMD_ISF_CONTROL_SHOWED);
2429                 else
2430                     trans.put_command (ISM_TRANS_CMD_ISF_CONTROL_HIDED);
2431                 trans.write_to_socket (client_socket);
2432                 break;
2433             }
2434         }
2435         return;
2436     }
2437
2438     void set_ise_return_key_type (int client_id)
2439     {
2440         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
2441         uint32 type;
2442
2443         if (m_recv_trans.get_data (type)) {
2444             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
2445                 set_helper_return_key_type (m_current_helper_uuid, type);
2446         }
2447     }
2448
2449     void get_ise_return_key_type (int client_id)
2450     {
2451         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
2452         uint32 type = 0;
2453         bool   ret  = false;
2454
2455         TOOLBAR_MODE_T mode = m_current_toolbar_mode;
2456
2457         if (TOOLBAR_HELPER_MODE == mode)
2458             ret = get_helper_return_key_type (m_current_helper_uuid, type);
2459
2460         Transaction trans;
2461         Socket client_socket (client_id);
2462
2463         trans.clear ();
2464         trans.put_command (SCIM_TRANS_CMD_REPLY);
2465         if (ret) {
2466             trans.put_command (SCIM_TRANS_CMD_OK);
2467             trans.put_data (type);
2468         } else {
2469             trans.put_command (SCIM_TRANS_CMD_FAIL);
2470         }
2471
2472         trans.write_to_socket (client_socket);
2473     }
2474
2475     void set_ise_return_key_disable (int client_id)
2476     {
2477         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
2478         uint32 disabled;
2479
2480         if (m_recv_trans.get_data (disabled)) {
2481             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
2482                 set_helper_return_key_disable (m_current_helper_uuid, disabled);
2483         }
2484     }
2485
2486     void get_ise_return_key_disable (int client_id)
2487     {
2488         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
2489         uint32 disabled = 0;
2490         bool   ret      = false;
2491
2492         TOOLBAR_MODE_T mode = m_current_toolbar_mode;
2493
2494         if (TOOLBAR_HELPER_MODE == mode)
2495             ret = get_helper_return_key_disable (m_current_helper_uuid, disabled);
2496
2497         Transaction trans;
2498         Socket client_socket (client_id);
2499
2500         trans.clear ();
2501         trans.put_command (SCIM_TRANS_CMD_REPLY);
2502         if (ret) {
2503             trans.put_command (SCIM_TRANS_CMD_OK);
2504             trans.put_data (disabled);
2505         } else {
2506             trans.put_command (SCIM_TRANS_CMD_FAIL);
2507         }
2508
2509         trans.write_to_socket (client_socket);
2510     }
2511
2512     int get_active_ise_list (std::vector<String> &strlist)
2513     {
2514         strlist.clear ();
2515         m_helper_manager.get_active_ise_list (strlist);
2516         return (int)(strlist.size ());
2517     }
2518
2519     int get_helper_manager_id (void)
2520     {
2521         return m_helper_manager.get_connection_number ();
2522     }
2523
2524     bool has_helper_manager_pending_event (void)
2525     {
2526         return m_helper_manager.has_pending_event ();
2527     }
2528
2529     bool filter_helper_manager_event (void)
2530     {
2531         return m_helper_manager.filter_event ();
2532     }
2533
2534     void reset_helper_context (const String &uuid)
2535     {
2536         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
2537
2538         if (it != m_helper_client_index.end ())
2539         {
2540             int client;
2541             uint32 context;
2542             Socket client_socket (it->second.id);
2543             uint32 ctx;
2544
2545             get_focused_context (client, context);
2546             ctx = get_helper_ic (client, context);
2547
2548             m_send_trans.clear ();
2549             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
2550             m_send_trans.put_data (ctx);
2551             m_send_trans.put_data (uuid);
2552             m_send_trans.put_command (ISM_TRANS_CMD_RESET_ISE_CONTEXT);
2553             m_send_trans.write_to_socket (client_socket);
2554         }
2555     }
2556
2557     void reset_ise_context (int client_id)
2558     {
2559         SCIM_DEBUG_MAIN(4) << "PanelAgent::reset_ise_context ()\n";
2560         TOOLBAR_MODE_T mode;
2561
2562         mode = m_current_toolbar_mode;
2563
2564         if (TOOLBAR_HELPER_MODE == mode)
2565         {
2566             reset_helper_context (m_current_helper_uuid);
2567         }
2568     }
2569
2570     void set_ise_caps_mode (int client_id)
2571     {
2572         SCIM_DEBUG_MAIN(4) << "PanelAgent::set_ise_caps_mode ()\n";
2573         uint32 mode;
2574
2575         if (m_recv_trans.get_data (mode))
2576         {
2577             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
2578                 set_helper_caps_mode (m_current_helper_uuid, mode);
2579         }
2580     }
2581
2582     int send_display_name (String &name)
2583     {
2584         return m_helper_manager.send_display_name (name);
2585     }
2586
2587     bool reload_config (void)
2588     {
2589         SCIM_DEBUG_MAIN(1) << "PanelAgent::reload_config ()\n";
2590
2591         lock ();
2592
2593         m_send_trans.clear ();
2594         m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
2595         m_send_trans.put_command (SCIM_TRANS_CMD_RELOAD_CONFIG);
2596
2597         for (ClientRepository::iterator it = m_client_repository.begin ();
2598              it != m_client_repository.end (); ++it) {
2599
2600             if (it->second.type == IMCONTROL_ACT_CLIENT
2601                 || it->second.type == IMCONTROL_CLIENT
2602                 || it->second.type == HELPER_ACT_CLIENT)
2603                 continue;
2604
2605             Socket client_socket (it->first);
2606             m_send_trans.write_to_socket (client_socket);
2607         }
2608
2609         unlock ();
2610         return true;
2611     }
2612
2613     bool exit (void)
2614     {
2615         SCIM_DEBUG_MAIN(1) << "PanelAgent::exit ()\n";
2616
2617         lock ();
2618
2619         m_send_trans.clear ();
2620         m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
2621         m_send_trans.put_command (SCIM_TRANS_CMD_EXIT);
2622
2623         for (ClientRepository::iterator it = m_client_repository.begin ();
2624              it != m_client_repository.end (); ++it) {
2625             Socket client_socket (it->first);
2626             m_send_trans.write_to_socket (client_socket);
2627         }
2628
2629         unlock ();
2630
2631         stop ();
2632
2633         return true;
2634     }
2635
2636     bool filter_event (int fd)
2637     {
2638         SCIM_DEBUG_MAIN (1) << "PanelAgent::filter_event ()\n";
2639
2640         return m_socket_server.filter_event (fd);
2641     }
2642
2643     bool filter_exception_event (int fd)
2644     {
2645         SCIM_DEBUG_MAIN (1) << "PanelAgent::filter_exception_event ()\n";
2646
2647         return m_socket_server.filter_exception_event (fd);
2648     }
2649
2650     int get_server_id ()
2651     {
2652         SCIM_DEBUG_MAIN (1) << "PanelAgent::get_server_id ()\n";
2653
2654         return m_socket_server.get_id ();
2655     }
2656
2657     void set_ise_changing (bool changing)
2658     {
2659         SCIM_DEBUG_MAIN (1) << "PanelAgent::set_ise_changing ()\n";
2660         m_ise_changing = changing;
2661     }
2662
2663     void update_ise_list (std::vector<String> &strList)
2664     {
2665         /* send ise list to frontend */
2666         String dst_str = scim_combine_string_list (strList);
2667         m_helper_manager.send_ise_list (dst_str);
2668
2669         /* request PanelClient to update keyboard ise list */
2670         update_keyboard_ise_list ();
2671     }
2672
2673     Connection signal_connect_reload_config              (PanelAgentSlotVoid                *slot)
2674     {
2675         return m_signal_reload_config.connect (slot);
2676     }
2677
2678     Connection signal_connect_turn_on                    (PanelAgentSlotVoid                *slot)
2679     {
2680         return m_signal_turn_on.connect (slot);
2681     }
2682
2683     Connection signal_connect_turn_off                   (PanelAgentSlotVoid                *slot)
2684     {
2685         return m_signal_turn_off.connect (slot);
2686     }
2687
2688     Connection signal_connect_show_panel                 (PanelAgentSlotVoid                *slot)
2689     {
2690         return m_signal_show_panel.connect (slot);
2691     }
2692
2693     Connection signal_connect_hide_panel                 (PanelAgentSlotVoid                *slot)
2694     {
2695         return m_signal_hide_panel.connect (slot);
2696     }
2697
2698     Connection signal_connect_update_screen              (PanelAgentSlotInt                 *slot)
2699     {
2700         return m_signal_update_screen.connect (slot);
2701     }
2702
2703     Connection signal_connect_update_spot_location       (PanelAgentSlotIntIntInt           *slot)
2704     {
2705         return m_signal_update_spot_location.connect (slot);
2706     }
2707
2708     Connection signal_connect_update_factory_info        (PanelAgentSlotFactoryInfo         *slot)
2709     {
2710         return m_signal_update_factory_info.connect (slot);
2711     }
2712
2713     Connection signal_connect_start_default_ise          (PanelAgentSlotVoid                *slot)
2714     {
2715         return m_signal_start_default_ise.connect (slot);
2716     }
2717
2718     Connection signal_connect_set_candidate_ui           (PanelAgentSlotIntInt              *slot)
2719     {
2720         return m_signal_set_candidate_ui.connect (slot);
2721     }
2722
2723     Connection signal_connect_get_candidate_ui           (PanelAgentSlotIntInt2             *slot)
2724     {
2725         return m_signal_get_candidate_ui.connect (slot);
2726     }
2727
2728     Connection signal_connect_set_candidate_position     (PanelAgentSlotIntInt              *slot)
2729     {
2730         return m_signal_set_candidate_position.connect (slot);
2731     }
2732
2733     Connection signal_connect_get_candidate_geometry     (PanelAgentSlotRect                *slot)
2734     {
2735         return m_signal_get_candidate_geometry.connect (slot);
2736     }
2737
2738     Connection signal_connect_get_input_panel_geometry   (PanelAgentSlotRect                *slot)
2739     {
2740         return m_signal_get_input_panel_geometry.connect (slot);
2741     }
2742
2743     Connection signal_connect_set_keyboard_ise           (PanelAgentSlotIntString           *slot)
2744     {
2745         return m_signal_set_keyboard_ise.connect (slot);
2746     }
2747
2748     Connection signal_connect_get_keyboard_ise           (PanelAgentSlotString2             *slot)
2749     {
2750         return m_signal_get_keyboard_ise.connect (slot);
2751     }
2752
2753     Connection signal_connect_show_help                  (PanelAgentSlotString              *slot)
2754     {
2755         return m_signal_show_help.connect (slot);
2756     }
2757
2758     Connection signal_connect_show_factory_menu          (PanelAgentSlotFactoryInfoVector   *slot)
2759     {
2760         return m_signal_show_factory_menu.connect (slot);
2761     }
2762
2763     Connection signal_connect_show_preedit_string        (PanelAgentSlotVoid                *slot)
2764     {
2765         return m_signal_show_preedit_string.connect (slot);
2766     }
2767
2768     Connection signal_connect_show_aux_string            (PanelAgentSlotVoid                *slot)
2769     {
2770         return m_signal_show_aux_string.connect (slot);
2771     }
2772
2773     Connection signal_connect_show_lookup_table          (PanelAgentSlotVoid                *slot)
2774     {
2775         return m_signal_show_lookup_table.connect (slot);
2776     }
2777
2778     Connection signal_connect_show_associate_table       (PanelAgentSlotVoid                *slot)
2779     {
2780         return m_signal_show_associate_table.connect (slot);
2781     }
2782
2783     Connection signal_connect_hide_preedit_string        (PanelAgentSlotVoid                *slot)
2784     {
2785         return m_signal_hide_preedit_string.connect (slot);
2786     }
2787
2788     Connection signal_connect_hide_aux_string            (PanelAgentSlotVoid                *slot)
2789     {
2790         return m_signal_hide_aux_string.connect (slot);
2791     }
2792
2793     Connection signal_connect_hide_lookup_table          (PanelAgentSlotVoid                *slot)
2794     {
2795         return m_signal_hide_lookup_table.connect (slot);
2796     }
2797
2798     Connection signal_connect_hide_associate_table       (PanelAgentSlotVoid                *slot)
2799     {
2800         return m_signal_hide_associate_table.connect (slot);
2801     }
2802
2803     Connection signal_connect_update_preedit_string      (PanelAgentSlotAttributeString     *slot)
2804     {
2805         return m_signal_update_preedit_string.connect (slot);
2806     }
2807
2808     Connection signal_connect_update_preedit_caret       (PanelAgentSlotInt                 *slot)
2809     {
2810         return m_signal_update_preedit_caret.connect (slot);
2811     }
2812
2813     Connection signal_connect_update_aux_string          (PanelAgentSlotAttributeString     *slot)
2814     {
2815         return m_signal_update_aux_string.connect (slot);
2816     }
2817
2818     Connection signal_connect_update_lookup_table        (PanelAgentSlotLookupTable         *slot)
2819     {
2820         return m_signal_update_lookup_table.connect (slot);
2821     }
2822
2823     Connection signal_connect_update_associate_table     (PanelAgentSlotLookupTable         *slot)
2824     {
2825         return m_signal_update_associate_table.connect (slot);
2826     }
2827
2828     Connection signal_connect_register_properties        (PanelAgentSlotPropertyList        *slot)
2829     {
2830         return m_signal_register_properties.connect (slot);
2831     }
2832
2833     Connection signal_connect_update_property            (PanelAgentSlotProperty            *slot)
2834     {
2835         return m_signal_update_property.connect (slot);
2836     }
2837
2838     Connection signal_connect_register_helper_properties (PanelAgentSlotIntPropertyList     *slot)
2839     {
2840         return m_signal_register_helper_properties.connect (slot);
2841     }
2842
2843     Connection signal_connect_update_helper_property     (PanelAgentSlotIntProperty         *slot)
2844     {
2845         return m_signal_update_helper_property.connect (slot);
2846     }
2847
2848     Connection signal_connect_register_helper            (PanelAgentSlotIntHelperInfo       *slot)
2849     {
2850         return m_signal_register_helper.connect (slot);
2851     }
2852
2853     Connection signal_connect_remove_helper              (PanelAgentSlotInt                 *slot)
2854     {
2855         return m_signal_remove_helper.connect (slot);
2856     }
2857
2858     Connection signal_connect_set_active_ise_by_uuid     (PanelAgentSlotStringBool          *slot)
2859     {
2860         return m_signal_set_active_ise_by_uuid.connect (slot);
2861     }
2862
2863     Connection signal_connect_set_active_ise_by_name     (PanelAgentSlotString                 *slot)
2864     {
2865         return m_signal_set_active_ise_by_name.connect (slot);
2866     }
2867
2868     Connection signal_connect_focus_in                   (PanelAgentSlotVoid                   *slot)
2869     {
2870         return m_signal_focus_in.connect (slot);
2871     }
2872
2873     Connection signal_connect_focus_out                  (PanelAgentSlotVoid                   *slot)
2874     {
2875         return m_signal_focus_out.connect (slot);
2876     }
2877
2878     Connection signal_connect_expand_candidate           (PanelAgentSlotVoid                   *slot)
2879     {
2880         return m_signal_expand_candidate.connect (slot);
2881     }
2882
2883     Connection signal_connect_contract_candidate         (PanelAgentSlotVoid                   *slot)
2884     {
2885         return m_signal_contract_candidate.connect (slot);
2886     }
2887
2888     Connection signal_connect_get_ise_list               (PanelAgentSlotBoolStringVector       *slot)
2889     {
2890         return m_signal_get_ise_list.connect (slot);
2891     }
2892
2893     Connection signal_connect_get_keyboard_ise_list      (PanelAgentSlotBoolStringVector       *slot)
2894     {
2895         return m_signal_get_keyboard_ise_list.connect (slot);
2896     }
2897
2898     Connection signal_connect_update_ise_geometry        (PanelAgentSlotIntIntIntInt           *slot)
2899     {
2900         return m_signal_update_ise_geometry.connect (slot);
2901     }
2902
2903     Connection signal_connect_get_language_list          (PanelAgentSlotStringVector           *slot)
2904     {
2905         return m_signal_get_language_list.connect (slot);
2906     }
2907
2908     Connection signal_connect_get_all_language           (PanelAgentSlotStringVector           *slot)
2909     {
2910         return m_signal_get_all_language.connect (slot);
2911     }
2912
2913     Connection signal_connect_get_ise_language           (PanelAgentSlotStrStringVector        *slot)
2914     {
2915         return m_signal_get_ise_language.connect (slot);
2916     }
2917
2918     Connection signal_connect_set_isf_language           (PanelAgentSlotString                 *slot)
2919     {
2920         return m_signal_set_isf_language.connect (slot);
2921     }
2922
2923     Connection signal_connect_get_ise_info_by_uuid       (PanelAgentSlotStringISEINFO          *slot)
2924     {
2925         return m_signal_get_ise_info_by_uuid.connect (slot);
2926     }
2927
2928     Connection signal_connect_get_ise_info_by_name       (PanelAgentSlotStringISEINFO          *slot)
2929     {
2930         return m_signal_get_ise_info_by_name.connect (slot);
2931     }
2932
2933     Connection signal_connect_send_key_event             (PanelAgentSlotKeyEvent               *slot)
2934     {
2935         return m_signal_send_key_event.connect (slot);
2936     }
2937
2938     Connection signal_connect_accept_connection          (PanelAgentSlotInt                    *slot)
2939     {
2940         return m_signal_accept_connection.connect (slot);
2941     }
2942
2943     Connection signal_connect_close_connection           (PanelAgentSlotInt                    *slot)
2944     {
2945         return m_signal_close_connection.connect (slot);
2946     }
2947
2948     Connection signal_connect_exit                       (PanelAgentSlotVoid                   *slot)
2949     {
2950         return m_signal_exit.connect (slot);
2951     }
2952
2953     Connection signal_connect_transaction_start          (PanelAgentSlotVoid                   *slot)
2954     {
2955         return m_signal_transaction_start.connect (slot);
2956     }
2957
2958     Connection signal_connect_transaction_end            (PanelAgentSlotVoid                   *slot)
2959     {
2960         return m_signal_transaction_end.connect (slot);
2961     }
2962
2963     Connection signal_connect_lock                       (PanelAgentSlotVoid                   *slot)
2964     {
2965         return m_signal_lock.connect (slot);
2966     }
2967
2968     Connection signal_connect_unlock                     (PanelAgentSlotVoid                   *slot)
2969     {
2970         return m_signal_unlock.connect (slot);
2971     }
2972
2973     Connection signal_connect_update_input_context       (PanelAgentSlotIntInt                 *slot)
2974     {
2975         return m_signal_update_input_context.connect (slot);
2976     }
2977
2978 private:
2979     bool socket_check_client_connection (const Socket &client)
2980     {
2981         SCIM_DEBUG_MAIN (3) << "PanelAgent::socket_check_client_connection (" << client.get_id () << ")\n";
2982
2983         unsigned char buf [sizeof(uint32)];
2984
2985         int nbytes = client.read_with_timeout (buf, sizeof(uint32), m_socket_timeout);
2986
2987         if (nbytes == sizeof (uint32))
2988             return true;
2989
2990         if (nbytes < 0) {
2991             SCIM_DEBUG_MAIN (4) << "Error occurred when reading socket: " << client.get_error_message () << ".\n";
2992         } else {
2993             SCIM_DEBUG_MAIN (4) << "Timeout when reading socket.\n";
2994         }
2995
2996         return false;
2997     }
2998
2999     void socket_accept_callback                 (SocketServer   *server,
3000                                                  const Socket   &client)
3001     {
3002         SCIM_DEBUG_MAIN (2) << "PanelAgent::socket_accept_callback (" << client.get_id () << ")\n";
3003
3004         lock ();
3005         if (m_should_exit) {
3006             SCIM_DEBUG_MAIN (3) << "Exit Socket Server Thread.\n";
3007             server->shutdown ();
3008         } else
3009             m_signal_accept_connection (client.get_id ());
3010         unlock ();
3011     }
3012
3013     void socket_receive_callback                (SocketServer   *server,
3014                                                  const Socket   &client)
3015     {
3016         int     client_id = client.get_id ();
3017         int     cmd     = 0;
3018         uint32  key     = 0;
3019         uint32  context = 0;
3020         String  uuid;
3021         bool    current = false;
3022         bool    last    = false;
3023
3024         ClientInfo client_info;
3025
3026         SCIM_DEBUG_MAIN (1) << "PanelAgent::socket_receive_callback (" << client_id << ")\n";
3027
3028         /* If the connection is closed then close this client. */
3029         if (!socket_check_client_connection (client)) {
3030             socket_close_connection (server, client);
3031             return;
3032         }
3033
3034         client_info = socket_get_client_info (client_id);
3035
3036         /* If it's a new client, then request to open the connection first. */
3037         if (client_info.type == UNKNOWN_CLIENT) {
3038             socket_open_connection (server, client);
3039             return;
3040         }
3041
3042         /* If can not read the transaction,
3043          * or the transaction is not started with SCIM_TRANS_CMD_REQUEST,
3044          * or the key is mismatch,
3045          * just return. */
3046         if (!m_recv_trans.read_from_socket (client, m_socket_timeout) ||
3047             !m_recv_trans.get_command (cmd) || cmd != SCIM_TRANS_CMD_REQUEST ||
3048             !m_recv_trans.get_data (key)    || key != (uint32) client_info.key)
3049             return;
3050
3051         if (client_info.type == FRONTEND_CLIENT) {
3052             if (m_recv_trans.get_data (context)) {
3053                 SCIM_DEBUG_MAIN (1) << "PanelAgent::FrontEnd Client, context = " << context << "\n";
3054                 socket_transaction_start();
3055                 while (m_recv_trans.get_command (cmd)) {
3056                     SCIM_DEBUG_MAIN (3) << "PanelAgent::cmd = " << cmd << "\n";
3057
3058                     if (cmd == SCIM_TRANS_CMD_PANEL_REGISTER_INPUT_CONTEXT) {
3059                         if (m_recv_trans.get_data (uuid)) {
3060                             SCIM_DEBUG_MAIN (2) << "PanelAgent::register_input_context (" << client_id << "," << "," << context << "," << uuid << ")\n";
3061                             uint32 ctx = get_helper_ic (client_id, context);
3062                             m_client_context_uuids [ctx] = uuid;
3063                         }
3064                         continue;
3065                     }
3066
3067                     if (cmd == ISM_TRANS_CMD_PANEL_START_DEFAULT_ISE) {
3068                         if ((m_default_ise.type == TOOLBAR_HELPER_MODE) && (m_default_ise.uuid.length () > 0))
3069                         {
3070                             m_current_toolbar_mode = TOOLBAR_HELPER_MODE;
3071                             start_helper (m_default_ise.uuid, client_id, context);
3072                         }
3073                         else if (m_default_ise.type == TOOLBAR_KEYBOARD_MODE)
3074                         {
3075                             m_current_toolbar_mode = TOOLBAR_KEYBOARD_MODE;
3076                         }
3077                         continue;
3078                     }
3079
3080                     if (cmd == SCIM_TRANS_CMD_PANEL_REMOVE_INPUT_CONTEXT) {
3081                         uint32 ctx = get_helper_ic (client_id, context);
3082                         m_client_context_uuids.erase (ctx);
3083 #ifdef ONE_HELPER_ISE_PROCESS
3084                         if (m_client_context_helper.find (ctx) != m_client_context_helper.end ())
3085                             stop_helper (m_client_context_helper[ctx], client_id, context);
3086 #endif
3087                         if (ctx == get_helper_ic (m_current_socket_client, m_current_client_context))
3088                         {
3089                             lock ();
3090                             m_current_socket_client  = m_last_socket_client;
3091                             m_current_client_context = m_last_client_context;
3092                             m_current_context_uuid   = m_last_context_uuid;
3093                             m_last_socket_client     = -1;
3094                             m_last_client_context    = 0;
3095                             m_last_context_uuid      = String ("");
3096                             if (m_current_socket_client == -1)
3097                             {
3098                                 unlock ();
3099                                 socket_update_control_panel ();
3100                             }
3101                             else
3102                                 unlock ();
3103                         }
3104                         else if (ctx == get_helper_ic (m_last_socket_client, m_last_client_context))
3105                         {
3106                             lock ();
3107                             m_last_socket_client  = -1;
3108                             m_last_client_context = 0;
3109                             m_last_context_uuid   = String ("");
3110                             unlock ();
3111                         }
3112                         continue;
3113                     }
3114
3115                     if (cmd == SCIM_TRANS_CMD_PANEL_RESET_INPUT_CONTEXT) {
3116                         socket_reset_input_context (client_id, context);
3117                         continue;
3118                     }
3119
3120                     if (cmd == SCIM_TRANS_CMD_FOCUS_IN) {
3121                         get_helper_ic (client_id, context);
3122                         m_signal_focus_in ();
3123                         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
3124                             focus_in_helper (m_current_helper_uuid, client_id, context);
3125 #ifdef ONE_HELPER_ISE_PROCESS
3126                         uint32 ctx = get_helper_ic (client_id, context);
3127                         ClientContextUUIDRepository::iterator it = m_client_context_helper.find (ctx);
3128                         if (it != m_client_context_helper.end ())
3129                         {
3130                             if (m_should_shared_ise)
3131                             {
3132                                 if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
3133                                 {
3134                                     if (m_current_helper_uuid != it->second)
3135                                     {
3136                                         stop_helper (it->second, client_id, context);
3137                                         start_helper (m_current_helper_uuid, client_id, context);
3138                                     }
3139                                     focus_in_helper (m_current_helper_uuid, client_id, context);
3140                                 }
3141                                 else if (TOOLBAR_KEYBOARD_MODE == m_current_toolbar_mode)
3142                                     stop_helper (it->second, client_id, context);
3143                             }
3144                             else
3145                             {
3146                                 /* focus in the helper if the context is associated with some helper */
3147                                 m_current_toolbar_mode = TOOLBAR_HELPER_MODE;
3148                                 m_current_helper_uuid  = it->second;
3149                                 focus_in_helper (m_current_helper_uuid, client_id, context);
3150                             }
3151                         }
3152                         else
3153                         {
3154                             if (m_should_shared_ise)
3155                             {
3156                                 if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
3157                                 {
3158                                     start_helper (m_current_helper_uuid, client_id, context);
3159                                     focus_in_helper (m_current_helper_uuid, client_id, context);
3160                                 }
3161                             }
3162                             else
3163                             {
3164                                 /* come here if the context is associated with some imengine */
3165                                 m_current_toolbar_mode = TOOLBAR_KEYBOARD_MODE;
3166                             }
3167                         }
3168 #endif
3169                         if (m_recv_trans.get_data (uuid)) {
3170                             SCIM_DEBUG_MAIN (2) << "PanelAgent::focus_in (" << client_id << "," << "," << context << "," << uuid << ")\n";
3171                             lock ();
3172                             if (m_current_socket_client >= 0) {
3173                                 m_last_socket_client  = m_current_socket_client;
3174                                 m_last_client_context = m_current_client_context;
3175                                 m_last_context_uuid   = m_current_context_uuid;
3176                             }
3177                             m_current_socket_client  = client_id;
3178                             m_current_client_context = context;
3179                             m_current_context_uuid   = uuid;
3180                             unlock ();
3181                         }
3182                         continue;
3183                     }
3184
3185                     if (cmd == ISM_TRANS_CMD_TURN_ON_LOG) {
3186                         socket_turn_on_log ();
3187                         continue;
3188                     }
3189
3190                     current = last = false;
3191                     uuid.clear ();
3192
3193                     /* Get the context uuid from the client context registration table. */
3194                     {
3195                         ClientContextUUIDRepository::iterator it = m_client_context_uuids.find (get_helper_ic (client_id, context));
3196                         if (it != m_client_context_uuids.end ())
3197                             uuid = it->second;
3198                     }
3199
3200                     if (m_current_socket_client == client_id && m_current_client_context == context) {
3201                         current = true;
3202                         if (!uuid.length ()) uuid = m_current_context_uuid;
3203                     } else if (m_last_socket_client == client_id && m_last_client_context == context) {
3204                         last = true;
3205                         if (!uuid.length ()) uuid = m_last_context_uuid;
3206                     }
3207
3208                     /* Skip to the next command and continue, if it's not current or last focused. */
3209                     if (!uuid.length ()) {
3210                         SCIM_DEBUG_MAIN (3) << "PanelAgent:: Couldn't find context uuid.\n";
3211                         while (m_recv_trans.get_data_type () != SCIM_TRANS_DATA_COMMAND && m_recv_trans.get_data_type () != SCIM_TRANS_DATA_UNKNOWN)
3212                             m_recv_trans.skip_data ();
3213                         continue;
3214                     }
3215
3216                     if (cmd == SCIM_TRANS_CMD_START_HELPER) {
3217                         socket_start_helper (client_id, context, uuid);
3218                         continue;
3219                     }
3220                     else if (cmd == SCIM_TRANS_CMD_SEND_HELPER_EVENT) {
3221                         socket_send_helper_event (client_id, context, uuid);
3222                         continue;
3223                     }
3224                     else if (cmd == SCIM_TRANS_CMD_STOP_HELPER) {
3225                         socket_stop_helper (client_id, context, uuid);
3226                         continue;
3227                     }
3228
3229                     /* If it's not focused, just continue. */
3230                     if ((!current && !last) || (last && m_current_socket_client >= 0)) {
3231                         SCIM_DEBUG_MAIN (3) << "PanelAgent::Not current focused.\n";
3232                         while (m_recv_trans.get_data_type () != SCIM_TRANS_DATA_COMMAND && m_recv_trans.get_data_type () != SCIM_TRANS_DATA_UNKNOWN)
3233                             m_recv_trans.skip_data ();
3234                         continue;
3235                     }
3236
3237                     /* Client must focus in before do any other things. */
3238                     if (cmd == SCIM_TRANS_CMD_PANEL_TURN_ON)
3239                         socket_turn_on ();
3240                     else if (cmd == SCIM_TRANS_CMD_PANEL_TURN_OFF)
3241                         socket_turn_off ();
3242                     else if (cmd == SCIM_TRANS_CMD_UPDATE_SCREEN)
3243                         socket_update_screen ();
3244                     else if (cmd == SCIM_TRANS_CMD_UPDATE_SPOT_LOCATION)
3245                         socket_update_spot_location ();
3246                     else if (cmd == ISM_TRANS_CMD_UPDATE_CURSOR_POSITION)
3247                         socket_update_cursor_position ();
3248                     else if (cmd == ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT)
3249                         socket_update_surrounding_text ();
3250                     else if (cmd == SCIM_TRANS_CMD_PANEL_UPDATE_FACTORY_INFO)
3251                         socket_update_factory_info ();
3252                     else if (cmd == SCIM_TRANS_CMD_SHOW_PREEDIT_STRING)
3253                         socket_show_preedit_string ();
3254                     else if (cmd == SCIM_TRANS_CMD_SHOW_AUX_STRING)
3255                         socket_show_aux_string ();
3256                     else if (cmd == SCIM_TRANS_CMD_SHOW_LOOKUP_TABLE)
3257                         socket_show_lookup_table ();
3258                     else if (cmd == ISM_TRANS_CMD_SHOW_ASSOCIATE_TABLE)
3259                         socket_show_associate_table ();
3260                     else if (cmd == SCIM_TRANS_CMD_HIDE_PREEDIT_STRING)
3261                         socket_hide_preedit_string ();
3262                     else if (cmd == SCIM_TRANS_CMD_HIDE_AUX_STRING)
3263                         socket_hide_aux_string ();
3264                     else if (cmd == SCIM_TRANS_CMD_HIDE_LOOKUP_TABLE)
3265                         socket_hide_lookup_table ();
3266                     else if (cmd == ISM_TRANS_CMD_HIDE_ASSOCIATE_TABLE)
3267                         socket_hide_associate_table ();
3268                     else if (cmd == SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING)
3269                         socket_update_preedit_string ();
3270                     else if (cmd == SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET)
3271                         socket_update_preedit_caret ();
3272                     else if (cmd == SCIM_TRANS_CMD_UPDATE_AUX_STRING)
3273                         socket_update_aux_string ();
3274                     else if (cmd == SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE)
3275                         socket_update_lookup_table ();
3276                     else if (cmd == ISM_TRANS_CMD_UPDATE_ASSOCIATE_TABLE)
3277                         socket_update_associate_table ();
3278                     else if (cmd == SCIM_TRANS_CMD_REGISTER_PROPERTIES)
3279                         socket_register_properties ();
3280                     else if (cmd == SCIM_TRANS_CMD_UPDATE_PROPERTY)
3281                         socket_update_property ();
3282                     else if (cmd == SCIM_TRANS_CMD_PANEL_SHOW_HELP)
3283                         socket_show_help ();
3284                     else if (cmd == SCIM_TRANS_CMD_PANEL_SHOW_FACTORY_MENU)
3285                         socket_show_factory_menu ();
3286                     else if (cmd == SCIM_TRANS_CMD_FOCUS_OUT) {
3287                         m_signal_focus_out ();
3288                         lock ();
3289                         TOOLBAR_MODE_T mode = m_current_toolbar_mode;
3290
3291                         if (TOOLBAR_HELPER_MODE == mode)
3292                             focus_out_helper (m_current_helper_uuid, client_id, context);
3293
3294                         if (m_current_socket_client >= 0) {
3295                             m_last_socket_client  = m_current_socket_client;
3296                             m_last_client_context = m_current_client_context;
3297                             m_last_context_uuid   = m_current_context_uuid;
3298                         }
3299                         m_current_socket_client  = -1;
3300                         m_current_client_context = 0;
3301                         m_current_context_uuid   = String ("");
3302                         unlock ();
3303                     }
3304                 }
3305                 socket_transaction_end ();
3306             }
3307         } else if (client_info.type == HELPER_CLIENT) {
3308             socket_transaction_start ();
3309             while (m_recv_trans.get_command (cmd)) {
3310                 if (cmd == SCIM_TRANS_CMD_PANEL_REGISTER_HELPER) {
3311                     socket_helper_register_helper (client_id);
3312                 }
3313             }
3314             socket_transaction_end ();
3315         }else if (client_info.type == HELPER_ACT_CLIENT) {
3316             socket_transaction_start ();
3317             while (m_recv_trans.get_command (cmd)) {
3318                 if (cmd == SCIM_TRANS_CMD_PANEL_REGISTER_ACTIVE_HELPER) {
3319                     socket_helper_register_helper_passive (client_id);
3320                 } else if (cmd == SCIM_TRANS_CMD_COMMIT_STRING) {
3321                     socket_helper_commit_string (client_id);
3322                 } else if (cmd == SCIM_TRANS_CMD_SHOW_PREEDIT_STRING) {
3323                     socket_helper_show_preedit_string (client_id);
3324                 } else if (cmd == SCIM_TRANS_CMD_SHOW_AUX_STRING) {
3325                     socket_show_aux_string ();
3326                 } else if (cmd == SCIM_TRANS_CMD_SHOW_LOOKUP_TABLE) {
3327                     socket_show_lookup_table ();
3328                 } else if (cmd == ISM_TRANS_CMD_SHOW_ASSOCIATE_TABLE) {
3329                     socket_show_associate_table ();
3330                 } else if (cmd == SCIM_TRANS_CMD_HIDE_PREEDIT_STRING) {
3331                     socket_helper_hide_preedit_string (client_id);
3332                 } else if (cmd == SCIM_TRANS_CMD_HIDE_AUX_STRING) {
3333                     socket_hide_aux_string ();
3334                 } else if (cmd == SCIM_TRANS_CMD_HIDE_LOOKUP_TABLE) {
3335                     socket_hide_lookup_table ();
3336                 } else if (cmd == ISM_TRANS_CMD_HIDE_ASSOCIATE_TABLE) {
3337                     socket_hide_associate_table ();
3338                 } else if (cmd == SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING) {
3339                     socket_helper_update_preedit_string (client_id);
3340                 } else if (cmd == SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET) {
3341                     socket_helper_update_preedit_caret (client_id);
3342                 } else if (cmd == SCIM_TRANS_CMD_UPDATE_AUX_STRING) {
3343                     socket_update_aux_string ();
3344                 } else if (cmd == SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE) {
3345                     socket_update_lookup_table ();
3346                 } else if (cmd == ISM_TRANS_CMD_UPDATE_ASSOCIATE_TABLE) {
3347                     socket_update_associate_table ();
3348                 } else if (cmd == SCIM_TRANS_CMD_PROCESS_KEY_EVENT ||
3349                            cmd == SCIM_TRANS_CMD_PANEL_SEND_KEY_EVENT) {
3350                     socket_helper_send_key_event (client_id);
3351                 } else if (cmd == SCIM_TRANS_CMD_FORWARD_KEY_EVENT) {
3352                     socket_helper_forward_key_event (client_id);
3353                 } else if (cmd == SCIM_TRANS_CMD_PANEL_SEND_IMENGINE_EVENT) {
3354                     socket_helper_send_imengine_event (client_id);
3355                 } else if (cmd == SCIM_TRANS_CMD_REGISTER_PROPERTIES) {
3356                     socket_helper_register_properties (client_id);
3357                 } else if (cmd == SCIM_TRANS_CMD_UPDATE_PROPERTY) {
3358                     socket_helper_update_property (client_id);
3359                 } else if (cmd == SCIM_TRANS_CMD_RELOAD_CONFIG) {
3360                     reload_config ();
3361                     m_signal_reload_config ();
3362                 } else if (cmd == ISM_TRANS_CMD_ISE_PANEL_HIDED) {
3363                     socket_helper_update_state_hided (client_id);
3364                 } else if (cmd == ISM_TRANS_CMD_ISE_PANEL_SHOWED) {
3365                     socket_helper_update_state_showed (client_id);
3366                 } else if (cmd == ISM_TRANS_CMD_UPDATE_ISE_INPUT_CONTEXT) {
3367                     socket_helper_update_input_context (client_id);
3368                 } else if (cmd == ISM_TRANS_CMD_ISE_RESULT_TO_IMCONTROL) {
3369                     socket_helper_commit_ise_result_to_imcontrol (client_id);
3370                 } else if (cmd == ISM_TRANS_CMD_GET_KEYBOARD_ISE_LIST) {
3371                     socket_get_keyboard_ise_list ();
3372                 } else if (cmd == ISM_TRANS_CMD_SET_CANDIDATE_UI) {
3373                     socket_set_candidate_ui ();
3374                 } else if (cmd == ISM_TRANS_CMD_GET_CANDIDATE_UI) {
3375                     socket_get_candidate_ui ();
3376                 } else if (cmd == ISM_TRANS_CMD_SET_CANDIDATE_POSITION) {
3377                     socket_set_candidate_position ();
3378                 } else if (cmd == ISM_TRANS_CMD_HIDE_CANDIDATE) {
3379                     socket_hide_candidate ();
3380                 } else if (cmd == ISM_TRANS_CMD_GET_CANDIDATE_GEOMETRY) {
3381                     socket_get_candidate_geometry ();
3382                 } else if (cmd == ISM_TRANS_CMD_SET_KEYBOARD_ISE_BY_NAME) {
3383                     socket_set_keyboard_ise (ISM_TRANS_CMD_SET_KEYBOARD_ISE_BY_NAME);
3384                 } else if (cmd == ISM_TRANS_CMD_SET_KEYBOARD_ISE_BY_UUID) {
3385                     socket_set_keyboard_ise (ISM_TRANS_CMD_SET_KEYBOARD_ISE_BY_UUID);
3386                 } else if (cmd == ISM_TRANS_CMD_GET_KEYBOARD_ISE) {
3387                     socket_get_keyboard_ise ();
3388                 } else if (cmd == ISM_TRANS_CMD_UPDATE_ISE_GEOMETRY) {
3389                     socket_helper_update_ise_geometry (client_id);
3390                 } else if (cmd == ISM_TRANS_CMD_EXPAND_CANDIDATE) {
3391                     socket_helper_expand_candidate (client_id);
3392                 } else if (cmd == ISM_TRANS_CMD_CONTRACT_CANDIDATE) {
3393                     socket_helper_contract_candidate (client_id);
3394                 } else if (cmd == SCIM_TRANS_CMD_GET_SURROUNDING_TEXT) {
3395                     socket_helper_get_surrounding_text (client_id);
3396                 } else if (cmd == SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT) {
3397                     socket_helper_delete_surrounding_text (client_id);
3398                 }
3399             }
3400             socket_transaction_end ();
3401         }
3402         else if (client_info.type == IMCONTROL_ACT_CLIENT)
3403         {
3404             socket_transaction_start ();
3405
3406             while (m_recv_trans.get_command (cmd))
3407             {
3408                 if (cmd == ISM_TRANS_CMD_SHOW_ISF_CONTROL)
3409                     show_isf_panel (client_id);
3410                 else if (cmd == ISM_TRANS_CMD_HIDE_ISF_CONTROL)
3411                     hide_isf_panel (client_id);
3412                 else if (cmd == ISM_TRANS_CMD_SHOW_ISE_PANEL)
3413                     show_ise_panel (client_id);
3414                 else if (cmd == ISM_TRANS_CMD_HIDE_ISE_PANEL)
3415                     hide_ise_panel (client_id);
3416                 else if (cmd == ISM_TRANS_CMD_GET_ACTIVE_ISE_GEOMETRY)
3417                     get_input_panel_geometry (client_id);
3418                 else if (cmd == ISM_TRANS_CMD_GET_CANDIDATE_GEOMETRY)
3419                     get_candidate_window_geometry (client_id);
3420                 else if (cmd == ISM_TRANS_CMD_GET_ISE_LANGUAGE_LOCALE)
3421                     get_ise_language_locale (client_id);
3422                 else if (cmd == ISM_TRANS_CMD_SET_ISE_MODE)
3423                     set_ise_mode (client_id);
3424                 else if (cmd == ISM_TRANS_CMD_SET_ISE_LANGUAGE)
3425                     set_ise_language (client_id);
3426                 else if (cmd == ISM_TRANS_CMD_SET_ISE_IMDATA)
3427                     set_ise_imdata (client_id);
3428                 else if (cmd == ISM_TRANS_CMD_GET_ISE_IMDATA)
3429                     get_ise_imdata (client_id);
3430                 else if (cmd == ISM_TRANS_CMD_GET_ACTIVE_ISE_NAME)
3431                     get_active_ise_name (client_id);
3432                 else if (cmd == ISM_TRANS_CMD_SET_ACTIVE_ISE_BY_NAME)
3433                     set_active_ise_by_name (client_id);
3434                 else if (cmd == ISM_TRANS_CMD_SET_ACTIVE_ISE_BY_UUID)
3435                     set_active_ise_by_uuid (client_id);
3436                 else if (cmd == ISM_TRANS_CMD_SET_RETURN_KEY_TYPE)
3437                     set_ise_return_key_type (client_id);
3438                 else if (cmd == ISM_TRANS_CMD_GET_RETURN_KEY_TYPE)
3439                     get_ise_return_key_type (client_id);
3440                 else if (cmd == ISM_TRANS_CMD_SET_RETURN_KEY_DISABLE)
3441                     set_ise_return_key_disable (client_id);
3442                 else if (cmd == ISM_TRANS_CMD_GET_RETURN_KEY_DISABLE)
3443                     get_ise_return_key_disable (client_id);
3444                 else if (cmd == ISM_TRANS_CMD_GET_LAYOUT)
3445                     get_ise_layout (client_id);
3446                 else if (cmd == ISM_TRANS_CMD_SET_LAYOUT)
3447                     set_ise_layout (client_id);
3448                 else if (cmd == ISM_TRANS_CMD_SET_CAPS_MODE)
3449                     set_ise_caps_mode (client_id);
3450                 else if (cmd == ISM_TRANS_CMD_GET_ISE_LIST)
3451                     get_ise_list (client_id);
3452                 else if (cmd == ISM_TRANS_CMD_RESET_ISE_OPTION)
3453                     reset_ise_option (client_id);
3454                 else if (cmd == ISM_TRANS_CMD_GET_LANGUAGE_LIST)
3455                     get_language_list (client_id);
3456                 else if (cmd == ISM_TRANS_CMD_GET_ALL_LANGUAGE_LIST)
3457                     get_all_language (client_id);
3458                 else if (cmd == ISM_TRANS_CMD_GET_ISE_LANGUAGE)
3459                     get_ise_language (client_id);
3460                 else if (cmd == ISM_TRANS_CMD_SET_ISF_LANGUAGE)
3461                     set_isf_language (client_id);
3462                 else if (cmd == ISM_TRANS_CMD_RESET_ISE_CONTEXT)
3463                     reset_ise_context (client_id);
3464             }
3465
3466             socket_transaction_end ();
3467         }
3468     }
3469
3470     void socket_exception_callback              (SocketServer   *server,
3471                                                  const Socket   &client)
3472     {
3473         SCIM_DEBUG_MAIN (2) << "PanelAgent::socket_exception_callback (" << client.get_id () << ")\n";
3474
3475         socket_close_connection (server, client);
3476     }
3477
3478     bool socket_open_connection                 (SocketServer   *server,
3479                                                  const Socket   &client)
3480     {
3481         SCIM_DEBUG_MAIN (3) << "PanelAgent::socket_open_connection (" << client.get_id () << ")\n";
3482
3483         uint32 key;
3484         String type = scim_socket_accept_connection (key,
3485                                                      String ("Panel"),
3486                                                      String ("FrontEnd,Helper,Helper_Active,IMControl_Active,IMControl_Passive"),
3487                                                      client,
3488                                                      m_socket_timeout);
3489
3490         if (type.length ()) {
3491             ClientInfo info;
3492             info.key = key;
3493             info.type = ((type == "FrontEnd") ? FRONTEND_CLIENT :
3494                         ((type == "IMControl_Active") ? IMCONTROL_ACT_CLIENT :
3495                         ((type == "Helper_Active") ? HELPER_ACT_CLIENT :
3496                         ((type == "IMControl_Passive") ? IMCONTROL_CLIENT : HELPER_CLIENT))));
3497
3498             SCIM_DEBUG_MAIN (4) << "Add client to repository. Type=" << type << " key=" << key << "\n";
3499             lock ();
3500             m_client_repository [client.get_id ()] = info;
3501
3502             if (info.type == IMCONTROL_ACT_CLIENT) {
3503                 m_pending_active_imcontrol_id = client.get_id ();
3504             } else if (info.type == IMCONTROL_CLIENT) {
3505                 m_imcontrol_map [m_pending_active_imcontrol_id] = client.get_id ();
3506                 m_pending_active_imcontrol_id = -1;
3507             }
3508
3509             const_cast<Socket &>(client).set_nonblock_mode ();
3510
3511             unlock ();
3512             return true;
3513         }
3514
3515         SCIM_DEBUG_MAIN (4) << "Close client connection " << client.get_id () << "\n";
3516         server->close_connection (client);
3517         return false;
3518     }
3519
3520     void socket_close_connection                (SocketServer   *server,
3521                                                  const Socket   &client)
3522     {
3523         SCIM_DEBUG_MAIN (3) << "PanelAgent::socket_close_connection (" << client.get_id () << ")\n";
3524
3525         lock ();
3526
3527         m_signal_close_connection (client.get_id ());
3528
3529         ClientInfo client_info = socket_get_client_info (client.get_id ());
3530
3531         m_client_repository.erase (client.get_id ());
3532
3533         server->close_connection (client);
3534
3535         /* Exit panel if there is no connected client anymore. */
3536         if (client_info.type != UNKNOWN_CLIENT && m_client_repository.size () == 0 && !m_should_resident) {
3537             SCIM_DEBUG_MAIN (4) << "Exit Socket Server Thread.\n";
3538             server->shutdown ();
3539             m_signal_exit.emit ();
3540         }
3541
3542         unlock ();
3543
3544         if (client_info.type == FRONTEND_CLIENT) {
3545             SCIM_DEBUG_MAIN(4) << "It's a FrontEnd client.\n";
3546             /* The focused client is closed. */
3547             if (m_current_socket_client == client.get_id ()) {
3548                 lock ();
3549                 m_current_socket_client = -1;
3550                 m_current_client_context = 0;
3551                 m_current_context_uuid = String ("");
3552                 unlock ();
3553
3554                 socket_transaction_start ();
3555                 socket_turn_off ();
3556                 socket_transaction_end ();
3557             }
3558
3559             if (m_last_socket_client == client.get_id ()) {
3560                 lock ();
3561                 m_last_socket_client = -1;
3562                 m_last_client_context = 0;
3563                 m_last_context_uuid = String ("");
3564                 unlock ();
3565             }
3566
3567             /* Erase all associated Client Context UUIDs. */
3568             std::vector <uint32> ctx_list;
3569             ClientContextUUIDRepository::iterator it = m_client_context_uuids.begin ();
3570             for (; it != m_client_context_uuids.end (); ++it) {
3571                 if ((it->first & 0xFFFF) == (client.get_id () & 0xFFFF))
3572                     ctx_list.push_back (it->first);
3573             }
3574
3575             for (size_t i = 0; i < ctx_list.size (); ++i)
3576                 m_client_context_uuids.erase (ctx_list [i]);
3577
3578             int client_id = client.get_id ();
3579
3580             /* Erase all helperise info associated with the client */
3581             ctx_list.clear ();
3582             it = m_client_context_helper.begin ();
3583             for (; it != m_client_context_helper.end (); ++it) {
3584                 if ((it->first & 0xFFFF) == (client_id & 0xFFFF)) {
3585                     ctx_list.push_back (it->first);
3586
3587                     /* similar to stop_helper except that it will not call get_focused_context() */
3588                     String uuid = it->second;
3589                     if (m_helper_uuid_count.find (uuid) != m_helper_uuid_count.end ()) {
3590                         uint32 count = m_helper_uuid_count[uuid];
3591                         if (1 == count) {
3592                             m_helper_uuid_count.erase (uuid);
3593
3594                             HelperClientIndex::iterator pise = m_helper_client_index.find (uuid);
3595                             if (pise != m_helper_client_index.end ())
3596                             {
3597                                 m_send_trans.clear ();
3598                                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
3599                                 m_send_trans.put_data (it->first);
3600                                 m_send_trans.put_data (uuid);
3601                                 m_send_trans.put_command (SCIM_TRANS_CMD_EXIT);
3602                                 m_send_trans.write_to_socket (pise->second.id);
3603                             }
3604                             SCIM_DEBUG_MAIN(1) << "Stop HelperISE " << uuid << " ...\n";
3605                         }
3606                         else
3607                         {
3608                             m_helper_uuid_count[uuid] = count - 1;
3609                             focus_out_helper (uuid, (it->first & 0xFFFF), ((it->first >> 16) & 0x7FFF));
3610                             SCIM_DEBUG_MAIN(1) << "Decrement usage count of HelperISE " << uuid
3611                                     << " to " << m_helper_uuid_count[uuid] << "\n";
3612                         }
3613                     }
3614                 }
3615             }
3616
3617             for (size_t i = 0; i < ctx_list.size (); ++i)
3618                  m_client_context_helper.erase (ctx_list [i]);
3619
3620             HelperInfoRepository::iterator iter = m_helper_info_repository.begin ();
3621             for (; iter != m_helper_info_repository.end (); iter++)
3622             {
3623                 if (!m_current_helper_uuid.compare (iter->second.uuid))
3624                     if (!(iter->second.option & ISM_ISE_HIDE_IN_CONTROL_PANEL))
3625                         socket_update_control_panel ();
3626             }
3627         } else if (client_info.type == HELPER_CLIENT) {
3628             SCIM_DEBUG_MAIN(4) << "It's a Helper client.\n";
3629
3630             lock ();
3631
3632             HelperInfoRepository::iterator hiit = m_helper_info_repository.find (client.get_id ());
3633
3634             if (hiit != m_helper_info_repository.end ()) {
3635                 bool restart = false;
3636                 String uuid = hiit->second.uuid;
3637
3638                 HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
3639                 if ((hiit->second.option & SCIM_HELPER_AUTO_RESTART) &&
3640                     (it != m_helper_client_index.end () && it->second.ref > 0))
3641                     restart = true;
3642
3643                 m_helper_manager.stop_helper (hiit->second.name);
3644
3645                 m_helper_client_index.erase (uuid);
3646                 m_helper_info_repository.erase (hiit);
3647
3648                 if (restart && !m_ise_exiting) {
3649                     m_helper_manager.run_helper (uuid, m_config_name, m_display_name);
3650                     std::cerr << "Auto restart soft ISE:" << uuid << "\n";
3651                 }
3652             }
3653
3654             m_ise_exiting = false;
3655             unlock ();
3656
3657             socket_transaction_start ();
3658             m_signal_remove_helper (client.get_id ());
3659             socket_transaction_end ();
3660         } else if (client_info.type == HELPER_ACT_CLIENT) {
3661             SCIM_DEBUG_MAIN(4) << "It's a Helper passive client.\n";
3662
3663             lock ();
3664
3665             HelperInfoRepository::iterator hiit = m_helper_active_info_repository.find (client.get_id ());
3666             if (hiit != m_helper_active_info_repository.end ())
3667                 m_helper_active_info_repository.erase (hiit);
3668
3669             unlock ();
3670         } else if (client_info.type == IMCONTROL_ACT_CLIENT) {
3671             SCIM_DEBUG_MAIN(4) << "It's a IMCONTROL_ACT_CLIENT client.\n";
3672             int client_id = client.get_id ();
3673
3674             if (client_id == m_current_active_imcontrol_id
3675                 && TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
3676                 hide_helper (m_current_helper_uuid);
3677
3678             IMControlRepository::iterator iter = m_imcontrol_repository.find (client_id);
3679             if (iter != m_imcontrol_repository.end ())
3680             {
3681                 int size = iter->second.info.size ();
3682                 int i = 0;
3683                 while (i < size) {
3684                     stop_helper ((iter->second.info)[i].uuid, (iter->second.count)[i], DEFAULT_CONTEXT_VALUE);
3685                     if ((iter->second.info)[i].option & ISM_ISE_HIDE_IN_CONTROL_PANEL)
3686                         m_current_helper_uuid = m_last_helper_uuid;
3687                     i++;
3688                 }
3689                 m_imcontrol_repository.erase (iter);
3690             }
3691
3692             IntIntRepository::iterator iter2 = m_imcontrol_map.find (client_id);
3693             if (iter2 != m_imcontrol_map.end ())
3694                 m_imcontrol_map.erase (iter2);
3695         }
3696     }
3697
3698     const ClientInfo & socket_get_client_info   (int client)
3699     {
3700         static ClientInfo null_client = { 0, UNKNOWN_CLIENT };
3701
3702         ClientRepository::iterator it = m_client_repository.find (client);
3703
3704         if (it != m_client_repository.end ())
3705             return it->second;
3706
3707         return null_client;
3708     }
3709
3710 private:
3711     void socket_turn_on                         (void)
3712     {
3713         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_turn_on ()\n";
3714
3715         m_signal_turn_on ();
3716     }
3717
3718     void socket_turn_off                        (void)
3719     {
3720         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_turn_off ()\n";
3721
3722         m_signal_turn_off ();
3723     }
3724
3725     void socket_update_screen                   (void)
3726     {
3727         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_screen ()\n";
3728
3729         uint32 num;
3730         if (m_recv_trans.get_data (num) && ((int) num) != m_current_screen) {
3731             SCIM_DEBUG_MAIN(4) << "New Screen number = " << num << "\n";
3732             m_signal_update_screen ((int) num);
3733             helper_all_update_screen ((int) num);
3734             m_current_screen = (num);
3735         }
3736     }
3737
3738     void socket_update_spot_location            (void)
3739     {
3740         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_spot_location ()\n";
3741
3742         uint32 x, y, top_y;
3743         if (m_recv_trans.get_data (x) && m_recv_trans.get_data (y) && m_recv_trans.get_data (top_y)) {
3744             SCIM_DEBUG_MAIN(4) << "New Spot location x=" << x << " y=" << y << "\n";
3745             m_signal_update_spot_location ((int)x, (int)y, (int)top_y);
3746             helper_all_update_spot_location ((int)x, (int)y);
3747         }
3748     }
3749
3750     void socket_update_cursor_position          (void)
3751     {
3752         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_cursor_position ()\n";
3753
3754         uint32 cursor_pos;
3755         if (m_recv_trans.get_data (cursor_pos)) {
3756             SCIM_DEBUG_MAIN(4) << "New cursor position pos=" << cursor_pos << "\n";
3757             helper_all_update_cursor_position ((int)cursor_pos);
3758         }
3759     }
3760
3761     void socket_update_surrounding_text         (void)
3762     {
3763         SCIM_DEBUG_MAIN(4) << __FUNCTION__ << "...\n";
3764
3765         String text;
3766         uint32 cursor;
3767         if (m_recv_trans.get_data (text) && m_recv_trans.get_data (cursor)) {
3768             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
3769
3770             if (it != m_helper_client_index.end ())
3771             {
3772                 int    client;
3773                 uint32 context;
3774                 Socket client_socket (it->second.id);
3775                 uint32 ctx;
3776
3777                 lock ();
3778
3779                 get_focused_context (client, context);
3780                 ctx = get_helper_ic (client, context);
3781
3782                 m_send_trans.clear ();
3783                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
3784                 m_send_trans.put_data (ctx);
3785                 m_send_trans.put_data (m_current_helper_uuid);
3786                 m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_SURROUNDING_TEXT);
3787                 m_send_trans.put_data (text);
3788                 m_send_trans.put_data (cursor);
3789                 m_send_trans.write_to_socket (client_socket);
3790
3791                 unlock ();
3792             }
3793         }
3794     }
3795
3796     void socket_update_factory_info             (void)
3797     {
3798         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_factory_info ()\n";
3799
3800         PanelFactoryInfo info;
3801         if (m_recv_trans.get_data (info.uuid) && m_recv_trans.get_data (info.name) &&
3802             m_recv_trans.get_data (info.lang) && m_recv_trans.get_data (info.icon)) {
3803             SCIM_DEBUG_MAIN(4) << "New Factory info uuid=" << info.uuid << " name=" << info.name << "\n";
3804             info.lang = scim_get_normalized_language (info.lang);
3805             m_signal_update_factory_info (info);
3806         }
3807     }
3808
3809     void socket_show_help                       (void)
3810     {
3811         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_show_help ()\n";
3812
3813         String help;
3814         if (m_recv_trans.get_data (help))
3815             m_signal_show_help (help);
3816     }
3817
3818     void socket_show_factory_menu               (void)
3819     {
3820         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_show_factory_menu ()\n";
3821
3822         PanelFactoryInfo info;
3823         std::vector <PanelFactoryInfo> vec;
3824
3825         while (m_recv_trans.get_data (info.uuid) && m_recv_trans.get_data (info.name) &&
3826                m_recv_trans.get_data (info.lang) && m_recv_trans.get_data (info.icon)) {
3827             info.lang = scim_get_normalized_language (info.lang);
3828             vec.push_back (info);
3829         }
3830
3831         if (vec.size ())
3832             m_signal_show_factory_menu (vec);
3833     }
3834
3835     void socket_turn_on_log                      (void)
3836     {
3837         uint32 isOn;
3838         if (m_recv_trans.get_data (isOn)) {
3839             if (isOn) {
3840                 DebugOutput::enable_debug (SCIM_DEBUG_AllMask);
3841                 DebugOutput::set_verbose_level (7);
3842                 SCIM_DEBUG_MAIN(4) << __func__ << " on\n";
3843             } else {
3844                 SCIM_DEBUG_MAIN(4) << __func__ << " off\n";
3845                 DebugOutput::disable_debug (SCIM_DEBUG_AllMask);
3846                 DebugOutput::set_verbose_level (0);
3847             }
3848
3849             int     focused_client;
3850             uint32  focused_context;
3851
3852             get_focused_context (focused_client, focused_context);
3853
3854             if (focused_client == -1) {
3855                 std::cerr << __func__ << " get_focused_context is failed!!!\n";
3856                 return;
3857             }
3858
3859             if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
3860             {
3861                 HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
3862
3863                 if (it != m_helper_client_index.end ())
3864                 {
3865                     Socket client_socket (it->second.id);
3866                     uint32 ctx;
3867
3868                     ctx = get_helper_ic (focused_client, focused_context);
3869
3870                     m_send_trans.clear ();
3871                     m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
3872                     m_send_trans.put_data (ctx);
3873                     m_send_trans.put_data (m_current_helper_uuid);
3874                     m_send_trans.put_command (ISM_TRANS_CMD_TURN_ON_LOG);
3875                     m_send_trans.put_data (isOn);
3876                     m_send_trans.write_to_socket (client_socket);
3877                 }
3878             }
3879
3880             ClientInfo client_info = socket_get_client_info (focused_client);
3881             if (client_info.type == FRONTEND_CLIENT) {
3882                 Socket socket_client (focused_client);
3883                 lock ();
3884                 m_send_trans.clear ();
3885                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
3886                 m_send_trans.put_data (focused_context);
3887                 m_send_trans.put_command (ISM_TRANS_CMD_TURN_ON_LOG);
3888                 m_send_trans.put_data (isOn);
3889                 m_send_trans.write_to_socket (socket_client);
3890                 unlock ();
3891             }
3892         }
3893     }
3894
3895     void socket_show_preedit_string             (void)
3896     {
3897         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_show_preedit_string ()\n";
3898         m_signal_show_preedit_string ();
3899     }
3900
3901     void socket_show_aux_string                 (void)
3902     {
3903         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_show_aux_string ()\n";
3904         m_signal_show_aux_string ();
3905     }
3906
3907     void socket_show_lookup_table               (void)
3908     {
3909         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_show_lookup_table ()\n";
3910         m_signal_show_lookup_table ();
3911     }
3912
3913     void socket_show_associate_table            (void)
3914     {
3915         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_show_associate_table ()\n";
3916         m_signal_show_associate_table ();
3917     }
3918
3919     void socket_hide_preedit_string             (void)
3920     {
3921         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_hide_preedit_string ()\n";
3922         m_signal_hide_preedit_string ();
3923     }
3924
3925     void socket_hide_aux_string                 (void)
3926     {
3927         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_hide_aux_string ()\n";
3928         m_signal_hide_aux_string ();
3929     }
3930
3931     void socket_hide_lookup_table               (void)
3932     {
3933         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_hide_lookup_table ()\n";
3934         m_signal_hide_lookup_table ();
3935     }
3936
3937     void socket_hide_associate_table            (void)
3938     {
3939         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_hide_associate_table ()\n";
3940         m_signal_hide_associate_table ();
3941     }
3942
3943     void socket_update_preedit_string           (void)
3944     {
3945         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_preedit_string ()\n";
3946
3947         String str;
3948         AttributeList attrs;
3949         if (m_recv_trans.get_data (str) && m_recv_trans.get_data (attrs))
3950             m_signal_update_preedit_string (str, attrs);
3951     }
3952
3953     void socket_update_preedit_caret            (void)
3954     {
3955         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_preedit_caret ()\n";
3956
3957         uint32 caret;
3958         if (m_recv_trans.get_data (caret))
3959             m_signal_update_preedit_caret ((int) caret);
3960     }
3961
3962     void socket_update_aux_string               (void)
3963     {
3964         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_aux_string ()\n";
3965
3966         String str;
3967         AttributeList attrs;
3968         if (m_recv_trans.get_data (str) && m_recv_trans.get_data (attrs))
3969             m_signal_update_aux_string (str, attrs);
3970     }
3971
3972     void socket_update_lookup_table             (void)
3973     {
3974         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_lookup_table ()\n";
3975
3976         lock ();
3977         if (m_recv_trans.get_data (g_isf_candidate_table))
3978         {
3979             unlock ();
3980             m_signal_update_lookup_table (g_isf_candidate_table);
3981         }
3982         else
3983         {
3984             unlock ();
3985         }
3986     }
3987
3988     void socket_update_associate_table          (void)
3989     {
3990         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_associate_table ()\n";
3991
3992         CommonLookupTable table;
3993         if (m_recv_trans.get_data (table))
3994             m_signal_update_associate_table (table);
3995     }
3996
3997     void socket_update_control_panel            (void)
3998     {
3999         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_control_panel ()\n";
4000         /* Check default ISE for no context app */
4001 #ifdef ONE_HELPER_ISE_PROCESS
4002         uint32 ctx = get_helper_ic (-1, 0);
4003         ClientContextUUIDRepository::iterator it = m_client_context_helper.find (ctx);
4004         if (it != m_client_context_helper.end ())
4005         {
4006             if (m_should_shared_ise)
4007             {
4008                 if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
4009                 {
4010                     if (m_current_helper_uuid != it->second)
4011                     {
4012                         stop_helper (it->second, -1, 0);
4013                         start_helper (m_current_helper_uuid, -1, 0);
4014                     }
4015                 }
4016                 else if (TOOLBAR_KEYBOARD_MODE == m_current_toolbar_mode)
4017                     stop_helper (it->second, -1, 0);
4018             }
4019             else
4020             {
4021                 m_current_toolbar_mode = TOOLBAR_HELPER_MODE;
4022                 m_current_helper_uuid  = it->second;
4023             }
4024         }
4025         else
4026         {
4027             if (m_should_shared_ise)
4028             {
4029                 if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
4030                     start_helper (m_current_helper_uuid, -1, 0);
4031             }
4032             else
4033             {
4034                 m_current_toolbar_mode = TOOLBAR_KEYBOARD_MODE;
4035             }
4036         }
4037
4038 #endif
4039         String name, uuid;
4040         m_signal_get_keyboard_ise (name, uuid);
4041
4042         PanelFactoryInfo info;
4043         if (name.length () > 0)
4044             info = PanelFactoryInfo (uuid, name, String (""), String (""));
4045         else
4046             info = PanelFactoryInfo (String (""), String (_("English/Keyboard")), String ("C"), String (SCIM_KEYBOARD_ICON_FILE));
4047         m_signal_update_factory_info (info);
4048     }
4049
4050     void socket_register_properties             (void)
4051     {
4052         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_register_properties ()\n";
4053
4054         PropertyList properties;
4055
4056         if (m_recv_trans.get_data (properties))
4057             m_signal_register_properties (properties);
4058     }
4059
4060     void socket_update_property                 (void)
4061     {
4062         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_update_property ()\n";
4063
4064         Property property;
4065         if (m_recv_trans.get_data (property))
4066             m_signal_update_property (property);
4067     }
4068
4069     void socket_get_keyboard_ise_list           (void)
4070     {
4071         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_get_keyboard_ise_list ()\n";
4072
4073         std::vector<String> list;
4074         list.clear ();
4075         m_signal_get_keyboard_ise_list (list);
4076
4077         String uuid;
4078         if (m_recv_trans.get_data (uuid))
4079         {
4080             HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
4081             if (it != m_helper_client_index.end ())
4082             {
4083                 int    client;
4084                 uint32 context;
4085                 get_focused_context (client, context);
4086                 uint32 ctx = get_helper_ic (client, context);
4087                 Socket socket_client (it->second.id);
4088                 m_send_trans.clear ();
4089                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4090                 m_send_trans.put_data (ctx);
4091                 m_send_trans.put_data (uuid);
4092                 m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_KEYBOARD_ISE_LIST);
4093                 m_send_trans.put_data (list.size ());
4094                 for (unsigned int i = 0; i < list.size (); i++)
4095                     m_send_trans.put_data (list[i]);
4096                 m_send_trans.write_to_socket (socket_client);
4097             }
4098         }
4099     }
4100
4101     void socket_set_candidate_ui                (void)
4102     {
4103         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_set_candidate_ui ()\n";
4104
4105         uint32 style, mode;
4106         if (m_recv_trans.get_data (style) && m_recv_trans.get_data (mode))
4107         {
4108             m_signal_set_candidate_ui (style, mode);
4109         }
4110     }
4111
4112     void socket_get_candidate_ui                (void)
4113     {
4114         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_get_candidate_ui ()\n";
4115
4116         int style = 0, mode = 0;
4117         m_signal_get_candidate_ui (style, mode);
4118
4119         String uuid;
4120         if (m_recv_trans.get_data (uuid))
4121         {
4122             HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
4123             if (it != m_helper_client_index.end ())
4124             {
4125                 int    client;
4126                 uint32 context;
4127                 get_focused_context (client, context);
4128                 uint32 ctx = get_helper_ic (client, context);
4129                 Socket socket_client (it->second.id);
4130                 m_send_trans.clear ();
4131                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4132                 m_send_trans.put_data (ctx);
4133                 m_send_trans.put_data (uuid);
4134                 m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_CANDIDATE_UI);
4135                 m_send_trans.put_data (style);
4136                 m_send_trans.put_data (mode);
4137                 m_send_trans.write_to_socket (socket_client);
4138             }
4139         }
4140     }
4141
4142     void socket_set_candidate_position          (void)
4143     {
4144         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_set_candidate_position ()\n";
4145
4146         uint32 left, top;
4147         if (m_recv_trans.get_data (left) && m_recv_trans.get_data (top))
4148         {
4149             m_signal_set_candidate_position (left, top);
4150         }
4151     }
4152
4153     void socket_hide_candidate                  (void)
4154     {
4155         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_hide_candidate ()\n";
4156
4157         m_signal_hide_preedit_string ();
4158         m_signal_hide_aux_string ();
4159         m_signal_hide_lookup_table ();
4160         m_signal_hide_associate_table ();
4161     }
4162
4163     void socket_get_candidate_geometry          (void)
4164     {
4165         SCIM_DEBUG_MAIN(4) << __func__ << " \n";
4166
4167         String uuid;
4168         if (m_recv_trans.get_data (uuid)) {
4169             HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
4170             if (it != m_helper_client_index.end ()) {
4171                 struct rectinfo info = {0, 0, 0, 0};
4172                 m_signal_get_candidate_geometry (info);
4173
4174                 int    client;
4175                 uint32 context;
4176                 get_focused_context (client, context);
4177                 uint32 ctx = get_helper_ic (client, context);
4178                 Socket socket_client (it->second.id);
4179                 m_send_trans.clear ();
4180                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4181                 m_send_trans.put_data (ctx);
4182                 m_send_trans.put_data (uuid);
4183                 m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_CANDIDATE_GEOMETRY);
4184                 m_send_trans.put_data (info.pos_x);
4185                 m_send_trans.put_data (info.pos_y);
4186                 m_send_trans.put_data (info.width);
4187                 m_send_trans.put_data (info.height);
4188                 m_send_trans.write_to_socket (socket_client);
4189             }
4190         }
4191     }
4192
4193     void socket_set_keyboard_ise                (int type)
4194     {
4195         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_set_keyboard_ise ()\n";
4196
4197         String ise;
4198         if (m_recv_trans.get_data (ise))
4199             m_signal_set_keyboard_ise (type, ise);
4200     }
4201
4202     void socket_helper_update_ise_geometry (int client)
4203     {
4204         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
4205
4206         uint32 x, y, width, height;
4207         if (m_recv_trans.get_data (x) && m_recv_trans.get_data (y) &&
4208             m_recv_trans.get_data (width) && m_recv_trans.get_data (height)) {
4209             HelperInfoRepository::iterator it = m_helper_active_info_repository.find (client);
4210             if (it != m_helper_active_info_repository.end ()) {
4211                 if (it->second.uuid == m_current_helper_uuid)
4212                     m_signal_update_ise_geometry (x, y, width, height);
4213             }
4214         }
4215     }
4216
4217     void socket_helper_expand_candidate (int client)
4218     {
4219         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
4220
4221         HelperInfoRepository::iterator it = m_helper_active_info_repository.find (client);
4222         if (it != m_helper_active_info_repository.end ()) {
4223             if (it->second.uuid == m_current_helper_uuid)
4224                 m_signal_expand_candidate ();
4225         }
4226     }
4227
4228     void socket_helper_contract_candidate (int client)
4229     {
4230         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
4231
4232         HelperInfoRepository::iterator it = m_helper_active_info_repository.find (client);
4233         if (it != m_helper_active_info_repository.end ()) {
4234             if (it->second.uuid == m_current_helper_uuid)
4235                 m_signal_contract_candidate ();
4236         }
4237     }
4238
4239     void socket_get_keyboard_ise                (void)
4240     {
4241         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_get_keyboard_ise ()\n";
4242
4243         String ise_name, ise_uuid;
4244         int    client  = -1;
4245         uint32 context = 0;
4246         uint32 ctx     = 0;
4247
4248         get_focused_context (client, context);
4249         ctx = get_helper_ic (client, context);
4250
4251         if (m_client_context_uuids.find (ctx) != m_client_context_uuids.end ())
4252             ise_uuid = m_client_context_uuids[ctx];
4253         m_signal_get_keyboard_ise (ise_name, ise_uuid);
4254
4255         String uuid;
4256         if (m_recv_trans.get_data (uuid))
4257         {
4258             HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
4259             if (it != m_helper_client_index.end ())
4260             {
4261                 int    client;
4262                 uint32 context;
4263                 get_focused_context (client, context);
4264                 uint32 ctx = get_helper_ic (client, context);
4265                 Socket socket_client (it->second.id);
4266                 m_send_trans.clear ();
4267                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4268                 m_send_trans.put_data (ctx);
4269                 m_send_trans.put_data (uuid);
4270                 m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_KEYBOARD_ISE);
4271                 m_send_trans.put_data (ise_name);
4272                 m_send_trans.put_data (ise_uuid);
4273                 m_send_trans.write_to_socket (socket_client);
4274             }
4275         }
4276     }
4277
4278     void socket_start_helper                    (int client, uint32 context, const String &ic_uuid)
4279     {
4280         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_start_helper ()\n";
4281
4282         String uuid;
4283         if (m_recv_trans.get_data (uuid) && uuid.length ()) {
4284             HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
4285
4286             lock ();
4287
4288             uint32 ic = get_helper_ic (client, context);
4289
4290             SCIM_DEBUG_MAIN(5) << "Helper UUID =" << uuid << "  IC UUID =" << ic_uuid <<"\n";
4291
4292             if (it == m_helper_client_index.end ()) {
4293                 SCIM_DEBUG_MAIN(5) << "Run this Helper.\n";
4294                 m_start_helper_ic_index [uuid].push_back (std::make_pair (ic, ic_uuid));
4295                 m_helper_manager.run_helper (uuid, m_config_name, m_display_name);
4296             } else {
4297                 SCIM_DEBUG_MAIN(5) << "Increase the Reference count.\n";
4298                 Socket client_socket (it->second.id);
4299                 m_send_trans.clear ();
4300                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4301                 m_send_trans.put_data (ic);
4302                 m_send_trans.put_data (ic_uuid);
4303                 m_send_trans.put_command (SCIM_TRANS_CMD_HELPER_ATTACH_INPUT_CONTEXT);
4304                 m_send_trans.write_to_socket (client_socket);
4305                 ++ it->second.ref;
4306             }
4307
4308             unlock ();
4309         }
4310     }
4311
4312     void socket_stop_helper                     (int client, uint32 context, const String &ic_uuid)
4313     {
4314         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_stop_helper ()\n";
4315
4316         String uuid;
4317         if (m_recv_trans.get_data (uuid) && uuid.length ()) {
4318             HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
4319
4320             lock ();
4321
4322             uint32 ic = get_helper_ic (client, context);
4323
4324             SCIM_DEBUG_MAIN(5) << "Helper UUID =" << uuid << "  IC UUID =" << ic_uuid <<"\n";
4325
4326             if (it != m_helper_client_index.end ()) {
4327                 SCIM_DEBUG_MAIN(5) << "Decrase the Reference count.\n";
4328                 -- it->second.ref;
4329                 Socket client_socket (it->second.id);
4330                 m_send_trans.clear ();
4331                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4332                 m_send_trans.put_data (ic);
4333                 m_send_trans.put_data (ic_uuid);
4334                 m_send_trans.put_command (SCIM_TRANS_CMD_HELPER_DETACH_INPUT_CONTEXT);
4335                 if (it->second.ref <= 0)
4336                     m_send_trans.put_command (SCIM_TRANS_CMD_EXIT);
4337                 m_send_trans.write_to_socket (client_socket);
4338             }
4339
4340             unlock ();
4341         }
4342     }
4343
4344     void socket_send_helper_event               (int client, uint32 context, const String &ic_uuid)
4345     {
4346         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_send_helper_event ()\n";
4347
4348         String uuid;
4349         if (m_recv_trans.get_data (uuid) && m_recv_trans.get_data (m_nest_trans) &&
4350             uuid.length () && m_nest_trans.valid ()) {
4351             HelperClientIndex::iterator it = m_helper_client_index.find (uuid);
4352             if (it != m_helper_client_index.end ()) {
4353                 Socket client_socket (it->second.id);
4354
4355                 lock ();
4356
4357                 m_send_trans.clear ();
4358                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4359
4360                 /* FIXME: We presume that client and context are both less than 65536.
4361                  * Hopefully, it should be true in any UNIXs.
4362                  * So it's ok to combine client and context into one uint32. */
4363                 m_send_trans.put_data (get_helper_ic (client, context));
4364                 m_send_trans.put_data (ic_uuid);
4365                 m_send_trans.put_command (SCIM_TRANS_CMD_HELPER_PROCESS_IMENGINE_EVENT);
4366                 m_send_trans.put_data (m_nest_trans);
4367                 m_send_trans.write_to_socket (client_socket);
4368
4369                 unlock ();
4370             }
4371         }
4372     }
4373
4374     void socket_helper_register_properties      (int client)
4375     {
4376         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_register_properties (" << client << ")\n";
4377
4378         PropertyList properties;
4379         if (m_recv_trans.get_data (properties))
4380             m_signal_register_helper_properties (client, properties);
4381     }
4382
4383     void socket_helper_update_property          (int client)
4384     {
4385         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_update_property (" << client << ")\n";
4386
4387         Property property;
4388         if (m_recv_trans.get_data (property))
4389             m_signal_update_helper_property (client, property);
4390     }
4391
4392     void socket_helper_send_imengine_event      (int client)
4393     {
4394         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_send_imengine_event (" << client << ")\n";
4395
4396         uint32 target_ic;
4397         String target_uuid;
4398
4399         HelperInfoRepository::iterator hiit = m_helper_active_info_repository.find (client);
4400
4401         if (m_recv_trans.get_data (target_ic)    &&
4402             m_recv_trans.get_data (target_uuid)  &&
4403             m_recv_trans.get_data (m_nest_trans) &&
4404             m_nest_trans.valid ()                &&
4405             hiit != m_helper_active_info_repository.end ()) {
4406
4407             int     target_client;
4408             uint32  target_context;
4409
4410             get_imengine_client_context (target_ic, target_client, target_context);
4411
4412             int     focused_client;
4413             uint32  focused_context;
4414             String  focused_uuid;
4415
4416             focused_uuid = get_focused_context (focused_client, focused_context);
4417
4418             if (target_ic == (uint32) (-1)) {
4419                 target_client  = focused_client;
4420                 target_context = focused_context;
4421             }
4422
4423             if (target_uuid.length () == 0)
4424                 target_uuid = focused_uuid;
4425
4426             ClientInfo  client_info = socket_get_client_info (target_client);
4427
4428             SCIM_DEBUG_MAIN(5) << "Target UUID = " << target_uuid << "  Focused UUId = " << focused_uuid << "\nTarget Client = " << target_client << "\n";
4429
4430             if (client_info.type == FRONTEND_CLIENT) {
4431                 Socket socket_client (target_client);
4432                 lock ();
4433                 m_send_trans.clear ();
4434                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4435                 m_send_trans.put_data (target_context);
4436                 m_send_trans.put_command (SCIM_TRANS_CMD_PROCESS_HELPER_EVENT);
4437                 m_send_trans.put_data (target_uuid);
4438                 m_send_trans.put_data (hiit->second.uuid);
4439                 m_send_trans.put_data (m_nest_trans);
4440                 m_send_trans.write_to_socket (socket_client);
4441                 unlock ();
4442             }
4443         }
4444     }
4445
4446     void socket_helper_key_event_op (int client, int cmd)
4447     {
4448         uint32 target_ic;
4449         String target_uuid;
4450         KeyEvent key;
4451
4452         if (m_recv_trans.get_data (target_ic)    &&
4453             m_recv_trans.get_data (target_uuid)  &&
4454             m_recv_trans.get_data (key)          &&
4455             !key.empty ()) {
4456
4457             int     target_client;
4458             uint32  target_context;
4459
4460             get_imengine_client_context (target_ic, target_client, target_context);
4461
4462             int     focused_client;
4463             uint32  focused_context;
4464             String  focused_uuid;
4465
4466             focused_uuid = get_focused_context (focused_client, focused_context);
4467
4468             if (target_ic == (uint32) (-1)) {
4469                 target_client  = focused_client;
4470                 target_context = focused_context;
4471             }
4472
4473             if (target_uuid.length () == 0)
4474                 target_uuid = focused_uuid;
4475
4476             if (target_client == -1)
4477             {
4478                 /* FIXUP: monitor 'Invalid Window' error */
4479                 std::cerr << "focused target client is NULL" << "\n";
4480             }
4481             else if (target_client  == focused_client &&
4482                 target_context == focused_context &&
4483                 target_uuid    == focused_uuid)
4484             {
4485                 ClientInfo client_info = socket_get_client_info (target_client);
4486                 if (client_info.type == FRONTEND_CLIENT) {
4487                     Socket socket_client (target_client);
4488                     lock ();
4489                     m_send_trans.clear ();
4490                     m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4491                     m_send_trans.put_data (target_context);
4492                     m_send_trans.put_command (cmd);
4493                     m_send_trans.put_data (key);
4494                     m_send_trans.write_to_socket (socket_client);
4495                     unlock ();
4496                 }
4497             }
4498         }
4499     }
4500
4501     void socket_helper_send_key_event (int client)
4502     {
4503         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_send_key_event (" << client << ")\n";
4504         ISF_PROF_DEBUG("first message")
4505
4506         socket_helper_key_event_op (client, SCIM_TRANS_CMD_PROCESS_KEY_EVENT);
4507     }
4508
4509     void socket_helper_forward_key_event        (int client)
4510     {
4511         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_forward_key_event (" << client << ")\n";
4512
4513         socket_helper_key_event_op (client, SCIM_TRANS_CMD_FORWARD_KEY_EVENT);
4514     }
4515
4516     void socket_helper_commit_string            (int client)
4517     {
4518         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_commit_string (" << client << ")\n";
4519
4520         uint32 target_ic;
4521         String target_uuid;
4522         WideString wstr;
4523
4524         if (m_recv_trans.get_data (target_ic)    &&
4525             m_recv_trans.get_data (target_uuid)  &&
4526             m_recv_trans.get_data (wstr)         &&
4527             wstr.length ()) {
4528
4529             int     target_client;
4530             uint32  target_context;
4531
4532             get_imengine_client_context (target_ic, target_client, target_context);
4533
4534             int     focused_client;
4535             uint32  focused_context;
4536             String  focused_uuid;
4537
4538             focused_uuid = get_focused_context (focused_client, focused_context);
4539
4540             if (target_ic == (uint32) (-1)) {
4541                 target_client  = focused_client;
4542                 target_context = focused_context;
4543             }
4544
4545             if (target_uuid.length () == 0)
4546                 target_uuid = focused_uuid;
4547
4548             if (target_client  == focused_client &&
4549                 target_context == focused_context &&
4550                 target_uuid    == focused_uuid) {
4551                 ClientInfo client_info = socket_get_client_info (target_client);
4552                 if (client_info.type == FRONTEND_CLIENT) {
4553                     Socket socket_client (target_client);
4554                     lock ();
4555                     m_send_trans.clear ();
4556                     m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4557                     m_send_trans.put_data (target_context);
4558                     m_send_trans.put_command (SCIM_TRANS_CMD_COMMIT_STRING);
4559                     m_send_trans.put_data (wstr);
4560                     m_send_trans.write_to_socket (socket_client);
4561                     unlock ();
4562                 }
4563             }
4564         }
4565     }
4566
4567     void socket_helper_get_surrounding_text     (int client)
4568     {
4569         SCIM_DEBUG_MAIN(4) << __FUNCTION__ << " (" << client << ")\n";
4570
4571         String uuid;
4572         uint32 maxlen_before;
4573         uint32 maxlen_after;
4574
4575         if (m_recv_trans.get_data (uuid) &&
4576             m_recv_trans.get_data (maxlen_before) &&
4577             m_recv_trans.get_data (maxlen_after)) {
4578
4579             int     focused_client;
4580             uint32  focused_context;
4581             String  focused_uuid;
4582
4583             focused_uuid = get_focused_context (focused_client, focused_context);
4584
4585             ClientInfo client_info = socket_get_client_info (focused_client);
4586             if (client_info.type == FRONTEND_CLIENT) {
4587                 Socket socket_client (focused_client);
4588                 lock ();
4589                 m_send_trans.clear ();
4590                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4591                 m_send_trans.put_data (focused_context);
4592                 m_send_trans.put_command (SCIM_TRANS_CMD_GET_SURROUNDING_TEXT);
4593                 m_send_trans.put_data (maxlen_before);
4594                 m_send_trans.put_data (maxlen_after);
4595                 m_send_trans.write_to_socket (socket_client);
4596                 unlock ();
4597             }
4598         }
4599     }
4600
4601     void socket_helper_delete_surrounding_text  (int client)
4602     {
4603         SCIM_DEBUG_MAIN(4) << __FUNCTION__ << " (" << client << ")\n";
4604
4605         uint32 offset;
4606         uint32 len;
4607
4608         if (m_recv_trans.get_data (offset) && m_recv_trans.get_data (len)) {
4609
4610             int     focused_client;
4611             uint32  focused_context;
4612             String  focused_uuid;
4613
4614             focused_uuid = get_focused_context (focused_client, focused_context);
4615
4616             ClientInfo client_info = socket_get_client_info (focused_client);
4617             if (client_info.type == FRONTEND_CLIENT) {
4618                 Socket socket_client (focused_client);
4619                 lock ();
4620                 m_send_trans.clear ();
4621                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4622                 m_send_trans.put_data (focused_context);
4623                 m_send_trans.put_command (SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT);
4624                 m_send_trans.put_data (offset);
4625                 m_send_trans.put_data (len);
4626                 m_send_trans.write_to_socket (socket_client);
4627                 unlock ();
4628             }
4629         }
4630     }
4631
4632     void socket_helper_show_preedit_string            (int client)
4633     {
4634         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_show_preedit_string (" << client << ")\n";
4635
4636         uint32 target_ic;
4637         String target_uuid;
4638
4639         if (m_recv_trans.get_data (target_ic) && m_recv_trans.get_data (target_uuid)) {
4640             int     target_client;
4641             uint32  target_context;
4642
4643             get_imengine_client_context (target_ic, target_client, target_context);
4644
4645             int     focused_client;
4646             uint32  focused_context;
4647             String  focused_uuid;
4648
4649             focused_uuid = get_focused_context (focused_client, focused_context);
4650
4651             if (target_ic == (uint32) (-1)) {
4652                 target_client  = focused_client;
4653                 target_context = focused_context;
4654             }
4655
4656             if (target_uuid.length () == 0)
4657                 target_uuid = focused_uuid;
4658
4659             if (target_client  == focused_client &&
4660                 target_context == focused_context &&
4661                 target_uuid    == focused_uuid) {
4662                 ClientInfo client_info = socket_get_client_info (target_client);
4663                 if (client_info.type == FRONTEND_CLIENT) {
4664                     Socket socket_client (target_client);
4665                     lock ();
4666                     m_send_trans.clear ();
4667                     m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4668                     m_send_trans.put_data (target_context);
4669                     m_send_trans.put_command (SCIM_TRANS_CMD_SHOW_PREEDIT_STRING);
4670                     m_send_trans.write_to_socket (socket_client);
4671                     unlock ();
4672                 }
4673             }
4674         }
4675     }
4676
4677     void socket_helper_hide_preedit_string            (int client)
4678     {
4679         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_hide_preedit_string (" << client << ")\n";
4680
4681         uint32 target_ic;
4682         String target_uuid;
4683
4684         if (m_recv_trans.get_data (target_ic) && m_recv_trans.get_data (target_uuid)) {
4685             int     target_client;
4686             uint32  target_context;
4687
4688             get_imengine_client_context (target_ic, target_client, target_context);
4689
4690             int     focused_client;
4691             uint32  focused_context;
4692             String  focused_uuid;
4693
4694             focused_uuid = get_focused_context (focused_client, focused_context);
4695
4696             if (target_ic == (uint32) (-1)) {
4697                 target_client  = focused_client;
4698                 target_context = focused_context;
4699             }
4700
4701             if (target_uuid.length () == 0)
4702                 target_uuid = focused_uuid;
4703
4704             if (target_client  == focused_client &&
4705                 target_context == focused_context &&
4706                 target_uuid    == focused_uuid) {
4707                 ClientInfo client_info = socket_get_client_info (target_client);
4708                 if (client_info.type == FRONTEND_CLIENT) {
4709                     Socket socket_client (target_client);
4710                     lock ();
4711                     m_send_trans.clear ();
4712                     m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4713                     m_send_trans.put_data (target_context);
4714                     m_send_trans.put_command (SCIM_TRANS_CMD_HIDE_PREEDIT_STRING);
4715                     m_send_trans.write_to_socket (socket_client);
4716                     unlock ();
4717                 }
4718             }
4719         }
4720     }
4721
4722     void socket_helper_update_preedit_string            (int client)
4723     {
4724         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_update_preedit_string (" << client << ")\n";
4725
4726         uint32 target_ic;
4727         String target_uuid;
4728         WideString wstr;
4729         AttributeList attrs;
4730
4731         if (m_recv_trans.get_data (target_ic)    &&
4732             m_recv_trans.get_data (target_uuid)  &&
4733             m_recv_trans.get_data (wstr) && wstr.length () &&
4734             m_recv_trans.get_data (attrs)) {
4735
4736             int     target_client;
4737             uint32  target_context;
4738
4739             get_imengine_client_context (target_ic, target_client, target_context);
4740
4741             int     focused_client;
4742             uint32  focused_context;
4743             String  focused_uuid;
4744
4745             focused_uuid = get_focused_context (focused_client, focused_context);
4746
4747             if (target_ic == (uint32) (-1)) {
4748                 target_client  = focused_client;
4749                 target_context = focused_context;
4750             }
4751
4752             if (target_uuid.length () == 0)
4753                 target_uuid = focused_uuid;
4754
4755             if (target_client  == focused_client &&
4756                 target_context == focused_context &&
4757                 target_uuid    == focused_uuid) {
4758                 ClientInfo client_info = socket_get_client_info (target_client);
4759                 if (client_info.type == FRONTEND_CLIENT) {
4760                     Socket socket_client (target_client);
4761                     lock ();
4762                     m_send_trans.clear ();
4763                     m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4764                     m_send_trans.put_data (target_context);
4765                     m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING);
4766                     m_send_trans.put_data (wstr);
4767                     m_send_trans.put_data (attrs);
4768                     m_send_trans.write_to_socket (socket_client);
4769                     unlock ();
4770                 }
4771             }
4772         }
4773     }
4774
4775     void socket_helper_update_preedit_caret (int client)
4776     {
4777         SCIM_DEBUG_MAIN(4) << __func__ << " (" << client << ")\n";
4778
4779         uint32 caret;
4780
4781         if (m_recv_trans.get_data (caret)) {
4782             int     focused_client;
4783             uint32  focused_context;
4784             String  focused_uuid;
4785             focused_uuid = get_focused_context (focused_client, focused_context);
4786
4787             ClientInfo client_info = socket_get_client_info (focused_client);
4788             if (client_info.type == FRONTEND_CLIENT) {
4789                 Socket socket_client (focused_client);
4790                 lock ();
4791                 m_send_trans.clear ();
4792                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4793                 m_send_trans.put_data (focused_context);
4794                 m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET);
4795                 m_send_trans.put_data (caret);
4796                 m_send_trans.write_to_socket (socket_client);
4797                 unlock ();
4798             }
4799         }
4800     }
4801
4802     void socket_helper_register_helper          (int client)
4803     {
4804         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_register_helper (" << client << ")\n";
4805
4806         HelperInfo info;
4807
4808         bool result = false;
4809
4810         lock ();
4811
4812         Socket socket_client (client);
4813         m_send_trans.clear ();
4814         m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
4815
4816         if (m_recv_trans.get_data (info.uuid) &&
4817             m_recv_trans.get_data (info.name) &&
4818             m_recv_trans.get_data (info.icon) &&
4819             m_recv_trans.get_data (info.description) &&
4820             m_recv_trans.get_data (info.option) &&
4821             info.uuid.length () &&
4822             info.name.length ()) {
4823
4824             SCIM_DEBUG_MAIN(4) << "New Helper uuid=" << info.uuid << " name=" << info.name << "\n";
4825
4826             HelperClientIndex::iterator it = m_helper_client_index.find (info.uuid);
4827
4828             if (it == m_helper_client_index.end ()) {
4829                 m_helper_info_repository [client] = info;
4830                 m_helper_client_index [info.uuid] = HelperClientStub (client, 1);
4831                 m_send_trans.put_command (SCIM_TRANS_CMD_OK);
4832
4833                 StartHelperICIndex::iterator icit = m_start_helper_ic_index.find (info.uuid);
4834
4835                 if (icit != m_start_helper_ic_index.end ()) {
4836                     m_send_trans.put_command (SCIM_TRANS_CMD_HELPER_ATTACH_INPUT_CONTEXT);
4837                     for (size_t i = 0; i < icit->second.size (); ++i) {
4838                         m_send_trans.put_data (icit->second [i].first);
4839                         m_send_trans.put_data (icit->second [i].second);
4840                     }
4841                     m_start_helper_ic_index.erase (icit);
4842                 }
4843
4844                 m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_SCREEN);
4845                 m_send_trans.put_data ((uint32)m_current_screen);
4846
4847                 result = true;
4848             } else {
4849                 m_send_trans.put_command (SCIM_TRANS_CMD_FAIL);
4850             }
4851         }
4852
4853         m_send_trans.write_to_socket (socket_client);
4854
4855         unlock ();
4856
4857         if (result)
4858             m_signal_register_helper (client, info);
4859     }
4860
4861     void socket_helper_register_helper_passive          (int client)
4862     {
4863         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_register_helper_passive (" << client << ")\n";
4864
4865         HelperInfo info;
4866
4867         lock ();
4868
4869         if (m_recv_trans.get_data (info.uuid) &&
4870             m_recv_trans.get_data (info.name) &&
4871             m_recv_trans.get_data (info.icon) &&
4872             m_recv_trans.get_data (info.description) &&
4873             m_recv_trans.get_data (info.option) &&
4874             info.uuid.length () &&
4875             info.name.length ()) {
4876
4877             SCIM_DEBUG_MAIN(4) << "New Helper Passive uuid=" << info.uuid << " name=" << info.name << "\n";
4878
4879             HelperInfoRepository::iterator it = m_helper_active_info_repository.find (client);
4880             if (it == m_helper_active_info_repository.end ()) {
4881                 m_helper_active_info_repository[client] =  info;
4882             }
4883
4884             StringIntRepository::iterator iter = m_ise_pending_repository.find (info.uuid);
4885             if (iter != m_ise_pending_repository.end ())
4886             {
4887                 Transaction trans;
4888                 Socket client_socket (iter->second);
4889                 trans.clear ();
4890                 trans.put_command (SCIM_TRANS_CMD_REPLY);
4891                 trans.put_command (SCIM_TRANS_CMD_OK);
4892                 trans.write_to_socket (client_socket);
4893                 m_ise_pending_repository.erase (iter);
4894             }
4895
4896             iter = m_ise_pending_repository.find (info.name);
4897             if (iter != m_ise_pending_repository.end ())
4898             {
4899                 Transaction trans;
4900                 Socket client_socket (iter->second);
4901                 trans.clear ();
4902                 trans.put_command (SCIM_TRANS_CMD_REPLY);
4903                 trans.put_command (SCIM_TRANS_CMD_OK);
4904                 trans.write_to_socket (client_socket);
4905                 m_ise_pending_repository.erase (iter);
4906             }
4907
4908             if (m_current_active_imcontrol_id != -1 &&
4909                 m_ise_settings != NULL && m_ise_changing)
4910             {
4911                 show_helper (info.uuid, m_ise_settings, m_ise_settings_len);
4912                 m_ise_changing = false;
4913             }
4914         }
4915
4916         unlock ();
4917     }
4918
4919     void socket_helper_update_state_hided          (int client)
4920     {
4921         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_update_state_hided (" << client << ")\n";
4922
4923         ClientRepository::iterator iter = m_client_repository.begin ();
4924
4925         for (; iter != m_client_repository.end (); iter++)
4926         {
4927             if (IMCONTROL_CLIENT == iter->second.type
4928                 && iter->first == m_imcontrol_map[m_current_active_imcontrol_id])
4929             {
4930                 Socket client_socket (iter->first);
4931                 Transaction trans;
4932
4933                 trans.clear ();
4934                 trans.put_command (SCIM_TRANS_CMD_REQUEST);
4935                 trans.put_command (ISM_TRANS_CMD_ISE_PANEL_HIDED);
4936
4937                 trans.write_to_socket (client_socket);
4938                 break;
4939             }
4940         }
4941     }
4942
4943     void socket_helper_update_state_showed          (int client)
4944     {
4945         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_update_state_showed (" << client << ")\n";
4946
4947         ClientRepository::iterator iter = m_client_repository.begin ();
4948
4949         for (; iter != m_client_repository.end (); iter++)
4950         {
4951             if (IMCONTROL_CLIENT == iter->second.type &&
4952                 iter->first == m_imcontrol_map[m_current_active_imcontrol_id])
4953             {
4954                 Socket client_socket (iter->first);
4955                 Transaction trans;
4956
4957                 trans.clear ();
4958                 trans.put_command (SCIM_TRANS_CMD_REQUEST);
4959                 trans.put_command (ISM_TRANS_CMD_ISE_PANEL_SHOWED);
4960
4961                 trans.write_to_socket (client_socket);
4962                 break;
4963             }
4964         }
4965     }
4966
4967     void socket_helper_update_input_context          (int client)
4968     {
4969         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_update_input_context (" << client << ")\n";
4970
4971         uint32 type;
4972         uint32 value;
4973
4974         if (m_recv_trans.get_data (type) && m_recv_trans.get_data (value))
4975         {
4976             m_signal_update_input_context ((int)type, (int)value);
4977             ClientRepository::iterator iter = m_client_repository.begin ();
4978
4979             for (; iter != m_client_repository.end (); iter++)
4980             {
4981                 if (IMCONTROL_CLIENT == iter->second.type &&
4982                     iter->first == m_imcontrol_map[m_current_active_imcontrol_id])
4983                 {
4984                     Socket client_socket (iter->first);
4985                     Transaction trans;
4986
4987                     trans.clear ();
4988                     trans.put_command (SCIM_TRANS_CMD_REQUEST);
4989                     trans.put_command (ISM_TRANS_CMD_UPDATE_ISE_INPUT_CONTEXT);
4990                     trans.put_data (type);
4991                     trans.put_data (value);
4992
4993                     trans.write_to_socket (client_socket);
4994                     break;
4995                 }
4996             }
4997         }
4998     }
4999
5000     void socket_helper_commit_ise_result_to_imcontrol          (int client)
5001     {
5002         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_helper_commit_ise_result_to_imcontrol (" << client << ")\n";
5003
5004         char * buf = NULL;
5005         size_t len;
5006
5007         if (m_recv_trans.get_data (&buf, len))
5008         {
5009             ClientRepository::iterator iter = m_client_repository.begin ();
5010
5011             for (; iter != m_client_repository.end (); iter++)
5012             {
5013                 if (IMCONTROL_CLIENT == iter->second.type &&
5014                     iter->first == m_imcontrol_map[m_current_active_imcontrol_id])
5015                 {
5016                     Socket client_socket (iter->first);
5017                     Transaction trans;
5018
5019                     trans.clear ();
5020                     trans.put_command (SCIM_TRANS_CMD_REQUEST);
5021                     trans.put_command (ISM_TRANS_CMD_ISE_RESULT_TO_IMCONTROL);
5022                     trans.put_data (buf, len);
5023                     trans.write_to_socket (client_socket);
5024                     break;
5025                 }
5026             }
5027
5028             if (buf)
5029                 delete [] buf;
5030         }
5031     }
5032
5033     void socket_reset_helper_input_context (const String &uuid, int client, uint32 context)
5034     {
5035         HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5036
5037         if (it != m_helper_client_index.end ())
5038         {
5039             Socket client_socket (it->second.id);
5040             uint32 ctx = get_helper_ic (client, context);
5041
5042             m_send_trans.clear ();
5043             m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5044             m_send_trans.put_data (ctx);
5045             m_send_trans.put_data (uuid);
5046             m_send_trans.put_command (SCIM_TRANS_CMD_PANEL_RESET_INPUT_CONTEXT);
5047             m_send_trans.write_to_socket (client_socket);
5048         }
5049     }
5050
5051     void socket_reset_input_context (int client, uint32 context)
5052     {
5053         SCIM_DEBUG_MAIN(4) << "PanelAgent::socket_reset_input_context \n";
5054
5055         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5056             socket_reset_helper_input_context (m_current_helper_uuid, client, context);
5057     }
5058
5059     bool helper_select_aux (uint32 item)
5060     {
5061         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_select_aux \n";
5062
5063         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5064         {
5065             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5066
5067             if (it != m_helper_client_index.end ())
5068             {
5069                 int    client;
5070                 uint32 context;
5071                 Socket client_socket (it->second.id);
5072                 uint32 ctx;
5073
5074                 get_focused_context (client, context);
5075                 ctx = get_helper_ic (client, context);
5076
5077                 m_send_trans.clear ();
5078                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5079                 m_send_trans.put_data (ctx);
5080                 m_send_trans.put_data (m_current_helper_uuid);
5081                 m_send_trans.put_command (ISM_TRANS_CMD_SELECT_AUX);
5082                 m_send_trans.put_data ((uint32)item);
5083                 m_send_trans.write_to_socket (client_socket);
5084
5085                 return true;
5086             }
5087         }
5088
5089         return false;
5090     }
5091
5092     bool helper_select_candidate (uint32 item)
5093     {
5094         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_select_candidate \n";
5095
5096         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5097         {
5098             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5099
5100             if (it != m_helper_client_index.end ())
5101             {
5102                 int    client;
5103                 uint32 context;
5104                 Socket client_socket (it->second.id);
5105                 uint32 ctx;
5106
5107                 get_focused_context (client, context);
5108                 ctx = get_helper_ic (client, context);
5109
5110                 m_send_trans.clear ();
5111                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5112                 m_send_trans.put_data (ctx);
5113                 m_send_trans.put_data (m_current_helper_uuid);
5114                 m_send_trans.put_command (SCIM_TRANS_CMD_SELECT_CANDIDATE);
5115                 m_send_trans.put_data ((uint32)item);
5116                 m_send_trans.write_to_socket (client_socket);
5117
5118                 return true;
5119             }
5120         }
5121
5122         return false;
5123     }
5124
5125     bool helper_lookup_table_page_up (void)
5126     {
5127         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_lookup_table_page_up \n";
5128
5129         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5130         {
5131             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5132
5133             if (it != m_helper_client_index.end ())
5134             {
5135                 int    client;
5136                 uint32 context;
5137                 Socket client_socket (it->second.id);
5138                 uint32 ctx;
5139
5140                 get_focused_context (client, context);
5141                 ctx = get_helper_ic (client, context);
5142
5143                 m_send_trans.clear ();
5144                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5145                 m_send_trans.put_data (ctx);
5146                 m_send_trans.put_data (m_current_helper_uuid);
5147                 m_send_trans.put_command (SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_UP);
5148                 m_send_trans.write_to_socket (client_socket);
5149
5150                 return true;
5151             }
5152         }
5153
5154         return false;
5155     }
5156
5157     bool helper_lookup_table_page_down (void)
5158     {
5159         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_lookup_table_page_down \n";
5160
5161         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5162         {
5163             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5164
5165             if (it != m_helper_client_index.end ())
5166             {
5167                 int    client;
5168                 uint32 context;
5169                 Socket client_socket (it->second.id);
5170                 uint32 ctx;
5171
5172                 get_focused_context (client, context);
5173                 ctx = get_helper_ic (client, context);
5174
5175                 m_send_trans.clear ();
5176                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5177                 m_send_trans.put_data (ctx);
5178                 m_send_trans.put_data (m_current_helper_uuid);
5179                 m_send_trans.put_command (SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_DOWN);
5180                 m_send_trans.write_to_socket (client_socket);
5181
5182                 return true;
5183             }
5184         }
5185
5186         return false;
5187     }
5188
5189     bool helper_update_lookup_table_page_size (uint32 size)
5190     {
5191         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_update_lookup_table_page_size \n";
5192
5193         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5194         {
5195             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5196
5197             if (it != m_helper_client_index.end ())
5198             {
5199                 int    client;
5200                 uint32 context;
5201                 Socket client_socket (it->second.id);
5202                 uint32 ctx;
5203
5204                 get_focused_context (client, context);
5205                 ctx = get_helper_ic (client, context);
5206
5207                 m_send_trans.clear ();
5208                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5209                 m_send_trans.put_data (ctx);
5210                 m_send_trans.put_data (m_current_helper_uuid);
5211                 m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE_PAGE_SIZE);
5212                 m_send_trans.put_data (size);
5213                 m_send_trans.write_to_socket (client_socket);
5214
5215                 return true;
5216             }
5217         }
5218
5219         return false;
5220     }
5221
5222     bool helper_select_associate (uint32 item)
5223     {
5224         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_select_associate \n";
5225
5226         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5227         {
5228             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5229
5230             if (it != m_helper_client_index.end ())
5231             {
5232                 int    client;
5233                 uint32 context;
5234                 Socket client_socket (it->second.id);
5235                 uint32 ctx;
5236
5237                 get_focused_context (client, context);
5238                 ctx = get_helper_ic (client, context);
5239
5240                 m_send_trans.clear ();
5241                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5242                 m_send_trans.put_data (ctx);
5243                 m_send_trans.put_data (m_current_helper_uuid);
5244                 m_send_trans.put_command (ISM_TRANS_CMD_SELECT_ASSOCIATE);
5245                 m_send_trans.put_data ((uint32)item);
5246                 m_send_trans.write_to_socket (client_socket);
5247
5248                 return true;
5249             }
5250         }
5251
5252         return false;
5253     }
5254
5255     bool helper_associate_table_page_up (void)
5256     {
5257         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_associate_table_page_up \n";
5258
5259         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5260         {
5261             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5262
5263             if (it != m_helper_client_index.end ())
5264             {
5265                 int    client;
5266                 uint32 context;
5267                 Socket client_socket (it->second.id);
5268                 uint32 ctx;
5269
5270                 get_focused_context (client, context);
5271                 ctx = get_helper_ic (client, context);
5272
5273                 m_send_trans.clear ();
5274                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5275                 m_send_trans.put_data (ctx);
5276                 m_send_trans.put_data (m_current_helper_uuid);
5277                 m_send_trans.put_command (ISM_TRANS_CMD_ASSOCIATE_TABLE_PAGE_UP);
5278                 m_send_trans.write_to_socket (client_socket);
5279
5280                 return true;
5281             }
5282         }
5283
5284         return false;
5285     }
5286
5287     bool helper_associate_table_page_down (void)
5288     {
5289         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_associate_table_page_down \n";
5290
5291         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5292         {
5293             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5294
5295             if (it != m_helper_client_index.end ())
5296             {
5297                 int    client;
5298                 uint32 context;
5299                 Socket client_socket (it->second.id);
5300                 uint32 ctx;
5301
5302                 get_focused_context (client, context);
5303                 ctx = get_helper_ic (client, context);
5304
5305                 m_send_trans.clear ();
5306                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5307                 m_send_trans.put_data (ctx);
5308                 m_send_trans.put_data (m_current_helper_uuid);
5309                 m_send_trans.put_command (ISM_TRANS_CMD_ASSOCIATE_TABLE_PAGE_DOWN);
5310                 m_send_trans.write_to_socket (client_socket);
5311
5312                 return true;
5313             }
5314         }
5315
5316         return false;
5317     }
5318
5319     bool helper_update_associate_table_page_size (uint32         size)
5320     {
5321         SCIM_DEBUG_MAIN(4) << "PanelAgent::helper_update_associate_table_page_size \n";
5322
5323         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode)
5324         {
5325             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5326
5327             if (it != m_helper_client_index.end ())
5328             {
5329                 int    client;
5330                 uint32 context;
5331                 Socket client_socket (it->second.id);
5332                 uint32 ctx;
5333
5334                 get_focused_context (client, context);
5335                 ctx = get_helper_ic (client, context);
5336
5337                 m_send_trans.clear ();
5338                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5339                 m_send_trans.put_data (ctx);
5340                 m_send_trans.put_data (m_current_helper_uuid);
5341                 m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_ASSOCIATE_TABLE_PAGE_SIZE);
5342                 m_send_trans.put_data (size);
5343                 m_send_trans.write_to_socket (client_socket);
5344
5345                 return true;
5346             }
5347         }
5348
5349         return false;
5350     }
5351
5352     bool helper_update_displayed_candidate_number (uint32 size)
5353     {
5354         SCIM_DEBUG_MAIN(4) << __func__ << "\n";
5355
5356         if (TOOLBAR_HELPER_MODE == m_current_toolbar_mode) {
5357             HelperClientIndex::iterator it = m_helper_client_index.find (m_current_helper_uuid);
5358
5359             if (it != m_helper_client_index.end ()) {
5360                 int    client;
5361                 uint32 context;
5362                 Socket client_socket (it->second.id);
5363                 uint32 ctx;
5364
5365                 get_focused_context (client, context);
5366                 ctx = get_helper_ic (client, context);
5367
5368                 m_send_trans.clear ();
5369                 m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5370                 m_send_trans.put_data (ctx);
5371                 m_send_trans.put_data (m_current_helper_uuid);
5372                 m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_DISPLAYED_CANDIDATE);
5373                 m_send_trans.put_data (size);
5374                 m_send_trans.write_to_socket (client_socket);
5375
5376                 return true;
5377             }
5378         }
5379
5380         return false;
5381     }
5382
5383     void helper_all_update_spot_location (int x, int y)
5384     {
5385         SCIM_DEBUG_MAIN (5) << "PanelAgent::helper_all_update_spot_location (" << x << "," << y << ")\n";
5386
5387         HelperInfoRepository::iterator hiit = m_helper_info_repository.begin ();
5388
5389         int    client;
5390         uint32 context;
5391         String uuid = get_focused_context (client, context);
5392
5393         lock ();
5394
5395         m_send_trans.clear ();
5396         m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5397
5398         /* FIXME: We presume that client and context are both less than 65536.
5399          * Hopefully, it should be true in any UNIXs.
5400          * So it's ok to combine client and context into one uint32. */
5401         m_send_trans.put_data (get_helper_ic (client, context));
5402         m_send_trans.put_data (uuid);
5403         m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_SPOT_LOCATION);
5404         m_send_trans.put_data ((uint32) x);
5405         m_send_trans.put_data ((uint32) y);
5406
5407         for (; hiit != m_helper_info_repository.end (); ++ hiit) {
5408             if (hiit->second.option & SCIM_HELPER_NEED_SPOT_LOCATION_INFO) {
5409                 Socket client_socket (hiit->first);
5410                 m_send_trans.write_to_socket (client_socket);
5411             }
5412         }
5413
5414         unlock ();
5415     }
5416
5417     void helper_all_update_cursor_position      (int cursor_pos)
5418     {
5419         SCIM_DEBUG_MAIN (5) << "PanelAgent::helper_all_update_cursor_position (" << cursor_pos << ")\n";
5420
5421         HelperInfoRepository::iterator hiit = m_helper_info_repository.begin ();
5422
5423         int    client;
5424         uint32 context;
5425         String uuid = get_focused_context (client, context);
5426
5427         lock ();
5428
5429         m_send_trans.clear ();
5430         m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5431         m_send_trans.put_data (get_helper_ic (client, context));
5432         m_send_trans.put_data (uuid);
5433         m_send_trans.put_command (ISM_TRANS_CMD_UPDATE_CURSOR_POSITION);
5434         m_send_trans.put_data ((uint32) cursor_pos);
5435
5436         for (; hiit != m_helper_info_repository.end (); ++ hiit) {
5437             Socket client_socket (hiit->first);
5438             m_send_trans.write_to_socket (client_socket);
5439         }
5440
5441         unlock ();
5442     }
5443
5444     void helper_all_update_screen               (int screen)
5445     {
5446         SCIM_DEBUG_MAIN (5) << "PanelAgent::helper_all_update_screen (" << screen << ")\n";
5447
5448         HelperInfoRepository::iterator hiit = m_helper_info_repository.begin ();
5449
5450         int    client;
5451         uint32 context;
5452         String uuid;
5453
5454         lock ();
5455
5456         uuid = get_focused_context (client, context);
5457
5458         m_send_trans.clear ();
5459         m_send_trans.put_command (SCIM_TRANS_CMD_REPLY);
5460
5461         /* FIXME: We presume that client and context are both less than 65536.
5462          * Hopefully, it should be true in any UNIXs.
5463          * So it's ok to combine client and context into one uint32. */
5464         m_send_trans.put_data (get_helper_ic (client, context));
5465         m_send_trans.put_data (uuid);
5466         m_send_trans.put_command (SCIM_TRANS_CMD_UPDATE_SCREEN);
5467         m_send_trans.put_data ((uint32) screen);
5468
5469         for (; hiit != m_helper_info_repository.end (); ++ hiit) {
5470             if (hiit->second.option & SCIM_HELPER_NEED_SCREEN_INFO) {
5471                 Socket client_socket (hiit->first);
5472                 m_send_trans.write_to_socket (client_socket);
5473             }
5474         }
5475
5476         unlock ();
5477     }
5478
5479     const String & get_focused_context (int &client, uint32 &context, bool force_last_context = false) const
5480     {
5481         if (m_current_socket_client >= 0) {
5482             client  = m_current_socket_client;
5483             context = m_current_client_context;
5484             return m_current_context_uuid;
5485         } else {
5486             client  = m_last_socket_client;
5487             context = m_last_client_context;
5488             return m_last_context_uuid;
5489         }
5490     }
5491
5492 private:
5493     void socket_transaction_start (void)
5494     {
5495         m_signal_transaction_start ();
5496     }
5497
5498     void socket_transaction_end (void)
5499     {
5500         m_signal_transaction_end ();
5501     }
5502
5503     void lock (void)
5504     {
5505         m_signal_lock ();
5506     }
5507     void unlock (void)
5508     {
5509         m_signal_unlock ();
5510     }
5511 };
5512
5513 PanelAgent::PanelAgent ()
5514     : m_impl (new PanelAgentImpl ())
5515 {
5516 }
5517
5518 PanelAgent::~PanelAgent ()
5519 {
5520     delete m_impl;
5521 }
5522
5523 bool
5524 PanelAgent::initialize (const String &config, const String &display, bool resident)
5525 {
5526     return m_impl->initialize (config, display, resident);
5527 }
5528
5529 bool
5530 PanelAgent::valid (void) const
5531 {
5532     return m_impl->valid ();
5533 }
5534
5535 bool
5536 PanelAgent::run (void)
5537 {
5538     return m_impl->run ();
5539 }
5540
5541 void
5542 PanelAgent::stop (void)
5543 {
5544     if (m_impl != NULL)
5545         m_impl->stop ();
5546 }
5547
5548 int
5549 PanelAgent::get_helper_list (std::vector <HelperInfo> & helpers) const
5550 {
5551     return m_impl->get_helper_list (helpers);
5552 }
5553
5554 void PanelAgent::hide_helper (const String &uuid)
5555 {
5556     m_impl->hide_helper (uuid);
5557 }
5558 TOOLBAR_MODE_T
5559 PanelAgent::get_current_toolbar_mode () const
5560 {
5561     return m_impl->get_current_toolbar_mode ();
5562 }
5563
5564 void
5565 PanelAgent::get_current_ise_geometry (rectinfo &rect)
5566 {
5567     m_impl->get_current_ise_geometry (rect);
5568 }
5569
5570 String
5571 PanelAgent::get_current_helper_uuid () const
5572 {
5573     return m_impl->get_current_helper_uuid ();
5574 }
5575
5576 String
5577 PanelAgent::get_current_helper_name () const
5578 {
5579     return m_impl->get_current_helper_name ();
5580 }
5581
5582 String
5583 PanelAgent::get_current_factory_icon () const
5584 {
5585     return m_impl->get_current_factory_icon ();
5586 }
5587
5588 String
5589 PanelAgent::get_current_ise_name () const
5590 {
5591     return m_impl->get_current_ise_name ();
5592 }
5593
5594 void
5595 PanelAgent::set_current_toolbar_mode (TOOLBAR_MODE_T mode)
5596 {
5597     m_impl->set_current_toolbar_mode (mode);
5598 }
5599
5600 void
5601 PanelAgent::set_current_ise_name (String &name)
5602 {
5603     m_impl->set_current_ise_name (name);
5604 }
5605
5606 void
5607 PanelAgent::set_current_ise_style (uint32 &style)
5608 {
5609     m_impl->set_current_ise_style (style);
5610 }
5611
5612 void
5613 PanelAgent::update_ise_name (String &name)
5614 {
5615     m_impl->update_ise_name (name);
5616 }
5617
5618 void
5619 PanelAgent::update_ise_style (uint32 &style)
5620 {
5621     m_impl->update_ise_style (style);
5622 }
5623
5624 void
5625 PanelAgent::update_candidate_panel_event (uint32 nType, uint32 nValue)
5626 {
5627     m_impl->update_panel_event (ISM_TRANS_CMD_UPDATE_ISF_CANDIDATE_PANEL, nType, nValue);
5628 }
5629
5630 void
5631 PanelAgent::update_input_panel_event (uint32 nType, uint32 nValue)
5632 {
5633     m_impl->update_panel_event (ISM_TRANS_CMD_UPDATE_ISE_INPUT_CONTEXT, nType, nValue);
5634 }
5635
5636 void
5637 PanelAgent::set_current_factory_icon (String &icon)
5638 {
5639     m_impl->set_current_factory_icon (icon);
5640 }
5641
5642 bool
5643 PanelAgent::move_preedit_caret             (uint32         position)
5644 {
5645     return m_impl->move_preedit_caret (position);
5646 }
5647
5648 bool
5649 PanelAgent::request_help                   (void)
5650 {
5651     return m_impl->request_help ();
5652 }
5653
5654 bool
5655 PanelAgent::request_factory_menu           (void)
5656 {
5657     return m_impl->request_factory_menu ();
5658 }
5659
5660 bool
5661 PanelAgent::change_factory                 (const String  &uuid)
5662 {
5663     return m_impl->change_factory (uuid);
5664 }
5665
5666 bool
5667 PanelAgent::candidate_more_window_show     (void)
5668 {
5669     return m_impl->candidate_more_window_show ();
5670 }
5671
5672 bool
5673 PanelAgent::candidate_more_window_hide     (void)
5674 {
5675     return m_impl->candidate_more_window_hide ();
5676 }
5677
5678 bool
5679 PanelAgent::select_aux                     (uint32         item)
5680 {
5681     return m_impl->select_aux (item);
5682 }
5683
5684 bool
5685 PanelAgent::select_candidate               (uint32         item)
5686 {
5687     return m_impl->select_candidate (item);
5688 }
5689
5690 bool
5691 PanelAgent::lookup_table_page_up           (void)
5692 {
5693     return m_impl->lookup_table_page_up ();
5694 }
5695
5696 bool
5697 PanelAgent::lookup_table_page_down         (void)
5698 {
5699     return m_impl->lookup_table_page_down ();
5700 }
5701
5702 bool
5703 PanelAgent::update_lookup_table_page_size  (uint32         size)
5704 {
5705     return m_impl->update_lookup_table_page_size (size);
5706 }
5707
5708 bool
5709 PanelAgent::select_associate               (uint32         item)
5710 {
5711     return m_impl->select_associate (item);
5712 }
5713
5714 bool
5715 PanelAgent::associate_table_page_up        (void)
5716 {
5717     return m_impl->associate_table_page_up ();
5718 }
5719
5720 bool
5721 PanelAgent::associate_table_page_down      (void)
5722 {
5723     return m_impl->associate_table_page_down ();
5724 }
5725
5726 bool
5727 PanelAgent::update_associate_table_page_size (uint32         size)
5728 {
5729     return m_impl->update_associate_table_page_size (size);
5730 }
5731
5732 bool
5733 PanelAgent::update_displayed_candidate_number (uint32        size)
5734 {
5735     return m_impl->update_displayed_candidate_number (size);
5736 }
5737
5738 bool
5739 PanelAgent::trigger_property               (const String  &property)
5740 {
5741     return m_impl->trigger_property (property);
5742 }
5743
5744 bool
5745 PanelAgent::trigger_helper_property        (int            client,
5746                                             const String  &property)
5747 {
5748     return m_impl->trigger_helper_property (client, property);
5749 }
5750
5751 bool
5752 PanelAgent::start_helper                   (const String  &uuid)
5753 {
5754     return m_impl->start_helper (uuid, -2, 0);
5755 }
5756
5757 bool
5758 PanelAgent::stop_helper                    (const String  &uuid)
5759 {
5760     return m_impl->stop_helper (uuid, -2, 0);
5761 }
5762
5763 void
5764 PanelAgent::set_default_ise                (const DEFAULT_ISE_T  &ise)
5765 {
5766     m_impl->set_default_ise (ise);
5767 }
5768
5769 void
5770 PanelAgent::set_should_shared_ise          (const bool should_shared_ise)
5771 {
5772     m_impl->set_should_shared_ise (should_shared_ise);
5773 }
5774
5775 bool
5776 PanelAgent::reset_keyboard_ise             () const
5777 {
5778     return m_impl->reset_keyboard_ise ();
5779 }
5780
5781 int
5782 PanelAgent::get_active_ise_list            (std::vector<String> &strlist)
5783 {
5784     return m_impl->get_active_ise_list (strlist);
5785 }
5786
5787 int
5788 PanelAgent::get_helper_manager_id          (void)
5789 {
5790     return m_impl->get_helper_manager_id ();
5791 }
5792
5793 bool
5794 PanelAgent::has_helper_manager_pending_event (void)
5795 {
5796     return m_impl->has_helper_manager_pending_event ();
5797 }
5798
5799 bool
5800 PanelAgent::filter_helper_manager_event    (void)
5801 {
5802     return m_impl->filter_helper_manager_event ();
5803 }
5804
5805 void
5806 PanelAgent::update_isf_control_status      (const bool showed)
5807 {
5808    m_impl->update_isf_control_status (showed);
5809 }
5810
5811 int
5812 PanelAgent::send_display_name              (String &name)
5813 {
5814     return m_impl->send_display_name (name);
5815 }
5816
5817 bool
5818 PanelAgent::reload_config                  (void)
5819 {
5820     return m_impl->reload_config ();
5821 }
5822
5823 bool
5824 PanelAgent::exit                           (void)
5825 {
5826     return m_impl->exit ();
5827 }
5828
5829 bool
5830 PanelAgent::filter_event (int fd)
5831 {
5832     return m_impl->filter_event (fd);
5833 }
5834
5835 bool
5836 PanelAgent::filter_exception_event (int fd)
5837 {
5838     return m_impl->filter_exception_event (fd);
5839 }
5840
5841 int
5842 PanelAgent::get_server_id (void)
5843 {
5844     return m_impl->get_server_id ();
5845 }
5846
5847 void
5848 PanelAgent::update_ise_list (std::vector<String> &strList)
5849 {
5850     m_impl->update_ise_list (strList);
5851 }
5852
5853 void
5854 PanelAgent::set_ise_changing (bool changing)
5855 {
5856     m_impl->set_ise_changing (changing);
5857 }
5858
5859 Connection
5860 PanelAgent::signal_connect_reload_config              (PanelAgentSlotVoid                *slot)
5861 {
5862     return m_impl->signal_connect_reload_config (slot);
5863 }
5864
5865 Connection
5866 PanelAgent::signal_connect_turn_on                    (PanelAgentSlotVoid                *slot)
5867 {
5868     return m_impl->signal_connect_turn_on (slot);
5869 }
5870
5871 Connection
5872 PanelAgent::signal_connect_turn_off                   (PanelAgentSlotVoid                *slot)
5873 {
5874     return m_impl->signal_connect_turn_off (slot);
5875 }
5876
5877 Connection
5878 PanelAgent::signal_connect_show_panel                 (PanelAgentSlotVoid                *slot)
5879 {
5880     return m_impl->signal_connect_show_panel (slot);
5881 }
5882
5883 Connection
5884 PanelAgent::signal_connect_hide_panel                 (PanelAgentSlotVoid                *slot)
5885 {
5886     return m_impl->signal_connect_hide_panel (slot);
5887 }
5888
5889 Connection
5890 PanelAgent::signal_connect_update_screen              (PanelAgentSlotInt                 *slot)
5891 {
5892     return m_impl->signal_connect_update_screen (slot);
5893 }
5894
5895 Connection
5896 PanelAgent::signal_connect_update_spot_location       (PanelAgentSlotIntIntInt           *slot)
5897 {
5898     return m_impl->signal_connect_update_spot_location (slot);
5899 }
5900
5901 Connection
5902 PanelAgent::signal_connect_update_factory_info        (PanelAgentSlotFactoryInfo         *slot)
5903 {
5904     return m_impl->signal_connect_update_factory_info (slot);
5905 }
5906
5907 Connection
5908 PanelAgent::signal_connect_start_default_ise          (PanelAgentSlotVoid                *slot)
5909 {
5910     return m_impl->signal_connect_start_default_ise (slot);
5911 }
5912
5913 Connection
5914 PanelAgent::signal_connect_set_candidate_ui           (PanelAgentSlotIntInt              *slot)
5915 {
5916     return m_impl->signal_connect_set_candidate_ui (slot);
5917 }
5918
5919 Connection
5920 PanelAgent::signal_connect_get_candidate_ui           (PanelAgentSlotIntInt2             *slot)
5921 {
5922     return m_impl->signal_connect_get_candidate_ui (slot);
5923 }
5924
5925 Connection
5926 PanelAgent::signal_connect_set_candidate_position     (PanelAgentSlotIntInt              *slot)
5927 {
5928     return m_impl->signal_connect_set_candidate_position (slot);
5929 }
5930
5931 Connection
5932 PanelAgent::signal_connect_get_candidate_geometry     (PanelAgentSlotRect                *slot)
5933 {
5934     return m_impl->signal_connect_get_candidate_geometry (slot);
5935 }
5936
5937 Connection
5938 PanelAgent::signal_connect_get_input_panel_geometry   (PanelAgentSlotRect                *slot)
5939 {
5940     return m_impl->signal_connect_get_input_panel_geometry (slot);
5941 }
5942
5943 Connection
5944 PanelAgent::signal_connect_set_keyboard_ise           (PanelAgentSlotIntString           *slot)
5945 {
5946     return m_impl->signal_connect_set_keyboard_ise (slot);
5947 }
5948
5949 Connection
5950 PanelAgent::signal_connect_get_keyboard_ise           (PanelAgentSlotString2             *slot)
5951 {
5952     return m_impl->signal_connect_get_keyboard_ise (slot);
5953 }
5954
5955 Connection
5956 PanelAgent::signal_connect_show_help                  (PanelAgentSlotString              *slot)
5957 {
5958     return m_impl->signal_connect_show_help (slot);
5959 }
5960
5961 Connection
5962 PanelAgent::signal_connect_show_factory_menu          (PanelAgentSlotFactoryInfoVector   *slot)
5963 {
5964     return m_impl->signal_connect_show_factory_menu (slot);
5965 }
5966
5967 Connection
5968 PanelAgent::signal_connect_show_preedit_string        (PanelAgentSlotVoid                *slot)
5969 {
5970     return m_impl->signal_connect_show_preedit_string (slot);
5971 }
5972
5973 Connection
5974 PanelAgent::signal_connect_show_aux_string            (PanelAgentSlotVoid                *slot)
5975 {
5976     return m_impl->signal_connect_show_aux_string (slot);
5977 }
5978
5979 Connection
5980 PanelAgent::signal_connect_show_lookup_table          (PanelAgentSlotVoid                *slot)
5981 {
5982     return m_impl->signal_connect_show_lookup_table (slot);
5983 }
5984
5985 Connection
5986 PanelAgent::signal_connect_show_associate_table       (PanelAgentSlotVoid                *slot)
5987 {
5988     return m_impl->signal_connect_show_associate_table (slot);
5989 }
5990
5991 Connection
5992 PanelAgent::signal_connect_hide_preedit_string        (PanelAgentSlotVoid                *slot)
5993 {
5994     return m_impl->signal_connect_hide_preedit_string (slot);
5995 }
5996
5997 Connection
5998 PanelAgent::signal_connect_hide_aux_string            (PanelAgentSlotVoid                *slot)
5999 {
6000     return m_impl->signal_connect_hide_aux_string (slot);
6001 }
6002
6003 Connection
6004 PanelAgent::signal_connect_hide_lookup_table          (PanelAgentSlotVoid                *slot)
6005 {
6006     return m_impl->signal_connect_hide_lookup_table (slot);
6007 }
6008
6009 Connection
6010 PanelAgent::signal_connect_hide_associate_table       (PanelAgentSlotVoid                *slot)
6011 {
6012     return m_impl->signal_connect_hide_associate_table (slot);
6013 }
6014
6015 Connection
6016 PanelAgent::signal_connect_update_preedit_string      (PanelAgentSlotAttributeString     *slot)
6017 {
6018     return m_impl->signal_connect_update_preedit_string (slot);
6019 }
6020
6021 Connection
6022 PanelAgent::signal_connect_update_preedit_caret       (PanelAgentSlotInt                 *slot)
6023 {
6024     return m_impl->signal_connect_update_preedit_caret (slot);
6025 }
6026
6027 Connection
6028 PanelAgent::signal_connect_update_aux_string          (PanelAgentSlotAttributeString     *slot)
6029 {
6030     return m_impl->signal_connect_update_aux_string (slot);
6031 }
6032
6033 Connection
6034 PanelAgent::signal_connect_update_lookup_table        (PanelAgentSlotLookupTable         *slot)
6035 {
6036     return m_impl->signal_connect_update_lookup_table (slot);
6037 }
6038
6039 Connection
6040 PanelAgent::signal_connect_update_associate_table     (PanelAgentSlotLookupTable         *slot)
6041 {
6042     return m_impl->signal_connect_update_associate_table (slot);
6043 }
6044
6045 Connection
6046 PanelAgent::signal_connect_register_properties        (PanelAgentSlotPropertyList        *slot)
6047 {
6048     return m_impl->signal_connect_register_properties (slot);
6049 }
6050
6051 Connection
6052 PanelAgent::signal_connect_update_property            (PanelAgentSlotProperty            *slot)
6053 {
6054     return m_impl->signal_connect_update_property (slot);
6055 }
6056
6057 Connection
6058 PanelAgent::signal_connect_register_helper_properties (PanelAgentSlotIntPropertyList     *slot)
6059 {
6060     return m_impl->signal_connect_register_helper_properties (slot);
6061 }
6062
6063 Connection
6064 PanelAgent::signal_connect_update_helper_property     (PanelAgentSlotIntProperty         *slot)
6065 {
6066     return m_impl->signal_connect_update_helper_property (slot);
6067 }
6068
6069 Connection
6070 PanelAgent::signal_connect_register_helper            (PanelAgentSlotIntHelperInfo       *slot)
6071 {
6072     return m_impl->signal_connect_register_helper (slot);
6073 }
6074
6075 Connection
6076 PanelAgent::signal_connect_remove_helper              (PanelAgentSlotInt                 *slot)
6077 {
6078     return m_impl->signal_connect_remove_helper (slot);
6079 }
6080
6081 Connection
6082 PanelAgent::signal_connect_set_active_ise_by_uuid     (PanelAgentSlotStringBool              *slot)
6083 {
6084     return m_impl->signal_connect_set_active_ise_by_uuid (slot);
6085 }
6086
6087 Connection
6088 PanelAgent::signal_connect_set_active_ise_by_name     (PanelAgentSlotString              *slot)
6089 {
6090     return m_impl->signal_connect_set_active_ise_by_name (slot);
6091 }
6092
6093 Connection
6094 PanelAgent::signal_connect_focus_in                   (PanelAgentSlotVoid                *slot)
6095 {
6096     return m_impl->signal_connect_focus_in (slot);
6097 }
6098
6099 Connection
6100 PanelAgent::signal_connect_focus_out                  (PanelAgentSlotVoid                *slot)
6101 {
6102     return m_impl->signal_connect_focus_out (slot);
6103 }
6104
6105 Connection
6106 PanelAgent::signal_connect_expand_candidate           (PanelAgentSlotVoid                *slot)
6107 {
6108     return m_impl->signal_connect_expand_candidate (slot);
6109 }
6110
6111 Connection
6112 PanelAgent::signal_connect_contract_candidate         (PanelAgentSlotVoid                *slot)
6113 {
6114     return m_impl->signal_connect_contract_candidate (slot);
6115 }
6116
6117 Connection
6118 PanelAgent::signal_connect_get_ise_list               (PanelAgentSlotBoolStringVector    *slot)
6119 {
6120     return m_impl->signal_connect_get_ise_list (slot);
6121 }
6122
6123 Connection
6124 PanelAgent::signal_connect_get_keyboard_ise_list      (PanelAgentSlotBoolStringVector    *slot)
6125 {
6126     return m_impl->signal_connect_get_keyboard_ise_list (slot);
6127 }
6128
6129 Connection
6130 PanelAgent::signal_connect_update_ise_geometry        (PanelAgentSlotIntIntIntInt        *slot)
6131 {
6132     return m_impl->signal_connect_update_ise_geometry (slot);
6133 }
6134
6135 Connection
6136 PanelAgent::signal_connect_get_language_list          (PanelAgentSlotStringVector        *slot)
6137 {
6138     return m_impl->signal_connect_get_language_list (slot);
6139 }
6140
6141 Connection
6142 PanelAgent::signal_connect_get_all_language           (PanelAgentSlotStringVector        *slot)
6143 {
6144     return m_impl->signal_connect_get_all_language (slot);
6145 }
6146
6147 Connection
6148 PanelAgent::signal_connect_get_ise_language           (PanelAgentSlotStrStringVector     *slot)
6149 {
6150     return m_impl->signal_connect_get_ise_language (slot);
6151 }
6152
6153 Connection
6154 PanelAgent::signal_connect_set_isf_language           (PanelAgentSlotString              *slot)
6155 {
6156     return m_impl->signal_connect_set_isf_language (slot);
6157 }
6158
6159 Connection
6160 PanelAgent::signal_connect_get_ise_info_by_uuid       (PanelAgentSlotStringISEINFO       *slot)
6161 {
6162     return m_impl->signal_connect_get_ise_info_by_uuid (slot);
6163 }
6164
6165 Connection
6166 PanelAgent::signal_connect_get_ise_info_by_name       (PanelAgentSlotStringISEINFO       *slot)
6167 {
6168     return m_impl->signal_connect_get_ise_info_by_name (slot);
6169 }
6170
6171 Connection
6172 PanelAgent::signal_connect_send_key_event             (PanelAgentSlotKeyEvent            *slot)
6173 {
6174     return m_impl->signal_connect_send_key_event (slot);
6175 }
6176
6177 Connection
6178 PanelAgent::signal_connect_accept_connection          (PanelAgentSlotInt                 *slot)
6179 {
6180     return m_impl->signal_connect_accept_connection (slot);
6181 }
6182
6183 Connection
6184 PanelAgent::signal_connect_close_connection           (PanelAgentSlotInt                 *slot)
6185 {
6186     return m_impl->signal_connect_close_connection (slot);
6187 }
6188
6189 Connection
6190 PanelAgent::signal_connect_exit                       (PanelAgentSlotVoid                *slot)
6191 {
6192     return m_impl->signal_connect_exit (slot);
6193 }
6194
6195 Connection
6196 PanelAgent::signal_connect_transaction_start          (PanelAgentSlotVoid                *slot)
6197 {
6198     return m_impl->signal_connect_transaction_start (slot);
6199 }
6200
6201 Connection
6202 PanelAgent::signal_connect_transaction_end            (PanelAgentSlotVoid                *slot)
6203 {
6204     return m_impl->signal_connect_transaction_end (slot);
6205 }
6206
6207 Connection
6208 PanelAgent::signal_connect_lock                       (PanelAgentSlotVoid                *slot)
6209 {
6210     return m_impl->signal_connect_lock (slot);
6211 }
6212
6213 Connection
6214 PanelAgent::signal_connect_unlock                     (PanelAgentSlotVoid                *slot)
6215 {
6216     return m_impl->signal_connect_unlock (slot);
6217 }
6218
6219 Connection
6220 PanelAgent::signal_connect_update_input_context       (PanelAgentSlotIntInt              *slot)
6221 {
6222     return m_impl->signal_connect_update_input_context (slot);
6223 }
6224
6225 } /* namespace scim */
6226
6227 /*
6228 vi:ts=4:nowrap:ai:expandtab
6229 */
6230