Back to index

im-sdk  12.3.91
ICState.cpp
Go to the documentation of this file.
00001 #include <config.h>
00002 #include <stdio.h>
00003 #include "ICState.hh"
00004 #include "IMLog.hh"
00005 
00006 bool
00007 ICState::deliver(
00008     void *message
00009 )
00010 {
00011     ICState *p;
00012     bool result = true;
00013 
00014     if (pproc_state) p = pproc_state;
00015     else p = this;
00016 
00017     if (!p->message_proc(message)) return false;
00018 
00019     if (send_avail_p() && get_imlexec()) {
00020        result = get_imlexec()->execute();
00021     }
00022 
00023     if (terminatingp()) {
00024        LOG_DEBUG("Try to terminate IC(%d).", get_ic_id());
00025        if (pproc_state) {
00026            LOG_DEBUG("Right now, the current state in IC(%d) may be "
00027                     "waiting for client responce.",
00028                     get_ic_id());
00029        } else if (!(get_imlexec()->empty())){
00030            LOG_DEBUG("Pending IML instruction(s) still remain in IC(%d), "
00031                     "wait for the next chance.",
00032                     get_ic_id());
00033        } else {
00034            int id = get_ic_id();
00035            destroy();
00036            LOG_DEBUG("Successfully IC(%d) is terminated.", id);
00037        }
00038     }
00039 
00040     return result;
00041 }
00042 
00043 int
00044 ICState::invalid_operation(
00045     const char *opstr
00046 )
00047 {
00048     LOG_ERROR("Current IC state cannot deal with %s.", opstr);
00049     abort();
00050     return 0;
00051 }
00052 
00053 int
00054 ICState::toggle_client_convmode(
00055     bool flag
00056 )
00057 {
00058     return invalid_operation("toggle_client_convmode");
00059 }
00060 
00061 int
00062 ICState::forward_keyevent(
00063     IMKeyEventStruct *pkeyevent
00064 )
00065 {
00066     return invalid_operation("forward_keyevent");
00067 }
00068 
00069 int
00070 ICState::commit_string(
00071     IMText *pimtext
00072 )
00073 {
00074     return invalid_operation("commit_string");
00075 }
00076 
00077 int
00078 ICState::preedit_start()
00079 {
00080     return invalid_operation("preedit_start");
00081 }
00082 
00083 int
00084 ICState::draw_preedit(
00085     IMPreeditDrawCallbackStruct *pimpdraw
00086 )
00087 {
00088     return invalid_operation("draw_preedit");
00089 }
00090 
00091 int
00092 ICState::preedit_done()
00093 {
00094     return invalid_operation("preedit_done");
00095 }
00096 
00097 int
00098 ICState::status_start()
00099 {
00100     return invalid_operation("status_start");
00101 }
00102 
00103 int
00104 ICState::draw_status(
00105     IMStatusDrawCallbackStruct *pimsdraw
00106 )
00107 {
00108     return invalid_operation("draw_status");
00109 }
00110 
00111 int
00112 ICState::status_done()
00113 {
00114     return invalid_operation("status_done");
00115 }
00116 
00117 int
00118 ICState::lookup_start(
00119     IMLookupStartCallbackStruct *pimls
00120 )
00121 {
00122     return invalid_operation("lookup_start");
00123 }
00124 
00125 int
00126 ICState::draw_lookup(
00127     IMLookupDrawCallbackStruct *pimld
00128 )
00129 {
00130     return invalid_operation("draw_lookup");
00131 }
00132 
00133 int
00134 ICState::lookup_process(
00135     IMLookupProcessCallbackStruct *pimlp
00136 )
00137 {
00138     return invalid_operation("lookup_process");
00139 }
00140 
00141 int
00142 ICState::lookup_done()
00143 {
00144     return invalid_operation("lookup_done");
00145 }
00146 
00147 int
00148 ICState::aux_start(
00149     IMAuxStartCallbackStruct *pimauxstart
00150 )
00151 {
00152     return invalid_operation("aux_start");
00153 }
00154 
00155 int
00156 ICState::draw_aux(
00157     IMAuxDrawCallbackStruct *pimauxstart
00158 )
00159 {
00160     return invalid_operation("draw_aux");
00161 }
00162 
00163 int
00164 ICState::aux_done(
00165     IMAuxDoneCallbackStruct *pimauxstart
00166 )
00167 {
00168     return invalid_operation("aux_done");
00169 }
00170 
00171 int
00172 ICState::ns_listener(
00173     IMNSListenerStruct *prns
00174 )
00175 {
00176     return invalid_operation("ns_listener");
00177 }
00178 
00179 /*******************************************************************************
00180                        IMLExec_ICState
00181 *******************************************************************************/
00182 
00183 /***************************************
00184       execution handlers
00185 ***************************************/
00186 int
00187 IMLExec_ICState::imli_nop(
00188     iml_inst *rv
00189 )
00190 {
00191     return 0;
00192 }
00193 
00194 #define IML_STATUS_HENKAN_MODE_P(s) (s & IMLSTATUS_Henkan_Mode)
00195 
00196 int 
00197 IMLExec_ICState::imli_set_status(
00198     iml_inst *rv
00199 )
00200 {
00201     iml_status_t status = *(iml_status_t *) & (rv->operand);
00202     return pics->toggle_client_convmode(IML_STATUS_HENKAN_MODE_P(status));
00203 } 
00204 
00205 int 
00206 IMLExec_ICState::imli_reset(
00207     iml_inst *rv
00208 )
00209 {
00210     return 0;
00211 }
00212 
00213 int 
00214 IMLExec_ICState::imli_keypress(
00215     iml_inst *rv
00216 )
00217 {
00218     IMKeyEventStruct *key = (IMKeyEventStruct*)&rv->operand ;
00219     return pics->forward_keyevent(key);
00220 }
00221 
00222 int 
00223 IMLExec_ICState::imli_commit(
00224     iml_inst *rv
00225 )
00226 {
00227     IMText *cs = (IMText*) &rv->operand;
00228     return pics->commit_string(cs); 
00229 }
00230 
00231 int 
00232 IMLExec_ICState::imli_reset_return(
00233     iml_inst *rv
00234 )
00235 {
00236     IMText *cs = (IMText*) &rv->operand;
00237     return pics->commit_string(cs); 
00238 }
00239 
00240 int 
00241 IMLExec_ICState::imli_preedit_start(
00242     iml_inst *rv
00243 )
00244 {
00245     return pics->preedit_start();
00246 }
00247 
00248 int 
00249 IMLExec_ICState::imli_preedit_draw(
00250     iml_inst *rv
00251 )
00252 {
00253     IMPreeditDrawCallbackStruct *pimpdraw = (IMPreeditDrawCallbackStruct*) &rv->operand;
00254     return pics->draw_preedit(pimpdraw);
00255 }
00256 
00257 int 
00258 IMLExec_ICState::imli_preedit_done(
00259     iml_inst *rv
00260 )
00261 {
00262     return pics->preedit_done();
00263 }
00264 
00265 int 
00266 IMLExec_ICState::imli_preedit_caret(
00267     iml_inst *rv
00268 )
00269 {
00270 #if 0
00271     IMPreeditCaretCallbackStruct *pimpcaret = (IMPreeditCaretCallbackStruct*) &rv->operand;
00272 #endif
00273     LOG_ERROR("preedit_caret has already been expired.  Simply ignore it. (%d, %d)",
00274              pics->get_im_id(), pics->get_ic_id());
00275 
00276     return 0;
00277 }
00278 
00279 int 
00280 IMLExec_ICState::imli_status_start(
00281     iml_inst *rv
00282 )
00283 {
00284     return pics->status_start();
00285 }
00286 
00287 int 
00288 IMLExec_ICState::imli_status_draw(
00289     iml_inst *rv
00290 )
00291 {
00292     IMStatusDrawCallbackStruct *pimsdraw = (IMStatusDrawCallbackStruct*) &rv->operand;
00293     return pics->draw_status(pimsdraw);
00294 }
00295 
00296 int 
00297 IMLExec_ICState::imli_status_done(
00298     iml_inst *rv
00299 )
00300 {
00301     return pics->status_done();
00302 }
00303 
00304 int 
00305 IMLExec_ICState::imli_lookup_start(
00306     iml_inst *rv
00307 )
00308 {
00309     IMLookupStartCallbackStruct *pimls = (IMLookupStartCallbackStruct*) &rv->operand;
00310     return pics->lookup_start(pimls);
00311 }
00312 
00313 int 
00314 IMLExec_ICState::imli_lookup_draw(
00315     iml_inst *rv
00316 )
00317 {
00318     IMLookupDrawCallbackStruct *pimld = (IMLookupDrawCallbackStruct*) &rv->operand;
00319     return pics->draw_lookup(pimld);
00320 }
00321 
00322 int 
00323 IMLExec_ICState::imli_lookup_process(
00324     iml_inst *rv
00325 )
00326 {
00327 #if 0
00328     IMLookupProcessCallbackStruct *pimlp = (IMLookupProcessCallbackStruct*) &rv->operand;
00329     return pics->lookup_process(pimlp);
00330 #else
00331     return 0;
00332 #endif
00333 }
00334 
00335 int 
00336 IMLExec_ICState::imli_lookup_done(
00337     iml_inst *rv
00338 )
00339 {
00340     return pics->lookup_done();
00341 }
00342 
00343 int 
00344 IMLExec_ICState::imli_aux_start(
00345     iml_inst *rv
00346 )
00347 {
00348     IMAuxStartCallbackStruct *pimauxstart = (IMAuxStartCallbackStruct*) &rv->operand;
00349     return pics->aux_start(pimauxstart);
00350 }
00351 
00352 int 
00353 IMLExec_ICState::imli_aux_draw(
00354     iml_inst *rv
00355 )
00356 {
00357     IMAuxDrawCallbackStruct *pimauxdraw = (IMAuxDrawCallbackStruct*) &rv->operand;
00358     return pics->draw_aux(pimauxdraw);
00359 }
00360 
00361 int 
00362 IMLExec_ICState::imli_aux_done(
00363     iml_inst *rv
00364 )
00365 {
00366     IMAuxDoneCallbackStruct *pimauxdone = (IMAuxDoneCallbackStruct*) &rv->operand;
00367     return pics->aux_done(pimauxdone);
00368 }
00369 
00370 int 
00371 IMLExec_ICState::imli_ns_listener(
00372     iml_inst *rv
00373 )
00374 {
00375     IMNSListenerStruct *prns = (IMNSListenerStruct *) &rv->operand;
00376     return pics->ns_listener(prns);
00377 }
00378 
00379 int 
00380 IMLExec_ICState::imli_key_info(
00381     iml_inst *rv
00382 )
00383 {
00384     return 0;
00385 }
00386 
00387 int 
00388 IMLExec_ICState::imli_put_queue(
00389     iml_inst *rv
00390 )
00391 {
00392     return 0;
00393 }
00394 
00395 
00396 int
00397 IMLExec_ICState::execute_opcode(
00398     int opcode,
00399     iml_inst *rv
00400 )
00401 {
00402     switch (opcode) {
00403       case IMM_NOP:
00404        return imli_nop(rv);
00405       case IMM_SET_STATUS:
00406        return imli_set_status(rv);
00407       case IMM_RESET:
00408        return imli_reset(rv);
00409       case IMM_KEYPRESS:
00410        return imli_keypress(rv);
00411       case IMM_COMMIT:
00412        return imli_commit(rv);
00413       case IMM_RESET_RETURN:
00414        return imli_reset_return(rv);
00415       case IMM_PREEDIT_START:
00416        return imli_preedit_start(rv);
00417       case IMM_PREEDIT_DRAW:
00418        return imli_preedit_draw(rv);
00419       case IMM_PREEDIT_DONE:
00420        return imli_preedit_done(rv);
00421       case IMM_PREEDIT_CARET: 
00422        return imli_preedit_caret(rv);
00423       case IMM_STATUS_START: 
00424        return imli_status_start(rv);
00425       case IMM_STATUS_DRAW:
00426        return imli_status_draw(rv);
00427       case IMM_STATUS_DONE:
00428        return imli_status_done(rv);
00429       case IMM_LOOKUP_START:
00430        return imli_lookup_start(rv);
00431       case IMM_LOOKUP_DRAW:
00432        return imli_lookup_draw(rv);
00433       case IMM_LOOKUP_PROCESS:
00434        return imli_lookup_process(rv);
00435       case IMM_LOOKUP_DONE:
00436        return imli_lookup_done(rv);
00437       case IMM_AUX_START_2:
00438        return imli_aux_start(rv);
00439       case IMM_AUX_DRAW_2:
00440        return imli_aux_draw(rv);
00441       case IMM_AUX_DONE_2:
00442        return imli_aux_done(rv);
00443       case IMM_NS_LISTENER:
00444        return imli_ns_listener(rv);
00445       case IMM_KEY_INFO:
00446        return imli_key_info(rv);
00447       case IMM_PUT_QUEUE:
00448        return imli_put_queue(rv);
00449     }
00450     return imli_nop(rv);
00451 }
00452 
00453 bool
00454 IMLExec_ICState::push_back(
00455     iml_inst *pinst
00456 )
00457 {
00458     pinst = iml_duplicate_inst(pinst);
00459     // memory error.
00460     if (!pinst) return false;
00461     pendinglist.push_back(pinst);
00462     return true;
00463 }
00464 
00465 iml_inst*
00466 IMLExec_ICState::push_insts(
00467     iml_inst **rrv
00468 )
00469 {
00470     iml_inst *pcur;
00471     iml_inst *result = NULL;
00472     int op;
00473 
00474     for (pcur = *rrv; pcur != (iml_inst*)0; pcur = pcur->next) {
00475        op = pcur->opcode & ~IMM_CB_RESULT_REQUIRED;
00476        if ((op < 0) || (op >= MAX_IMM_OPCODE)) {
00477            break;
00478        }
00479        push_back(pcur);
00480        if (pcur->opcode & IMM_CB_RESULT_REQUIRED) {
00481            if (!result) result = pcur;
00482        }
00483     }
00484     return result ;
00485 }
00486 
00487 bool
00488 IMLExec_ICState::execute()
00489 {
00490     iml_inst *pinst;
00491     int op;
00492 
00493     while (pics->send_avail_p() && !pendinglist.empty()) {
00494        pinst = pendinglist.front();
00495        op = pinst->opcode & ~IMM_CB_RESULT_REQUIRED;
00496        execute_opcode(op, pinst);
00497        pendinglist.pop_front();
00498        iml_delete_inst(pinst);
00499     }
00500 
00501     return true;
00502 }
00503 
00504 IMLExec_ICState::~IMLExec_ICState()
00505 {
00506     IMLInstList::iterator it;
00507     for (it = pendinglist.begin(); it != pendinglist.end(); it++) {
00508        iml_delete_inst(*it);
00509     }
00510 }
00511 
00512 
00513 /* Local Variables: */
00514 /* c-file-style: "iiim-project" */
00515 /* End: */