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::set_prediction_allow (bool allow)
710 global->init_transaction (trans);
712 SCIM_DEBUG_IMENGINE(1) << __func__<< " (" << m_peer_id << ")\n";
714 trans.put_command (ISM_TRANS_CMD_SET_PREDICTION_ALLOW);
715 trans.put_data (m_peer_id);
716 trans.put_data ((uint32) allow);
718 commit_transaction (trans);
722 SocketInstance::set_layout (unsigned int layout)
726 global->init_transaction (trans);
728 SCIM_DEBUG_IMENGINE(1) << __func__<< " (" << m_peer_id << ")\n";
730 trans.put_command (ISM_TRANS_CMD_SET_LAYOUT);
731 trans.put_data (m_peer_id);
732 trans.put_data (layout);
734 commit_transaction (trans);
738 SocketInstance::reset_option ()
742 global->init_transaction (trans);
744 SCIM_DEBUG_IMENGINE(1) << "reset_option (" << m_peer_id << ")\n";
746 trans.put_command (ISM_TRANS_CMD_RESET_ISE_OPTION);
747 trans.put_data (m_peer_id);
749 commit_transaction (trans);
753 SocketInstance::reset ()
757 global->init_transaction (trans);
759 SCIM_DEBUG_IMENGINE(1) << "reset (" << m_peer_id << ")\n";
761 trans.put_command (SCIM_TRANS_CMD_RESET);
762 trans.put_data (m_peer_id);
764 commit_transaction (trans);
768 SocketInstance::focus_in ()
772 global->init_transaction (trans);
774 SCIM_DEBUG_IMENGINE(1) << "focus_in (" << m_peer_id << ")\n";
776 trans.put_command (SCIM_TRANS_CMD_FOCUS_IN);
777 trans.put_data (m_peer_id);
779 commit_transaction (trans);
783 SocketInstance::focus_out ()
787 global->init_transaction (trans);
789 SCIM_DEBUG_IMENGINE(1) << "focus_out (" << m_peer_id << ")\n";
791 trans.put_command (SCIM_TRANS_CMD_FOCUS_OUT);
792 trans.put_data (m_peer_id);
794 commit_transaction (trans);
798 SocketInstance::trigger_property (const String &property)
802 global->init_transaction (trans);
804 SCIM_DEBUG_IMENGINE(1) << "trigger_property (" << m_peer_id << ", " << property << ")\n";
806 trans.put_command (SCIM_TRANS_CMD_TRIGGER_PROPERTY);
807 trans.put_data (m_peer_id);
808 trans.put_data (property);
810 commit_transaction (trans);
814 SocketInstance::process_helper_event (const String &helper_uuid, const Transaction &helper_trans)
818 global->init_transaction (trans);
820 SCIM_DEBUG_IMENGINE(1) << "process_helper_event (" << m_peer_id << ", " << helper_uuid << ")\n";
822 trans.put_command (SCIM_TRANS_CMD_PROCESS_HELPER_EVENT);
823 trans.put_data (m_peer_id);
824 trans.put_data (helper_uuid);
825 trans.put_data (helper_trans);
827 commit_transaction (trans);
831 SocketInstance::update_client_capabilities (unsigned int cap)
835 global->init_transaction (trans);
837 SCIM_DEBUG_IMENGINE(1) << "update_client_capabilities (" << m_peer_id << ", " << cap << ")\n";
839 trans.put_command (SCIM_TRANS_CMD_UPDATE_CLIENT_CAPABILITIES);
840 trans.put_data (m_peer_id);
841 trans.put_data ((uint32) cap);
843 commit_transaction (trans);
847 SocketInstance::commit_transaction (Transaction &trans)
849 SCIM_DEBUG_IMENGINE(2) << " commit_transaction:\n";
853 if (m_peer_id >= 0) {
854 if (global->send_transaction (trans)) {
856 if (!global->receive_transaction (trans)) break;
857 if (!do_transaction (trans, ret)) return ret;
862 if (global->create_connection ())
869 SocketInstance::do_transaction (Transaction &trans, bool &ret)
876 SCIM_DEBUG_IMENGINE(2) << " Do transaction:\n";
878 if (trans.get_command (cmd) && cmd == SCIM_TRANS_CMD_REPLY) {
879 while (trans.get_command (cmd)) {
881 case SCIM_TRANS_CMD_SHOW_PREEDIT_STRING:
883 SCIM_DEBUG_IMENGINE(3) << " show_preedit_string ()\n";
884 show_preedit_string ();
887 case SCIM_TRANS_CMD_SHOW_AUX_STRING:
889 SCIM_DEBUG_IMENGINE(3) << " show_aux_string ()\n";
893 case SCIM_TRANS_CMD_SHOW_LOOKUP_TABLE:
895 SCIM_DEBUG_IMENGINE(3) << " show_lookup_table ()\n";
896 show_lookup_table ();
899 case SCIM_TRANS_CMD_HIDE_PREEDIT_STRING:
901 SCIM_DEBUG_IMENGINE(3) << " hide_preedit_string ()\n";
902 hide_preedit_string ();
905 case SCIM_TRANS_CMD_HIDE_AUX_STRING:
907 SCIM_DEBUG_IMENGINE(3) << " hide_aux_string ()\n";
911 case SCIM_TRANS_CMD_HIDE_LOOKUP_TABLE:
913 SCIM_DEBUG_IMENGINE(3) << " hide_lookup_table ()\n";
914 hide_lookup_table ();
917 case SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET:
920 if (trans.get_data (caret)) {
921 SCIM_DEBUG_IMENGINE(3) << " update_preedit_caret (" << caret << ")\n";
922 update_preedit_caret (caret);
926 case SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING:
930 if (trans.get_data (str) && trans.get_data (attrs)) {
931 SCIM_DEBUG_IMENGINE(3) << " update_preedit_string ()\n";
932 update_preedit_string (str, attrs);
936 case SCIM_TRANS_CMD_UPDATE_AUX_STRING:
940 if (trans.get_data (str) && trans.get_data (attrs)) {
941 SCIM_DEBUG_IMENGINE(3) << " update_aux_string ()\n";
942 update_aux_string (str, attrs);
946 case SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE:
948 CommonLookupTable table;
949 if (trans.get_data (table)) {
950 SCIM_DEBUG_IMENGINE(3) << " update_lookup_table ()\n";
951 update_lookup_table (table);
955 case SCIM_TRANS_CMD_COMMIT_STRING:
958 if (trans.get_data (str)) {
959 SCIM_DEBUG_IMENGINE(3) << " commit_string ()\n";
964 case SCIM_TRANS_CMD_FORWARD_KEY_EVENT:
967 if (trans.get_data (key)) {
968 SCIM_DEBUG_IMENGINE(3) << " forward_key_event ()\n";
969 forward_key_event (key);
973 case SCIM_TRANS_CMD_REGISTER_PROPERTIES:
975 PropertyList proplist;
976 if (trans.get_data (proplist)) {
977 SCIM_DEBUG_IMENGINE(3) << " register_properties ()\n";
979 // Load icon files of these properties from remote SocketFrontEnd.
980 for (PropertyList::iterator it = proplist.begin (); it != proplist.end (); ++it)
981 it->set_icon (global->load_icon (it->get_icon ()));
983 register_properties (proplist);
987 case SCIM_TRANS_CMD_UPDATE_PROPERTY:
990 if (trans.get_data (prop)) {
991 SCIM_DEBUG_IMENGINE(3) << " update_property ()\n";
993 // Load the icon file of this property from remote SocketFrontEnd.
994 prop.set_icon (global->load_icon (prop.get_icon ()));
996 update_property (prop);
1000 case SCIM_TRANS_CMD_BEEP:
1002 SCIM_DEBUG_IMENGINE(3) << " beep ()\n";
1006 case SCIM_TRANS_CMD_START_HELPER:
1009 if (trans.get_data (helper_uuid)) {
1010 SCIM_DEBUG_IMENGINE(3) << " start_helper (" << helper_uuid << ")\n";
1011 start_helper (helper_uuid);
1015 case SCIM_TRANS_CMD_STOP_HELPER:
1018 if (trans.get_data (helper_uuid)) {
1019 SCIM_DEBUG_IMENGINE(3) << " stop_helper (" << helper_uuid << ")\n";
1020 stop_helper (helper_uuid);
1024 case SCIM_TRANS_CMD_SEND_HELPER_EVENT:
1027 Transaction temp_trans;
1028 if (trans.get_data (helper_uuid) && trans.get_data (temp_trans)) {
1029 SCIM_DEBUG_IMENGINE(3) << " send_helper_event (" << helper_uuid << ")\n";
1030 send_helper_event (helper_uuid, temp_trans);
1034 case SCIM_TRANS_CMD_OK:
1036 SCIM_DEBUG_IMENGINE(3) << " ret = true\n";
1040 case SCIM_TRANS_CMD_GET_SURROUNDING_TEXT:
1044 uint32 maxlen_before;
1045 uint32 maxlen_after;
1046 Transaction temp_trans;
1047 if (trans.get_data (maxlen_before) && trans.get_data (maxlen_after)) {
1048 global->init_transaction (temp_trans);
1049 if (get_surrounding_text (text, cursor, (int) maxlen_before, (int) maxlen_after)) {
1050 temp_trans.put_command (SCIM_TRANS_CMD_GET_SURROUNDING_TEXT);
1051 temp_trans.put_data (text);
1052 temp_trans.put_data ((uint32) cursor);
1054 temp_trans.put_command (SCIM_TRANS_CMD_FAIL);
1056 if (!global->send_transaction (temp_trans))
1057 std::cerr << "GET_SURROUNDING_TEXT: global->send_transaction () is failed!!!\n";
1062 case SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT:
1066 Transaction temp_trans;
1067 if (trans.get_data (offset) && trans.get_data (len)) {
1068 global->init_transaction (temp_trans);
1069 if (delete_surrounding_text ((int) offset, (int) len)) {
1070 temp_trans.put_command (SCIM_TRANS_CMD_DELETE_SURROUNDING_TEXT);
1071 temp_trans.put_command (SCIM_TRANS_CMD_OK);
1073 temp_trans.put_command (SCIM_TRANS_CMD_FAIL);
1075 if (!global->send_transaction (temp_trans))
1076 std::cerr << "DELETE_SURROUNDING_TEXT: global->send_transaction () is failed!!!\n";
1082 SCIM_DEBUG_IMENGINE(3) << " Strange cmd: " << cmd << "\n";;
1086 SCIM_DEBUG_IMENGINE(3) << " Failed to get cmd: " << cmd << "\n";
1089 SCIM_DEBUG_IMENGINE(2) << " End of Do transaction\n";
1095 SocketInstance::reconnect_callback (void)
1097 m_peer_id = m_factory->create_peer_instance (get_encoding ());
1103 vi:ts=4:nowrap:ai:expandtab