Back to index

im-sdk  12.3.91
IMState.hh
Go to the documentation of this file.
00001 #ifndef IMSTATE_HH_
00002 #define IMSTATE_HH_
00003 #include <config.h>
00004 #include <IMProtocolStruct.h>
00005 #include "basictype.hh"
00006 #include "IMHandler.hh"
00007 #include "IMLog.hh"
00008 
00009 class IMAccept;
00010 class IMProtocol;
00011 class ICState;
00012 class IIIMP_hotkey_profile;
00013 
00014 class IMState
00015 {
00016   public:
00017     typedef map<CARD16BIT, ICState*> ICStateMap;
00018 
00019   private:
00020     struct IMShared {
00021        CARD16BIT im_id;
00022        IMProtocol *pimp;
00023        IMHandler *pimh;
00024        ICStateMap icmap;
00025         IIIMP_hotkey_profile *hotkey_profile;
00026         bool register_hotkey_flag;
00027     };
00028     IMState *pbase_state;
00029     IMState *pproc_state;
00030     IMShared *pshared;
00031     int protocol_version;
00032 
00033   protected:
00034     void add_icstate(ICState *pics);
00035     void remove_icstate(ICState *pics);
00036     void reset_state()
00037     {
00038        IMState *p = pbase_state;
00039        if (p->pproc_state) delete p->pproc_state;
00040        p->pproc_state = NULL;
00041     }
00042     void change_state(IMState &newstate)
00043     { 
00044        IMState *p = pbase_state;
00045        if (p->pproc_state) delete p->pproc_state;
00046        p->pproc_state = &newstate;
00047     }
00048 
00049     IMProtocol* get_improtocol()
00050     { return pshared->pimp; }
00051     IMHandler* get_imhandler()
00052     { return pshared->pimh; }
00053     void set_imhandler(IMHandler *pimh)
00054     { pshared->pimh = pimh; }
00055     int get_current_protocol_version()
00056     {
00057        if (pproc_state)
00058            return pproc_state->protocol_version;
00059        return protocol_version;
00060     }
00061     bool check_protocol_version(int version)
00062     { return (get_current_protocol_version() >= version); }
00063 
00064     IMAccept* get_imaccept();
00065 
00066     bool new_ic_id(CARD16BIT &newid) const;
00067 
00068     void cleanup_ic();
00069 
00070     virtual bool message_proc(
00071        void *message
00072     ) = 0;
00073 
00074     virtual ~IMState();
00075 
00076   public:
00077     bool substatep()
00078     { return (pbase_state != this); }
00079 
00080     CARD16BIT get_im_id() const
00081     { return pshared->im_id; }
00082 
00083     IIIMP_hotkey_profile* get_hotkey_profile() const
00084     { return pshared->hotkey_profile; }
00085 
00086     void set_register_hotkey_flag(bool flag) 
00087     { pshared->register_hotkey_flag = flag; }
00088 
00089     bool get_register_hotkey_flag() const
00090     { return pshared->register_hotkey_flag; }
00091 
00092     ICState* get_icstate(CARD16BIT ic_id)
00093     {
00094        ICStateMap *pmap = &pshared->icmap;
00095        ICStateMap::iterator it;
00096        it = pmap->find(ic_id);
00097        if (it == pmap->end()) return NULL;
00098        return it->second;
00099     }
00100 
00101     enum CONTEXT_ID_SPECIAL {
00102            INVALID_CONTEXT_ID = -1
00103     };
00104     bool dispatch(
00105        CARD16BIT im_id,
00106        CARD16BIT ic_id,
00107        void *message
00108     );
00109     bool deliver(
00110        void *message
00111     )
00112     {
00113        if (pproc_state)
00114            return pproc_state->message_proc(message);
00115        return message_proc(message);
00116     }
00117 
00118     virtual void destroy();
00119 
00120     IMState(
00121        IMState &x,
00122        int x_protocol_version = -1
00123     )
00124     {
00125        pshared = x.pshared;
00126        pproc_state = NULL;
00127        pbase_state = &x;
00128        if ((x_protocol_version > 0)
00129            && (x_protocol_version < x.protocol_version)) {
00130            protocol_version = x_protocol_version;
00131        } else {
00132            protocol_version = x.protocol_version;
00133        }
00134     }
00135     IMState(
00136        CARD16BIT x_im_id,
00137        IMProtocol *x_pimp,
00138        IMHandler *x_pimh,
00139        int x_protocol_version
00140        );
00141 
00142   friend class ICState;
00143 };
00144 
00145 #endif /* not IMSTATE_HH_ */
00146 
00147 /* Local Variables: */
00148 /* c-file-style: "iiim-project" */
00149 /* End: */