Back to index

im-sdk  12.3.91
im-status-draw.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 
00005 #include <iiimp-data.h>
00006 #include <iiimp-opcode.h>
00007 
00008 #include "iiimp-dataP.h"
00009 
00010 
00011 IIIMP_message *
00012 iiimp_status_draw_new(
00013     IIIMP_data_s *   data_s,
00014     IIIMP_card16     im_id,
00015     IIIMP_card16     ic_id,
00016     IIIMP_contents * status)
00017 {
00018     IIIMP_message *  m;
00019     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00020     if (NULL == m) {
00021        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00022        return NULL;
00023     }
00024     m->opcode = IM_STATUS_DRAW;
00025     m->im_id = im_id;
00026     m->ic_id = ic_id;
00027     m->v.status_draw.status = status;
00028     return m;
00029 }
00030 
00031 
00032 void
00033 iiimp_status_draw_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00034 {
00035     if (NULL == m) return;
00036     iiimp_contents_delete(data_s, m->v.status_draw.status);
00037     free(m);
00038     return;
00039 }
00040 
00041 
00042 uchar_t *
00043 iiimp_status_draw_pack(
00044     IIIMP_data_s *   data_s,
00045     IIIMP_card16     im_id,
00046     IIIMP_card16     ic_id,
00047     IIIMP_contents * status,
00048     size_t *         buf_size)
00049 {
00050     size_t           nbyte;
00051     int                     length;
00052     uchar_t *        buf;
00053     size_t           rest;
00054     uchar_t *        p;
00055 
00056     nbyte = 0;
00057     nbyte += 2;                    /* input method id */
00058     nbyte += 2;                    /* input context id */
00059     nbyte += status->nbyte; /* status string of text */
00060 
00061     length = (nbyte >> 2);
00062     *buf_size = (1 + 3 + nbyte);
00063 
00064     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00065     if (NULL == buf) {
00066        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00067        return NULL;
00068     }
00069 
00070     PUT_PACKET_HEADER(buf, IM_STATUS_DRAW, length);
00071 
00072     rest = nbyte;
00073     p = (buf + 4);
00074 
00075     PUTU16(im_id, rest, p, data_s->byte_swap);
00076     PUTU16(ic_id, rest, p, data_s->byte_swap);
00077     iiimp_contents_pack(data_s, status, &rest, &p);
00078 
00079     return buf;
00080 }
00081 
00082 
00083 IIIMP_message *
00084 iiimp_status_draw_unpack(
00085     IIIMP_data_s *   data_s,
00086     IIIMP_card7             opcode,
00087     size_t *         nbyte,
00088     const uchar_t ** ptr)
00089 {
00090     IIIMP_message *         m;
00091     IIIMP_status_draw_v *   v;
00092     size_t                  rest;
00093     const uchar_t *         p;
00094 
00095     rest = *nbyte;
00096     p = *ptr;
00097 
00098     if (rest < (2 + 2 + 4)) {
00099        data_s->status = IIIMP_DATA_INVALID;
00100        return NULL;
00101     }
00102 
00103     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00104     if (NULL == m) {
00105        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00106        return NULL;
00107     }
00108     v = &(m->v.status_draw);
00109 
00110     m->opcode = opcode;
00111 
00112     GETU16(m->im_id, rest, p, data_s->byte_swap);
00113     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00114 
00115     v->status = iiimp_contents_unpack(data_s, &rest, &p, rest);
00116     if (NULL == v->status) {
00117        free(m);
00118        return NULL;
00119     }
00120 
00121     *nbyte = rest;
00122     *ptr = p;
00123 
00124     return m;
00125 }
00126 
00127 
00128 void
00129 iiimp_status_draw_print(
00130     IIIMP_data_s *   data_s,
00131     IIIMP_message *  m)
00132 {
00133     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00134     iiimp_contents_print(data_s, m->v.status_draw.status);
00135 }
00136 
00137 
00138 /* Local Variables: */
00139 /* c-file-style: "iiim-project" */
00140 /* End: */