pcsc-lite
1.8.2
|
00001 /* 00002 * Copyright (c) 2007,2008 Mij <mij@bitchx.it> 00003 * 00004 * Permission to use, copy, modify, and distribute this software for any 00005 * purpose with or without fee is hereby granted, provided that the above 00006 * copyright notice and this permission notice appear in all copies. 00007 * 00008 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 00009 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 00010 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 00011 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00012 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 00013 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 00014 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 */ 00016 00017 00018 /* 00019 * SimCList library. See http://mij.oltrelinux.com/devel/simclist 00020 */ 00021 00022 00023 #ifndef SIMCLIST_H 00024 #define SIMCLIST_H 00025 00026 #ifdef __cplusplus 00027 extern "C" { 00028 #endif 00029 00030 #include <inttypes.h> 00031 #include <errno.h> 00032 #include <sys/types.h> 00033 00034 #ifndef SIMCLIST_NO_DUMPRESTORE 00035 # ifndef _WIN32 00036 # include <sys/time.h> /* list_dump_info_t's struct timeval */ 00037 # else 00038 # include <time.h> 00039 # endif 00040 #endif 00041 00042 00043 /* Be friend of both C90 and C99 compilers */ 00044 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L 00045 /* "inline" and "restrict" are keywords */ 00046 #else 00047 # define inline /* inline */ 00048 # define restrict /* restrict */ 00049 #endif 00050 00051 00057 typedef int32_t list_hash_t; 00058 00059 #ifndef SIMCLIST_NO_DUMPRESTORE 00060 typedef struct { 00061 uint16_t version; /* dump version */ 00062 struct timeval timestamp; /* when the list has been dumped, seconds since UNIX epoch */ 00063 uint32_t list_size; 00064 uint32_t list_numels; 00065 list_hash_t list_hash; /* hash of the list when dumped, or 0 if invalid */ 00066 uint32_t dumpsize; 00067 int consistent; /* 1 if the dump is verified complete/consistent; 0 otherwise */ 00068 } list_dump_info_t; 00069 #endif 00070 00080 typedef int (*element_comparator)(const void *a, const void *b); 00081 00093 typedef int (*element_seeker)(const void *el, const void *indicator); 00094 00104 typedef size_t (*element_meter)(const void *el); 00105 00115 typedef list_hash_t (*element_hash_computer)(const void *el); 00116 00135 typedef void *(*element_serializer)(const void *restrict el, uint32_t *restrict serializ_len); 00136 00152 typedef void *(*element_unserializer)(const void *restrict data, uint32_t *restrict data_len); 00153 00154 /* [private-use] list entry -- olds actual user datum */ 00155 struct list_entry_s { 00156 void *data; 00157 00158 /* doubly-linked list service references */ 00159 struct list_entry_s *next; 00160 struct list_entry_s *prev; 00161 }; 00162 00163 /* [private-use] list attributes */ 00164 struct list_attributes_s { 00165 /* user-set routine for comparing list elements */ 00166 element_comparator comparator; 00167 /* user-set routing for seeking elements */ 00168 element_seeker seeker; 00169 /* user-set routine for determining the length of an element */ 00170 element_meter meter; 00171 int copy_data; 00172 /* user-set routine for computing the hash of an element */ 00173 element_hash_computer hasher; 00174 /* user-set routine for serializing an element */ 00175 element_serializer serializer; 00176 /* user-set routine for unserializing an element */ 00177 element_unserializer unserializer; 00178 }; 00179 00181 typedef struct { 00182 struct list_entry_s *head_sentinel; 00183 struct list_entry_s *tail_sentinel; 00184 struct list_entry_s *mid; 00185 00186 unsigned int numels; 00187 00188 /* array of spare elements */ 00189 struct list_entry_s **spareels; 00190 unsigned int spareelsnum; 00191 00192 #ifdef SIMCLIST_WITH_THREADS 00193 /* how many threads are currently running */ 00194 unsigned int threadcount; 00195 #endif 00196 00197 /* service variables for list iteration */ 00198 int iter_active; 00199 unsigned int iter_pos; 00200 struct list_entry_s *iter_curentry; 00201 00202 /* list attributes */ 00203 struct list_attributes_s attrs; 00204 } list_t; 00205 00212 int list_init(list_t *restrict l); 00213 00223 void list_destroy(list_t *restrict l); 00224 00237 int list_attributes_comparator(list_t *restrict l, element_comparator comparator_fun); 00238 00251 int list_attributes_seeker(list_t *restrict l, element_seeker seeker_fun); 00252 00283 int list_attributes_copy(list_t *restrict l, element_meter metric_fun, int copy_data); 00284 00303 int list_attributes_hash_computer(list_t *restrict l, element_hash_computer hash_computer_fun); 00304 00324 int list_attributes_serializer(list_t *restrict l, element_serializer serializer_fun); 00325 00346 int list_attributes_unserializer(list_t *restrict l, element_unserializer unserializer_fun); 00347 00358 int list_append(list_t *restrict l, const void *data); 00359 00370 int list_prepend(list_t *restrict l, const void *restrict data); 00371 00380 void *list_fetch(list_t *restrict l); 00381 00389 void *list_get_at(const list_t *restrict l, unsigned int pos); 00390 00403 void *list_get_max(const list_t *restrict l); 00404 00417 void *list_get_min(const list_t *restrict l); 00418 00426 void *list_extract_at(list_t *restrict l, unsigned int pos); 00427 00436 int list_insert_at(list_t *restrict l, const void *data, unsigned int pos); 00437 00453 int list_delete(list_t *restrict l, const void *data); 00454 00462 int list_delete_at(list_t *restrict l, unsigned int pos); 00463 00472 int list_delete_range(list_t *restrict l, unsigned int posstart, unsigned int posend); 00473 00485 int list_clear(list_t *restrict l); 00486 00493 unsigned int list_size(const list_t *restrict l); 00494 00503 int list_empty(const list_t *restrict l); 00504 00522 int list_locate(const list_t *restrict l, const void *data); 00523 00537 void *list_seek(list_t *restrict l, const void *indicator); 00538 00558 int list_contains(const list_t *restrict l, const void *data); 00559 00577 int list_concat(const list_t *l1, const list_t *l2, list_t *restrict dest); 00578 00594 int list_sort(list_t *restrict l, int versus); 00595 00606 int list_iterator_start(list_t *restrict l); 00607 00614 void *list_iterator_next(list_t *restrict l); 00615 00622 int list_iterator_hasnext(const list_t *restrict l); 00623 00630 int list_iterator_stop(list_t *restrict l); 00631 00640 int list_hash(const list_t *restrict l, list_hash_t *restrict hash); 00641 00642 #ifndef SIMCLIST_NO_DUMPRESTORE 00643 00658 int list_dump_getinfo_filedescriptor(int fd, list_dump_info_t *restrict info); 00659 00673 int list_dump_getinfo_file(const char *restrict filename, list_dump_info_t *restrict info); 00674 00709 int list_dump_filedescriptor(const list_t *restrict l, int fd, size_t *restrict len); 00710 00732 int list_dump_file(const list_t *restrict l, const char *restrict filename, size_t *restrict len); 00733 00752 int list_restore_filedescriptor(list_t *restrict l, int fd, size_t *restrict len); 00753 00770 int list_restore_file(list_t *restrict l, const char *restrict filename, size_t *len); 00771 #endif 00772 00773 /* ready-made comparators, meters and hash computers */ 00774 /* comparator functions */ 00779 int list_comparator_int8_t(const void *a, const void *b); 00780 00785 int list_comparator_int16_t(const void *a, const void *b); 00786 00791 int list_comparator_int32_t(const void *a, const void *b); 00792 00797 int list_comparator_int64_t(const void *a, const void *b); 00798 00803 int list_comparator_uint8_t(const void *a, const void *b); 00804 00809 int list_comparator_uint16_t(const void *a, const void *b); 00810 00815 int list_comparator_uint32_t(const void *a, const void *b); 00816 00821 int list_comparator_uint64_t(const void *a, const void *b); 00822 00827 int list_comparator_float(const void *a, const void *b); 00828 00833 int list_comparator_double(const void *a, const void *b); 00834 00839 int list_comparator_string(const void *a, const void *b); 00840 00841 /* metric functions */ 00846 size_t list_meter_int8_t(const void *el); 00847 00852 size_t list_meter_int16_t(const void *el); 00853 00858 size_t list_meter_int32_t(const void *el); 00859 00864 size_t list_meter_int64_t(const void *el); 00865 00870 size_t list_meter_uint8_t(const void *el); 00871 00876 size_t list_meter_uint16_t(const void *el); 00877 00882 size_t list_meter_uint32_t(const void *el); 00883 00888 size_t list_meter_uint64_t(const void *el); 00889 00894 size_t list_meter_float(const void *el); 00895 00900 size_t list_meter_double(const void *el); 00901 00906 size_t list_meter_string(const void *el); 00907 00908 /* hash functions */ 00913 list_hash_t list_hashcomputer_int8_t(const void *el); 00914 00919 list_hash_t list_hashcomputer_int16_t(const void *el); 00920 00925 list_hash_t list_hashcomputer_int32_t(const void *el); 00926 00931 list_hash_t list_hashcomputer_int64_t(const void *el); 00932 00937 list_hash_t list_hashcomputer_uint8_t(const void *el); 00938 00943 list_hash_t list_hashcomputer_uint16_t(const void *el); 00944 00949 list_hash_t list_hashcomputer_uint32_t(const void *el); 00950 00955 list_hash_t list_hashcomputer_uint64_t(const void *el); 00956 00961 list_hash_t list_hashcomputer_float(const void *el); 00962 00967 list_hash_t list_hashcomputer_double(const void *el); 00968 00973 list_hash_t list_hashcomputer_string(const void *el); 00974 00975 #ifdef __cplusplus 00976 } 00977 #endif 00978 00979 #endif 00980