Add stringring implementation
[blerg.git] / common / stringring.h
diff --git a/common/stringring.h b/common/stringring.h
new file mode 100644 (file)
index 0000000..7aedeb4
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef _STRINGRING_H
+#define _STRINGRING_H
+
+#include <stdint.h>
+
+#define STRINGRING_DATA_SIZE 32
+#define STRINGRING_N_ENTRIES 102
+
+struct stringring {
+       uint8_t counter;
+       uint8_t reserved[15];
+       struct {
+               uint64_t timestamp;
+               uint8_t data[STRINGRING_DATA_SIZE];
+       } entries[STRINGRING_N_ENTRIES];
+};
+
+struct stringring_handle {
+       int fd;
+       struct stringring *sr;
+};
+
+struct stringring_handle * stringring_open(const char *filename);
+void stringring_close(struct stringring_handle *sh);
+int stringring_add(struct stringring_handle *sh, const char *data);
+int stringring_find(struct stringring_handle *sh, const char *data, unsigned int max_age);
+int stringring_remove(struct stringring_handle *sh, const char *data);
+int stringring_clear(struct stringring_handle *sh);
+
+#endif /* _STRINGRING_H */