Back to index

im-sdk  12.3.91
IIIMPClient.hh
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #ifndef _iiimpclient_hh
00043 #define _iiimpclient_hh
00044 
00045 #include "IMList.hh"
00046 #include "CompoundString.hh"
00047 
00048 #include "IIIMProtocol.hh"
00049 
00050 struct IMCommitCBStruct;
00051 struct IMForwardEventCBStruct;
00052 struct IMPreeditCBStruct;
00053 struct IMStatusCBStruct;
00054 struct IMLookupCBStruct;
00055 struct IMAuxCBStruct;
00056 struct IMConvStateCBStruct;
00057 
00058 class IIIMProtocol;
00059 class IMThread;
00060 class InputContext;
00061 class IMTransAccept;
00062 union IMProtocolStruct;
00063 struct ICAttribute;
00064 struct IMAttr;
00065 typedef struct _FrameMgr *FrameMgr;
00066 typedef struct _XimFrame *XimFrame;
00067 
00068 struct IIimpProtoHdr {
00069   unsigned char opcode;
00070   unsigned char length[3];
00071 };
00072 
00073 class IIIMPClient {
00074  public:
00075   IIIMPClient(IIIMProtocol*, IMTransAccept*);
00076   ~IIIMPClient();
00077 
00078   const CompoundString& getUser() const {return username;}
00079 
00080   // CLIENT DESCRIPTOR
00081   const CompoundString& getApplicationName() const {return application_name;}
00082   const CompoundString& getOSName() const {return os_name;}
00083   const CompoundString& getOSArch() const {return os_arch;}
00084   const CompoundString& getOSVersion() const {return os_version;}
00085   // Client Display Info
00086   const CompoundString& getXDisplayString() const {return xDisplayName;}
00087   const CompoundString& getXServerVendor() const {return xServerVendor;}
00088 
00089   int commit_string(IMCommitCBStruct *commit);
00090   int forward_event(IMForwardEventCBStruct *commit);
00091 
00092   int preedit_start(IMPreeditCBStruct *preedit);
00093   int preedit_draw(IMPreeditCBStruct *preedit);
00094   int preedit_caret(IMPreeditCBStruct *preedit);
00095   int preedit_done(IMPreeditCBStruct *preedit);
00096 
00097   int status_start(IMStatusCBStruct *status);
00098   int status_draw(IMStatusCBStruct *status);
00099   int status_done(IMStatusCBStruct *status);
00100 
00101   int lookup_start(IMLookupCBStruct *lookup);
00102   int lookup_draw(IMLookupCBStruct *lookup);
00103   int lookup_process(IMLookupCBStruct *lookup);
00104   int lookup_done(IMLookupCBStruct *lookup);
00105 
00106   int auxiliary_start(IMAuxCBStruct *auxiliary);
00107   int auxiliary_draw(IMAuxCBStruct *auxiliary);
00108   int auxiliary_done(IMAuxCBStruct *auxiliary);
00109 
00110   int conversion_start(IMConvStateCBStruct *state);
00111   int conversion_end(IMConvStateCBStruct *state);
00112 
00113   void register_triggerkeys();
00114 
00115   static void *socket_listener(void* data);
00116 
00117   int getICID(InputContext *ic) {
00118     return input_context_list.getIndex(ic);
00119   }
00120  private:
00121   void SetStringToFrame(FrameMgr fm, UTFCHAR* utf_str, int char_length);
00122 
00123   void SetStringToFrame(FrameMgr fm, char* str, int length);
00124 
00125   void send_message(int, CompoundString&, int);
00126 #if !defined(USE_FRAMEMGR_ALWAYS)
00127 #else /* USE_FRAMEMGR_ALWAYS */
00128   void send_message(int, int, XimFrame, int);
00129 #endif /* USE_FRAMEMGR_ALWAYS */
00130   void send_message(int, int, int);
00131   void send_message(int, char *, int);
00132   void send_imvalues_message(int, int, ICAttribute*, int);
00133 
00134   unsigned char *create_ccdef_object_frame(IMObjectDescriptorStruct *,
00135                                       char *, int, unsigned int *);
00136   unsigned char *create_jarfile_object_frame(IMObjectDescriptorStruct *,
00137                                         char *, int, unsigned int *);
00138   unsigned char *create_binfile_object_frame(IMObjectDescriptorStruct *,
00139                                         unsigned int *);
00140   enum PREDEFINED_IMATTRIBID {
00141     INPUT_METHOD_LIST = 0x1001,
00142     OBJECT_DESCRIPTOR_LIST = 0x1010,
00143     CLIENT_DESCRIPTOR = 0x1011,
00144     CHARACTER_CONVERSION_DEFINITION_RULE = 0x1030,
00145     JAR_GUI_OBJECT = 0x1031,
00146     JAR_LWE_OBJECT = 0x1032,
00147     BIN_GUI_OBJECT = 0x1033,
00148     BIN_LWE_OBJECT = 0x1034,
00149     SCRIPT_GUI_OBJECT = 0x1035,
00150     SCRIPT_LWE_OBJECT = 0x1036
00151   };
00152 
00153   //
00154   // Basic Protocol number
00155   //
00156   enum IIIM_PROTOCOL {
00157     IM_CONNECT = 1, IM_CONNECT_REPLY = 2,
00158     IM_DISCONNECT = 3, IM_DISCONNECT_REPLY = 4,
00159     IM_REGISTER_TRIGGER_KEYS  = 5,
00160     IM_TRIGGER_NOTIFY = 6, IM_TRIGGER_NOTIFY_REPLY = 7,
00161     IM_SETIMVALUES = 8, IM_SETIMVALUES_REPLY = 9,
00162     IM_GETIMVALUES = 10, IM_GETIMVALUES_REPLY = 11,
00163     IM_FORWARD_EVENT = 12, IM_FORWARD_EVENT_REPLY = 13,
00164     IM_COMMIT_STRING = 14,
00165 
00166     IM_CREATEIC = 20, IM_CREATEIC_REPLY = 21,
00167     IM_DESTROYIC = 22, IM_DESTROYIC_REPLY = 23,
00168     IM_SETICVALUES = 24, IM_SETICVALUES_REPLY = 25,
00169     IM_GETICVALUES = 26, IM_GETICVALUES_REPLY = 27,
00170     IM_SETICFOCUS = 28, IM_SETICFOCUS_REPLY = 29,
00171     IM_UNSETICFOCUS = 30, IM_UNSETICFOCUS_REPLY = 31,
00172     IM_RESETIC = 32, IM_RESETIC_REPLY = 33,
00173 
00174     IM_PREEDIT_START = 40, IM_PREEDIT_START_REPLY = 41,
00175     IM_PREEDIT_DRAW = 42, IM_PREEDIT_DRAW_REPLY = 43,
00176     IM_PREEDIT_CARET = 44, IM_PREEDIT_CARET_REPLY = 45,
00177     IM_PREEDIT_DONE = 46, IM_PREEDIT_DONE_REPLY = 47,
00178 
00179     IM_STATUS_START = 50, IM_STATUS_START_REPLY = 51,
00180     IM_STATUS_DRAW = 52, IM_STATUS_DRAW_REPLY = 53,
00181     IM_STATUS_DONE = 54, IM_STATUS_DONE_REPLY = 55,
00182 
00183     IM_LOOKUP_START = 70, IM_LOOKUP_START_REPLY = 71,
00184     IM_LOOKUP_DRAW = 72, IM_LOOKUP_DRAW_REPLY = 73,
00185     IM_LOOKUP_DONE = 74, IM_LOOKUP_DONE_REPLY = 75,
00186     IM_LOOKUP_PROCESS = 76, IM_LOOKUP_PROCESS_REPLY = 77,
00187 
00188     IM_AUX_START = 90, IM_AUX_START_REPLY = 91,
00189     IM_AUX_DRAW = 92, IM_AUX_DRAW_REPLY = 93,
00190     IM_AUX_DONE = 94, IM_AUX_DONE_REPLY = 95,
00191     IM_AUX_SETVALUES = 96, IM_AUX_SETVALUES_REPLY = 97,
00192 
00193     IM_ERROR = 99
00194   };
00195 
00196   IIIMProtocol *iiim_protocol;
00197   CompoundString username;
00198 
00199   // CLIENTDESCRIPTOR
00200   CompoundString application_name;
00201   CompoundString os_name;
00202   CompoundString os_arch;
00203   CompoundString os_version;
00204 
00205   CompoundString xDisplayName;
00206   CompoundString xServerVendor;
00207 
00208   ICAttribute *imAttribute_list; // IMAttribute_list
00209   int alloc_attr;
00210   int active_attr;
00211 
00212   char byteOrder;
00213 
00214 #if !defined(USE_FRAMEMGR_ALWAYS)
00215   CompoundString *authorization_list;
00216   int alloc_auth;
00217 #else /* USE_FRAMEMGR_ALWAYS */
00218   CompoundString authorization;
00219 #endif /* USE_FRAMEMGR_ALWAYS */
00220 
00221   int need_swap;
00222   /*
00223     '?': initial value
00224     'B': for Big-Endian
00225     'l': for little-endian
00226   */
00227   IMTransAccept *accept_fd;
00228   unsigned int im_id;              // copy of accept_fd->connection_id();
00229                             // initialized at IM_CREATE_IC
00230 
00231   IMThread *thread;
00232 
00233   IMList<InputContext>  input_context_list;
00234 
00235   unsigned char* get_content(char*, int);
00236   unsigned char* get_amessage();
00237   unsigned char* get_im_connect();
00238 
00239   int read_data(const char *buf, const int len) const;
00240   int write_data(const char *buf, const int len) const;
00241 
00242   void dispatch(unsigned char*, int&);
00243 
00244   int Select();
00245 
00246 #if !defined(USE_FRAMEMGR_ALWAYS)
00247   void change_icvalues(char *, IMProtocolStruct*);
00248 #else /* USE_FRAMEMGR_ALWAYS */
00249   void change_icvalues(FrameMgr, int, IMProtocolStruct*);
00250 #endif /* USE_FRAMEMGR_ALWAYS */
00251   void free_icvalues(IMProtocolStruct*);
00252 
00253   ICAttribute *get_icattr(unsigned short*, int);
00254 
00255   int preedit_state(IMConvStateCBStruct*);
00256   int preedit_erase_text(IMPreeditCBStruct*);
00257   int preedit_draw_text(IMPreeditCBStruct*);
00258   int status_draw_string(IMStatusCBStruct*);
00259   int status_draw_text(IMStatusCBStruct*);
00260 
00261   // Protocol message procedure
00262   void connect(IMProtocolStruct *, unsigned char *);
00263   void dis_connect(IMProtocolStruct *, unsigned char *);
00264   void set_imvalues(IMProtocolStruct *, unsigned char *);
00265   void get_imvalues(IMProtocolStruct *, unsigned char *);
00266   void create_ic(IMProtocolStruct *, unsigned char *);
00267   void set_icvalues(IMProtocolStruct *, unsigned char *);
00268   void get_icvalues(IMProtocolStruct *, unsigned char *);
00269   void set_icfocus(IMProtocolStruct *, unsigned char *);
00270   void unset_icfocus(IMProtocolStruct *, unsigned char *);
00271   void destroy_ic(IMProtocolStruct *, unsigned char *);
00272   void reset_ic(IMProtocolStruct *, unsigned char *);
00273   void forward_string(IMProtocolStruct *, unsigned char *) {}
00274   void forward_text(IMProtocolStruct *, unsigned char *) {}
00275   void forward_keyevent(IMProtocolStruct *, unsigned char *);
00276   void forward_event(IMProtocolStruct *, unsigned char *);
00277   void trigger_notify(IMProtocolStruct *, unsigned char *);
00278   void preedit_start_reply(IMProtocolStruct *, unsigned char *);
00279   void preedit_caret_reply(IMProtocolStruct *, unsigned char *);
00280   void aux_set_values(IMProtocolStruct *, unsigned char *);
00281 
00282   void set_card(ICAttribute*, char*, IMAttr*, int);
00283   int read_icvalue(unsigned short, int, void *p, ICAttribute*);
00284   int read_imvalue(unsigned short, int, void *p, ICAttribute*);
00285 
00286 #if !defined(USE_FRAMEMGR_ALWAYS)
00287   int  imtext_size(IMText *text);
00288   char *req_put_imtext(char * ptr, IMText * text);
00289   char *req_put_imtext_s(char * ptr, IMText * text);
00290   int  utf16_string_size(int len);
00291   char *req_put_utf16_string(char * ptr, UTFCHAR * string, int length);
00292   char *req_put_utf16_string_s(char * ptr, UTFCHAR * string, int length);
00293   int  ascii_string_size(char * string);
00294   char *req_put_ascii_string(char * ptr, char * string);
00295   char *req_put_ascii_string_s(char * ptr, char * string);
00296   char *req_get_ascii_string(char * ptr, char ** string,
00297                           int * size_ret, int * buf_size_ret);
00298   char *req_get_ascii_string_s(char * ptr, char ** string,
00299                             int * size_ret, int * buf_size_ret);
00300   int  string_list_count(char *p);
00301   int  string_list_count2(char *p, int str_list_size);
00302   int  icattr_list_count(char * p);
00303   int  icattr_size(ICAttribute * icattr);
00304   char *req_put_icattr_list(char * ptr, ICAttribute * icattr, int num);
00305   char *req_put_icattr_list_s(char * ptr, ICAttribute * icattr, int num);
00306 #else /* USE_FRAMEMGR_ALWAYS */
00307 #endif /* USE_FRAMEMGR_ALWAYS */
00308 
00309   enum Msg { MAX_RW_DATA_LEN = 32768};
00310 
00311   enum ATTR { MAX_ATTRNUM = 10};
00312 
00313   enum ForwardEventType {
00314     FORWARD_STRING = 0,
00315     FORWARD_TEXT,
00316     FORWARD_KEYEVENT
00317   };
00318 
00319   // mark true if this client is being deleted
00320   int being_deleted;
00321 
00322   // mark true if this client can respond keep alive protocol
00323   int respond_keepalive;
00324 };
00325 
00326 #if !defined(USE_FRAMEMGR_ALWAYS)
00327 typedef unsigned int   CARD32;
00328 typedef unsigned short CARD16;
00329 typedef unsigned char  CARD8;
00330 #else /* USE_FRAMEMGR_ALWAYS */
00331 #endif /* USE_FRAMEMGR_ALWAYS */
00332 
00333 #define req_put8(p, d)             (*((CARD8 *)(p))  = (d), (p) += 1)
00334 #define req_put16(p, d)            (*((CARD16 *)(p)) = (d), (p) += 2)
00335 #define req_put32(p, d)            (*((CARD32 *)(p)) = (d), (p) += 4)
00336 
00337 #define req_put8s(p, d)            (*((CARD8 *)(p))  = (d), (p) += 1)
00338 #define req_put16s(p, d)    (*((CARD16 *)(p)) = req_swap16(d), (p) += 2)
00339 #define req_put32s(p, d)    (*((CARD32 *)(p)) = req_swap32(d), (p) += 4)
00340 
00341 #define req_get8(p, d)             ((d) = *((CARD8 *)(p)), (p) += 1)
00342 #define req_get16(p, d)            ((d) = *((CARD16 *)(p)), (p) += 2)
00343 #define req_get32(p, d)            ((d) = *((CARD32 *)(p)), (p) += 4)
00344 
00345 #define req_get8s(p, d)            ((d) = *((CARD8 *)(p)), (p) += 1)
00346 #define req_get16s(p, d)    ((d) = req_swap16(*((CARD16 *)(p))), (p) += 2)
00347 #define req_get32s(p, d)    ((d) = req_swap32(*((CARD32 *)(p))), (p) += 4)
00348 
00349 #define req_swap16(n)       ((((n) <<  8) & 0x0000ff00) |      \
00350                       (((n) >>  8) & 0x000000ff))
00351 #define req_swap32(n)       ((((n) << 24) & 0xff000000) |      \
00352                       (((n) <<  8) & 0x00ff0000) |      \
00353                       (((n) >>  8) & 0x0000ff00) |      \
00354                       (((n) >> 24) & 0x000000ff))
00355 
00356 #endif