aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2011-10-09 18:37:31 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2011-10-09 18:38:32 +0200
commit74ae64b3551b8061380b8f4f120096a57dea8c7e (patch)
tree0c453d22f129f99f0f16502aeaf03203d6885e5a /io.c
parent587730174f15220538ca3a1db1ccc601d079632c (diff)
sam: Select the IO Backend at runtime when a device name is specified
The configure part is more messy than I had hoped for. One can not just specify @VARIABLE_THAT_HAS_SOURCES@, I need to go through the every backend and add the sourcecode.
Diffstat (limited to 'io.c')
-rw-r--r--io.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/io.c b/io.c
index 304e4ed..165962b 100644
--- a/io.c
+++ b/io.c
@@ -31,14 +31,7 @@ int io_driver_register(struct io_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)
+static void io_driver_activate(struct io_driver *driver)
{
printf("Activating driver: %s\n", driver->name);
g_driver = driver;
@@ -63,3 +56,24 @@ int io_read(void *buff, int len)
{
return g_driver->io_read(buff, len);
}
+
+void io_driver_select_backend(const char *name)
+{
+ int i;
+ struct io_driver *driver = drivers[0];
+
+ for ( i = 0; ;++i) {
+ if (!drivers[i])
+ break;
+
+ if (name && strcmp("posix", drivers[i]->name) == 0) {
+ driver = drivers[i];
+ break;
+ } else if (!name && strcmp("libusb", drivers[i]->name) == 0) {
+ driver = drivers[i];
+ break;
+ }
+ }
+
+ io_driver_activate(driver);
+}