summaryrefslogtreecommitdiff
path: root/src/cli.c
diff options
context:
space:
mode:
authorNicolas Schodet2020-05-04 22:32:40 +0200
committerNicolas Schodet2020-05-06 21:26:34 +0200
commitb4703718ece48fc5a6f01ae6873fae7d8ca0b710 (patch)
treeaa2b0e46c710d3bed25a5943e7a0596c76beac40 /src/cli.c
parent359eb3df1a1513acb4dfd6a57687fde3605057eb (diff)
Add device manager
Diffstat (limited to 'src/cli.c')
-rw-r--r--src/cli.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/src/cli.c b/src/cli.c
index a5c20c7..608aa58 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -23,12 +23,12 @@
#include <glib.h>
#include "cli.h"
-#include "device.h"
+#include "device_manager.h"
#include "utils.h"
static bool
-cli_read_images(libusb_context *usb, struct device *device, int count,
- bool raw, const char *out, GError **error)
+cli_read_images(struct device *device, int count, bool raw, const char *out,
+ GError **error)
{
g_return_val_if_fail(error == NULL || *error == NULL, false);
if (!device_start(device, error))
@@ -43,10 +43,7 @@ cli_read_images(libusb_context *usb, struct device *device, int count,
ret = false;
} else if (!image) {
/* No image yet, handle events. */
- int r = libusb_handle_events(usb);
- if (r)
- utils_fatal("unable to handle libusb events: %s",
- libusb_strerror(r));
+ g_main_context_iteration(NULL, TRUE);
} else {
/* Image received. */
if (!raw && image->format != IMAGE_FORMAT_XBGR32) {
@@ -73,12 +70,9 @@ cli_read_images(libusb_context *usb, struct device *device, int count,
int
cli_run(struct options *options)
{
- libusb_context *usb;
- int r = libusb_init(&usb);
- if (r)
- utils_fatal("unable to initialize libusb: %s", libusb_strerror(r));
+ struct device_manager *device_manager = device_manager_new(NULL);
GError *error = NULL;
- struct device *device = device_open(usb, &error);
+ struct device *device = device_manager_open(device_manager, &error);
if (!device)
utils_fatal("unable to find device: %s", error->message);
const struct device_info *info = device_get_info(device);
@@ -98,11 +92,11 @@ cli_run(struct options *options)
if (width == -1)
utils_fatal("no matching resolution");
device_set_resolution(device, width, height, 0);
- if (!cli_read_images(usb, device, options->count, options->raw,
- options->out, &error))
+ if (!cli_read_images(device, options->count, options->raw, options->out,
+ &error))
utils_fatal("unable to read images: %s", error->message);
if (!device_close(device, &error))
utils_fatal("unable to close device: %s", error->message);
- libusb_exit(usb);
+ device_manager_destroy(device_manager);
return EXIT_SUCCESS;
}