Back to index

im-sdk  12.3.91
im-trigger-notify.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <sys/types.h>
00004 #if defined(lint) && defined(HAVE_NOTE_H)
00005 #include <note.h>
00006 #endif /* lint && HAVE_NOTE_H */
00007 
00008 #include <iiimp-data.h>
00009 #include <iiimp-opcode.h>
00010 
00011 #include "iiimp-dataP.h"
00012 
00013 
00014 IIIMP_message *
00015 iiimp_trigger_notify_new(
00016     IIIMP_data_s *   data_s,
00017     IIIMP_card16     im_id,
00018     IIIMP_card16     ic_id,
00019     IIIMP_card16     flag)
00020 {
00021     IIIMP_message *  m;
00022     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00023     if (NULL == m) {
00024        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00025        return NULL;
00026     }
00027     m->opcode = IM_TRIGGER_NOTIFY;
00028     m->im_id = im_id;
00029     m->ic_id = ic_id;
00030     m->v.trigger_notify.flag = flag;
00031     return m;
00032 }
00033 
00034 
00035 void
00036 iiimp_trigger_notify_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00037 {
00038 #if defined(lint) && defined(HAVE_NOTE_H)
00039     NOTE(ARGUNUSED(data_s))
00040 #endif /* lint && HAVE_NOTE_H */
00041     free(m);
00042 }
00043 
00044 
00045 uchar_t *
00046 iiimp_trigger_notify_pack(
00047     IIIMP_data_s *   data_s,
00048     IIIMP_card16     im_id,
00049     IIIMP_card16     ic_id,
00050     IIIMP_card16     flag,
00051     size_t *         buf_size)
00052 {
00053     size_t           nbyte;
00054     int                     length;
00055     uchar_t *        buf;
00056     size_t           rest;
00057     uchar_t *        p;
00058 
00059     nbyte = 0;
00060     nbyte += 2;      /* input method id */
00061     nbyte += 2;      /* input context id */
00062     nbyte += 2;      /* flag */
00063     nbyte += 2;      /* PAD(2) */
00064 
00065     length = (nbyte >> 2);
00066     *buf_size = (1 + 3 + nbyte);
00067 
00068     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00069     if (NULL == buf) {
00070        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00071        return NULL;
00072     }
00073 
00074     PUT_PACKET_HEADER(buf, IM_TRIGGER_NOTIFY, length);
00075 
00076     rest = nbyte;
00077     p = (buf + 4);
00078 
00079     PUTU16(im_id, rest, p, data_s->byte_swap);
00080     PUTU16(ic_id, rest, p, data_s->byte_swap);
00081     PUTU16(flag, rest, p, data_s->byte_swap);
00082     PUTU16(0, rest, p, data_s->byte_swap);
00083 
00084     return buf;
00085 }
00086 
00087 
00088 IIIMP_message *
00089 iiimp_trigger_notify_unpack(
00090     IIIMP_data_s *   data_s,
00091     IIIMP_card7             opcode,
00092     size_t *         nbyte,
00093     const uchar_t ** ptr)
00094 {
00095     IIIMP_message *         m;
00096     IIIMP_trigger_notify_v *       v;
00097     size_t                  rest;
00098     const uchar_t *         p;
00099 
00100     rest = *nbyte;
00101     p = *ptr;
00102 
00103     if (rest < (2 + 2 + 2 + 2)) {
00104        data_s->status = IIIMP_DATA_INVALID;
00105        return NULL;
00106     }
00107 
00108     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00109     if (NULL == m) {
00110        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00111        return NULL;
00112     }
00113     v = &(m->v.trigger_notify);
00114 
00115     m->opcode = opcode;
00116 
00117     GETU16(m->im_id, rest, p, data_s->byte_swap);
00118     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00119     GETU16(v->flag, rest, p, data_s->byte_swap);
00120     SKIP16(rest, p);
00121 
00122     if ((0 != v->flag) && (1 != v->flag)) {
00123        iiimp_trigger_notify_delete(data_s, m);
00124        data_s->status = IIIMP_DATA_INVALID;
00125        return NULL;
00126     }
00127 
00128     *nbyte = rest;
00129     *ptr = p;
00130 
00131     return m;
00132 }
00133 
00134 
00135 void
00136 iiimp_trigger_notify_print(
00137     IIIMP_data_s *   data_s,
00138     IIIMP_message *  m)
00139 {
00140     iiimp_message_header_print(data_s, m->opcode, m->im_id, m->ic_id);
00141     (void)fprintf(data_s->print_fp, "\tflag = %s\n",
00142                 ((0 == m->v.trigger_notify.flag) ?
00143                  "on" : ((1 == m->v.trigger_notify.flag) ?
00144                         "off" : "unknown")));
00145 }
00146 
00147 
00148 /* Local Variables: */
00149 /* c-file-style: "iiim-project" */
00150 /* End: */