diff options
author | Olivier Fourdan <ofourdan@redhat.com> | 2012-02-24 11:56:57 +0100 |
---|---|---|
committer | Bastien Nocera <hadess@hadess.net> | 2012-02-24 11:56:57 +0100 |
commit | 93dc2413517f4c7760e6218143bad6eec59cfd71 (patch) | |
tree | 7598424d1b8e3da2ed0b54653468324486580a4a | |
parent | 31b4a3261a54d8a27de75c3421fe26cc0b22c4e4 (diff) |
lib: Add API to list all items in the database
-rw-r--r-- | libwacom/libwacom-database.c | 25 | ||||
-rw-r--r-- | libwacom/libwacom.h | 13 |
2 files changed, 38 insertions, 0 deletions
diff --git a/libwacom/libwacom-database.c b/libwacom/libwacom-database.c index b30cc10..c9f31b6 100644 --- a/libwacom/libwacom-database.c +++ b/libwacom/libwacom-database.c @@ -466,4 +466,29 @@ libwacom_database_destroy(WacomDeviceDatabase *db) g_free (db); } +WacomDevice** +libwacom_list_devices_from_database(WacomDeviceDatabase *db, WacomError *error) +{ + GList *cur, *devices; + WacomDevice **list, **p; + + if (!db) { + libwacom_error_set(error, WERROR_INVALID_DB, "db is NULL"); + return NULL; + } + + devices = g_hash_table_get_values (db->device_ht); + list = calloc (g_list_length (devices) + 1, sizeof (WacomDevice *)); + if (!list) { + libwacom_error_set(error, WERROR_BAD_ALLOC, "Memory allocation failed"); + return NULL; + } + + for (p = list, cur = devices; cur; cur = g_list_next (cur)) + *p++ = (WacomDevice *) cur->data; + g_list_free (devices); + + return list; +} + /* vim: set noexpandtab tabstop=8 shiftwidth=8: */ diff --git a/libwacom/libwacom.h b/libwacom/libwacom.h index b1122eb..4f537c4 100644 --- a/libwacom/libwacom.h +++ b/libwacom/libwacom.h @@ -244,6 +244,19 @@ WacomDevice* libwacom_new_from_usbid(WacomDeviceDatabase *db, int vendor_id, int WacomDevice* libwacom_new_from_name(WacomDeviceDatabase *db, const char *name, WacomError *error); /** + * Returns the list of devices in the given database. + * + * @param db A device database + * @param error If not NULL, set to the error if any occurs + * + * @return A NULL terminated list of pointers to all the devices inside the + * database. + * The content of the list is owned by the database and should not be + * modified of freed. Use free() to free the list. + */ +WacomDevice** libwacom_list_devices_from_database(WacomDeviceDatabase *db, WacomError *error); + +/** * Remove the device and free all memory and references to it. * * @param device The device to delete |