aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-10-09 16:28:57 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-10-09 16:39:41 +0200
commitf5a4783b701e9e620767d6ac3b2f96b4966278c2 (patch)
tree6fe2d08d66a57543d69ea8c5ce112c1ba889a3f3 /io.c
parente5c0adc53e6f5e34857e42e42b5cf5e606430857 (diff)
io: Create an io indirection to allow to compile multiple io backends
Right now only one io driver is compiled in and this one will be selected at application start.
Diffstat (limited to 'io.c')
-rw-r--r--io.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/io.c b/io.c
new file mode 100644
index 0000000..304e4ed
--- /dev/null
+++ b/io.c
@@ -0,0 +1,65 @@
+/*
+ * io.c
+ *
+ * Copyright (C) 2011 Holger Freyther, all rights reserved
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ */
+
+#include "io.h"
+
+#include <stdio.h>
+
+static struct io_driver *g_driver = NULL;
+
+static struct io_driver *drivers[5] = { NULL, };
+static int last_driver = 0;
+
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
+
+int io_driver_register(struct io_driver *driver)
+{
+ if (last_driver > ARRAY_SIZE(drivers)) {
+ fprintf(stderr, "Registered more than %d devices.\n",
+ ARRAY_SIZE(drivers));
+ return -1;
+ }
+
+ drivers[last_driver++] = driver;
+ return 0;
+}
+
+struct io_driver *io_driver_at(int i)
+{
+ if (i >= last_driver)
+ return NULL;
+ return drivers[i];
+}
+
+void io_driver_activate(struct io_driver *driver)
+{
+ printf("Activating driver: %s\n", driver->name);
+ g_driver = driver;
+}
+
+int io_init(char *dev)
+{
+ return g_driver->io_init(dev);
+}
+
+int io_cleanup(void)
+{
+ return g_driver->io_cleanup();
+}
+
+int io_write(void *buff, int len)
+{
+ return g_driver->io_write(buff, len);
+}
+
+int io_read(void *buff, int len)
+{
+ return g_driver->io_read(buff, len);
+}