Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

scim_socket_transaction.h

Go to the documentation of this file.
00001 /**
00002  * @file scim_socket_transaction.h
00003  * @brief Socket transaction class.
00004  */
00005 
00006 /* 
00007  * Smart Common Input Method
00008  * 
00009  * Copyright (c) 2004 James Su <suzhe@turbolinux.com.cn>
00010  * Copyright (c) 2003 James Su <suzhe@turbolinux.com.cn>
00011  * Copyright (c) 2002 James Su <suzhe@turbolinux.com.cn>
00012  *
00013  *
00014  * This library is free software; you can redistribute it and/or
00015  * modify it under the terms of the GNU Lesser General Public
00016  * License as published by the Free Software Foundation; either
00017  * version 2 of the License, or (at your option) any later version.
00018  *
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU Lesser General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this program; if not, write to the
00026  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
00027  * Boston, MA  02111-1307  USA
00028  *
00029  * $Id: scim_socket_transaction.h,v 1.16 2004/02/06 07:53:15 suzhe Exp $
00030  */
00031 
00032 #ifndef __SCIM_SOCKET_TRANSACTION_H
00033 #define __SCIM_SOCKET_TRANSACTION_H
00034 
00035 namespace scim {
00036 
00037 /**
00038  * @addtogroup Helper
00039  * @{
00040  */
00041 
00042 /**
00043  * Signature of all of valid data types can be store into transaction.
00044  */
00045 enum SocketTransactionDataType
00046 {
00047     SCIM_TRANS_DATA_UNKNOWN,
00048     SCIM_TRANS_DATA_COMMAND,        //!< Send/Receive command.
00049     SCIM_TRANS_DATA_RAW,            //!< Send/Receive raw buffer.
00050     SCIM_TRANS_DATA_UINT32,         //!< Send/Receive uint32.
00051     SCIM_TRANS_DATA_STRING,         //!< Send/Receive String.
00052     SCIM_TRANS_DATA_WSTRING,        //!< Send/Receive WideString.
00053     SCIM_TRANS_DATA_KEYEVENT,       //!< Send/Receive KeyEvent.
00054     SCIM_TRANS_DATA_ATTRLIST,       //!< Send/Receive AttributeList.
00055     SCIM_TRANS_DATA_LOOKUP_TABLE,   //!< Send/Receive LookupTable.
00056     SCIM_TRANS_DATA_VECTOR_UINT32,  //!< Send/Receive vector<uint32>.
00057     SCIM_TRANS_DATA_VECTOR_STRING,  //!< Send/Receive vector<String>.
00058     SCIM_TRANS_DATA_VECTOR_WSTRING  //!< Send/Receive vector<WideString>.
00059 };
00060 
00061 /**
00062  * command types used by socket frontend server and config.
00063  */
00064 const int
00065     //Generic commands.
00066     SCIM_TRANS_CMD_UNKNOWN                          = 0,
00067 
00068     SCIM_TRANS_CMD_REQUEST                          = 1,
00069     SCIM_TRANS_CMD_REPLY                            = 2,
00070     SCIM_TRANS_CMD_OK                               = 3,
00071     SCIM_TRANS_CMD_FAIL                             = 4,
00072 
00073     SCIM_TRANS_CMD_OPEN_CONNECTION                  = 5,
00074     SCIM_TRANS_CMD_CLOSE_CONNECTION                 = 6,
00075 
00076     SCIM_TRANS_CMD_LOAD_FILE                        = 7,
00077 
00078     //Commands for SocketFrontEnd<->SocketServerInstance
00079     SCIM_TRANS_CMD_PROCESS_KEYEVENT                 = 100,
00080     SCIM_TRANS_CMD_MOVE_PREEDIT_CARET               = 101,
00081     SCIM_TRANS_CMD_SELECT_LOOKUP_TABLE              = 102,
00082     SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE_PAGE_SIZE    = 103,
00083     SCIM_TRANS_CMD_RESET                            = 104,
00084     SCIM_TRANS_CMD_FOCUS_IN                         = 105,
00085     SCIM_TRANS_CMD_FOCUS_OUT                        = 106,
00086     SCIM_TRANS_CMD_TOGGLE_FULL_WIDTH_PUNCTUATION    = 107,
00087     SCIM_TRANS_CMD_TOGGLE_FULL_WIDTH_LETTER         = 108,
00088     SCIM_TRANS_CMD_TOGGLE_INPUT_STATUS              = 109,
00089 
00090     SCIM_TRANS_CMD_SHOW_PREEDIT_STRING              = 110,
00091     SCIM_TRANS_CMD_SHOW_STATUS_STRING               = 111,
00092     SCIM_TRANS_CMD_SHOW_AUX_STRING                  = 112,
00093     SCIM_TRANS_CMD_SHOW_LOOKUP_TABLE                = 113,
00094     SCIM_TRANS_CMD_HIDE_PREEDIT_STRING              = 114,
00095     SCIM_TRANS_CMD_HIDE_STATUS_STRING               = 115,
00096     SCIM_TRANS_CMD_HIDE_AUX_STRING                  = 116,
00097     SCIM_TRANS_CMD_HIDE_LOOKUP_TABLE                = 117,
00098     SCIM_TRANS_CMD_UPDATE_PREEDIT_CARET             = 118,
00099     SCIM_TRANS_CMD_UPDATE_PREEDIT_STRING            = 119,
00100     SCIM_TRANS_CMD_UPDATE_STATUS_STRING             = 120,
00101     SCIM_TRANS_CMD_UPDATE_AUX_STRING                = 121,
00102     SCIM_TRANS_CMD_UPDATE_LOOKUP_TABLE              = 122,
00103     SCIM_TRANS_CMD_COMMIT_STRING                    = 123,
00104     SCIM_TRANS_CMD_FORWARD_KEYEVENT                 = 124,
00105     SCIM_TRANS_CMD_UPDATE_FULL_WIDTH_PUNCTUATION    = 125,
00106     SCIM_TRANS_CMD_UPDATE_FULL_WIDTH_LETTER         = 126,
00107 
00108     //Commands for SocketFrontEnd<->SocketServerFactory
00109     SCIM_TRANS_CMD_NEW_SERVER_INSTANCE              = 200,
00110     SCIM_TRANS_CMD_DELETE_SERVER_INSTANCE           = 201,
00111     SCIM_TRANS_CMD_DELETE_ALL_SERVER_INSTANCES      = 202,
00112 
00113     SCIM_TRANS_CMD_GET_SERVER_FACTORY_LIST          = 203,
00114     SCIM_TRANS_CMD_GET_SERVER_FACTORY_NAME          = 204,
00115     SCIM_TRANS_CMD_GET_SERVER_FACTORY_AUTHORS       = 205,
00116     SCIM_TRANS_CMD_GET_SERVER_FACTORY_CREDITS       = 206,
00117     SCIM_TRANS_CMD_GET_SERVER_FACTORY_HELP          = 207,
00118     SCIM_TRANS_CMD_GET_SERVER_FACTORY_LOCALES       = 208,
00119     SCIM_TRANS_CMD_GET_SERVER_FACTORY_ICON_FILE     = 209,
00120 
00121     //Commands for SocketFrontEnd<->SocketConfig
00122     SCIM_TRANS_CMD_FLUSH_CONFIG                     = 300,
00123     SCIM_TRANS_CMD_ERASE_CONFIG                     = 301,
00124     SCIM_TRANS_CMD_GET_CONFIG_STRING                = 302,
00125     SCIM_TRANS_CMD_SET_CONFIG_STRING                = 303,
00126     SCIM_TRANS_CMD_GET_CONFIG_INT                   = 304,
00127     SCIM_TRANS_CMD_SET_CONFIG_INT                   = 305,
00128     SCIM_TRANS_CMD_GET_CONFIG_BOOL                  = 306,
00129     SCIM_TRANS_CMD_SET_CONFIG_BOOL                  = 307,
00130     SCIM_TRANS_CMD_GET_CONFIG_DOUBLE                = 308,
00131     SCIM_TRANS_CMD_SET_CONFIG_DOUBLE                = 309,
00132     SCIM_TRANS_CMD_GET_CONFIG_VECTOR_STRING         = 310,
00133     SCIM_TRANS_CMD_SET_CONFIG_VECTOR_STRING         = 311,
00134     SCIM_TRANS_CMD_GET_CONFIG_VECTOR_INT            = 312,
00135     SCIM_TRANS_CMD_SET_CONFIG_VECTOR_INT            = 313,
00136 
00137     //User defined area
00138     SCIM_TRANS_CMD_USER_DEFINED                     = 10000;
00139 
00140 
00141 class SocketTransactionError: public Exception
00142 {
00143 public:
00144     SocketTransactionError (const String& what_arg)
00145         : Exception (String("scim::SocketTransaction: ") + what_arg) { }
00146 };
00147 
00148 /**
00149  * This class can pack up many data into one package
00150  * and send them via socket.
00151  */
00152 class SocketTransaction
00153 {
00154     class SocketTransactionImpl;
00155 
00156     SocketTransactionImpl * m_impl;
00157 
00158     SocketTransaction (const SocketTransaction &);
00159     const SocketTransaction & operator = (const SocketTransaction &);
00160 
00161 public:
00162     /**
00163      * constructor.
00164      *
00165      * @param bufsize the initial buffer size, maybe grow afterwards.
00166      */
00167     SocketTransaction (size_t bufsize = 512);
00168 
00169     /**
00170      * destructor.
00171      */
00172     ~SocketTransaction ();
00173 
00174     /**
00175      * check if the transaction is valid.
00176      */
00177     bool valid () const;
00178 
00179     /**
00180      * write the transaction to socket.
00181      *
00182      * @param socket the socket to be written.
00183      * @param signature the leading signature to be written
00184      *        into the socket before the transaction itself,
00185      *        this signature maybe missing when receive the transaction.
00186      */
00187     bool write_to_socket (const Socket &socket, uint32 signature = 0) const;
00188 
00189     /**
00190      * read a transaction from socket.
00191      *
00192      * @param socket the socket to be read.
00193      * @param timeout time out in millisecond (1/1000 second), -1 means infinity.
00194      */
00195     bool read_from_socket (const Socket &socket, int timeout = -1);
00196 
00197     /**
00198      * store a command into transaction.
00199      */
00200     void put_command (int type);
00201 
00202     /**
00203      * store a uint32 value into transaction.
00204      */
00205     void put_data (uint32 val);
00206 
00207     /**
00208      * store a String object into transaction.
00209      */
00210     void put_data (const String &str);
00211 
00212     /**
00213      * store a WideString object into transaction.
00214      */
00215     void put_data (const WideString &str);
00216 
00217     /**
00218      * store a KeyEvent object into transaction.
00219      */
00220     void put_data (const KeyEvent &key);
00221 
00222     /**
00223      * store a AttributeList object info transaction.
00224      */
00225     void put_data (const AttributeList &attrs);
00226 
00227     /**
00228      * store a LookupTable object into transaction.
00229      */
00230     void put_data (const LookupTable &table);
00231 
00232     /**
00233      * store a std::vector<uint32> object into transaction.
00234      */
00235     void put_data (const std::vector<uint32> &vec);
00236 
00237     /**
00238      * store a std::vector<String> object into transaction.
00239      */
00240     void put_data (const std::vector<String> &vec);
00241 
00242     /**
00243      * store a std::vector<WideString> object into transaction.
00244      */
00245     void put_data (const std::vector<WideString> &vec);
00246 
00247     /**
00248      * store a raw buffer into transaction.
00249      */
00250     void put_data (const char *raw, size_t bufsize);
00251 
00252     /**
00253      * get the type of the data at current read position.
00254      */
00255     SocketTransactionDataType get_data_type () const;
00256 
00257     /**
00258      * get a command from current read position.
00259      */
00260     bool get_command (int &type);
00261 
00262     /**
00263      * get a uint32 value from current read position.
00264      */
00265     bool get_data (uint32 &val);
00266 
00267     /**
00268      * get a String from current read position.
00269      */
00270     bool get_data (String &str);
00271 
00272     /**
00273      * get a WideString from current read position.
00274      */
00275     bool get_data (WideString &str);
00276 
00277     /**
00278      * get a KeyEvent from current read position.
00279      */
00280     bool get_data (KeyEvent &key);
00281 
00282     /**
00283      * get an AttributeList from current read position.
00284      */
00285     bool get_data (AttributeList &attrs);
00286 
00287     /**
00288      * get a CommonLookupTable from current read position.
00289      */
00290     bool get_data (CommonLookupTable &table);
00291 
00292     /**
00293      * get a std::vector<uint32> from current read position.
00294      */
00295     bool get_data (std::vector<uint32> &vec);
00296 
00297     /**
00298      * get a std::vector<String> from current read position.
00299      */
00300     bool get_data (std::vector<String> &vec);
00301 
00302     /**
00303      * get a std::vector<WideString> from current read position.
00304      */
00305     bool get_data (std::vector<WideString> &vec);
00306 
00307     /**
00308      * get a raw buffer from current read position.
00309      * if raw == NULL then return the bufsize and skip this data.
00310      * *raw should be deleted afterwards (do not use free!).
00311      */
00312     bool get_data (char **raw, size_t &bufsize);
00313 
00314     /**
00315      * skip one data from current read position.
00316      */
00317     bool skip_data ();
00318 
00319     /**
00320      * rewind the current read position, then the data can be read again.
00321      */
00322     void rewind_read_pos ();
00323 
00324     /**
00325      * clear the transaction.
00326      */
00327     void clear ();
00328 };
00329 
00330 /** @} */
00331 
00332 } // namespace scim
00333 
00334 #endif //__SCIM_SOCKET_TRANSACTION_H
00335 
00336 /*
00337 vi:ts=4:nowrap:ai:expandtab
00338 */
00339 

Generated on Fri May 7 17:27:25 2004 for scim by doxygen 1.3.6