Back to index

im-sdk  12.3.91
sequence.c
Go to the documentation of this file.
00001 #include <iiimp.h>
00002 
00003 #include "input-method.h"
00004 #include "input-context.h"
00005 #include "sequence.h"
00006 #include "opcode-reply.h"
00007 
00008 
00009 #define       ATTR_NONE            IIIMF_MESSAGE_ATTR_NONE
00010 #define       ROLE_CLIENT          IIIMF_MESSAGE_ATTR_ROLE_CLIENT
00011 #define       ROLE_SERVER          IIIMF_MESSAGE_ATTR_ROLE_SERVER
00012 #define       ROLE_BOTH            IIIMF_MESSAGE_ATTR_ROLE_BOTH
00013 #define REQUEST                    IIIMF_MESSAGE_ATTR_REQUEST
00014 #define REPLY               IIIMF_MESSAGE_ATTR_REPLY
00015 #define NO_REPLY            IIIMF_MESSAGE_ATTR_NO_REPLY
00016 #define IM_ACTIVE           IIIMF_MESSAGE_ATTR_IM_ACTIVE
00017 #define IC_ACTIVE           IIIMF_MESSAGE_ATTR_IC_ACTIVE
00018 #define STATUS_ACTIVE              IIIMF_MESSAGE_ATTR_STATUS_ACTIVE
00019 #define PREEDIT_ACTIVE             IIIMF_MESSAGE_ATTR_PREEDIT_ACTIVE
00020 #define LUC_ACTIVE          IIIMF_MESSAGE_ATTR_LOOKUP_CHOICE_ACTIVE
00021 #define AUX_ACTIVE          IIIMF_MESSAGE_ATTR_AUX_ACTIVE
00022 
00023 
00024 static const int     message_attribute[128] = {
00025        ATTR_NONE,    /* 0 */
00026 
00027        ROLE_CLIENT | REQUEST,                    /* IM_CONNECT */
00028        ROLE_SERVER | REPLY,               /* IM_CONNECT_REPLY */
00029        ROLE_CLIENT | REQUEST       | IM_ACTIVE,  /* IM_DISCONNECT */
00030        ROLE_SERVER | REPLY  | IM_ACTIVE,  /* IM_DISCONNECT_REPLY */
00031        ROLE_SERVER | REQUEST,                    /* IM_REGISTER_TRIGGER_KEYS */
00032        ROLE_BOTH   | REQUEST       | IC_ACTIVE,  /* IM_TRIGGER_NOTIFY */
00033        ROLE_BOTH   | REPLY  | IC_ACTIVE,  /* IM_TRIGGER_NOTIFY_REPLY */
00034        ROLE_BOTH   | REQUEST       | IM_ACTIVE,  /* IM_SETIMVALUES */
00035        ROLE_BOTH   | REPLY  | IM_ACTIVE,  /* IM_SETIMVALUES_REPLY */
00036        ROLE_CLIENT | REQUEST       | IM_ACTIVE,  /* IM_GETIMVALUES */
00037        ROLE_SERVER | REPLY  | IM_ACTIVE,  /* IM_GETIMVALUES_REPLY */
00038 
00039        ROLE_BOTH   | REQUEST       | IC_ACTIVE,  /* IM_FORWARD_EVENT */
00040        ROLE_BOTH   | REPLY  | IC_ACTIVE,  /* IM_FORWARD_EVENT_REPLY */
00041        ROLE_SERVER | NO_REPLY      | IC_ACTIVE,  /* IM_COMMIT_STRING */
00042        ROLE_BOTH   | REQUEST       | IC_ACTIVE,  /* IM_FORWARD_EVENT_WITH_OPERATIONS */
00043        ROLE_BOTH   | REPLY  | IC_ACTIVE,  /* IM_FORWARD_EVENT_WITH_OPERATIONS_REPLY */
00044 
00045        ATTR_NONE,    /* 17 */
00046        ATTR_NONE,    /* 18 */
00047        ATTR_NONE,    /* 19 */
00048 
00049        ROLE_CLIENT | REQUEST       | IM_ACTIVE,  /* IM_CREATEIC */
00050        ROLE_SERVER | REPLY  | IM_ACTIVE,  /* IM_CREATEIC_REPLY */
00051        ROLE_CLIENT | REQUEST       | IC_ACTIVE,  /* IM_DESTROYIC */
00052        ROLE_SERVER | REPLY  | IC_ACTIVE,  /* IM_DESTROYIC_REPLY */
00053        ROLE_CLIENT | REQUEST       | IC_ACTIVE,  /* IM_SETICVALUES */
00054        ROLE_SERVER | REPLY  | IC_ACTIVE,  /* IM_SETICVALUES_REPLY */
00055        ROLE_CLIENT | REQUEST       | IC_ACTIVE,  /* IM_GETICVALUES */
00056        ROLE_SERVER | REPLY  | IC_ACTIVE,  /* IM_GETICVALUES_REPLY */
00057        ROLE_CLIENT | REQUEST       | IC_ACTIVE,  /* IM_SETICFOCUS */
00058        ROLE_SERVER | REPLY  | IC_ACTIVE,  /* IM_SETICFOCUS_REPLY */
00059        ROLE_CLIENT | REQUEST       | IC_ACTIVE,  /* IM_UNSETICFOCUS */
00060        ROLE_SERVER | REPLY  | IC_ACTIVE,  /* IM_UNSETICFOCUS_REPLY */
00061        ROLE_CLIENT | REQUEST       | IC_ACTIVE,  /* IM_RESETIC */
00062        ROLE_SERVER | REPLY  | IC_ACTIVE,  /* IM_RESETIC_REPLY */
00063 
00064        ATTR_NONE,    /* 34 */
00065        ATTR_NONE,    /* 35 */
00066        ATTR_NONE,    /* 36 */
00067        ATTR_NONE,    /* 37 */
00068        ATTR_NONE,    /* 38 */
00069        ATTR_NONE,    /* 39 */
00070 
00071        ROLE_SERVER | REQUEST       | IC_ACTIVE,                /* IM_PREEDIT_START */
00072        ROLE_CLIENT | REPLY  | IC_ACTIVE,                /* IM_PREEDIT_START_REPLY */
00073        ROLE_SERVER | REQUEST       | IC_ACTIVE | PREEDIT_ACTIVE,      /* IM_PREEDIT_DRAW */
00074        ROLE_CLIENT | REPLY  | IC_ACTIVE | PREEDIT_ACTIVE,      /* IM_PREEDIT_DRAW_REPLY */
00075        ATTR_NONE,    /* 44 */
00076        ATTR_NONE,    /* 45 */
00077        ROLE_SERVER | REQUEST       | IC_ACTIVE,                /* IM_PREEDIT_DONE */
00078        ROLE_CLIENT | REPLY  | IC_ACTIVE,                /* IM_PREEDIT_DONE_REPLY */
00079 
00080        ATTR_NONE,    /* 48 */
00081        ATTR_NONE,    /* 49 */
00082 
00083        ROLE_SERVER | REQUEST       | IC_ACTIVE,                /* IM_STATUS_START */
00084        ROLE_CLIENT | REPLY  | IC_ACTIVE,                /* IM_STATUS_START_REPLY */
00085        ROLE_SERVER | REQUEST       | IC_ACTIVE | STATUS_ACTIVE,       /* IM_STATUS_DRAW */
00086        ROLE_CLIENT | REPLY  | IC_ACTIVE | STATUS_ACTIVE,       /* IM_STATUS_DRAW_REPLY */
00087        ROLE_SERVER | REQUEST       | IC_ACTIVE,                /* IM_STATUS_DONE */
00088        ROLE_CLIENT | REPLY  | IC_ACTIVE,                /* IM_STATUS_DONE_REPLY */
00089 
00090        ATTR_NONE,    /* 56 */
00091        ATTR_NONE,    /* 57 */
00092        ATTR_NONE,    /* 58 */
00093        ATTR_NONE,    /* 59 */
00094        ATTR_NONE,    /* 60 */
00095        ATTR_NONE,    /* 61 */
00096        ATTR_NONE,    /* 62 */
00097        ATTR_NONE,    /* 63 */
00098        ATTR_NONE,    /* 64 */
00099        ATTR_NONE,    /* 65 */
00100        ATTR_NONE,    /* 66 */
00101        ATTR_NONE,    /* 67 */
00102        ATTR_NONE,    /* 68 */
00103        ATTR_NONE,    /* 69 */
00104 
00105        ROLE_SERVER | REQUEST       | IC_ACTIVE,                /* IM_LOOKUP_CHOICE_START */
00106        ROLE_CLIENT | REPLY  | IC_ACTIVE,                /* IM_LOOKUP_CHOICE_START_REPLY */
00107        ROLE_SERVER | REQUEST       | IC_ACTIVE | LUC_ACTIVE,   /* IM_LOOKUP_CHOICE_DRAW */
00108        ROLE_CLIENT | REPLY  | IC_ACTIVE | LUC_ACTIVE,   /* IM_LOOKUP_CHOICE_DRAW_REPLY */
00109        ROLE_SERVER | REQUEST       | IC_ACTIVE,                /* IM_LOOKUP_CHOICE_DONE */
00110        ROLE_CLIENT | REPLY  | IC_ACTIVE,                /* IM_LOOKUP_CHOICE_DONE_REPLY */
00111        ROLE_SERVER | REQUEST       | IC_ACTIVE | LUC_ACTIVE,   /* IM_LOOKUP_CHOICE_PROCESS */
00112        ROLE_CLIENT | REPLY  | IC_ACTIVE | LUC_ACTIVE,   /* IM_LOOKUP_CHOICE_PROCESS_REPLY */
00113 
00114        ATTR_NONE,    /* 78 */
00115        ATTR_NONE,    /* 79 */
00116        ATTR_NONE,    /* 80 */
00117        ATTR_NONE,    /* 81 */
00118        ATTR_NONE,    /* 82 */
00119        ATTR_NONE,    /* 83 */
00120        ATTR_NONE,    /* 84 */
00121        ATTR_NONE,    /* 85 */
00122        ATTR_NONE,    /* 86 */
00123        ATTR_NONE,    /* 87 */
00124        ATTR_NONE,    /* 88 */
00125        ATTR_NONE,    /* 89 */
00126 
00127        ROLE_SERVER | REQUEST       | IC_ACTIVE,                /* IM_AUX_START */
00128        ROLE_CLIENT | REPLY  | IC_ACTIVE,                /* IM_AUX_START_REPLY */
00129        ROLE_SERVER | REQUEST       | IC_ACTIVE /* | AUX_ACTIVE */,    /* IM_AUX_DRAW */
00130        ROLE_CLIENT | REPLY  | IC_ACTIVE /* | AUX_ACTIVE */,    /* IM_AUX_DRAW_REPLY */
00131        ROLE_SERVER | REQUEST       | IC_ACTIVE,                /* IM_AUX_DONE */
00132        ROLE_CLIENT | REPLY  | IC_ACTIVE,                /* IM_AUX_DONE_REPLY */
00133        ROLE_CLIENT | REQUEST       | IC_ACTIVE /* | AUX_ACTIVE */,    /* IM_AUX_SETVALUES */
00134        ROLE_SERVER | REPLY  | IC_ACTIVE /* | AUX_ACTIVE */,    /* IM_AUX_SETVALUES_REPLY */
00135 
00136        ROLE_CLIENT | REQUEST       | IC_ACTIVE /* | AUX_ACTIVE */,    /* IM_AUX_GETVALUES */
00137        ROLE_SERVER | REPLY  | IC_ACTIVE /* | AUX_ACTIVE */,    /* IM_AUX_GETVALUES_REPLY */
00138        ATTR_NONE,    /* 100 */
00139        ATTR_NONE,    /* 101 */
00140        ATTR_NONE,    /* 102 */
00141        ATTR_NONE,    /* 103 */
00142        ATTR_NONE,    /* 104 */
00143        ATTR_NONE,    /* 105 */
00144        ATTR_NONE,    /* 106 */
00145        ATTR_NONE,    /* 107 */
00146        ATTR_NONE,    /* 108 */
00147        ATTR_NONE,    /* 109 */
00148        ATTR_NONE,    /* 110 */
00149        ATTR_NONE,    /* 111 */
00150        ATTR_NONE,    /* 112 */
00151        ATTR_NONE,    /* 113 */
00152        ATTR_NONE,    /* 114 */
00153        ATTR_NONE,    /* 115 */
00154        ATTR_NONE,    /* 116 */
00155        ATTR_NONE,    /* 117 */
00156        ATTR_NONE,    /* 118 */
00157        ATTR_NONE,    /* 119 */
00158        ATTR_NONE,    /* 120 */
00159        ATTR_NONE,    /* 121 */
00160        ATTR_NONE,    /* 122 */
00161        ATTR_NONE,    /* 123 */
00162        ATTR_NONE,    /* 124 */
00163        ATTR_NONE,    /* 125 */
00164        ATTR_NONE,    /* 126 */
00165        ATTR_NONE,    /* 127 */
00166 };
00167 
00168 
00169 IIIMF_status
00170 iiimf_message_sequence(
00171     IIIMF_im *              im,
00172     IIIMF_ic *              ic,
00173     IIIMP_message *  message,
00174     int                     direction)
00175 {
00176     IIIMF_status            status;
00177     int                            attr_cur;
00178     int                            attr;
00179     int                            attr_active;
00180     int                            opcode_reply;
00181     IIIMF_message_pending * mp;
00182 
00183     status = IIIMF_STATUS_SUCCESS;
00184 
00185     attr = message_attribute[message->opcode];
00186 
00187     if ((0 == (IIIMF_MESSAGE_ATTR_ROLE_BOTH & attr)) &&
00188        ((IIIMF_MESSAGE_ATTR_ROLE_DIRECTION_MASK & attr) ==
00189         (im->role ^ direction))) {
00190        return IIIMF_STATUS_SEQUENCE_ROLE;
00191     }
00192 
00193     attr_cur = ((NULL == ic) ? im->state : (im->state | ic->state));
00194 
00195     attr_active = (IIIMF_MESSAGE_ATTR_ACTIVE_MASK & attr);
00196     if (attr_active != (attr_active & attr_cur)) {
00197        return IIIMF_STATUS_SEQUENCE_STATE;
00198     }
00199 
00200     if (0 != (IIIMF_MESSAGE_ATTR_REPLY & attr)) {
00201        /*
00202         * REPLY message must follow REQUEST message
00203         */
00204        if (im->message_depth <= 0) {
00205            return IIIMF_STATUS_SEQUENCE_REQUEST;
00206        }
00207 
00208        im->message_depth -= 1;
00209        mp = (im->message_pending + im->message_depth);
00210        opcode_reply = iiimf_opcode_reply_internal(mp->opcode);
00211 
00212        if ((message->opcode != opcode_reply) || (direction == mp->direction)) {
00213            return IIIMF_STATUS_SEQUENCE_REQUEST;
00214        }
00215 
00216     } else {
00217        opcode_reply = iiimf_opcode_reply_internal(message->opcode);
00218        if (IM_NOP != opcode_reply) {
00219            if (im->message_depth_maximum <= im->message_depth) {
00220               return IIIMF_STATUS_SEQUENCE_NEST;
00221            }
00222            mp = (im->message_pending + im->message_depth);
00223            mp->opcode = message->opcode;
00224            mp->direction = direction;
00225            im->message_depth += 1;
00226        }
00227     }
00228 
00229     switch (message->opcode) {
00230     case IM_CONNECT:
00231        im->state |= IIIMF_MESSAGE_ATTR_IM_IM_CONNECT;
00232        break;
00233 
00234     case IM_CONNECT_REPLY:
00235        if (-1 == im->im_id) {
00236            im->im_id = message->im_id;
00237        } else if (message->im_id != im->im_id) {
00238            return IIIMF_STATUS_SEQUENCE_STATE;
00239        }
00240        im->state &= ~IIIMF_MESSAGE_ATTR_IM_IM_CONNECT;
00241        im->state |= IIIMF_MESSAGE_ATTR_IM_ACTIVE;
00242        break;
00243 
00244     case IM_DISCONNECT:
00245        break;
00246 
00247     case IM_DISCONNECT_REPLY:
00248        im->state &= IIIMF_MESSAGE_ATTR_NONE;
00249        break;
00250 
00251     case IM_REGISTER_TRIGGER_KEYS:
00252        if ((0 != (IIIMF_MESSAGE_ATTR_IM_ACTIVE & im->state)) ||
00253            (0 == (IIIMF_MESSAGE_ATTR_IM_IM_CONNECT & im->state))) {
00254            return IIIMF_STATUS_SEQUENCE_STATE;
00255        }
00256        im->im_id = message->im_id;
00257        break;
00258 
00259     case IM_TRIGGER_NOTIFY:
00260     case IM_TRIGGER_NOTIFY_REPLY:
00261     case IM_SETIMVALUES:
00262     case IM_SETIMVALUES_REPLY:
00263     case IM_GETIMVALUES:
00264     case IM_GETIMVALUES_REPLY:
00265     case IM_FORWARD_EVENT:
00266     case IM_FORWARD_EVENT_REPLY:
00267     case IM_COMMIT_STRING:
00268     case IM_FORWARD_EVENT_WITH_OPERATIONS:
00269     case IM_FORWARD_EVENT_WITH_OPERATIONS_REPLY:
00270     case IM_CREATEIC:
00271        break;
00272 
00273     case IM_CREATEIC_REPLY:
00274        im->state |= IIIMF_MESSAGE_ATTR_IC_ACTIVE;
00275        ic->ic_id = message->ic_id;
00276        break;
00277 
00278     case IM_DESTROYIC:
00279        break;
00280 
00281     case IM_DESTROYIC_REPLY:
00282        im->state &= ~(IIIMF_MESSAGE_ATTR_IC_ACTIVE |
00283                      IIIMF_MESSAGE_ATTR_STATUS_ACTIVE |
00284                      IIIMF_MESSAGE_ATTR_PREEDIT_ACTIVE |
00285                      IIIMF_MESSAGE_ATTR_LOOKUP_CHOICE_ACTIVE |
00286                      IIIMF_MESSAGE_ATTR_AUX_ACTIVE);
00287        break;
00288 
00289     case IM_SETICVALUES:
00290     case IM_SETICVALUES_REPLY:
00291     case IM_GETICVALUES:
00292     case IM_GETICVALUES_REPLY:
00293     case IM_SETICFOCUS:
00294     case IM_SETICFOCUS_REPLY:
00295     case IM_UNSETICFOCUS:
00296     case IM_UNSETICFOCUS_REPLY:
00297     case IM_RESETIC:
00298     case IM_RESETIC_REPLY:
00299     case IM_PREEDIT_START:
00300        break;
00301 
00302     case IM_PREEDIT_START_REPLY:
00303        im->state |= IIIMF_MESSAGE_ATTR_PREEDIT_ACTIVE;
00304        break;
00305 
00306     case IM_PREEDIT_DRAW:
00307     case IM_PREEDIT_DRAW_REPLY:
00308     case IM_PREEDIT_DONE:
00309        break;
00310 
00311     case IM_PREEDIT_DONE_REPLY:
00312 
00313        im->state &= ~IIIMF_MESSAGE_ATTR_PREEDIT_ACTIVE;
00314        break;
00315 
00316     case IM_STATUS_START:
00317        break;
00318 
00319     case IM_STATUS_START_REPLY:
00320        im->state |= IIIMF_MESSAGE_ATTR_STATUS_ACTIVE;
00321        break;
00322 
00323     case IM_STATUS_DRAW:
00324     case IM_STATUS_DRAW_REPLY:
00325     case IM_STATUS_DONE:
00326        break;
00327 
00328     case IM_STATUS_DONE_REPLY:
00329        im->state &= ~IIIMF_MESSAGE_ATTR_STATUS_ACTIVE;
00330        break;
00331 
00332     case IM_LOOKUP_CHOICE_START:
00333        break;
00334 
00335     case IM_LOOKUP_CHOICE_START_REPLY:
00336        im->state |= IIIMF_MESSAGE_ATTR_LOOKUP_CHOICE_ACTIVE;
00337        break;
00338 
00339     case IM_LOOKUP_CHOICE_DRAW:
00340     case IM_LOOKUP_CHOICE_DRAW_REPLY:
00341     case IM_LOOKUP_CHOICE_DONE:
00342        break;
00343 
00344     case IM_LOOKUP_CHOICE_DONE_REPLY:
00345        im->state &= ~IIIMF_MESSAGE_ATTR_LOOKUP_CHOICE_ACTIVE;
00346        break;
00347 
00348     case IM_LOOKUP_CHOICE_PROCESS:
00349     case IM_LOOKUP_CHOICE_PROCESS_REPLY:
00350     case IM_AUX_START:
00351        break;
00352 
00353     case IM_AUX_START_REPLY:
00354        im->state |= IIIMF_MESSAGE_ATTR_AUX_ACTIVE;
00355        break;
00356 
00357     case IM_AUX_DRAW:
00358     case IM_AUX_DRAW_REPLY:
00359     case IM_AUX_DONE:
00360        break;
00361 
00362     case IM_AUX_DONE_REPLY:
00363        im->state &= ~IIIMF_MESSAGE_ATTR_AUX_ACTIVE;
00364        break;
00365 
00366     case IM_AUX_SETVALUES:
00367     case IM_AUX_SETVALUES_REPLY:
00368        break;
00369 
00370     case IM_AUX_GETVALUES:
00371     case IM_AUX_GETVALUES_REPLY:
00372        break;
00373     }
00374 
00375     return status;
00376 }
00377 
00378 
00379 /* Local Variables: */
00380 /* c-file-style: "iiim-project" */
00381 /* End: */