summaryrefslogtreecommitdiff
path: root/device.h
diff options
context:
space:
mode:
Diffstat (limited to 'device.h')
-rw-r--r--device.h48
1 files changed, 32 insertions, 16 deletions
diff --git a/device.h b/device.h
index 01c6336..7028ebb 100644
--- a/device.h
+++ b/device.h
@@ -26,9 +26,13 @@
*/
#include <libusb.h>
#include <stdint.h>
+#include <glib.h>
#include "image.h"
+/* Error domain for device related errors. */
+#define DEVICE_ERROR device_error_quark()
+
struct device;
/* USB poll function. If the device is handled by this driver, it should
@@ -39,7 +43,7 @@ typedef char *(*device_driver_usb_poll_f)(
/* USB open function. The device driver previously declared that it handles
* this device. */
typedef struct device *(*device_driver_usb_open_f)(
- libusb_context *usb, libusb_device *usb_device);
+ libusb_context *usb, libusb_device *usb_device, GError **error);
/* Information on a device driver. */
struct device_driver {
@@ -97,20 +101,20 @@ typedef void (*device_set_resolution_f)(
struct device *device, int width, int height, int stride);
/* Start streaming. */
-typedef void (*device_start_f)(
- struct device *device);
+typedef bool (*device_start_f)(
+ struct device *device, GError **error);
/* Return an image if one is available, else, return NULL. */
typedef struct image *(*device_read_f)(
- struct device *device);
+ struct device *device, GError **error);
/* Stop streaming. */
-typedef void (*device_stop_f)(
- struct device *device);
+typedef bool (*device_stop_f)(
+ struct device *device, GError **error);
/* Close device. */
-typedef void (*device_close_f)(
- struct device *device);
+typedef bool (*device_close_f)(
+ struct device *device, GError **error);
/* Open device. */
struct device {
@@ -132,9 +136,21 @@ struct device {
device_close_f close;
};
+/* Error codes. */
+enum DeviceError {
+ /* Error listing devices. */
+ DEVICE_ERROR_LIST,
+ /* Generic USB error. */
+ DEVICE_ERROR_USB,
+};
+
+/* Return quark of error domain for device related errors. */
+GQuark
+device_error_quark(void);
+
/* Find and open device. */
struct device *
-device_open(libusb_context *usb);
+device_open(libusb_context *usb, GError **error);
/* Retrieve informations. */
const struct device_info *
@@ -154,19 +170,19 @@ device_set_resolution(struct device *device, int width, int height,
int stride);
/* Start streaming. */
-void
-device_start(struct device *device);
+bool
+device_start(struct device *device, GError **error);
/* Read an image. */
struct image *
-device_read(struct device *device);
+device_read(struct device *device, GError **error);
/* Stop streaming. */
-void
-device_stop(struct device *device);
+bool
+device_stop(struct device *device, GError **error);
/* Close device. */
-void
-device_close(struct device *device);
+bool
+device_close(struct device *device, GError **error);
#endif /* device_h */