dundee: Add device un/register

This commit is contained in:
Daniel Wagner 2011-12-20 15:12:51 +01:00
parent b1030d281d
commit 3e69d58570
2 changed files with 89 additions and 1 deletions

View File

@ -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)

View File

@ -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);