source: trunk/include/sh_fifo.h@ 575

Last change on this file since 575 was 481, checked in by katerina, 9 years ago

Enhancements and fixes for tickets #374, #375, #376, #377, #378, and #379.

File size: 2.7 KB
Line 
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
12#define SH_FIFO_MAX 16384
13
14/*****************************************************
15 *
16 * the type definitions for the fifo
17 *
18 *****************************************************/
19
20struct dlist {
21 struct dlist * next;
22 char * data;
23 char * s_xtra;
24 int i_xtra;
25 int transact;
26 struct dlist * prev;
27};
28
29typedef struct fifo_str {
30 struct dlist * head_ptr;
31 struct dlist * tail_ptr;
32 int fifo_cts;
33} SH_FIFO;
34
35#define SH_FIFO_INITIALIZER { NULL, NULL, 0 }
36
37/*****************************************************
38 *
39 * fifo functions
40 *
41 *****************************************************/
42
43/* Initialize the list.
44 *
45 */
46#define fifo_init(fifo_p) { (fifo_p)->fifo_cts = 0; (fifo_p)->head_ptr = NULL; \
47 (fifo_p)->tail_ptr = NULL; }
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 */
54int 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)
56
57/* Push an item on the tail of the list.
58 *
59 * Returns: -1 if the list is full, 0 on success
60 */
61int 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)
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 */
69char * pop_list (SH_FIFO * fifo);
70#define sh_fifo_pop(a) pop_list((a))
71
72/* ---- Special functions -------------------------------------------------*/
73
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 */
82sh_string * tag_list (SH_FIFO * fifo, char * tag,
83 int(*check)(int, const char*, const char*, const void*),
84 const void * info, int okNull);
85
86/* Flag all tagged as candidate to keep */
87void rollback_list (SH_FIFO * fifo);
88/* Flag all tagged as candidate to delete */
89void mark_list (SH_FIFO * fifo);
90/* Remove all flags */
91void reset_list (SH_FIFO * fifo);
92/* Delete all marked for delete that are not flagged for keep */
93int commit_list (SH_FIFO * fifo);
94
95#endif
Note: See TracBrowser for help on using the repository browser.