1 /** @file scim_socket_imengine.cpp
2 * implementation of class SocketFactory and SocketInstance.
5 /* ISF is based on SCIM 1.4.7 and extended for supporting more mobile fitable. */
8 * Smart Common Input Method
10 * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn>
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.
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.
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
28 * $Id: scim_socket_imengine.cpp,v 1.21 2005/07/06 03:57:04 suzhe Exp $
32 #define Uses_SCIM_IMENGINE
33 #define Uses_SCIM_CONFIG_BASE
34 #define Uses_SCIM_CONFIG_PATH
35 #define Uses_SCIM_SOCKET
36 #define Uses_SCIM_TRANSACTION
38 #define Uses_SCIM_PANEL_AGENT
43 #include "scim_private.h"
45 #include "scim_socket_imengine.h"
46 #include "scim_stl_map.h"
47 #include "isf_query_utility.h"
50 #define scim_module_init socket_LTX_scim_module_init
51 #define scim_module_exit socket_LTX_scim_module_exit
52 #define scim_imengine_module_init socket_LTX_scim_imengine_module_init
53 #define scim_imengine_module_create_factory socket_LTX_scim_imengine_module_create_factory
55 #define SCIM_CONFIG_IMENGINE_SOCKET_TIMEOUT "/IMEngine/Socket/Timeout"
56 #define SCIM_CONFIG_IMENGINE_SOCKET_ADDRESS "/IMEngine/Socket/Address"
58 #define SCIM_SOCKET_FRONTEND_DEF_ADDRESS "local:/tmp/scim-socket-frontend"
61 #define SCIM_TEMPDIR "/tmp"
67 class scim::SocketIMEngineGlobal
69 #if SCIM_USE_STL_EXT_HASH_MAP
70 typedef __gnu_cxx::hash_map <String, String, scim_hash_string> IconRepository;
71 #elif SCIM_USE_STL_HASH_MAP
72 typedef std::hash_map <String, String, scim_hash_string> IconRepository;
74 typedef std::map <String, String> IconRepository;
77 SocketClient m_socket_client;
78 SocketAddress m_socket_address;
79 uint32 m_socket_magic_key;
82 std::vector<String> m_peer_factories;
84 IconRepository m_icon_repository;
86 Signal0<void> m_signal_reconnect;
89 SocketIMEngineGlobal ();
90 ~SocketIMEngineGlobal ();
92 bool create_connection ();
93 unsigned int number_of_factories ();
94 SocketFactory * create_factory (unsigned int index);
96 void init_transaction (Transaction &trans);
97 bool send_transaction (Transaction &trans);
98 bool receive_transaction (Transaction &trans);
100 void get_ise_info_map (const char *filename);
101 String load_icon (const String &icon);
103 Connection connect_reconnect_signal (Slot0<void> *slot_reconnect);
109 void destroy_all_icons ();
112 static SocketIMEngineGlobal *global = 0;
113 static std::map<String, ISEINFO> ise_info_repository;
116 void scim_module_init (void)
119 global = new SocketIMEngineGlobal;
122 void scim_module_exit (void)
130 unsigned int scim_imengine_module_init (const ConfigPointer &config)
133 return global->number_of_factories ();
137 IMEngineFactoryPointer scim_imengine_module_create_factory (unsigned int index)
142 SocketFactory *sf = global->create_factory (index);
144 if (!sf || !sf->valid ()) {
155 SocketIMEngineGlobal::SocketIMEngineGlobal ()
156 : m_socket_magic_key (0),
157 m_socket_timeout (-1)
162 SocketIMEngineGlobal::~SocketIMEngineGlobal ()
168 SocketIMEngineGlobal::init ()
170 SCIM_DEBUG_IMENGINE(1) << "Init SocketIMEngine Global.\n";
172 String address = scim_get_default_socket_imengine_address ();
174 m_socket_timeout = scim_get_default_socket_timeout ();
175 m_socket_address.set_address (address);
177 if (!m_socket_address.valid ())
180 // Connect to SocketFrontEnd.
181 if (!create_connection ()) {
182 SCIM_DEBUG_IMENGINE(2) << " Cannot connect to SocketFrontEnd (" << address << ").\n";
186 SCIM_DEBUG_IMENGINE(2) << " Connected to SocketFrontEnd (" << address
187 << ") MagicKey (" << m_socket_magic_key << ").\n";
189 // Get IMEngineFactory list.
190 String user_file_name = String (USER_ENGINE_FILE_NAME);
192 ise_info_repository.clear ();
193 m_peer_factories.clear ();
194 get_ise_info_map (user_file_name.c_str ());
198 SocketIMEngineGlobal::create_connection ()
200 SCIM_DEBUG_IMENGINE(1) << __FUNCTION__ << "...\n";
202 // Connect to SocketFrontEnd.
203 if (!m_socket_client.connect (m_socket_address))
206 if (!scim_socket_open_connection (m_socket_magic_key,
207 String ("SocketIMEngine"),
208 String ("SocketFrontEnd"),
211 m_socket_client.close ();
215 m_signal_reconnect.emit ();
221 SocketIMEngineGlobal::destroy ()
223 SCIM_DEBUG_IMENGINE(1) << "Destroy SocketIMEngine Global.\n";
225 m_socket_client.close ();
227 destroy_all_icons ();
231 SocketIMEngineGlobal::number_of_factories ()
233 return m_peer_factories.size ();
237 SocketIMEngineGlobal::create_factory (unsigned int index)
239 if (index < m_peer_factories.size ()) {
240 return new SocketFactory (m_peer_factories [index]);
246 SocketIMEngineGlobal::init_transaction (Transaction &trans)
249 trans.put_command (SCIM_TRANS_CMD_REQUEST);
250 trans.put_data (m_socket_magic_key);
254 SocketIMEngineGlobal::send_transaction (Transaction &trans)
256 return trans.write_to_socket (m_socket_client);
260 SocketIMEngineGlobal::receive_transaction (Transaction &trans)
262 return trans.read_from_socket (m_socket_client, m_socket_timeout);
266 SocketIMEngineGlobal::get_ise_info_map (const char *filename)
268 FILE *engine_list_file = fopen (filename, "r");
269 if (engine_list_file == NULL) {
270 std::cerr << "failed to open " << filename << "\n";
276 while (fgets (buf, MAXLINE, engine_list_file) != NULL && strlen (buf) > 0) {
278 isf_get_ise_info_from_string (buf, info);
280 if (info.mode == TOOLBAR_KEYBOARD_MODE) {
281 m_peer_factories.push_back (info.uuid);
282 ise_info_repository[info.uuid] = info;
286 fclose (engine_list_file);
291 SocketIMEngineGlobal::load_icon (const String &icon)
293 String local_icon = icon;
295 IconRepository::const_iterator it = m_icon_repository.find (icon);
297 // The icon has been loaded, just return the local copy filename.
298 if (it != m_icon_repository.end ())
299 local_icon = it->second;
301 // This icon is already available in local system, just return.
302 if (scim_load_file (local_icon, 0) != 0)
310 local_icon = String ("");
312 init_transaction (trans);
313 trans.put_command (SCIM_TRANS_CMD_LOAD_FILE);
314 trans.put_data (icon);
316 // Load icon file from remote SocketFrontEnd.
317 if (send_transaction (trans) && receive_transaction (trans) &&
318 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
319 trans.get_data (&bufptr, filesize) &&
320 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {
323 String::size_type pos = icon.rfind (SCIM_PATH_DELIM);
325 if (pos != String::npos) {
326 tempfile = icon.substr (pos + 1, String::npos);
332 snprintf (tmp, 80, "%lu", (unsigned long) m_socket_magic_key);
334 tempfile = String (SCIM_TEMPDIR) + String (SCIM_PATH_DELIM_STRING) +
335 String ("scim-") + String (tmp) + String ("-") +
338 SCIM_DEBUG_IMENGINE(1) << "Creating temporary icon file: " << tempfile << "\n";
340 std::ofstream os (tempfile.c_str ());
343 os.write (bufptr, filesize);
346 // Check if the file is written correctly.
347 if (scim_load_file (tempfile, 0) == filesize) {
348 m_icon_repository [icon] = tempfile;
349 local_icon = tempfile;
351 unlink (tempfile.c_str ());
362 SocketIMEngineGlobal::connect_reconnect_signal (Slot0<void> *slot_reconnect)
364 return m_signal_reconnect.connect (slot_reconnect);
368 SocketIMEngineGlobal::destroy_all_icons ()
370 IconRepository::const_iterator it = m_icon_repository.begin ();
372 for (; it != m_icon_repository.end (); ++ it) {
373 unlink (it->second.c_str ());
376 m_icon_repository.clear ();
380 SocketFactory::create_peer_instance (const String &encoding)
387 SCIM_DEBUG_IMENGINE(1) << "Create IMEngine Instance " << m_peer_uuid << ".\n";
389 global->init_transaction (trans);
390 trans.put_command (SCIM_TRANS_CMD_NEW_INSTANCE);
391 trans.put_data (m_peer_uuid);
392 trans.put_data (encoding);
393 if (global->send_transaction (trans)) {
394 if (global->receive_transaction (trans) &&
395 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
396 trans.get_data (val) &&
397 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK) {
399 si_peer_id = (int) val;
403 SCIM_DEBUG_IMENGINE(2) << " IMEngineInstance created (" << si_peer_id << ")\n";
408 SocketFactory::SocketFactory (const String &peer_uuid)
409 : m_name (utf8_mbstowcs (_("Unknown"))),
410 m_language (String ("")),
411 m_peer_uuid (peer_uuid),
412 m_icon_file (String ("")),
419 SCIM_DEBUG_IMENGINE(1) << "Create SocketFactory " << peer_uuid << ".\n";
421 // Get factory name, locales, language and icon file.
422 std::map<String, ISEINFO>::iterator iter;
423 iter = ise_info_repository.find (m_peer_uuid);
424 if (iter != ise_info_repository.end ()) {
425 m_name = utf8_mbstowcs (iter->second.name);
426 set_locales (iter->second.locales);
427 m_language = iter->second.language;
428 //m_icon_file = global->load_icon (iter->second.icon);
435 SocketFactory::~SocketFactory ()
440 SocketFactory::get_name () const
446 SocketFactory::get_authors () const
452 SCIM_DEBUG_IMENGINE(1) << "Get Authors " << m_peer_uuid << ".\n";
454 // Get factory authors.
455 for (int retry = 0; retry < 3; ++retry) {
456 global->init_transaction (trans);
457 trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_AUTHORS);
458 trans.put_data (m_peer_uuid);
460 if (global->send_transaction (trans) && global->receive_transaction (trans) &&
461 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
462 trans.get_data (authors) &&
463 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK)
466 authors = utf8_mbstowcs (_("Unknown"));
468 if (!global->create_connection ())
476 SocketFactory::get_credits () const
482 SCIM_DEBUG_IMENGINE(1) << "Get Credits " << m_peer_uuid << ".\n";
484 // Get factory credits.
485 for (int retry = 0; retry < 3; ++retry) {
486 global->init_transaction (trans);
487 trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_CREDITS);
488 trans.put_data (m_peer_uuid);
490 if (global->send_transaction (trans) && global->receive_transaction (trans) &&
491 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
492 trans.get_data (credits) &&
493 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK)
496 credits = utf8_mbstowcs (_("Unknown"));
498 if (!global->create_connection ())
506 SocketFactory::get_help () const
512 SCIM_DEBUG_IMENGINE(1) << "Get Help " << m_peer_uuid << ".\n";
515 for (int retry = 0; retry < 3; ++retry) {
516 global->init_transaction (trans);
517 trans.put_command (SCIM_TRANS_CMD_GET_FACTORY_HELP);
518 trans.put_data (m_peer_uuid);
520 if (global->send_transaction (trans) && global->receive_transaction (trans) &&
521 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY &&
522 trans.get_data (help) &&
523 trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_OK)
526 help = utf8_mbstowcs (_("Unknown"));
528 if (!global->create_connection ())
536 SocketFactory::get_uuid () const
542 SocketFactory::get_icon_file () const
548 SocketFactory::get_language () const
550 if (m_language.length ())
553 return IMEngineFactoryBase::get_language ();
556 IMEngineInstancePointer
557 SocketFactory::create_instance (const String& encoding, int id)
559 int si_peer_id = create_peer_instance (encoding);
561 SCIM_DEBUG_IMENGINE(2) << " IMEngineInstance created (" << si_peer_id << ")\n";
563 return new SocketInstance (this, encoding, id, si_peer_id);
566 SocketInstance::SocketInstance (SocketFactory *factory,
567 const String& encoding,
570 : IMEngineInstanceBase (factory, encoding, id),
574 m_signal_reconnect_connection = global->connect_reconnect_signal (slot (this, &SocketInstance::reconnect_callback));
577 SocketInstance::~SocketInstance ()
581 SCIM_DEBUG_IMENGINE(1) << "Destroy IMEngine Instance " << m_peer_id << ".\n";
583 m_signal_reconnect_connection.disconnect ();
585 if (m_peer_id >= 0) {
586 global->init_transaction (trans);
588 trans.put_command (SCIM_TRANS_CMD_DELETE_INSTANCE);
589 trans.put_data (m_peer_id);
591 commit_transaction (trans);
596 SocketInstance::process_key_event (const KeyEvent& key)
600 global->init_transaction (trans);
602 SCIM_DEBUG_IMENGINE(1) << "process_key_event (" << m_peer_id << ")\n";
604 trans.put_command (SCIM_TRANS_CMD_PROCESS_KEY_EVENT);
605 trans.put_data (m_peer_id);
606 trans.put_data (key);
608 return commit_transaction (trans);
612 SocketInstance::move_preedit_caret (unsigned int pos)
616 global->init_transaction (trans);
618 SCIM_DEBUG_IMENGINE(1) << "move_preedit_caret (" << m_peer_id << ")\n";
620 trans.put_command (SCIM_TRANS_CMD_MOVE_PREEDIT_CARET);
621 trans.put_data (m_peer_id);
622 trans.put_data ((uint32) pos);
624 commit_transaction (trans);
628 SocketInstance::select_aux (unsigned int item)
632 global->init_transaction (trans);
634 SCIM_DEBUG_IMENGINE(1) << "select_aux (" << m_peer_id << ")\n";
636 trans.put_command (ISM_TRANS_CMD_SELECT_AUX);
637 trans.put_data (m_peer_id);
638 trans.put_data ((uint32) item);
640 commit_transaction (trans);
644 SocketInstance::select_candidate (unsigned int item)
648 global->init_transaction (trans);
650 SCIM_DEBUG_IMENGINE(1) << "select_candidate (" << m_peer_id << ")\n";
652 trans.put_command (SCIM_TRANS_CMD_SELECT_CANDIDATE);
653 trans.put_data (m_peer_id);
654 trans.put_data ((uint32) item);
656 commit_transaction (trans);
660 SocketInstance::update_lookup_table_page_size (unsigned int page_size)
664 global->init_transaction (trans);
666 SCIM_DEBUG_IMENGINE(1) << "update_lookup_table_page_size (" << m_peer_id << ")\n";
668 trans.put_command (SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE_PAGE_SIZE);
669 trans.put_data (m_peer_id);
670 trans.put_data ((uint32) page_size);
672 commit_transaction (trans);
676 SocketInstance::lookup_table_page_up ()
680 global->init_transaction (trans);
682 SCIM_DEBUG_IMENGINE(1) << "lookup_table_page_up (" << m_peer_id << ")\n";
684 trans.put_command (SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_UP);
685 trans.put_data (m_peer_id);
687 commit_transaction (trans);
691 SocketInstance::lookup_table_page_down ()
695 global->init_transaction (trans);
697 SCIM_DEBUG_IMENGINE(1) << "lookup_table_page_up (" << m_peer_id << ")\n";
699 trans.put_command (SCIM_TRANS_CMD_LOOKUP_TABLE_PAGE_DOWN);
700 trans.put_data (m_peer_id);
702 commit_transaction (trans);
706 SocketInstance::reset_option ()
710 global->init_transaction (trans);
712 SCIM_DEBUG_IMENGINE(1) << "reset_option (" << m_peer_id << ")\n";
714 trans.put_command (ISM_TRANS_CMD_RESET_ISE_OPTION);
715 trans.put_data (m_peer_id);
717 commit_transaction (trans);
721 SocketInstance::reset ()
725 global->init_transaction (trans);
727 SCIM_DEBUG_IMENGINE(1) << "reset (" << m_peer_id << ")\n";
729 trans.put_command (SCIM_TRANS_CMD_RESET);
730 trans.put_data (m_peer_id);
732 commit_transaction (trans);
736 SocketInstance::focus_in ()
740 global->init_transaction (trans);
742 SCIM_DEBUG_IMENGINE(1) << "focus_in (" << m_peer_id << ")\n";
744 trans.put_command (SCIM_TRANS_CMD_FOCUS_IN);
745 trans.put_data (m_peer_id);
747 commit_transaction (trans);
751 SocketInstance::focus_out ()
755 global->init_transaction (trans);
757 SCIM_DEBUG_IMENGINE(1) << "focus_out (" << m_peer_id << ")\n";
759 trans.put_command (SCIM_TRANS_CMD_FOCUS_OUT);
760 trans.put_data (m_peer_id);
762 commit_transaction (trans);
766 SocketInstance::trigger_property (const String &property)
770 global->init_transaction (trans);
772 SCIM_DEBUG_IMENGINE(1) << "trigger_property (" << m_peer_id << ", " << property << ")\n";
774 trans.put_command (SCIM_TRANS_CMD_TRIGGER_PROPERTY);
775 trans.put_data (m_peer_id);
776 trans.put_data (property);
778 commit_transaction (trans);
782 SocketInstance::process_helper_event (const String &helper_uuid, const Transaction &helper_trans)
786 global->init_transaction (trans);
788 SCIM_DEBUG_IMENGINE(1) << "process_helper_event (" << m_peer_id << ", " << helper_uuid << ")\n";
790 trans.put_command (SCIM_TRANS_CMD_PROCESS_HELPER_EVENT);
791 trans.put_data (m_peer_id);
792 trans.put_data (helper_uuid);
793 trans.put_data (helper_trans);
795 commit_transaction (trans);
799 SocketInstance::update_client_capabilities (unsigned int cap)
803 global->init_transaction (trans);
805 SCIM_DEBUG_IMENGINE(1) << "update_client_capabilities (" << m_peer_id << ", " << cap << ")\n";
807 trans.put_command (SCIM_TRANS_CMD_UPDATE_CLIENT_CAPABILITIES);
808 trans.put_data (m_peer_id);
809 trans.put_data ((uint32) cap);
811 commit_transaction (trans);
815 SocketInstance::commit_transaction (Transaction &trans)
817 SCIM_DEBUG_IMENGINE(2) << " commit_transaction:\n";
821 if (m_peer_id >= 0) {
822 if (global->send_transaction (trans)) {
824 if (!global->receive_transaction (trans)) break;
825 if (!do_transaction (trans, ret)) return ret;
830 if (global->create_connection ())
837 SocketInstance::do_transaction (Transaction &trans, bool &ret)
844 SCIM_DEBUG_IMENGINE(2) << " Do transaction:\n";
846 if (trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY) {
847 while (trans.get_command (cmd)) {
849 case SCIM_TRANS_CMD_SHOW_PREEDIT_STRING:
851 SCIM_DEBUG_IMENGINE(3) << " show_preedit_string ()\n";
852 show_preedit_string ();
855 case SCIM_TRANS_CMD_SHOW_AUX_STRING:
857 SCIM_DEBUG_IMENGINE(3) << " show_aux_string ()\n";
861 case SCIM_TRANS_CMD_SHOW_LOOKUP_TABLE:
863 SCIM_DEBUG_IMENGINE(3) << " show_lookup_table ()\n";
864 show_lookup_table ();
867 case SCIM_TRANS_CMD_HIDE_PREEDIT_STRING:
869 SCIM_DEBUG_IMENGINE(3) << " hide_preedit_string ()\n";
870 hide_preedit_string ();
873 case SCIM_TRANS_CMD_HIDE_AUX_STRING:
875 SCIM_DEBUG_IMENGINE(3) << " hide_aux_string ()\n";
879 case SCIM_TRANS_CMD_HIDE_LOOKUP_TABLE:
881 SCIM_DEBUG_IMENGINE(3) << " hide_lookup_table ()\n";
882 hide_lookup_table ();
885 case SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET:
888 if (trans.get_data (caret)) {
889 SCIM_DEBUG_IMENGINE(3) << " update_preedit_caret (" << caret << ")\n";
890 update_preedit_caret (caret);
894 case SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING:
898 if (trans.get_data (str) && trans.get_data (attrs)) {
899 SCIM_DEBUG_IMENGINE(3) << " update_preedit_string ()\n";
900 update_preedit_string (str, attrs);
904 case SCIM_TRANS_CMD_UPDATE_AUX_STRING:
908 if (trans.get_data (str) && trans.get_data (attrs)) {
909 SCIM_DEBUG_IMENGINE(3) << " update_aux_string ()\n";
910 update_aux_string (str, attrs);
914 case SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE:
916 CommonLookupTable table;
917 if (trans.get_data (table)) {
918 SCIM_DEBUG_IMENGINE(3) << " update_lookup_table ()\n";
919 update_lookup_table (table);
923 case SCIM_TRANS_CMD_COMMIT_STRING:
926 if (trans.get_data (str)) {
927 SCIM_DEBUG_IMENGINE(3) << " commit_string ()\n";
932 case SCIM_TRANS_CMD_FORWARD_KEY_EVENT:
935 if (trans.get_data (key)) {
936 SCIM_DEBUG_IMENGINE(3) << " forward_key_event ()\n";
937 forward_key_event (key);
941 case SCIM_TRANS_CMD_REGISTER_PROPERTIES:
943 PropertyList proplist;
944 if (trans.get_data (proplist)) {
945 SCIM_DEBUG_IMENGINE(3) << " register_properties ()\n";
947 // Load icon files of these properties from remote SocketFrontEnd.
948 for (PropertyList::iterator it = proplist.begin (); it != proplist.end (); ++it)
949 it->set_icon (global->load_icon (it->get_icon ()));
951 register_properties (proplist);
955 case SCIM_TRANS_CMD_UPDATE_PROPERTY:
958 if (trans.get_data (prop)) {
959 SCIM_DEBUG_IMENGINE(3) << " update_property ()\n";
961 // Load the icon file of this property from remote SocketFrontEnd.
962 prop.set_icon (global->load_icon (prop.get_icon ()));
964 update_property (prop);
968 case SCIM_TRANS_CMD_BEEP:
970 SCIM_DEBUG_IMENGINE(3) << " beep ()\n";
974 case SCIM_TRANS_CMD_START_HELPER:
977 if (trans.get_data (helper_uuid)) {
978 SCIM_DEBUG_IMENGINE(3) << " start_helper (" << helper_uuid << ")\n";
979 start_helper (helper_uuid);
983 case SCIM_TRANS_CMD_STOP_HELPER:
986 if (trans.get_data (helper_uuid)) {
987 SCIM_DEBUG_IMENGINE(3) << " stop_helper (" << helper_uuid << ")\n";
988 stop_helper (helper_uuid);
992 case SCIM_TRANS_CMD_SEND_HELPER_EVENT:
995 Transaction temp_trans;
996 if (trans.get_data (helper_uuid) && trans.get_data (temp_trans)) {
997 SCIM_DEBUG_IMENGINE(3) << " send_helper_event (" << helper_uuid << ")\n";
998 send_helper_event (helper_uuid, temp_trans);
1002 case SCIM_TRANS_CMD_OK:
1004 SCIM_DEBUG_IMENGINE(3) << " ret = true\n";
1008 case SCIM_TRANS_CMD_GET_SURROUNDING_TEXT:
1012 uint32 maxlen_before;
1013 uint32 maxlen_after;
1014 Transaction temp_trans;
1015 if (trans.get_data (maxlen_before) && trans.get_data (maxlen_after)) {
1016 global->init_transaction (temp_trans);
1017 if (get_surrounding_text (text, cursor, (int) maxlen_before, (int) maxlen_after)) {
1018 temp_trans.put_command (SCIM_TRANS_CMD_GET_SURROUNDING_TEXT);
1019 temp_trans.put_data (text);
1020 temp_trans.put_data ((uint32) cursor);
1022 temp_trans.put_command (SCIM_TRANS_CMD_FAIL);
1024 if (!global->send_transaction (temp_trans))
1025 std::cerr << "GET_SURROUNDING_TEXT: global->send_transaction () is failed!!!\n";
1030 case SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT:
1034 Transaction temp_trans;
1035 if (trans.get_data (offset) && trans.get_data (len)) {
1036 global->init_transaction (temp_trans);
1037 if (delete_surrounding_text ((int) offset, (int) len)) {
1038 temp_trans.put_command (SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT);
1039 temp_trans.put_command (SCIM_TRANS_CMD_OK);
1041 temp_trans.put_command (SCIM_TRANS_CMD_FAIL);
1043 if (!global->send_transaction (temp_trans))
1044 std::cerr << "DELETE_SURROUNDING_TEXT: global->send_transaction () is failed!!!\n";
1050 SCIM_DEBUG_IMENGINE(3) << " Strange cmd: " << cmd << "\n";;
1054 SCIM_DEBUG_IMENGINE(3) << " Failed to get cmd: " << cmd << "\n";
1057 SCIM_DEBUG_IMENGINE(2) << " End of Do transaction\n";
1063 SocketInstance::reconnect_callback (void)
1065 m_peer_id = m_factory->create_peer_instance (get_encoding ());
1071 vi:ts=4:nowrap:ai:expandtab