Back to index

im-sdk  12.3.91
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
IIIMP_IMState Class Reference

#include <IIIMP_IMState.hh>

Inheritance diagram for IIIMP_IMState:
Inheritance graph
[legend]
Collaboration diagram for IIIMP_IMState:
Collaboration graph
[legend]

List of all members.

Public Types

typedef pair< u16string, string > UserHostPair
typedef std::multimap
< UserHostPair, IIIMP_IMState * > 
UserIMStateMap
enum  CONTEXT_ID_SPECIAL { INVALID_CONTEXT_ID = -1 }
typedef map< CARD16BIT, ICState * > ICStateMap

Public Member Functions

bool send_trigger_keys ()
bool send_hotkeys (const u16string &curr_input_lang, HotKeyList *hlist)
bool switch_hotkey_profile ()
void create (IIIMP_IMState *pims)
bool send (IIIMP_message *pmes, bool deletep=false)
IIIMPTransget_iiimptrans ()
 IIIMP_IMState (IIIMP_IMState &x, int proto_version)
 IIIMP_IMState (IIIMProtocol *pimp, IIIMPTrans *pimt, int proto_version)
bool substatep ()
CARD16BIT get_im_id () const
IIIMP_hotkey_profileget_hotkey_profile () const
void set_register_hotkey_flag (bool flag)
bool get_register_hotkey_flag () const
ICStateget_icstate (CARD16BIT ic_id)
bool dispatch (CARD16BIT im_id, CARD16BIT ic_id, void *message)
bool deliver (void *message)

Static Public Member Functions

static IIIMP_IMStateget_imstate_from_desktop (iml_desktop_t *desktop)

Protected Member Functions

void add_icstate (ICState *pics)
void remove_icstate (ICState *pics)
void reset_state ()
void change_state (IMState &newstate)
IMProtocolget_improtocol ()
IMHandlerget_imhandler ()
void set_imhandler (IMHandler *pimh)
int get_current_protocol_version ()
bool check_protocol_version (int version)
IMAcceptget_imaccept ()
bool new_ic_id (CARD16BIT &newid) const
void cleanup_ic ()

Private Member Functions

bool parse_user_name (const u16string &uname, u16string &username, u16string &password, string &hostname)
bool send_protocol_version (int client_proto_version)
virtual bool message_proc (void *message)
virtual void destroy ()

Private Attributes

IIIMPTranspimt

Static Private Attributes

static UserIMStateMap user_imstate_map

Friends

int update_supported_langlist_for_le (iml_desktop_t *desktop, IMLEName *lename, IMLocale *locales, int nLocales)
int switch_le_profile (iml_desktop_t *desktop, IMLEName *lename)
class ICState

Detailed Description

Definition at line 12 of file IIIMP_IMState.hh.


Member Typedef Documentation

typedef map<CARD16BIT, ICState*> IMState::ICStateMap [inherited]

Definition at line 17 of file IMState.hh.

typedef pair<u16string, string> IIIMP_IMState::UserHostPair

Definition at line 15 of file IIIMP_IMState.hh.

Definition at line 16 of file IIIMP_IMState.hh.


Member Enumeration Documentation

enum IMState::CONTEXT_ID_SPECIAL [inherited]
Enumerator:
INVALID_CONTEXT_ID 

Definition at line 101 of file IMState.hh.

                            {
           INVALID_CONTEXT_ID = -1
    };

Constructor & Destructor Documentation

IIIMP_IMState::IIIMP_IMState ( IIIMP_IMState x,
int  proto_version 
) [inline]

Definition at line 49 of file IIIMP_IMState.hh.

      : IMState(x, proto_version)
    {
       pimt = x.pimt;
    }
IIIMP_IMState::IIIMP_IMState ( IIIMProtocol pimp,
IIIMPTrans pimt,
int  proto_version 
)

Definition at line 296 of file IIIMP_IMState.cpp.

  :
    IMState(1, pimp, NULL, proto_version)
{
    pimt = x_pimt;
}

Member Function Documentation

void IMState::add_icstate ( ICState pics) [protected, inherited]

Definition at line 49 of file IMState.cpp.

