1 /** 2 * @file scim_socket_frontend.h 3 * @brief definition of SocketFrontEnd related classes. 4 */ 5 6 /* 7 * Smart Common Input Method 8 * 9 * Copyright (c) 2002-2005 James Su <suzhe@tsinghua.org.cn> 10 * 11 * 12 * This library is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU Lesser General Public 14 * License as published by the Free Software Foundation; either 15 * version 2 of the License, or (at your option) any later version. 16 * 17 * This library is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU Lesser General Public License for more details. 21 * 22 * You should have received a copy of the GNU Lesser General Public 23 * License along with this program; if not, write to the 24 * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 25 * Boston, MA 02111-1307 USA 26 * 27 * $Id: scim_socket_frontend.h,v 1.26 2005/04/14 17:01:56 suzhe Exp $ 28 */ 29 30 #if !defined (__SCIM_SOCKET_FRONTEND_H) 31 #define __SCIM_SOCKET_FRONTEND_H 32 33 #include "scim_stl_map.h" 34 35 using namespace scim; 36 37 class SocketFrontEnd : public FrontEndBase 38 { 39 enum ClientType { 40 UNKNOWN_CLIENT, 41 IMENGINE_CLIENT, 42 CONFIG_CLIENT 43 }; 44 45 struct ClientInfo { 46 uint32 key; 47 ClientType type; 48 }; 49 50 /** 51 * ::first = socket id, ::second = instance id. 52 */ 53 typedef std::vector <std::pair <int, int> > SocketInstanceRepository; 54 55 #if SCIM_USE_STL_EXT_HASH_MAP 56 typedef __gnu_cxx::hash_map <int, ClientInfo, __gnu_cxx::hash <int> > SocketClientRepository; 57 #elif SCIM_USE_STL_HASH_MAP 58 typedef std::hash_map <int, ClientInfo, std::hash <int> > SocketClientRepository; 59 #else 60 typedef std::map <int, ClientInfo> SocketClientRepository; 61 #endif 62 63 ConfigPointer m_config; 64 65 SocketServer m_socket_server; 66 67 Transaction m_send_trans; 68 Transaction m_receive_trans; 69 Transaction m_temp_trans; 70 71 SocketInstanceRepository m_socket_instance_repository; 72 73 SocketClientRepository m_socket_client_repository; 74 75 bool m_stay; 76 77 bool m_config_readonly; 78 79 int m_socket_timeout; 80 81 int m_current_instance; 82 83 int m_current_socket_client; 84 85 uint32 m_current_socket_client_key; 86 87 public: 88 SocketFrontEnd (const BackEndPointer &backend, 89 const ConfigPointer &config); 90 91 virtual ~SocketFrontEnd (); 92 93 protected: 94 virtual void show_preedit_string (int id); 95 virtual void show_aux_string (int id); 96 virtual void show_lookup_table (int id); 97 98 virtual void hide_preedit_string (int id); 99 virtual void hide_aux_string (int id); 100 virtual void hide_lookup_table (int id); 101 102 virtual void update_preedit_caret (int id, int caret); 103 virtual void update_preedit_string (int id, const WideString & str, const AttributeList & attrs); 104 virtual void update_aux_string (int id, const WideString & str, const AttributeList & attrs); 105 virtual void commit_string (int id, const WideString & str); 106 virtual void forward_key_event (int id, const KeyEvent & key); 107 virtual void update_lookup_table (int id, const LookupTable & table); 108 109 virtual void register_properties (int id, const PropertyList & properties); 110 virtual void update_property (int id, const Property & property); 111 112 virtual void beep (int id); 113 114 virtual void start_helper (int id, const String &helper_uuid); 115 virtual void stop_helper (int id, const String &helper_uuid); 116 virtual void send_helper_event (int id, const String &helper_uuid, const Transaction &trans); 117 118 virtual bool get_surrounding_text (int id, WideString &text, int &cursor, int maxlen_before, int maxlen_after); 119 virtual bool delete_surrounding_text (int id, int offset, int len); 120 121 public: 122 virtual void init (int argc, char **argv); 123 virtual void run (); 124 125 private: 126 uint32 generate_key () const; 127 128 bool check_client_connection (const Socket &client) const; 129 130 void socket_accept_callback (SocketServer *server, const Socket &client); 131 void socket_receive_callback (SocketServer *server, const Socket &client); 132 void socket_exception_callback (SocketServer *server, const Socket &client); 133 134 bool socket_open_connection (SocketServer *server, const Socket &client); 135 void socket_close_connection (SocketServer *server, const Socket &client); 136 ClientInfo socket_get_client_info (const Socket &client); 137 138 //client_id is client's socket id 139 void socket_get_factory_list (int client_id); 140 void socket_get_factory_name (int client_id); 141 void socket_get_factory_authors (int client_id); 142 void socket_get_factory_credits (int client_id); 143 void socket_get_factory_help (int client_id); 144 void socket_get_factory_locales (int client_id); 145 void socket_get_factory_icon_file (int client_id); 146 void socket_get_factory_language (int client_id); 147 148 void socket_new_instance (int client_id); 149 void socket_delete_instance (int client_id); 150 void socket_delete_all_instances (int client_id); 151 152 void socket_process_key_event (int client_id); 153 void socket_move_preedit_caret (int client_id); 154 void socket_select_candidate (int client_id); 155 void socket_update_lookup_table_page_size (int client_id); 156 void socket_lookup_table_page_up (int client_id); 157 void socket_lookup_table_page_down (int client_id); 158 void socket_reset (int client_id); 159 void socket_focus_in (int client_id); 160 void socket_focus_out (int client_id); 161 void socket_trigger_property (int client_id); 162 void socket_process_helper_event (int client_id); 163 void socket_update_client_capabilities (int client_id); 164 165 void socket_flush_config (int client_id); 166 void socket_erase_config (int client_id); 167 void socket_get_config_string (int client_id); 168 void socket_set_config_string (int client_id); 169 void socket_get_config_int (int client_id); 170 void socket_set_config_int (int client_id); 171 void socket_get_config_bool (int client_id); 172 void socket_set_config_bool (int client_id); 173 void socket_get_config_double (int client_id); 174 void socket_set_config_double (int client_id); 175 void socket_get_config_vector_string (int client_id); 176 void socket_set_config_vector_string (int client_id); 177 void socket_get_config_vector_int (int client_id); 178 void socket_set_config_vector_int (int client_id); 179 void socket_reload_config (int client_id); 180 181 void socket_load_file (int client_id); 182 183 void reload_config_callback (const ConfigPointer &config); 184 }; 185 186 #endif 187 188 /* 189 vi:ts=4:nowrap:ai:expandtab 190 */ 191