Back to index

im-sdk  12.3.91
im-register-trigger-keys.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_register_trigger_keys_new(
00013     IIIMP_data_s *          data_s,
00014     IIIMP_card16            im_id,
00015     IIIMP_keyevent_list *   trigger_on,
00016     IIIMP_keyevent_list *   trigger_off)
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_REGISTER_TRIGGER_KEYS;
00025     m->im_id = im_id;
00026     m->ic_id = -1;
00027     m->v.register_trigger_keys.trigger_on = trigger_on;
00028     m->v.register_trigger_keys.trigger_off = trigger_off;
00029     return m;
00030 }
00031 
00032 
00033 
00034 void
00035 iiimp_register_trigger_keys_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00036 {
00037     if (NULL == m) return;
00038     iiimp_keyevent_list_delete(data_s, m->v.register_trigger_keys.trigger_on);
00039     iiimp_keyevent_list_delete(data_s, m->v.register_trigger_keys.trigger_off);
00040     free(m);
00041 }
00042 
00043 
00044 uchar_t *
00045 iiimp_register_trigger_keys_pack(
00046     IIIMP_data_s *          data_s,
00047     IIIMP_card16            im_id,
00048     IIIMP_keyevent_list *   trigger_on,
00049     IIIMP_keyevent_list *   trigger_off,
00050     size_t *                buf_size)
00051 {
00052     size_t                  nbyte;
00053     int                            length;
00054     uchar_t *               buf;
00055     size_t                  rest;
00056     uchar_t *               p;
00057 
00058     nbyte = 0;
00059     nbyte += 2;                           /* input method id */
00060     nbyte += 2;                           /* PAD(2) */
00061     nbyte += 4;                           /* byte length of on-keys */
00062     if (NULL != trigger_on) {
00063        nbyte += trigger_on->nbyte; /* trigger keys to turn on */
00064     }
00065     nbyte += 4;                           /* byte length of off-keys */
00066     if (NULL != trigger_off) {
00067        nbyte += trigger_off->nbyte;       /* trigger keys to turn off */
00068     }
00069 
00070     length = (nbyte >> 2);
00071     *buf_size = (1 + 3 + nbyte);
00072 
00073     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00074     if (NULL == buf) {
00075        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00076        return NULL;
00077     }
00078 
00079     PUT_PACKET_HEADER(buf, IM_REGISTER_TRIGGER_KEYS, length);
00080 
00081     rest = nbyte;
00082     p = (buf + 4);
00083 
00084     PUTU16(im_id, rest, p, data_s->byte_swap);
00085     PUTU16(0, rest, p, data_s->byte_swap);
00086     if (NULL == trigger_on) {
00087        PUTU32(0, rest, p, data_s->byte_swap);
00088     } else {
00089        PUTU32(trigger_on->nbyte, rest, p, data_s->byte_swap);
00090        iiimp_keyevent_list_pack(data_s, trigger_on, &rest, &p);
00091     }
00092     if (NULL == trigger_off) {
00093        PUTU32(0, rest, p, data_s->byte_swap);
00094     } else {
00095        PUTU32(trigger_off->nbyte, rest, p, data_s->byte_swap);
00096        iiimp_keyevent_list_pack(data_s, trigger_off, &rest, &p);
00097     }
00098 
00099     return buf;
00100 }
00101 
00102 
00103 IIIMP_message *
00104 iiimp_register_trigger_keys_unpack(
00105     IIIMP_data_s *   data_s,
00106     IIIMP_card7             opcode,
00107     size_t *         nbyte,
00108     const uchar_t ** ptr)
00109 {
00110     IIIMP_message *                m;
00111     IIIMP_register_trigger_keys_v *       v;
00112     size_t                         rest;
00113     const uchar_t *                p;
00114     int                                   len;
00115 
00116     rest = *nbyte;
00117     p = *ptr;
00118 
00119     if (rest < (2 + 2 + 4 + 0 + 4 + 0)) {
00120        data_s->status = IIIMP_DATA_INVALID;
00121        return NULL;
00122     }
00123 
00124     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00125     if (NULL == m) {
00126        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00127        return NULL;
00128     }
00129     v = &(m->v.register_trigger_keys);
00130 
00131     m->opcode = opcode;
00132     v->trigger_on = NULL;
00133     v->trigger_off = NULL;
00134 
00135     GET16(m->im_id, rest, p, data_s->byte_swap);
00136     m->ic_id = -1;
00137     SKIP16(rest, p);
00138 
00139     GET32(len, rest, p, data_s->byte_swap);
00140     if ((len < 0) || (rest < len)) {
00141        iiimp_register_trigger_keys_delete(data_s, m);
00142        data_s->status = IIIMP_DATA_INVALID;
00143        return NULL;
00144     }
00145 
00146     v->trigger_on = iiimp_keyevent_list_unpack(data_s, &rest, &p, len);
00147     if (NULL == v->trigger_on) {
00148        iiimp_register_trigger_keys_delete(data_s, m);
00149        return NULL;
00150     }
00151 
00152     GET32(len, rest, p, data_s->byte_swap);
00153     if ((len < 0) || (rest < len)) {
00154        iiimp_register_trigger_keys_delete(data_s, m);
00155        data_s->status = IIIMP_DATA_INVALID;
00156        return NULL;
00157     }
00158 
00159     v->trigger_off = iiimp_keyevent_list_unpack(data_s, &rest, &p, len);
00160     if (NULL == v->trigger_off) {
00161        iiimp_register_trigger_keys_delete(data_s, m);
00162        return NULL;
00163     }
00164 
00165     *nbyte = rest;
00166     *ptr = p;
00167 
00168     return (IIIMP_message *)m;
00169 }
00170 
00171 
00172 void
00173 iiimp_register_trigger_keys_print(
00174     IIIMP_data_s *   data_s,
00175     IIIMP_message *  m)
00176 {
00177     iiimp_message_header_print(data_s, m->opcode, m->im_id, -1);
00178     (void)fprintf(data_s->print_fp, "\ttrigger key to turn on =\n");
00179     iiimp_keyevent_list_print(data_s, m->v.register_trigger_keys.trigger_on);
00180     (void)fprintf(data_s->print_fp, "\ttrigger key to turn off =\n");
00181     iiimp_keyevent_list_print(data_s, m->v.register_trigger_keys.trigger_off);
00182 }
00183 
00184 
00185 /* Local Variables: */
00186 /* c-file-style: "iiim-project" */
00187 /* End: */