Back to index

im-sdk  12.3.91
im-hotkey-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_hotkey_notify_new(
00016     IIIMP_data_s *   data_s,
00017     IIIMP_card16     im_id,
00018     IIIMP_card16     ic_id,
00019     IIIMP_card16     hotkey_id,
00020     IIIMP_card16        index)
00021 {
00022     IIIMP_message *  m;
00023 
00024     REQUIRE_PROTOCOL_VERSION(data_s, 3);
00025 
00026     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00027     if (NULL == m) {
00028        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00029        return NULL;
00030     }
00031     m->opcode = IM_HOTKEY_NOTIFY;
00032     m->im_id = im_id;
00033     m->ic_id = ic_id;
00034     m->v.hotkey_notify.hotkey_id = hotkey_id;
00035     m->v.hotkey_notify.index = index;
00036     return m;
00037 }
00038 
00039 
00040 void
00041 iiimp_hotkey_notify_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00042 {
00043 #if defined(lint) && defined(HAVE_NOTE_H)
00044     NOTE(ARGUNUSED(data_s))
00045 #endif /* lint && HAVE_NOTE_H */
00046        free(m);
00047 }
00048 
00049 
00050 uchar_t *
00051 iiimp_hotkey_notify_pack(
00052     IIIMP_data_s *   data_s,
00053     IIIMP_card16     im_id,
00054     IIIMP_card16     ic_id,
00055     IIIMP_card16     hotkey_id,
00056     IIIMP_card16     index,
00057     size_t *         buf_size)
00058 {
00059     size_t           nbyte;
00060     int                     length;
00061     uchar_t *        buf;
00062     size_t           rest;
00063     uchar_t *        p;
00064 
00065     nbyte = 0
00066        + 2     /* input method id */
00067        + 2     /* input context id */
00068        + 2     /* HOTKEY ID */
00069        + 2;     /* Index of KEYEVENT in List of Hotkeys */
00070 
00071     length = (nbyte >> 2);
00072     *buf_size = (1 + 3 + nbyte);
00073 
00074     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00075     if (NULL == buf) {
00076        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00077        return NULL;
00078     }
00079 
00080     PUT_PACKET_HEADER(buf, IM_HOTKEY_NOTIFY, length);
00081 
00082     rest = nbyte;
00083     p = (buf + 4);
00084 
00085     PUTU16(im_id, rest, p, data_s->byte_swap);
00086     PUTU16(ic_id, rest, p, data_s->byte_swap);
00087     PUTU16(hotkey_id, rest, p, data_s->byte_swap);
00088     PUTU16(index, rest, p, data_s->byte_swap);
00089 
00090     return buf;
00091 }
00092 
00093 
00094 IIIMP_message *
00095 iiimp_hotkey_notify_unpack(
00096     IIIMP_data_s *   data_s,
00097     IIIMP_card7             opcode,
00098     size_t *         nbyte,
00099     const uchar_t ** ptr)
00100 {
00101     IIIMP_message *         m;
00102     IIIMP_hotkey_notify_v * v;
00103     size_t                  rest;
00104     const uchar_t *         p;
00105 
00106     rest = *nbyte;
00107     p = *ptr;
00108 
00109     if (rest < (2 + 2 + 2 + 2)) {
00110        data_s->status = IIIMP_DATA_INVALID;
00111        return NULL;
00112     }
00113 
00114     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00115     if (NULL == m) {
00116        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00117        return NULL;
00118     }
00119     v = &(m->v.hotkey_notify);
00120 
00121     m->opcode = opcode;
00122 
00123     GETU16(m->im_id, rest, p, data_s->byte_swap);
00124     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00125     GETU16(v->hotkey_id, rest, p, data_s->byte_swap);
00126     GETU16(v->index, rest, p, data_s->byte_swap);
00127 
00128     *nbyte = rest;
00129     *ptr = p;
00130 
00131     return m;
00132 }
00133 
00134 
00135 void
00136 iiimp_hotkey_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, "\thotkey_id = %d\n",
00142                 m->v.hotkey_notify.hotkey_id);
00143     (void)fprintf(data_s->print_fp, "\tIndex of KeyEvent = %d\n", m->v.hotkey_notify.index);
00144 }
00145 
00146 
00147 /* Local Variables: */
00148 /* c-file-style: "iiim-project" */
00149 /* End: */