summaryrefslogtreecommitdiff
path: root/idlist.h
diff options
context:
space:
mode:
authorStefan Bühler <stbuehler@web.de>2010-09-09 14:26:43 +0200
committerStefan Bühler <stbuehler@web.de>2010-09-09 14:26:43 +0200
commit7a88d7a2887dcfea8371e7e84bb905a2527f4133 (patch)
tree3c3b23528af46391a45209b6b2f187dd76ebd3f0 /idlist.h
parent87bb51239cb3ecd64407c4e06fb14e35da21db8c (diff)
downloadlibmanda-7a88d7a2887dcfea8371e7e84bb905a2527f4133.tar.gz
libmanda-7a88d7a2887dcfea8371e7e84bb905a2527f4133.zip
Add idlist, code basic message handling
Diffstat (limited to 'idlist.h')
-rw-r--r--idlist.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/idlist.h b/idlist.h
new file mode 100644
index 0000000..879b894
--- /dev/null
+++ b/idlist.h
@@ -0,0 +1,39 @@
+#ifndef _LIBMANDA_IDLIST_H_
+#define _LIBMANDA_IDLIST_H_
+
+#include "libmanda.h"
+
+struct manda_IDList {
+ /* used ids are marked with a "1" in the bitvector (represented as array of gulong) */
+ GArray *bitvector;
+
+ /* all ids are in the range [0, max_ids[, i.e. 0 <= id < max_ids
+ * although the type is guint, it has to fit in a gint too, as we
+ * use gint for the ids in the interface, so we can use -1 as a special value.
+ */
+ guint max_ids;
+
+ /* if all ids in [0, used_ids-1] are used, next_free_id is -1
+ * if not, then all available ids are >= next_free_id,
+ * so we can start at next_free_id for searching the next free id
+ */
+ gint next_free_id;
+ guint used_ids;
+};
+
+/* create new idlist; the parameter max_ids is "signed" on purpose */
+manda_IDList* manda_idlist_new(gint max_ids);
+
+/* free idlist */
+void manda_idlist_free(manda_IDList *l);
+
+/* request new id; return -1 if no id is available, valid ids are always > 0 */
+gint manda_idlist_get(manda_IDList *l);
+
+/* check whether an id is in use and can be "_put" */
+gboolean manda_idlist_is_used(manda_IDList *l, gint id);
+
+/* release id. never release an id more than once! */
+void manda_idlist_put(manda_IDList *l, gint id);
+
+#endif