summaryrefslogtreecommitdiffstats
path: root/dundee
diff options
context:
space:
mode:
authorDaniel Wagner <daniel.wagner@bmw-carit.de>2011-12-20 15:12:51 +0100
committerDaniel Wagner <daniel.wagner@bmw-carit.de>2012-05-22 18:44:46 +0200
commit3e69d5857021a125a1559dc72ee4363d20a57124 (patch)
tree377e567fa9abcda34bd1e94ebe8c03a70923f387 /dundee
parentb1030d281dc575742d4e033a89a83a4bc9a4a1b5 (diff)
downloadofono-3e69d5857021a125a1559dc72ee4363d20a57124.tar.bz2
dundee: Add device un/register
Diffstat (limited to 'dundee')
-rw-r--r--dundee/device.c69
-rw-r--r--dundee/dundee.h21
2 files changed, 89 insertions, 1 deletions
diff --git a/dundee/device.c b/dundee/device.c
index d9fc9286..9ed16872 100644
--- a/dundee/device.c
+++ b/dundee/device.c
@@ -33,14 +33,19 @@
#include "dundee.h"
+static int next_device_id = 0;
static GHashTable *device_hash;
struct dundee_device {
+ char *path;
+ struct dundee_device_driver *driver;
+ gboolean registered;
+
};
const char *__dundee_device_get_path(struct dundee_device *device)
{
- return "/";
+ return device->path;
}
void __dundee_device_append_properties(struct dundee_device *device,
@@ -64,15 +69,77 @@ void __dundee_device_foreach(dundee_device_foreach_func func, void *userdata)
}
}
+static int register_device(struct dundee_device *device)
+{
+ return 0;
+}
+
+static int unregister_device(struct dundee_device *device)
+{
+ return 0;
+}
+
static void destroy_device(gpointer user)
{
struct dundee_device *device = user;
+ g_free(device->path);
+
g_free(device);
}
+struct dundee_device *dundee_device_create(struct dundee_device_driver *d)
+{
+ struct dundee_device *device;
+
+ device = g_try_new0(struct dundee_device, 1);
+ if (device == NULL)
+ return NULL;
+
+ device->driver = d;
+
+ device->path = g_strdup_printf("/device%d", next_device_id);
+ if (device->path == NULL) {
+ g_free(device);
+ return NULL;
+ }
+
+ next_device_id += 1;
+
+ return device;
+}
+
+int dundee_device_register(struct dundee_device *device)
+{
+ int err;
+
+ err = register_device(device);
+ if (err < 0)
+ return err;
+
+ device->registered = TRUE;
+
+ g_hash_table_insert(device_hash, g_strdup(device->path), device);
+
+ return 0;
+}
+
+void dundee_device_unregister(struct dundee_device *device)
+{
+ DBG("%p", device);
+
+ unregister_device(device);
+
+ device->registered = FALSE;
+
+ g_hash_table_remove(device_hash, device->path);
+}
+
static void device_shutdown(gpointer key, gpointer value, gpointer user_data)
{
+ struct dundee_device *device = value;
+
+ unregister_device(device);
}
void __dundee_device_shutdown(void)
diff --git a/dundee/dundee.h b/dundee/dundee.h
index 366938e3..ae14e013 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -105,6 +105,27 @@ int __dundee_device_init(void);
void __dundee_device_cleanup(void);
void __dundee_device_shutdown(void);
+typedef void (*dundee_device_connect_cb_t)(const struct dundee_error *error,
+ int fd, void *data);
+typedef void (*dundee_device_disconnect_cb_t)(const struct dundee_error *error,
+ void *data);
+
+struct dundee_device_driver {
+ const char *name;
+
+ /* Connect and dial */
+ void (*connect)(struct dundee_device *device,
+ dundee_device_connect_cb_t cb, void *data);
+
+ /* Hangup and disconnect */
+ void (*disconnect)(struct dundee_device *device,
+ dundee_device_disconnect_cb_t cb, void *data);
+};
+
+struct dundee_device *dundee_device_create(struct dundee_device_driver *d);
+int dundee_device_register(struct dundee_device *device);
+void dundee_device_unregister(struct dundee_device *device);
+
typedef void (*dundee_device_foreach_func)(struct dundee_device *device,
void *data);
void __dundee_device_foreach(dundee_device_foreach_func cb, void *userdata);