Back to index

im-sdk  12.3.91
iiimp-misc.c
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 
00005 #include <iiimp.h>
00006 
00007 #include "iiimp-dataP.h"
00008 
00009 
00010 int
00011 iiimp_data_s_get_protocol_version(
00012     IIIMP_data_s * data_s
00013 )
00014 {
00015     return data_s->protocol_version;
00016 }
00017 
00018 
00019 IIIMF_status
00020 iiimp_data_s_limit_protocol_version(
00021     IIIMP_data_s * data_s,
00022     int version
00023 )
00024 {
00025     if (version > data_s->protocol_version)
00026        return IIIMF_STATUS_PROTOCOL_VERSION;
00027     data_s->protocol_version = version;
00028 
00029     return IIIMF_STATUS_SUCCESS;
00030 }
00031 
00032 
00033 IIIMP_data_s*
00034 iiimp_data_s_with_protocol_version_new(
00035     int protocol_version
00036 )
00037 {
00038     IIIMP_data_s *   data_s;
00039 
00040     if (protocol_version >= 0x100) {
00041        return NULL;
00042     }
00043 
00044     data_s = (IIIMP_data_s *)malloc(sizeof (IIIMP_data_s));
00045     if (NULL == data_s) return NULL;
00046     data_s->byte_swap = 0;
00047     data_s->attribute_id = NULL;
00048     data_s->status = 0;
00049     data_s->print_fp = stdout;
00050     data_s->print_flag = 0;
00051     data_s->protocol_version = protocol_version;
00052     data_s->capability = NULL;
00053 
00054     return data_s;
00055 }
00056 
00057 
00058 int
00059 iiimp_data_s_capability(
00060     IIIMP_data_s *   data_s,
00061     int                     capability
00062 )
00063 {
00064     int       list_index;
00065     int       bit_index;
00066 
00067     if ((NULL == data_s) || (NULL == data_s->capability)) return 0;
00068 
00069     return iiimp_card32_list_bit_p(data_s, data_s->capability, capability);
00070 }
00071 
00072 
00073 IIIMP_data_s *
00074 iiimp_data_s_new(void)
00075 {
00076     return iiimp_data_s_with_protocol_version_new(3);
00077 }
00078 
00079 
00080 void
00081 iiimp_data_s_delete(IIIMP_data_s * data_s)
00082 {
00083     if (NULL == data_s) return;
00084     (void)iiimp_data_print_fp(data_s, NULL);
00085     (void)iiimp_attribute_id_destroy(data_s);
00086     (void)iiimp_card32_list_delete(data_s, data_s->capability);
00087     free(data_s);
00088 }
00089 
00090 
00091 FILE *
00092 iiimp_data_print_fp(IIIMP_data_s * data_s, FILE * fp)
00093 {
00094     if (NULL == data_s) return NULL;
00095     data_s->print_fp = fp;
00096     return data_s->print_fp;
00097 }
00098 
00099 
00100 uint_t
00101 iiimp_data_print_flag(IIIMP_data_s * data_s, uint_t print_flag)
00102 {
00103     if (IIIMP_PRINT_QUERY != print_flag) {
00104        data_s->print_flag = print_flag;
00105     }
00106     return data_s->print_flag;
00107 }
00108 
00109 
00110 int
00111 iiimp_data_status(IIIMP_data_s * data_s)
00112 {
00113     return data_s->status;
00114 }
00115 
00116 
00117 IIIMP_card16
00118 iiimp_attribute_id_search(IIIMP_data_s * data_s, IIIMP_card16 id_dynamic)
00119 {
00120     IIIMP_attribute_id *    attr;
00121 
00122     for (attr = data_s->attribute_id; NULL != attr; attr = attr->next) {
00123        if (id_dynamic == attr->id_dynamic) {
00124            return attr->id_predefined;
00125        }
00126     }
00127 
00128     return 0;
00129 }
00130 
00131 
00132 void
00133 iiimp_attribute_id_update(
00134     IIIMP_data_s *   data_s,
00135     IIIMP_card16     id_predefined,
00136     IIIMP_card16     id_dynamic)
00137 {
00138     IIIMP_attribute_id *    attr;
00139 
00140     for (attr = data_s->attribute_id; NULL != attr; attr = attr->next) {
00141        if (id_dynamic == attr->id_dynamic) {
00142            attr->id_predefined = id_predefined;
00143            return;
00144        }
00145     }
00146     attr = (IIIMP_attribute_id *)malloc(sizeof (IIIMP_attribute_id));
00147     if (NULL == attr) return;
00148     attr->id_predefined = id_predefined;
00149     attr->id_dynamic = id_dynamic;
00150     attr->next = data_s->attribute_id;
00151     data_s->attribute_id = attr;
00152 
00153     return;
00154 }
00155 
00156 
00157 void
00158 iiimp_attribute_id_destroy(IIIMP_data_s * data_s)
00159 {
00160     IIIMP_attribute_id *    attr;
00161     IIIMP_attribute_id *    attr_next;
00162 
00163     for (attr = data_s->attribute_id; NULL != attr; attr = attr_next) {
00164        attr_next = attr->next;
00165        free(attr);
00166     }
00167     data_s->attribute_id = NULL;
00168 
00169     return;
00170 }
00171 
00172 
00173 /* Local Variables: */
00174 /* c-file-style: "iiim-project" */
00175 /* End: */