Back to index

im-sdk  12.3.91
im-hotkey-state-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_state_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_card8         current_state_flag)
00021 {
00022     IIIMP_message *  m;
00023     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00024     if (NULL == m) {
00025        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00026        return NULL;
00027     }
00028     m->opcode = IM_HOTKEY_STATE_NOTIFY;
00029     m->im_id = im_id;
00030     m->ic_id = ic_id;
00031     m->v.hotkey_state_notify.hotkey_id = hotkey_id;
00032     m->v.hotkey_state_notify.current_state_flag = current_state_flag;
00033     return m;
00034 }
00035 
00036 
00037 void
00038 iiimp_hotkey_state_notify_delete(IIIMP_data_s * data_s, IIIMP_message * m)
00039 {
00040 #if defined(lint) && defined(HAVE_NOTE_H)
00041     NOTE(ARGUNUSED(data_s))
00042 #endif /* lint && HAVE_NOTE_H */
00043        free(m);
00044 }
00045 
00046 
00047 uchar_t *
00048 iiimp_hotkey_state_notify_pack(
00049     IIIMP_data_s *   data_s,
00050     IIIMP_card16     im_id,
00051     IIIMP_card16     ic_id,
00052     IIIMP_card16     hotkey_id,
00053     IIIMP_card8             current_state_flag,
00054     size_t *         buf_size)
00055 {
00056     size_t           nbyte;
00057     int                     length;
00058     uchar_t *        buf;
00059     size_t           rest;
00060     uchar_t *        p;
00061 
00062     nbyte = 0
00063        + 2     /* input method id */
00064        + 2     /* input context id */
00065        + 2     /* HOTKEY ID */
00066        + 1     /* Pad */
00067        + 1;     /* State Flag */
00068 
00069     length = (nbyte >> 2);
00070     *buf_size = (1 + 3 + nbyte);
00071 
00072     buf = (uchar_t *)malloc(1 + 3 + nbyte);
00073     if (NULL == buf) {
00074        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00075        return NULL;
00076     }
00077 
00078     PUT_PACKET_HEADER(buf, IM_HOTKEY_STATE_NOTIFY, length);
00079 
00080     rest = nbyte;
00081     p = (buf + 4);
00082 
00083     PUTU16(im_id, rest, p, data_s->byte_swap);
00084     PUTU16(ic_id, rest, p, data_s->byte_swap);
00085     PUTU16(hotkey_id, rest, p, data_s->byte_swap);
00086     PUTU8(0, rest, p, data_s->byte_swap);
00087     PUTU8(current_state_flag, rest, p, data_s->byte_swap);
00088 
00089     return buf;
00090 }
00091 
00092 
00093 IIIMP_message *
00094 iiimp_hotkey_state_notify_unpack(
00095     IIIMP_data_s *   data_s,
00096     IIIMP_card7             opcode,
00097     size_t *         nbyte,
00098     const uchar_t ** ptr)
00099 {
00100     IIIMP_message *                m;
00101     IIIMP_hotkey_state_notify_v *  v;
00102     size_t                         rest;
00103     const uchar_t *                p;
00104 
00105     rest = *nbyte;
00106     p = *ptr;
00107 
00108     if (rest < (2 + 2 + 2 + 1 + 1)) {
00109        data_s->status = IIIMP_DATA_INVALID;
00110        return NULL;
00111     }
00112 
00113     m = (IIIMP_message *)malloc(sizeof (IIIMP_message));
00114     if (NULL == m) {
00115        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00116        return NULL;
00117     }
00118     v = &(m->v.hotkey_state_notify);
00119 
00120     m->opcode = opcode;
00121 
00122     GETU16(m->im_id, rest, p, data_s->byte_swap);
00123     GETU16(m->ic_id, rest, p, data_s->byte_swap);
00124     GETU16(v->hotkey_id, rest, p, data_s->byte_swap);
00125     SKIP8(rest, p);
00126     GETU8(v->current_state_flag, 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_state_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_state_notify.hotkey_id);
00143     (void)fprintf(data_s->print_fp, "\tcurrent_state_flag = %d\n", m->v.hotkey_state_notify.current_state_flag);
00144 }
00145 
00146 /* Local Variables: */
00147 /* c-file-style: "iiim-project" */
00148 /* End: */