aboutsummaryrefslogtreecommitdiffstats
path: root/src/sticker.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-03-14 14:20:01 +0100
committerMax Kellermann <max@duempel.org>2009-03-14 14:20:01 +0100
commitdd67992a0c403ff23b071fe9b1e312cfaa4bd924 (patch)
tree7f5d03f53e48dc63ff6c0bea369dd249c6b6bcea /src/sticker.c
parent5b687795c499e9fef4eeed234552f1171a845a95 (diff)
downloadmpd-dd67992a0c403ff23b071fe9b1e312cfaa4bd924.tar.gz
mpd-dd67992a0c403ff23b071fe9b1e312cfaa4bd924.tar.xz
mpd-dd67992a0c403ff23b071fe9b1e312cfaa4bd924.zip
sticker: added "struct sticker"
The sticker struct can be used for enumerating values. This will replace the sticker_list_values() function.
Diffstat (limited to 'src/sticker.c')
-rw-r--r--src/sticker.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/src/sticker.c b/src/sticker.c
index ce8b1d68b..cad4e1c97 100644
--- a/src/sticker.c
+++ b/src/sticker.c
@@ -27,6 +27,10 @@
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "sticker"
+struct sticker {
+ GHashTable *table;
+};
+
static const char sticker_sql_create[] =
"CREATE TABLE IF NOT EXISTS sticker("
" type VARCHAR NOT NULL, "
@@ -433,3 +437,61 @@ sticker_delete(const char *type, const char *uri)
idle_add(IDLE_STICKER);
return true;
}
+
+void
+sticker_free(struct sticker *sticker)
+{
+ assert(sticker != NULL);
+ assert(sticker->table != NULL);
+
+ g_hash_table_destroy(sticker->table);
+ g_free(sticker);
+}
+
+const char *
+sticker_get_value(struct sticker *sticker, const char *name)
+{
+ return g_hash_table_lookup(sticker->table, name);
+}
+
+struct sticker_foreach_data {
+ void (*func)(const char *name, const char *value,
+ gpointer user_data);
+ gpointer user_data;
+};
+
+static void
+sticker_foreach_func(gpointer key, gpointer value, gpointer user_data)
+{
+ struct sticker_foreach_data *data = user_data;
+
+ data->func(key, value, data->user_data);
+}
+
+void
+sticker_foreach(struct sticker *sticker,
+ void (*func)(const char *name, const char *value,
+ gpointer user_data),
+ gpointer user_data)
+{
+ struct sticker_foreach_data data = {
+ .func = func,
+ .user_data = user_data,
+ };
+
+ g_hash_table_foreach(sticker->table, sticker_foreach_func, &data);
+}
+
+struct sticker *
+sticker_load(const char *type, const char *uri)
+{
+ struct sticker *sticker = g_new(struct sticker, 1);
+
+ sticker->table = sticker_list_values(type, uri);
+ if (sticker->table == NULL) {
+ g_free(sticker);
+ return NULL;
+ }
+
+ return sticker;
+}