{
    CARD16BIT ic_id = pics->get_ic_id();
    ICStateMap& icmap = pshared->icmap;
    ASSERT(icmap.find(ic_id) == icmap.end());
    icmap[ic_id] = pics;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void IMState::change_state ( IMState newstate) [inline, protected, inherited]

Definition at line 42 of file IMState.hh.

    { 
       IMState *p = pbase_state;
       if (p->pproc_state) delete p->pproc_state;
       p->pproc_state = &newstate;
    }

Here is the caller graph for this function:

bool IMState::check_protocol_version ( int  version) [inline, protected, inherited]

Definition at line 61 of file IMState.hh.

    { return (get_current_protocol_version() >= version); }

Here is the call graph for this function:

Here is the caller graph for this function:

void IMState::cleanup_ic ( ) [protected, inherited]

Definition at line 69 of file IMState.cpp.

{
    ICStateMap::iterator it, it2;
    ICStateMap& icmap = pshared->icmap;
    for (it = icmap.begin(); it != icmap.end();) {
       it2 = it;
       it++;
       // this operation may invalidate it2.
       it2->second->destroy();
    }
}

Here is the caller graph for this function:

Here is the caller graph for this function:

bool IMState::deliver ( void *  message) [inline, inherited]

Definition at line 109 of file IMState.hh.

    {
       if (pproc_state)
           return pproc_state->message_proc(message);
       return message_proc(message);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void IIIMP_IMState::destroy ( ) [private, virtual]

Reimplemented from IMState.

Definition at line 281 of file IIIMP_IMState.cpp.

{
    UserIMStateMap::iterator it;

    for (it = IIIMP_IMState::user_imstate_map.begin(); it != IIIMP_IMState::user_imstate_map.end(); ++it) {
       if (it->second == this) {
           user_imstate_map.erase(it);
           break;
       }
    }

    delete get_iiimptrans();
    IMState::destroy();
}

Here is the call graph for this function:

bool IMState::dispatch ( CARD16BIT  im_id,
CARD16BIT  ic_id,
void *  message 
) [inherited]

Definition at line 89 of file IMState.cpp.

{
    if ((im_id != void_im_id) && (im_id != get_im_id())) {
       LOG_ERROR("Invalid im_id(%d).  This must be %d.",
                (int) im_id, (int) get_im_id());
       return false;
    }
    if (ic_id != void_ic_id) {
       ICStateMap::iterator it;

       it = pshared->icmap.find(ic_id);
       if (it != pshared->icmap.end()) {
           it->second->deliver(message);
           return true;
       } else {
           LOG_ERROR("Invalid ic_id(%d).  This ic_id is never issued.",
                    (int) ic_id);
       }
    } else {
       deliver(message);
       return true;
    }
    LOG_ERROR("Invalid im_id and ic_id (%d, %d)",
             (int) im_id, (int) ic_id);
    return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int IMState::get_current_protocol_version ( ) [inline, protected, inherited]

Definition at line 55 of file IMState.hh.

Here is the caller graph for this function:

IIIMP_hotkey_profile* IMState::get_hotkey_profile ( ) const [inline, inherited]

Definition at line 83 of file IMState.hh.

    { return pshared->hotkey_profile; }

Here is the caller graph for this function:

ICState* IMState::get_icstate ( CARD16BIT  ic_id) [inline, inherited]

Definition at line 92 of file IMState.hh.

    {
       ICStateMap *pmap = &pshared->icmap;
       ICStateMap::iterator it;
       it = pmap->find(ic_id);
       if (it == pmap->end()) return NULL;
       return it->second;
    }

Here is the caller graph for this function:

Definition at line 47 of file IIIMP_IMState.hh.

    { return pimt; }

Here is the caller graph for this function:

CARD16BIT IMState::get_im_id ( ) const [inline, inherited]

Definition at line 80 of file IMState.hh.

    { return pshared->im_id; }

Here is the caller graph for this function:

IMAccept * IMState::get_imaccept ( ) [protected, inherited]

Definition at line 43 of file IMState.cpp.

{
    return get_improtocol()->pimaccept;
}

Here is the call graph for this function:

Here is the caller graph for this function:

IMHandler* IMState::get_imhandler ( ) [inline, protected, inherited]

Definition at line 51 of file IMState.hh.

    { return pshared->pimh; }

Here is the caller graph for this function:

IMProtocol* IMState::get_improtocol ( ) [inline, protected, inherited]

Definition at line 49 of file IMState.hh.

    { return pshared->pimp; }

Here is the caller graph for this function:

Definition at line 948 of file IIIMP_IMState.cpp.

{
    UserIMStateMap::iterator it;

    for (it = IIIMP_IMState::user_imstate_map.begin(); it != IIIMP_IMState::user_imstate_map.end(); ++it) {
      const UserHostPair& p = it->first;
      u16string username = p.first;
      string hostname = p.second;
      unsigned int pos_colon;
      string d = string(desktop->display_id);
      pos_colon = d.find(':');
      string display_id = d.substr(pos_colon, d.size());
      string hnameDpy1 = string(desktop->host_name) + string(desktop->display_id);
      string hnameDpy = string(desktop->host_name) + string(display_id);
      if (strcmp(desktop->user_name, username.get_charstr()) == 0 &&
         strcmp(hnameDpy.c_str(), hostname.c_str()) == 0) {
       return it->second;
      }
    }

    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IMState::get_register_hotkey_flag ( ) const [inline, inherited]

Definition at line 89 of file IMState.hh.

Here is the caller graph for this function:

bool IIIMP_IMState::message_proc ( void *  message) [private, virtual]

Implements IMState.

Reimplemented in IIIMP_IMState_Session, and IIIMP_IMState_Identified.

Definition at line 203 of file IIIMP_IMState.cpp.

{
    IIIMP_message *pmes = (IIIMP_message*) x_pmes;
    IMState *pimns;

    switch (pmes->opcode) {
      case IM_CONNECT:
      {
         IMAccept *pima = get_imaccept();
         IMHandler *pimh;
         const IMLangList *planglist;
         u16string username, password;
         string hostname;
         int proto_version = pmes->v.connect.protocol_version;

         if (!parse_user_name(CONV_IIIMP_STR(pmes->v.connect.user_name),
                            username,
                            password,
                            hostname))
             return false;
         pimh = pima->request_connect(pimt->get_fd(),
                                   username,
                                   hostname,
                                   password,
                                   IMAuthList());
         if (!pimh) break;

         // Authentication is completed.  Now start communication!
         send_protocol_version(proto_version);

         planglist = pimh->get_langlist(NULL);

         {
             IIIMP_string *phead, *pcur = NULL, *pstr;
             IMLangList::const_iterator it;
             u16string langid;

             phead = NULL;
             for (it = planglist->begin(); it != planglist->end(); it++) {
                langid = it->get_id();
                pstr = iiimp_string_new(pimt->get_data_s(),
                                     langid.size(),
                                     langid.data());
                // memory error
                if (!pstr) break;
                if (!phead) phead = pstr;
                else pcur->next = pstr;
                pcur = pstr;
             }
             if (!send(iiimp_connect_reply_new(pimt->get_data_s(),
                                          get_im_id(),
                                          phead),
                     true))
                return false;
         }
         
         pimns = new IIIMP_IMState_Identified(this, pimh, proto_version);

         // send_trigger_keys();

         // send_hotkeys();

          // switch_hotkey_profile();
 
         change_state(*pimns);

         break;
      }
      default:
       LOG_ERROR("Invalid opcode:%d.  (Authentication is requied.)", pmes->opcode);
       return false;
    }
    return true;
}

Here is the call graph for this function:

bool IMState::new_ic_id ( CARD16BIT &  newid) const [protected, inherited]

Definition at line 121 of file IMState.cpp.

{
    int tid, size;
    ICStateMap *pmap = &pshared->icmap;

    size = pmap->size();
    for (tid = size + 1; ; ) {
       if (pmap->find(tid) == pmap->end()) {
           newid = tid;
           return true;
       }
       tid++;
       if (tid > ic_id_max) {
           tid = 1;
       }
       if (tid == size) {
           LOG_ERROR("Could not allocate new input context.");
           return false;
       }
    }
// not reached
    return false;
}

Here is the caller graph for this function:

bool IIIMP_IMState::parse_user_name ( const u16string uname,
u16string username,
u16string password,
string &  hostname 
) [private]

Definition at line 16 of file IIIMP_IMState.cpp.

{
    unsigned int pos_at, pos_sharp, pos_colon;
    u16string hname_u16;

    pos_at = uname.find('@');
    if (pos_at == u16string::npos) {
       hname_u16 = "";
       pos_sharp = uname.find('#');
       if (pos_sharp == u16string::npos) {
           username = uname;
           password = "";
       } else {
           username = uname.substr(0, pos_sharp);
           password = uname.substr(pos_sharp + 1);
       }
    } else {
       username = uname.substr(0, pos_at);
       pos_sharp = uname.find('#', pos_at);
       if (pos_sharp == u16string::npos) {
           hname_u16 = uname.substr(pos_at + 1);
           password = "";
       } else {
           hname_u16 = uname.substr(pos_at + 1, pos_sharp - pos_at - 1);
           password = uname.substr(pos_sharp + 1);
       }
    }

    if (!hname_u16.get_charstr()) return false;
    pos_colon = hname_u16.find(":");
    if (pos_colon == u16string::npos) {
      hostname = hname_u16.get_charstr();
    } else {
      hostname = (hname_u16.substr(0, pos_colon)).get_charstr();
    }
    UserHostPair user_host_pair = make_pair(username, std::string(hname_u16.get_charstr()));
    std::pair<const UserHostPair, IIIMP_IMState* > user_imstate_pair(user_host_pair, this);
    user_imstate_map.insert(user_imstate_pair);

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void IMState::remove_icstate ( ICState pics) [protected, inherited]

Definition at line 60 of file IMState.cpp.

{
    pshared->icmap.erase(pics->get_ic_id());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void IMState::reset_state ( ) [inline, protected, inherited]

Definition at line 36 of file IMState.hh.

    {
       IMState *p = pbase_state;
       if (p->pproc_state) delete p->pproc_state;
       p->pproc_state = NULL;
    }

Here is the caller graph for this function:

bool IIIMP_IMState::send ( IIIMP_message pmes,
bool  deletep = false 
)

Definition at line 64 of file IIIMP_IMState.cpp.

{
    if (!pmes) return false;
    // TODO...
    pimt->send(pmes);
    if (deletep)
       iiimp_message_delete(pimt->get_data_s(), pmes);
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IIIMP_IMState::send_hotkeys ( const u16string curr_input_lang,
HotKeyList *  hlist 
)

Definition at line 138 of file IIIMP_IMState.cpp.

{
    IIIMP_data_s *pdata_s = get_iiimptrans()->get_data_s();
    HOTKEY_LIST *hklist = (HOTKEY_LIST *)NULL;
    int i, profile_id, num_profiles, n_hotkeys;
    IMKeySpecList onkeys;
    IMKeySpecList offkeys;
    IIIMP_card16 scope_and_profile_id;
    IMHotkeyProfileStruct *hkps = const_cast<IMHotkeyProfileStruct *>(get_imhandler()->get_hotkey_profiles(&num_profiles));
    IMHotkeyStruct *hks;
    HotKeyList *tmp;

    if (hlist != NULL) {
       for (tmp = hlist; tmp != NULL; tmp = tmp->next) {
           LOG_DEBUG("Registering a trigger key <%s[%d]>%s[%d]", tmp->hotkey->modifiers, tmp->hotkey->modmask, tmp->hotkey->key, tmp->hotkey->keycode);
           onkeys.push_back(IMKeySpec(tmp->hotkey->keycode, 0, tmp->hotkey->modmask, 0));
       }
    } else {
       get_imhandler()->get_triggerkeys(onkeys, offkeys);
       onkeys.push_back(IMKeySpec(IM_VK_KANJI, 0, 0, 0));
       onkeys.push_back(IMKeySpec(IM_VK_KANJI, 0, IM_ALT_MASK, 0));
       if (strstr(curr_input_lang.get_charstr(), (char *)"ja") ||
           strstr(curr_input_lang.get_charstr(), (char *)"ko")) {
           LOG_DEBUG("For ja/ko locale clients, Shift+space is enabled for hotkey\n");
           onkeys.push_back(IMKeySpec(IM_VK_SPACE, 0, IM_SHIFT_MASK, 0));
       }
    }
    hks = get_hotkey_profile()->get_super_hotkeys(onkeys, curr_input_lang.get_charstr(), &n_hotkeys);
    get_hotkey_profile()->init_hotkey_profile_list(hkps, num_profiles);
    get_hotkey_profile()->add_super_hotkey_profiles(curr_input_lang, hks, n_hotkeys);
    num_profiles = get_hotkey_profile()->get_num_profiles();
    for (int i = 0; i < n_hotkeys; i++) {
       free(hks[i].label);
       delete [] hks[i].keys;
    }
    delete [] hks;

    for (i = 0; i < num_profiles; i++) {
       hklist = get_hotkey_profile()->retrive_hotkeys(pdata_s, i, &profile_id);
       scope_and_profile_id = (GLOBAL_HOTKEY << 15) | profile_id;
       if (!send(iiimp_register_hotkeys_new(pdata_s, get_im_id(), scope_and_profile_id, hklist), true))
           return false;
       scope_and_profile_id = 0;
       hklist = (HOTKEY_LIST *)NULL;
    }
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool IIIMP_IMState::send_protocol_version ( int  client_proto_version) [private]

Definition at line 78 of file IIIMP_IMState.cpp.

{
    if (client_proto_version > get_current_protocol_version())
       client_proto_version = get_current_protocol_version();

    // For version 2 clients or older ones,
    // we must not send IM_PROTOCOL_VERSION.
    if (client_proto_version <= 2)
       return true;

    IIIMP_data_s *pdata_s = get_iiimptrans()->get_data_s();
    if (!send(iiimp_protocol_version_new(pdata_s, get_im_id(), client_proto_version),
             true))
       return false;

    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 99 of file IIIMP_IMState.cpp.

{
    int i;
    int profile_id = get_hotkey_profile()->get_default_hotkey_profile_id();
    const IMKeySpecList *keylist = get_hotkey_profile()->retrieve_trigger_keys(profile_id);

    if (keylist != NULL) {
       IIIMP_keyevent_list *pion;
       IIIMP_keyevent_list *pioff;
       IIIMP_keyevent *keys = new IIIMP_keyevent[keylist->size()];
       IIIMP_data_s *pdata_s = get_iiimptrans()->get_data_s();
       IMKeySpecList::const_iterator it;

       for (i = 0, it = keylist->begin(); it != keylist->end(), i < keylist->size(); it++, i++) {
           keys[i].keycode = it->get_keycode();
           keys[i].keychar = it->get_keychar();
           keys[i].modifier = it->get_modifier();
           keys[i].time_stamp = it->get_timestamp();
       }
       pion = iiimp_keyevent_list_new(pdata_s, i, keys);
       pioff = iiimp_keyevent_list_new(pdata_s, i, keys);
       delete[] keys;
       if (!pion || !pioff) {
           if (pion)
              iiimp_keyevent_list_delete(pdata_s, pion);
           if (pioff)
              iiimp_keyevent_list_delete(pdata_s, pioff);
           return false;
       }
       if (!send(iiimp_register_trigger_keys_new(pdata_s, get_im_id(), pion, pioff), true))
           return false;

       return true;
    }

    return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void IMState::set_imhandler ( IMHandler pimh) [inline, protected, inherited]

Definition at line 53 of file IMState.hh.

    { pshared->pimh = pimh; }

Here is the caller graph for this function:

void IMState::set_register_hotkey_flag ( bool  flag) [inline, inherited]

Definition at line 86 of file IMState.hh.

Here is the caller graph for this function:

bool IMState::substatep ( ) [inline, inherited]

Definition at line 77 of file IMState.hh.

    { return (pbase_state != this); }

Here is the caller graph for this function:

Definition at line 190 of file IIIMP_IMState.cpp.

{
    IIIMP_data_s *pdata_s = get_iiimptrans()->get_data_s();
    IIIMP_card16 scope_and_profile_id;
    IIIMP_card16 profile_id = get_hotkey_profile()->get_default_hotkey_profile_id();
    LOG_DEBUG("Switching Hotkey Profile to default [%d]\n", profile_id);
    scope_and_profile_id = (GLOBAL_HOTKEY << 15) | profile_id;
    if (!send(iiimp_select_hotkey_profile_new(pdata_s, get_im_id(), scope_and_profile_id), true))
       return false;
    return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class ICState [friend, inherited]

Definition at line 142 of file IMState.hh.

int switch_le_profile ( iml_desktop_t desktop,
IMLEName lename 
) [friend]
int update_supported_langlist_for_le ( iml_desktop_t desktop,
IMLEName lename,
IMLocale locales,
int  nLocales 
) [friend]

Definition at line 1124 of file IIIMP_IMState.cpp.

{
    IIIMP_IMState *xims = IIIMP_IMState::get_imstate_from_desktop(desktop);

    if (xims == NULL)
       return false;
    // Update LEMgr's IMDescriptorList

    xims->get_imhandler()->update_imdesclist(lename, locales, nLocales);

    // TODO!! Send the updated IMDescriptorList to Client using IM_SETIMVALUES
    // IIIMP_IMState_Identified *xims_id = new IIIMP_IMState_Identified(xims, xims->get_imhandler(), xims->get_current_protocol_version());
    // xims_id->set_data_to_client();
    // receive_message = xims->get_iiimptrans()->receive();

    return true;
}

Member Data Documentation

Definition at line 20 of file IIIMP_IMState.hh.

Definition at line 19 of file IIIMP_IMState.hh.


The documentation for this class was generated from the following files: