summaryrefslogtreecommitdiff
path: root/src/config.c
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-12-12 21:11:19 +0100
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-12-12 21:31:59 +0100
commitdacdcf2516ef4520b0bb32fa34837381f65faf30 (patch)
treee58a517a421e6daba2934e6ab69d2f19ce914135 /src/config.c
parent3c9e3b69c425ff5bad208f2c52c3d4c3aaeaf2f9 (diff)
downloadpa-sink-ctl-dacdcf2516ef4520b0bb32fa34837381f65faf30.tar.gz
pa-sink-ctl-dacdcf2516ef4520b0bb32fa34837381f65faf30.tar.bz2
pa-sink-ctl-dacdcf2516ef4520b0bb32fa34837381f65faf30.zip
Implement a priority based sink order assignment
This is handsome when using udev based device discovery.
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/config.c b/src/config.c
new file mode 100644
index 0000000..e24ece0
--- /dev/null
+++ b/src/config.c
@@ -0,0 +1,93 @@
+#include <glib.h>
+#include <string.h>
+
+#include "pa-sink-ctl.h"
+#include "config.h"
+
+static int
+parse_priorities(struct config *cfg)
+{
+ gchar **groups;
+ struct priority p;
+ int i;
+ gsize length;
+ GError *error = NULL;
+
+ groups = g_key_file_get_groups(cfg->keyfile, &length);
+
+ for (i = 0; i < length; ++i) {
+ if (strncmp(groups[i], "priority", 8) != 0)
+ continue;
+
+ memset(&p, 0, sizeof p);
+
+ p.match = g_key_file_get_value(cfg->keyfile, groups[i],
+ "match", &error);
+ if (error)
+ goto error;
+ p.value = g_key_file_get_value(cfg->keyfile, groups[i],
+ "value", &error);
+ if (error)
+ goto error;
+ p.priority = g_key_file_get_integer(cfg->keyfile, groups[i],
+ "priority", &error);
+ if (error)
+ goto error;
+
+ list_append_struct(cfg->priorities, p);
+ }
+
+ return 0;
+
+error:
+ if (p.value)
+ g_free(p.value);
+ if (p.match)
+ g_free(p.match);
+
+ g_printerr("Failed to read property in prioritiy group '%s': %s\n",
+ groups[i], error->message);
+
+ return -1;
+}
+
+static void
+destroy_priority(gpointer data)
+{
+ struct priority *p = data;
+
+ g_free(p->value);
+ g_free(p->match);
+ g_free(p);
+}
+
+int
+config_init(struct config *cfg)
+{
+ GError *error = NULL;
+
+ memset(cfg, 0, sizeof *cfg);
+ cfg->keyfile = g_key_file_new();
+ cfg->priorities = NULL;
+
+ if (!g_key_file_load_from_data_dirs(cfg->keyfile,
+ "pa-sink-ctl/config.ini",
+ NULL, G_KEY_FILE_NONE, &error)
+ && error) {
+ g_printerr("Failed to open config file: %s\n", error->message);
+ return -1;
+ }
+
+ if (parse_priorities(cfg) < 0)
+ return -1;
+
+ return 0;
+}
+
+void
+config_uninit(struct config *cfg)
+{
+ g_list_free_full(cfg->priorities, destroy_priority);
+
+ g_key_file_free(cfg->keyfile);
+}