Back to index

im-sdk  12.3.91
comp-feedback-attr.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <sys/types.h>
00005 #if defined(lint) && defined(HAVE_NOTE_H)
00006 #include <note.h>
00007 #endif /* lint && HAVE_NOTE_H */
00008 
00009 #include <iiimp-data.h>
00010 
00011 #include "iiimp-dataP.h"
00012 #include "print-misc.h"
00013 
00014 
00015 IIIMP_feedback_attr_list *
00016 iiimp_feedback_attr_list_new(
00017     IIIMP_data_s *          data_s,
00018     int                            count,
00019     const IIIMP_feedback_attr *    ptr)
00020 {
00021     IIIMP_feedback_attr_list *     data;
00022     size_t                  nbyte;
00023     int                            i;
00024 
00025     data = (IIIMP_feedback_attr_list *)
00026        malloc(sizeof (IIIMP_feedback_attr_list));
00027     if (NULL == data) {
00028        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00029        return NULL;
00030     }
00031 
00032     nbyte = ((4 + 4) * count);
00033 
00034     data->nbyte = nbyte;
00035     data->count = count;
00036 
00037     nbyte = ((sizeof (IIIMP_feedback_attr)) * data->count);
00038 
00039     if (0 == data) {
00040        data->ptr = NULL;
00041     } else {
00042        data->ptr = (IIIMP_feedback_attr *)malloc(nbyte);
00043        if (NULL == data->ptr) {
00044            iiimp_feedback_attr_list_delete(data_s, data);
00045            data_s->status = IIIMP_DATA_MALLOC_ERROR;
00046            return NULL;
00047        }
00048     }
00049 
00050     if (NULL != ptr) {
00051        for (i = 0; i < count; i++) {
00052            (data->ptr + i)->nbyte = 8;
00053            (data->ptr + i)->id = (ptr + i)->id;
00054            (data->ptr + i)->feedback = (ptr + i)->feedback;
00055        }
00056     }
00057 
00058     return data;
00059 }
00060 
00061 
00062 void
00063 iiimp_feedback_attr_list_delete(
00064     IIIMP_data_s *          data_s,
00065     IIIMP_feedback_attr_list *     data)
00066 {
00067 #if defined(lint) && defined(HAVE_NOTE_H)
00068     NOTE(ARGUNUSED(data_s))
00069 #endif /* lint && HAVE_NOTE_H */
00070     if (NULL == data) return;
00071     free(data->ptr);
00072     free(data);
00073     return;
00074 }
00075 
00076 
00077 void
00078 iiimp_feedback_attr_list_pack(
00079     IIIMP_data_s *          data_s,
00080     IIIMP_feedback_attr_list *     m,
00081     size_t *                nbyte,
00082     uchar_t **                     ptr)
00083 {
00084     size_t    rest;
00085     uchar_t * p;
00086     int              i;
00087 
00088     rest = *nbyte;
00089     p = *ptr;
00090 
00091     for (i = 0; i < m->count; i++) {
00092        PUTU32((m->ptr + i)->id, rest, p, data_s->byte_swap);
00093        PUTU32((m->ptr + i)->feedback, rest, p, data_s->byte_swap);
00094     }
00095 
00096     *nbyte = rest;
00097     *ptr = p;
00098 
00099     return;
00100 }
00101 
00102 
00103 IIIMP_feedback_attr_list *
00104 iiimp_feedback_attr_list_unpack(
00105     IIIMP_data_s *   data_s,
00106     size_t *         nbyte,
00107     const uchar_t ** ptr,
00108     size_t           nbyte_max)
00109 {
00110     IIIMP_feedback_attr_list *     data;
00111     const uchar_t *         p;
00112     size_t                  rest;
00113     int                            data_count;
00114     int                            i;
00115 
00116     rest = nbyte_max;
00117     p = *ptr;
00118 
00119     if ((*nbyte < rest) || (0 != (nbyte_max & 0x07))) {
00120        data_s->status = IIIMP_DATA_INVALID;
00121        return NULL;
00122     }
00123 
00124     data_count = (nbyte_max / (4 + 4));
00125 
00126     data = (IIIMP_feedback_attr_list *)
00127        malloc(sizeof (IIIMP_feedback_attr_list));
00128     if (NULL == data) {
00129        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00130        return NULL;
00131     }
00132 
00133     data->count = data_count;
00134 
00135     data->ptr = (IIIMP_feedback_attr *)
00136        malloc((sizeof (IIIMP_feedback_attr)) * data_count);
00137     if (NULL == data->ptr) {
00138        iiimp_feedback_attr_list_delete(data_s, data);
00139        data_s->status = IIIMP_DATA_MALLOC_ERROR;
00140        return NULL;
00141     }
00142 
00143     for (i = 0; i < data_count; i++) {
00144        GETU32((data->ptr + i)->id, rest, p, data_s->byte_swap);
00145        GETU32((data->ptr + i)->feedback, rest, p, data_s->byte_swap);
00146     }
00147 
00148     *nbyte -= (nbyte_max - rest);
00149     *ptr += nbyte_max;
00150 
00151     return data;
00152 }
00153 
00154 
00155 void
00156 iiimp_feedback_attr_print(
00157     IIIMP_data_s *          data_s,
00158     IIIMP_feedback_attr *   m)
00159 {
00160     if (NULL == m) return;
00161     if (0 == m->id) {
00162        (void)fprintf(data_s->print_fp, "%s", feedback_string_get(m->feedback));
00163     } else {
00164        (void)fprintf(data_s->print_fp, "\n\tFeedback ID=%d Feedback=%d\n",
00165                     m->id, m->feedback);
00166     }
00167 }
00168 
00169 
00170 void
00171 iiimp_feedback_attr_list_print(
00172     IIIMP_data_s *          data_s,
00173     IIIMP_feedback_attr_list *     m)
00174 {
00175     int       i;
00176 
00177     if (NULL == m) return;
00178 
00179     for (i = 0; i < m->count; i++) {
00180        (void)fputc(' ', data_s->print_fp);
00181        iiimp_feedback_attr_print(data_s, m->ptr + i);
00182     }
00183 }
00184 
00185 
00186 /* Local Variables: */
00187 /* c-file-style: "iiim-project" */
00188 /* End: */