[1] | 1 |
|
---|
| 2 | #ifndef SH_FIFO_H
|
---|
| 3 | #define SH_FIFO_H
|
---|
| 4 |
|
---|
| 5 | /*****************************************************
|
---|
| 6 | *
|
---|
| 7 | * the maximum number of entries the fifo will hold
|
---|
| 8 | * - additional entries are simply not accepted -
|
---|
| 9 | *
|
---|
| 10 | *****************************************************/
|
---|
| 11 |
|
---|
[214] | 12 | #define SH_FIFO_MAX 16384
|
---|
[1] | 13 |
|
---|
| 14 | /*****************************************************
|
---|
| 15 | *
|
---|
| 16 | * the type definitions for the fifo
|
---|
| 17 | *
|
---|
| 18 | *****************************************************/
|
---|
| 19 |
|
---|
| 20 | struct dlist {
|
---|
| 21 | struct dlist * next;
|
---|
| 22 | char * data;
|
---|
[214] | 23 | char * s_xtra;
|
---|
| 24 | int i_xtra;
|
---|
| 25 | int transact;
|
---|
[1] | 26 | struct dlist * prev;
|
---|
| 27 | };
|
---|
| 28 |
|
---|
| 29 | typedef struct fifo_str {
|
---|
| 30 | struct dlist * head_ptr;
|
---|
| 31 | struct dlist * tail_ptr;
|
---|
| 32 | int fifo_cts;
|
---|
| 33 | } SH_FIFO;
|
---|
| 34 |
|
---|
[481] | 35 | #define SH_FIFO_INITIALIZER { NULL, NULL, 0 }
|
---|
| 36 |
|
---|
[1] | 37 | /*****************************************************
|
---|
| 38 | *
|
---|
| 39 | * fifo functions
|
---|
| 40 | *
|
---|
| 41 | *****************************************************/
|
---|
| 42 |
|
---|
| 43 | /* Initialize the list.
|
---|
| 44 | *
|
---|
| 45 | */
|
---|
[481] | 46 | #define fifo_init(fifo_p) { (fifo_p)->fifo_cts = 0; (fifo_p)->head_ptr = NULL; \
|
---|
| 47 | (fifo_p)->tail_ptr = NULL; }
|
---|
[1] | 48 |
|
---|
| 49 |
|
---|
| 50 | /* Push an item on the head of the list.
|
---|
| 51 | *
|
---|
| 52 | * Returns: -1 if the list is full, 0 on success
|
---|
| 53 | */
|
---|
[481] | 54 | int push_list (SH_FIFO * fifo, const char * indat, int in_i, const char * in_str);
|
---|
| 55 | #define sh_fifo_push(a, b) push_list((a), (b), 0, NULL)
|
---|
[1] | 56 |
|
---|
| 57 | /* Push an item on the tail of the list.
|
---|
| 58 | *
|
---|
| 59 | * Returns: -1 if the list is full, 0 on success
|
---|
| 60 | */
|
---|
[481] | 61 | int push_tail_list (SH_FIFO * fifo, const char * indat, int in_i, const char * in_str);
|
---|
| 62 | #define sh_fifo_push_tail(a, b) push_tail_list((a), (b), 0, NULL)
|
---|
[1] | 63 |
|
---|
| 64 | /* pop an item from the tail of the list
|
---|
| 65 | *
|
---|
| 66 | * Returns: NULL if the list is empty,
|
---|
| 67 | * freshly allocated memory on success (should be free'd by caller)
|
---|
| 68 | */
|
---|
| 69 | char * pop_list (SH_FIFO * fifo);
|
---|
[481] | 70 | #define sh_fifo_pop(a) pop_list((a))
|
---|
[1] | 71 |
|
---|
[481] | 72 | /* ---- Special functions -------------------------------------------------*/
|
---|
[214] | 73 |
|
---|
[481] | 74 | /* This is for eMail where different recipients may be eligible for *
|
---|
| 75 | * different subsets of messages. We need to delete all that were sent *
|
---|
| 76 | * to all intended recipients, and keep all with at least one failure. */
|
---|
| 77 |
|
---|
| 78 | /* Iterate over list and check for each if it is valid for 'tag';
|
---|
| 79 | * i.e. (item->s_extra == tag). If yes, add to the returned string.
|
---|
| 80 | * If (okNull == False) then item->s_xtra must be defined
|
---|
| 81 | */
|
---|
[214] | 82 | sh_string * tag_list (SH_FIFO * fifo, char * tag,
|
---|
| 83 | int(*check)(int, const char*, const char*, const void*),
|
---|
[272] | 84 | const void * info, int okNull);
|
---|
[481] | 85 |
|
---|
| 86 | /* Flag all tagged as candidate to keep */
|
---|
[214] | 87 | void rollback_list (SH_FIFO * fifo);
|
---|
[481] | 88 | /* Flag all tagged as candidate to delete */
|
---|
[214] | 89 | void mark_list (SH_FIFO * fifo);
|
---|
[481] | 90 | /* Remove all flags */
|
---|
[214] | 91 | void reset_list (SH_FIFO * fifo);
|
---|
[481] | 92 | /* Delete all marked for delete that are not flagged for keep */
|
---|
[214] | 93 | int commit_list (SH_FIFO * fifo);
|
---|
| 94 |
|
---|
[1] | 95 | #endif
|
---|