summaryrefslogtreecommitdiff
path: root/src/device.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.c')
-rw-r--r--src/device.c71
1 files changed, 0 insertions, 71 deletions
diff --git a/src/device.c b/src/device.c
index 6189de1..5d98b2a 100644
--- a/src/device.c
+++ b/src/device.c
@@ -22,83 +22,12 @@
*/
#include "device.h"
-#include "moticam.h"
-#include "dummy.h"
-
-static const struct device_driver *drivers[] = {
- &moticam_device_driver,
- &dummy_device_driver,
- NULL
-};
-
GQuark
device_error_quark(void)
{
return g_quark_from_static_string("device-error-quark");
}
-struct device *
-device_open(libusb_context *usb, GError **error)
-{
- g_return_val_if_fail(error == NULL || *error == NULL, NULL);
- libusb_device **list;
- libusb_device *found_usb_device = NULL;
- char *found_device_name = NULL;
- const struct device_driver *found_device_driver = NULL;
- ssize_t cnt = libusb_get_device_list(usb, &list);
- if (cnt < 0) {
- g_set_error(error, DEVICE_ERROR, DEVICE_ERROR_LIST,
- "can not list devices: %s", libusb_strerror(cnt));
- return NULL;
- }
- for (ssize_t i = 0; !found_usb_device && i < cnt; i++) {
- libusb_device *usb_device = list[i];
- struct libusb_device_descriptor desc;
- int r = libusb_get_device_descriptor(usb_device, &desc);
- if (r) {
- g_warning("can not get device descriptor: %s",
- libusb_strerror(r));
- } else {
- for (const struct device_driver **dd = drivers;
- !found_usb_device && *dd; dd++) {
- if ((*dd)->usb_poll) {
- char *device_name = (*dd)->usb_poll(&desc);
- if (device_name) {
- found_usb_device = usb_device;
- found_device_name = device_name;
- found_device_driver = *dd;
- }
- }
- }
- }
- }
- struct device *device = NULL;
- if (found_usb_device) {
- g_free(found_device_name);
- device = found_device_driver->usb_open(usb, found_usb_device, error);
- } else {
- for (const struct device_driver **dd = drivers;
- !found_device_name && *dd; dd++) {
- if ((*dd)->poll) {
- char *device_name = (*dd)->poll();
- if (device_name) {
- found_device_name = device_name;
- found_device_driver = *dd;
- }
- }
- }
- if (found_device_name) {
- g_free(found_device_name);
- device = found_device_driver->open(error);
- } else {
- g_set_error(error, DEVICE_ERROR, DEVICE_ERROR_LIST,
- "no device found");
- }
- }
- libusb_free_device_list(list, 1);
- return device;
-}
-
const struct device_info *
device_get_info(struct device *device)
{