summaryrefslogtreecommitdiff
path: root/src/gui_app.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gui_app.c')
-rw-r--r--src/gui_app.c40
1 files changed, 11 insertions, 29 deletions
diff --git a/src/gui_app.c b/src/gui_app.c
index e7cc862..1a2f501 100644
--- a/src/gui_app.c
+++ b/src/gui_app.c
@@ -21,9 +21,9 @@
* Email: <nico at ni.fr.eu.org>
*/
#include "gui_app.h"
+#include "device_manager.h"
#include "gui_app_window.h"
#include "options.h"
-#include "usb_source.h"
#include "utils.h"
struct _GuiApp {
@@ -33,33 +33,23 @@ struct _GuiApp {
typedef struct _GuiAppPrivate GuiAppPrivate;
struct _GuiAppPrivate {
- libusb_context *usb;
- GSource *usb_source;
+ struct device_manager *device_manager;
};
G_DEFINE_TYPE_WITH_PRIVATE(GuiApp, gui_app, GTK_TYPE_APPLICATION)
-static gboolean
-gui_app_usb_source_cb(gpointer user_data)
+static void
+gui_app_device_manager_cb(gpointer user_data)
{
GuiApp *app = user_data;
- GuiAppPrivate *priv = gui_app_get_instance_private(app);
- struct timeval tv;
- tv.tv_sec = 0;
- tv.tv_usec = 0;
- int r = libusb_handle_events_timeout(priv->usb, &tv);
- if (r)
- g_error("unable to handle libusb events: %s", libusb_strerror(r));
g_signal_emit_by_name(app, "video-ready");
- return G_SOURCE_CONTINUE;
}
static void
gui_app_init(GuiApp *app)
{
GuiAppPrivate *priv = gui_app_get_instance_private(app);
- priv->usb = NULL;
- priv->usb_source = NULL;
+ priv->device_manager = NULL;
options_add(G_APPLICATION(app));
}
@@ -68,13 +58,9 @@ gui_app_startup(GApplication *app)
{
G_APPLICATION_CLASS(gui_app_parent_class)->startup(app);
GuiAppPrivate *priv = gui_app_get_instance_private(GUI_APP(app));
- int r = libusb_init(&priv->usb);
- if (r)
- g_error("unable to initialize libusb: %s", libusb_strerror(r));
- priv->usb_source = usb_source_new(priv->usb);
- g_source_set_callback(priv->usb_source, gui_app_usb_source_cb, app,
- NULL);
- g_source_attach(priv->usb_source, NULL);
+ priv->device_manager = device_manager_new(NULL);
+ device_manager_set_callback(priv->device_manager,
+ gui_app_device_manager_cb, app);
}
static void
@@ -82,7 +68,7 @@ gui_app_activate(GApplication *app)
{
GuiAppPrivate *priv = gui_app_get_instance_private(GUI_APP(app));
GError *error = NULL;
- struct device *device = device_open(priv->usb, &error);
+ struct device *device = device_manager_open(priv->device_manager, &error);
if (!device) {
utils_dialog_error(NULL, "unable to find device: %s", error->message);
g_error_free(error);
@@ -98,12 +84,8 @@ static void
gui_app_shutdown(GApplication *app)
{
GuiAppPrivate *priv = gui_app_get_instance_private(GUI_APP(app));
- if (priv->usb_source) {
- g_source_destroy(priv->usb_source);
- g_source_unref(priv->usb_source);
- }
- if (priv->usb)
- libusb_exit(priv->usb);
+ if (priv->device_manager)
+ device_manager_destroy(priv->device_manager);
G_APPLICATION_CLASS(gui_app_parent_class)->shutdown(app);
}