Back to index

im-sdk  12.3.91
request.c
Go to the documentation of this file.
00001 #include <iiimp-data.h>
00002 #include <iiimp.h>
00003 
00004 #include "input-method.h"
00005 #include "input-context.h"
00006 #include "sequence.h"
00007 #include "stream.h"
00008 #include "opcode-reply.h"
00009 
00010 
00011 IIIMF_status
00012 iiimf_request_send(
00013     IIIMF_im *              im,
00014     IIIMF_ic *              ic,
00015     IIIMP_message *  message)
00016 {
00017     IIIMF_status     status;
00018     int                     opcode_reply;
00019     IIIMP_message *  message_receive;
00020 
00021     message_receive = NULL;
00022 
00023     status = iiimf_message_sequence(im, ic, message, IIIMF_MESSAGE_ATTR_SEND);
00024     if (IIIMF_STATUS_SUCCESS != status) return status;
00025 
00026     status = iiimf_stream_send(im->stream, im->data_s, message);
00027     if (IIIMF_STATUS_SUCCESS != status) return status;
00028 
00029     opcode_reply = iiimf_opcode_reply_internal(message->opcode);
00030     if (IM_NOP == opcode_reply) return IIIMF_STATUS_SUCCESS;
00031 
00032     for (;;) {
00033        if (NULL != message_receive) {
00034            iiimp_message_delete(im->data_s, message_receive);
00035        }
00036 
00037        status = iiimf_stream_receive(im->stream, im->data_s, &message_receive);
00038        if (IIIMF_STATUS_SUCCESS != status) break;
00039 
00040        status = iiimf_message_sequence(im, ic, message_receive,
00041                                    IIIMF_MESSAGE_ATTR_RECEIVE);
00042        if (IIIMF_STATUS_SUCCESS != status) break;
00043 
00044        if (IM_CREATEIC_REPLY == message_receive->opcode) {
00045            ic->ic_id = message_receive->ic_id;
00046        }
00047 
00048        status = (im->message_handler_call)(im, message_receive);
00049        if (IIIMF_STATUS_SUCCESS != status) {
00050            break;
00051        }
00052 
00053        if (opcode_reply == message_receive->opcode) {
00054            break;
00055        }
00056 
00057        status = iiimf_request_reply(im, ic, message_receive);
00058        if (IIIMF_STATUS_SUCCESS != status) break;
00059     }
00060 
00061     if (NULL != message_receive) {
00062        iiimp_message_delete(im->data_s, message_receive);
00063     }
00064 
00065     return status;
00066 }
00067 
00068 
00069 IIIMF_status
00070 iiimf_request_loop(IIIMF_im * im)
00071 {
00072     IIIMF_ic *              ic;
00073     IIIMP_message *  message;
00074     IIIMF_status     status;
00075     IIIMP_data_s *   data_s;
00076 
00077     ic = NULL;
00078     message = NULL;
00079     data_s = im->data_s;
00080 
00081     for (;;) {
00082        if (NULL != message) {
00083            iiimp_message_delete(data_s, message);
00084        }
00085 
00086        status = iiimf_stream_receive(im->stream, data_s, &message);
00087        if (IIIMF_STATUS_SUCCESS != status) return status;
00088 
00089        status = iiimf_message_sequence(im, ic, message,
00090                                    IIIMF_MESSAGE_ATTR_RECEIVE);
00091        if (IIIMF_STATUS_SUCCESS != status) break;
00092 
00093        status = (im->message_handler_call)(im, message);
00094        if (IIIMF_STATUS_SUCCESS != status) {
00095            break;
00096        }
00097 
00098        if (-1 == message->ic_id) {
00099            ic = NULL;
00100        } else {
00101            for (ic = im->ic_list; NULL != ic; ic = ic->next) {
00102               if (message->ic_id == ic->ic_id) break;
00103            }
00104            if (NULL == ic) return IIIMF_STATUS_IC_INVALID;
00105        }
00106 
00107        status = iiimf_request_reply(im, ic, message);
00108        if (IIIMF_STATUS_SUCCESS != status) break;
00109     }
00110 
00111     if (NULL != message) {
00112        iiimp_message_delete(data_s, message);
00113     }
00114 
00115     return status;
00116 }
00117 
00118 /* Local Variables: */
00119 /* c-file-style: "iiim-project" */
00120 /* End: */