2 This file is part of catta.
4 catta is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2.1 of the
7 License, or (at your option) any later version.
9 catta is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
12 Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with catta; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
27 #include <catta/llist.h>
28 #include <catta/malloc.h>
31 #include <catta/log.h>
33 typedef struct CattaRecordListItem CattaRecordListItem;
35 struct CattaRecordListItem {
41 CATTA_LLIST_FIELDS(CattaRecordListItem, items);
44 struct CattaRecordList {
45 CATTA_LLIST_HEAD(CattaRecordListItem, read);
46 CATTA_LLIST_HEAD(CattaRecordListItem, unread);
51 CattaRecordList *catta_record_list_new(void) {
54 if (!(l = catta_new(CattaRecordList, 1))) {
55 catta_log_error("catta_new() failed.");
59 CATTA_LLIST_HEAD_INIT(CattaRecordListItem, l->read);
60 CATTA_LLIST_HEAD_INIT(CattaRecordListItem, l->unread);
62 l->all_flush_cache = 1;
66 void catta_record_list_free(CattaRecordList *l) {
69 catta_record_list_flush(l);
73 static void item_free(CattaRecordList *l, CattaRecordListItem *i) {
78 CATTA_LLIST_REMOVE(CattaRecordListItem, items, l->read, i);
80 CATTA_LLIST_REMOVE(CattaRecordListItem, items, l->unread, i);
82 catta_record_unref(i->record);
86 void catta_record_list_flush(CattaRecordList *l) {
90 item_free(l, l->read);
92 item_free(l, l->unread);
94 l->all_flush_cache = 1;
97 CattaRecord* catta_record_list_next(CattaRecordList *l, int *ret_flush_cache, int *ret_unicast_response, int *ret_auxiliary) {
99 CattaRecordListItem *i;
101 if (!(i = l->unread))
106 r = catta_record_ref(i->record);
107 if (ret_unicast_response)
108 *ret_unicast_response = i->unicast_response;
110 *ret_flush_cache = i->flush_cache;
112 *ret_auxiliary = i->auxiliary;
114 CATTA_LLIST_REMOVE(CattaRecordListItem, items, l->unread, i);
115 CATTA_LLIST_PREPEND(CattaRecordListItem, items, l->read, i);
122 static CattaRecordListItem *get(CattaRecordList *l, CattaRecord *r) {
123 CattaRecordListItem *i;
128 for (i = l->read; i; i = i->items_next)
129 if (catta_record_equal_no_ttl(i->record, r))
132 for (i = l->unread; i; i = i->items_next)
133 if (catta_record_equal_no_ttl(i->record, r))
139 void catta_record_list_push(CattaRecordList *l, CattaRecord *r, int flush_cache, int unicast_response, int auxiliary) {
140 CattaRecordListItem *i;
148 if (!(i = catta_new(CattaRecordListItem, 1))) {
149 catta_log_error("catta_new() failed.");
153 i->unicast_response = unicast_response;
154 i->flush_cache = flush_cache;
155 i->auxiliary = auxiliary;
156 i->record = catta_record_ref(r);
159 l->all_flush_cache = l->all_flush_cache && flush_cache;
161 CATTA_LLIST_PREPEND(CattaRecordListItem, items, l->unread, i);
164 void catta_record_list_drop(CattaRecordList *l, CattaRecord *r) {
165 CattaRecordListItem *i;
170 if (!(i = get(l, r)))
176 int catta_record_list_is_empty(CattaRecordList *l) {
179 return !l->unread && !l->read;
182 int catta_record_list_all_flush_cache(CattaRecordList *l) {
185 /* Return TRUE if all entries in this list have flush_cache set */
187 return l->all_flush_cache;