summaryrefslogtreecommitdiff
path: root/playlist.h
diff options
context:
space:
mode:
Diffstat (limited to 'playlist.h')
-rw-r--r--playlist.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/playlist.h b/playlist.h
new file mode 100644
index 0000000..ed4b19d
--- /dev/null
+++ b/playlist.h
@@ -0,0 +1,33 @@
+#ifndef PLAYLIST_H_
+#define PLAYLIST_H_
+
+#include "common.h"
+
+/**
+ * Playlist - A thread-safe string queue with support for indexed insert/remove.
+ */
+typedef struct Playlist Playlist;
+
+Playlist *playlist_init (void);
+void playlist_free (Playlist *pl);
+int playlist_enqueue (Playlist *pl, const char *entry);
+
+/**
+ * Fetch the next entry in the playlist, blocking the current thread and waiting
+ * for an entry if needed. The function can be interrupted by sending a signal
+ * to the waiting thread, in which case *entry remains untouched, -1 is
+ * returned, and errno is set to EINTR. Returns 0 on success.
+ */
+int playlist_dequeue(Playlist *pl, struct Entry *entry);
+
+/**
+ * Like playlist_dequeue, but returns -1 when the playlist is empty instead of
+ * locking the thread. Returns 0 on success.
+ */
+int playlist_try_dequeue(Playlist *pl, struct Entry *entry);
+
+int playlist_insert (Playlist *pl, unsigned int id, const char *entry);
+int playlist_remove (Playlist *pl, unsigned int id, struct Entry *entry);
+int playlist_list (Playlist *pl, struct StateInfo *list);
+
+#endif // PLAYLIST_H_