summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2022-09-04 19:35:35 +0100
committerRichard Hughes <richard@hughsie.com>2022-09-04 22:32:55 +0100
commit91a213f7687c39f83cadb022739d09d37d392cee (patch)
treeb6637e85954baf0e522f58e17d8d1003f26b0f98
parent36f53da169cd5ad7f690b682729f35d057353758 (diff)
downloadgusb-91a213f7687c39f83cadb022739d09d37d392cee.tar.gz
Reformat the code using clang-format
This frees up mental energy when reviewing patches and is something I should have done a long time ago.
-rw-r--r--.clang-format47
-rw-r--r--gusb/gusb-autocleanups.h2
-rw-r--r--gusb/gusb-bos-descriptor-private.h6
-rw-r--r--gusb/gusb-bos-descriptor.c37
-rw-r--r--gusb/gusb-bos-descriptor.h10
-rw-r--r--gusb/gusb-context-private.h17
-rw-r--r--gusb/gusb-context.c705
-rw-r--r--gusb/gusb-context.h124
-rw-r--r--gusb/gusb-device-list.c173
-rw-r--r--gusb/gusb-device-list.h58
-rw-r--r--gusb/gusb-device-private.h12
-rw-r--r--gusb/gusb-device.c1274
-rw-r--r--gusb/gusb-device.h417
-rw-r--r--gusb/gusb-endpoint-private.h6
-rw-r--r--gusb/gusb-endpoint.c76
-rw-r--r--gusb/gusb-endpoint.h31
-rw-r--r--gusb/gusb-interface-private.h6
-rw-r--r--gusb/gusb-interface.c84
-rw-r--r--gusb/gusb-interface.h34
-rw-r--r--gusb/gusb-private.h2
-rw-r--r--gusb/gusb-self-test.c587
-rw-r--r--gusb/gusb-source.c14
-rw-r--r--gusb/gusb-source.h18
-rw-r--r--gusb/gusb-umockdev-test.c196
-rw-r--r--gusb/gusb-util.c4
-rw-r--r--gusb/gusb-util.h3
-rw-r--r--gusb/gusb-version.c7
-rw-r--r--gusb/gusb.h10
-rw-r--r--tools/gusb-main.c406
29 files changed, 2169 insertions, 2197 deletions
diff --git a/.clang-format b/.clang-format
new file mode 100644
index 0000000..0e593d1
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,47 @@
+---
+AlignAfterOpenBracket: 'Align'
+AlignConsecutiveAssignments: 'false'
+AlignConsecutiveDeclarations: 'false'
+AlignConsecutiveMacros: 'true'
+AlignOperands: 'true'
+AlignTrailingComments: 'true'
+AllowAllArgumentsOnNextLine: 'false'
+AllowAllParametersOfDeclarationOnNextLine: 'false'
+AllowShortBlocksOnASingleLine: 'false'
+AllowShortCaseLabelsOnASingleLine: 'false'
+AllowShortFunctionsOnASingleLine: 'Inline'
+AllowShortIfStatementsOnASingleLine: 'false'
+AlwaysBreakAfterReturnType: 'All'
+BinPackParameters: 'false'
+BinPackArguments: 'false'
+BreakBeforeBraces: 'Linux'
+ColumnLimit: '100'
+DerivePointerAlignment: 'false'
+IndentCaseLabels: 'false'
+IndentWidth: '8'
+IncludeBlocks: 'Regroup'
+KeepEmptyLinesAtTheStartOfBlocks: 'false'
+MaxEmptyLinesToKeep: '1'
+PointerAlignment: 'Right'
+SortIncludes: 'true'
+SpaceAfterCStyleCast: 'false'
+SpaceBeforeAssignmentOperators : 'true'
+SpaceBeforeParens: 'ControlStatements'
+SpaceInEmptyParentheses: 'false'
+SpacesInSquareBrackets: 'false'
+TabWidth: '8'
+UseTab: 'Always'
+PenaltyBreakAssignment: '3'
+PenaltyBreakBeforeFirstCallParameter: '15'
+---
+Language: 'Proto'
+---
+Language: 'Cpp'
+IncludeCategories:
+ - Regex: '^"config.h"$'
+ Priority: '0'
+ - Regex: '^<'
+ Priority: '2'
+ - Regex: '.*'
+ Priority: '4'
+...
diff --git a/gusb/gusb-autocleanups.h b/gusb/gusb-autocleanups.h
index ad71b57..c831041 100644
--- a/gusb/gusb-autocleanups.h
+++ b/gusb/gusb-autocleanups.h
@@ -8,8 +8,8 @@
#pragma once
#include <gusb/gusb-context.h>
-#include <gusb/gusb-device.h>
#include <gusb/gusb-device-list.h>
+#include <gusb/gusb-device.h>
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
diff --git a/gusb/gusb-bos-descriptor-private.h b/gusb/gusb-bos-descriptor-private.h
index 4db8320..fed994b 100644
--- a/gusb/gusb-bos-descriptor-private.h
+++ b/gusb/gusb-bos-descriptor-private.h
@@ -7,12 +7,12 @@
#pragma once
-#include <libusb.h>
-
#include <gusb/gusb-bos-descriptor.h>
+#include <libusb.h>
G_BEGIN_DECLS
-GUsbBosDescriptor *_g_usb_bos_descriptor_new (const struct libusb_bos_dev_capability_descriptor *bos_cap);
+GUsbBosDescriptor *
+_g_usb_bos_descriptor_new(const struct libusb_bos_dev_capability_descriptor *bos_cap);
G_END_DECLS
diff --git a/gusb/gusb-bos-descriptor.c b/gusb/gusb-bos-descriptor.c
index b0664f8..48265dd 100644
--- a/gusb/gusb-bos-descriptor.c
+++ b/gusb/gusb-bos-descriptor.c
@@ -21,36 +21,35 @@
#include "gusb-bos-descriptor-private.h"
-struct _GUsbBosDescriptor
-{
+struct _GUsbBosDescriptor {
GObject parent_instance;
struct libusb_bos_dev_capability_descriptor bos_cap;
GBytes *extra;
};
-G_DEFINE_TYPE (GUsbBosDescriptor, g_usb_bos_descriptor, G_TYPE_OBJECT)
+G_DEFINE_TYPE(GUsbBosDescriptor, g_usb_bos_descriptor, G_TYPE_OBJECT)
static void
-g_usb_bos_descriptor_finalize (GObject *object)
+g_usb_bos_descriptor_finalize(GObject *object)
{
- GUsbBosDescriptor *self = G_USB_BOS_DESCRIPTOR (object);
+ GUsbBosDescriptor *self = G_USB_BOS_DESCRIPTOR(object);
- g_bytes_unref (self->extra);
+ g_bytes_unref(self->extra);
- G_OBJECT_CLASS (g_usb_bos_descriptor_parent_class)->finalize (object);
+ G_OBJECT_CLASS(g_usb_bos_descriptor_parent_class)->finalize(object);
}
static void
-g_usb_bos_descriptor_class_init (GUsbBosDescriptorClass *klass)
+g_usb_bos_descriptor_class_init(GUsbBosDescriptorClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->finalize = g_usb_bos_descriptor_finalize;
}
static void
-g_usb_bos_descriptor_init (GUsbBosDescriptor *self)
+g_usb_bos_descriptor_init(GUsbBosDescriptor *self)
{
}
@@ -62,16 +61,16 @@ g_usb_bos_descriptor_init (GUsbBosDescriptor *self)
* Since: 0.4.0
**/
GUsbBosDescriptor *
-_g_usb_bos_descriptor_new (const struct libusb_bos_dev_capability_descriptor *bos_cap)
+_g_usb_bos_descriptor_new(const struct libusb_bos_dev_capability_descriptor *bos_cap)
{
GUsbBosDescriptor *self;
- self = g_object_new (G_USB_TYPE_BOS_DESCRIPTOR, NULL);
+ self = g_object_new(G_USB_TYPE_BOS_DESCRIPTOR, NULL);
/* copy the data */
- memcpy (&self->bos_cap, bos_cap, sizeof (*bos_cap));
- self->extra = g_bytes_new (bos_cap->dev_capability_data, bos_cap->bLength - 0x03);
+ memcpy(&self->bos_cap, bos_cap, sizeof(*bos_cap));
+ self->extra = g_bytes_new(bos_cap->dev_capability_data, bos_cap->bLength - 0x03);
- return G_USB_BOS_DESCRIPTOR (self);
+ return G_USB_BOS_DESCRIPTOR(self);
}
/**
@@ -85,9 +84,9 @@ _g_usb_bos_descriptor_new (const struct libusb_bos_dev_capability_descriptor *bo
* Since: 0.4.0
**/
guint8
-g_usb_bos_descriptor_get_capability (GUsbBosDescriptor *self)
+g_usb_bos_descriptor_get_capability(GUsbBosDescriptor *self)
{
- g_return_val_if_fail (G_USB_IS_BOS_DESCRIPTOR (self), 0);
+ g_return_val_if_fail(G_USB_IS_BOS_DESCRIPTOR(self), 0);
return self->bos_cap.bDevCapabilityType;
}
@@ -102,8 +101,8 @@ g_usb_bos_descriptor_get_capability (GUsbBosDescriptor *self)
* Since: 0.4.0
**/
GBytes *
-g_usb_bos_descriptor_get_extra (GUsbBosDescriptor *self)
+g_usb_bos_descriptor_get_extra(GUsbBosDescriptor *self)
{
- g_return_val_if_fail (G_USB_IS_BOS_DESCRIPTOR (self), NULL);
+ g_return_val_if_fail(G_USB_IS_BOS_DESCRIPTOR(self), NULL);
return self->extra;
}
diff --git a/gusb/gusb-bos-descriptor.h b/gusb/gusb-bos-descriptor.h
index 813779e..b230a7c 100644
--- a/gusb/gusb-bos-descriptor.h
+++ b/gusb/gusb-bos-descriptor.h
@@ -11,10 +11,12 @@
G_BEGIN_DECLS
-#define G_USB_TYPE_BOS_DESCRIPTOR (g_usb_bos_descriptor_get_type ())
-G_DECLARE_FINAL_TYPE (GUsbBosDescriptor, g_usb_bos_descriptor, G_USB, BOS_DESCRIPTOR, GObject)
+#define G_USB_TYPE_BOS_DESCRIPTOR (g_usb_bos_descriptor_get_type())
+G_DECLARE_FINAL_TYPE(GUsbBosDescriptor, g_usb_bos_descriptor, G_USB, BOS_DESCRIPTOR, GObject)
-guint8 g_usb_bos_descriptor_get_capability (GUsbBosDescriptor *self);
-GBytes *g_usb_bos_descriptor_get_extra (GUsbBosDescriptor *self);
+guint8
+g_usb_bos_descriptor_get_capability(GUsbBosDescriptor *self);
+GBytes *
+g_usb_bos_descriptor_get_extra(GUsbBosDescriptor *self);
G_END_DECLS
diff --git a/gusb/gusb-context-private.h b/gusb/gusb-context-private.h
index c3ef226..6824308 100644
--- a/gusb/gusb-context-private.h
+++ b/gusb/gusb-context-private.h
@@ -7,20 +7,17 @@
#pragma once
-#include <libusb.h>
-
#include <gusb/gusb-context.h>
+#include <libusb.h>
G_BEGIN_DECLS
-libusb_context *_g_usb_context_get_context (GUsbContext *context);
+libusb_context *
+_g_usb_context_get_context(GUsbContext *context);
-const gchar *_g_usb_context_lookup_vendor (GUsbContext *context,
- guint16 vid,
- GError **error);
-const gchar *_g_usb_context_lookup_product (GUsbContext *context,
- guint16 vid,
- guint16 pid,
- GError **error);
+const gchar *
+_g_usb_context_lookup_vendor(GUsbContext *context, guint16 vid, GError **error);
+const gchar *
+_g_usb_context_lookup_product(GUsbContext *context, guint16 vid, guint16 pid, GError **error);
G_END_DECLS
diff --git a/gusb/gusb-context.c b/gusb/gusb-context.c
index 8f0f5d6..4ccfd17 100644
--- a/gusb/gusb-context.c
+++ b/gusb/gusb-context.c
@@ -22,18 +22,9 @@
#include "gusb-device-private.h"
#include "gusb-util.h"
-enum {
- PROP_0,
- PROP_LIBUSB_CONTEXT,
- PROP_DEBUG_LEVEL,
- N_PROPERTIES
-};
+enum { PROP_0, PROP_LIBUSB_CONTEXT, PROP_DEBUG_LEVEL, N_PROPERTIES };
-enum {
- DEVICE_ADDED_SIGNAL,
- DEVICE_REMOVED_SIGNAL,
- LAST_SIGNAL
-};
+enum { DEVICE_ADDED_SIGNAL, DEVICE_REMOVED_SIGNAL, LAST_SIGNAL };
#define G_USB_CONTEXT_HOTPLUG_POLL_INTERVAL_DEFAULT 1000 /* ms */
@@ -42,24 +33,23 @@ enum {
*
* Private #GUsbContext data
**/
-struct _GUsbContextPrivate
-{
- GMainContext *main_ctx;
- GPtrArray *devices;
- GHashTable *dict_usb_ids;
- GHashTable *dict_replug;
- GThread *thread_event;
- gboolean done_enumerate;
- volatile gint thread_event_run;
- guint hotplug_poll_id;
- guint hotplug_poll_interval;
- int debug_level;
- GUsbContextFlags flags;
- libusb_context *ctx;
- libusb_hotplug_callback_handle hotplug_id;
- GPtrArray *idle_events;
- GMutex idle_events_mutex;
- guint idle_events_id;
+struct _GUsbContextPrivate {
+ GMainContext *main_ctx;
+ GPtrArray *devices;
+ GHashTable *dict_usb_ids;
+ GHashTable *dict_replug;
+ GThread *thread_event;
+ gboolean done_enumerate;
+ volatile gint thread_event_run;
+ guint hotplug_poll_id;
+ guint hotplug_poll_interval;
+ int debug_level;
+ GUsbContextFlags flags;
+ libusb_context *ctx;
+ libusb_hotplug_callback_handle hotplug_id;
+ GPtrArray *idle_events;
+ GMutex idle_events_mutex;
+ guint idle_events_id;
};
/* not defined in FreeBSD */
@@ -68,25 +58,30 @@ struct _GUsbContextPrivate
#endif
typedef struct {
- GMainLoop *loop;
- GUsbDevice *device;
- guint timeout_id;
+ GMainLoop *loop;
+ GUsbDevice *device;
+ guint timeout_id;
} GUsbContextReplugHelper;
-static guint signals[LAST_SIGNAL] = { 0 };
-static GParamSpec *pspecs[N_PROPERTIES] = { NULL, };
+static guint signals[LAST_SIGNAL] = {0};
+static GParamSpec *pspecs[N_PROPERTIES] = {
+ NULL,
+};
-static void g_usb_context_initable_iface_init (GInitableIface *iface);
+static void
+g_usb_context_initable_iface_init(GInitableIface *iface);
-G_DEFINE_TYPE_WITH_CODE (GUsbContext, g_usb_context, G_TYPE_OBJECT,
- G_ADD_PRIVATE (GUsbContext)
- G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE,
- g_usb_context_initable_iface_init))
+G_DEFINE_TYPE_WITH_CODE(GUsbContext,
+ g_usb_context,
+ G_TYPE_OBJECT,
+ G_ADD_PRIVATE(GUsbContext)
+ G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE,
+ g_usb_context_initable_iface_init))
/* not defined in FreeBSD */
#ifndef HAVE_LIBUSB_HAS_CAPABILITY
static gboolean
-libusb_has_capability (int cap)
+libusb_has_capability(int cap)
{
if (cap == LIBUSB_CAP_HAS_HOTPLUG)
return TRUE;
@@ -95,15 +90,16 @@ libusb_has_capability (int cap)
#endif
static void
-g_usb_context_replug_helper_free (GUsbContextReplugHelper *replug_helper)
+g_usb_context_replug_helper_free(GUsbContextReplugHelper *replug_helper)
{
if (replug_helper->timeout_id != 0)
- g_source_remove (replug_helper->timeout_id);
- g_main_loop_unref (replug_helper->loop);
- g_object_unref (replug_helper->device);
- g_free (replug_helper);
+ g_source_remove(replug_helper->timeout_id);
+ g_main_loop_unref(replug_helper->loop);
+ g_object_unref(replug_helper->device);
+ g_free(replug_helper);
}
+/* clang-format off */
/**
* g_usb_context_error_quark:
*
@@ -112,89 +108,84 @@ g_usb_context_replug_helper_free (GUsbContextReplugHelper *replug_helper)
* Since: 0.1.0
**/
G_DEFINE_QUARK (g-usb-context-error-quark, g_usb_context_error)
+/* clang-format on */
static void
-g_usb_context_dispose (GObject *object)
+g_usb_context_dispose(GObject *object)
{
- GUsbContext *context = G_USB_CONTEXT (object);
+ GUsbContext *context = G_USB_CONTEXT(object);
GUsbContextPrivate *priv = context->priv;
/* this is safe to call even when priv->hotplug_id is unset */
- if (g_atomic_int_dec_and_test (&priv->thread_event_run)) {
- libusb_hotplug_deregister_callback (priv->ctx, priv->hotplug_id);
- g_thread_join (priv->thread_event);
+ if (g_atomic_int_dec_and_test(&priv->thread_event_run)) {
+ libusb_hotplug_deregister_callback(priv->ctx, priv->hotplug_id);
+ g_thread_join(priv->thread_event);
}
if (priv->hotplug_poll_id > 0) {
- g_source_remove (priv->hotplug_poll_id);
+ g_source_remove(priv->hotplug_poll_id);
priv->hotplug_poll_id = 0;
}
if (priv->idle_events_id > 0) {
- g_source_remove (priv->idle_events_id);
+ g_source_remove(priv->idle_events_id);
priv->idle_events_id = 0;
}
- g_clear_pointer (&priv->main_ctx, g_main_context_unref);
- g_clear_pointer (&priv->devices, g_ptr_array_unref);
- g_clear_pointer (&priv->dict_usb_ids, g_hash_table_unref);
- g_clear_pointer (&priv->dict_replug, g_hash_table_unref);
- g_clear_pointer (&priv->ctx, libusb_exit);
- g_clear_pointer (&priv->idle_events, g_ptr_array_unref);
+ g_clear_pointer(&priv->main_ctx, g_main_context_unref);
+ g_clear_pointer(&priv->devices, g_ptr_array_unref);
+ g_clear_pointer(&priv->dict_usb_ids, g_hash_table_unref);
+ g_clear_pointer(&priv->dict_replug, g_hash_table_unref);
+ g_clear_pointer(&priv->ctx, libusb_exit);
+ g_clear_pointer(&priv->idle_events, g_ptr_array_unref);
g_mutex_clear(&priv->idle_events_mutex);
- G_OBJECT_CLASS (g_usb_context_parent_class)->dispose (object);
+ G_OBJECT_CLASS(g_usb_context_parent_class)->dispose(object);
}
static void
-g_usb_context_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+g_usb_context_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
- GUsbContext *context = G_USB_CONTEXT (object);
+ GUsbContext *context = G_USB_CONTEXT(object);
GUsbContextPrivate *priv = context->priv;
switch (prop_id) {
case PROP_LIBUSB_CONTEXT:
- g_value_set_pointer (value, priv->ctx);
+ g_value_set_pointer(value, priv->ctx);
break;
case PROP_DEBUG_LEVEL:
- g_value_set_int (value, priv->debug_level);
+ g_value_set_int(value, priv->debug_level);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
-g_usb_context_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+g_usb_context_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
- GUsbContext *context = G_USB_CONTEXT (object);
+ GUsbContext *context = G_USB_CONTEXT(object);
GUsbContextPrivate *priv = context->priv;
switch (prop_id) {
case PROP_DEBUG_LEVEL:
- priv->debug_level = g_value_get_int (value);
+ priv->debug_level = g_value_get_int(value);
#ifdef HAVE_LIBUSB_SET_OPTION
- libusb_set_option (priv->ctx, LIBUSB_OPTION_LOG_LEVEL, priv->debug_level);
+ libusb_set_option(priv->ctx, LIBUSB_OPTION_LOG_LEVEL, priv->debug_level);
#else
- libusb_set_debug (priv->ctx, priv->debug_level);
+ libusb_set_debug(priv->ctx, priv->debug_level);
#endif
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
-g_usb_context_class_init (GUsbContextClass *klass)
+g_usb_context_class_init(GUsbContextClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->dispose = g_usb_context_dispose;
object_class->get_property = g_usb_context_get_property;
@@ -204,18 +195,15 @@ g_usb_context_class_init (GUsbContextClass *klass)
* GUsbContext:libusb_context:
*/
pspecs[PROP_LIBUSB_CONTEXT] =
- g_param_spec_pointer ("libusb_context", NULL, NULL,
- G_PARAM_READABLE);
+ g_param_spec_pointer("libusb_context", NULL, NULL, G_PARAM_READABLE);
/**
* GUsbContext:debug_level:
*/
pspecs[PROP_DEBUG_LEVEL] =
- g_param_spec_int ("debug_level", NULL, NULL,
- 0, 3, 0,
- G_PARAM_READWRITE);
+ g_param_spec_int("debug_level", NULL, NULL, 0, 3, 0, G_PARAM_READWRITE);
- g_object_class_install_properties (object_class, N_PROPERTIES, pspecs);
+ g_object_class_install_properties(object_class, N_PROPERTIES, pspecs);
/**
* GUsbContext::device-added:
@@ -224,16 +212,16 @@ g_usb_context_class_init (GUsbContextClass *klass)
*
* This signal is emitted when a USB device is added.
**/
- signals[DEVICE_ADDED_SIGNAL] = g_signal_new ("device-added",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GUsbContextClass, device_added),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1,
- G_USB_TYPE_DEVICE);
+ signals[DEVICE_ADDED_SIGNAL] = g_signal_new("device-added",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(GUsbContextClass, device_added),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ G_USB_TYPE_DEVICE);
/**
* GUsbContext::device-removed:
@@ -242,43 +230,41 @@ g_usb_context_class_init (GUsbContextClass *klass)
*
* This signal is emitted when a USB device is removed.
**/
- signals[DEVICE_REMOVED_SIGNAL] = g_signal_new ("device-removed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GUsbContextClass, device_removed),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1,
- G_USB_TYPE_DEVICE);
+ signals[DEVICE_REMOVED_SIGNAL] =
+ g_signal_new("device-removed",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(GUsbContextClass, device_removed),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ G_USB_TYPE_DEVICE);
}
static void
-g_usb_context_emit_device_add (GUsbContext *context,
- GUsbDevice *device)
+g_usb_context_emit_device_add(GUsbContext *context, GUsbDevice *device)
{
/* emitted directly by g_usb_context_enumerate */
if (!context->priv->done_enumerate)
return;
- g_signal_emit (context, signals[DEVICE_ADDED_SIGNAL], 0, device);
+ g_signal_emit(context, signals[DEVICE_ADDED_SIGNAL], 0, device);
}
static void
-g_usb_context_emit_device_remove (GUsbContext *context,
- GUsbDevice *device)
+g_usb_context_emit_device_remove(GUsbContext *context, GUsbDevice *device)
{
/* should not happen, if it does we would not fire any signal */
if (!context->priv->done_enumerate)
return;
- g_signal_emit (context, signals[DEVICE_REMOVED_SIGNAL], 0, device);
+ g_signal_emit(context, signals[DEVICE_REMOVED_SIGNAL], 0, device);
}
static void
-g_usb_context_add_device (GUsbContext *context,
- struct libusb_device *dev)
+g_usb_context_add_device(GUsbContext *context, struct libusb_device *dev)
{
GUsbContextPrivate *priv = context->priv;
GUsbContextReplugHelper *replug_helper;
@@ -289,51 +275,49 @@ g_usb_context_add_device (GUsbContext *context,
g_autoptr(GUsbDevice) device = NULL;
/* does any existing device exist */
- bus = libusb_get_bus_number (dev);
- address = libusb_get_device_address (dev);
+ bus = libusb_get_bus_number(dev);
+ address = libusb_get_device_address(dev);
if (priv->done_enumerate)
- device = g_usb_context_find_by_bus_address (context, bus, address, NULL);
+ device = g_usb_context_find_by_bus_address(context, bus, address, NULL);
if (device != NULL)
return;
/* add the device */
- device = _g_usb_device_new (context, dev, &error);
+ device = _g_usb_device_new(context, dev, &error);
if (device == NULL) {
- g_debug ("There was a problem creating the device: %s",
- error->message);
+ g_debug("There was a problem creating the device: %s", error->message);
return;
}
/* auto-open */
if (priv->flags & G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES) {
- if (!_g_usb_device_open_internal (device, &error)) {
- g_warning ("cannot open the device: %s", error->message);
+ if (!_g_usb_device_open_internal(device, &error)) {
+ g_warning("cannot open the device: %s", error->message);
return;
}
}
/* add to enumerated list */
- g_ptr_array_add (priv->devices, g_object_ref (device));
+ g_ptr_array_add(priv->devices, g_object_ref(device));
/* if we're waiting for replug, suppress the signal */
- platform_id = g_usb_device_get_platform_id (device);
- replug_helper = g_hash_table_lookup (priv->dict_replug, platform_id);
+ platform_id = g_usb_device_get_platform_id(device);
+ replug_helper = g_hash_table_lookup(priv->dict_replug, platform_id);
if (replug_helper != NULL) {
- g_debug ("%s is in replug, ignoring add", platform_id);
- g_object_unref (replug_helper->device);
- replug_helper->device = g_object_ref (device);
- g_main_loop_quit (replug_helper->loop);
+ g_debug("%s is in replug, ignoring add", platform_id);
+ g_object_unref(replug_helper->device);
+ replug_helper->device = g_object_ref(device);
+ g_main_loop_quit(replug_helper->loop);
return;
}
/* emit signal */
- g_usb_context_emit_device_add (context, device);
+ g_usb_context_emit_device_add(context, device);
}
static void
-g_usb_context_remove_device (GUsbContext *context,
- struct libusb_device *dev)
+g_usb_context_remove_device(GUsbContext *context, struct libusb_device *dev)
{
GUsbContextPrivate *priv = context->priv;
GUsbContextReplugHelper *replug_helper;
@@ -343,58 +327,58 @@ g_usb_context_remove_device (GUsbContext *context,
g_autoptr(GUsbDevice) device = NULL;
/* does any existing device exist */
- bus = libusb_get_bus_number (dev);
- address = libusb_get_device_address (dev);
- device = g_usb_context_find_by_bus_address (context, bus, address, NULL);
+ bus = libusb_get_bus_number(dev);
+ address = libusb_get_device_address(dev);
+ device = g_usb_context_find_by_bus_address(context, bus, address, NULL);
if (device == NULL) {
- g_debug ("%i:%i does not exist", bus, address);
+ g_debug("%i:%i does not exist", bus, address);
return;
}
/* remove from enumerated list */
- g_ptr_array_remove (priv->devices, device);
+ g_ptr_array_remove(priv->devices, device);
/* if we're waiting for replug, suppress the signal */
- platform_id = g_usb_device_get_platform_id (device);
- replug_helper = g_hash_table_lookup (priv->dict_replug, platform_id);
+ platform_id = g_usb_device_get_platform_id(device);
+ replug_helper = g_hash_table_lookup(priv->dict_replug, platform_id);
if (replug_helper != NULL) {
- g_debug ("%s is in replug, ignoring remove", platform_id);
+ g_debug("%s is in replug, ignoring remove", platform_id);
return;
}
/* emit signal */
- g_usb_context_emit_device_remove (context, device);
+ g_usb_context_emit_device_remove(context, device);
}
typedef struct {
- GUsbContext *context;
- libusb_device *dev;
- libusb_hotplug_event event;
+ GUsbContext *context;
+ libusb_device *dev;
+ libusb_hotplug_event event;
} GUsbContextIdleHelper;
static void
-g_usb_context_idle_helper_free (GUsbContextIdleHelper *helper)
+g_usb_context_idle_helper_free(GUsbContextIdleHelper *helper)
{
- g_object_unref (helper->context);
- libusb_unref_device (helper->dev);
- g_free (helper);
+ g_object_unref(helper->context);
+ libusb_unref_device(helper->dev);
+ g_free(helper);
}
static gboolean
-g_usb_context_idle_hotplug_cb (gpointer user_data)
+g_usb_context_idle_hotplug_cb(gpointer user_data)
{
- GUsbContext *context = G_USB_CONTEXT (user_data);
+ GUsbContext *context = G_USB_CONTEXT(user_data);
GUsbContextPrivate *priv = context->priv;
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->idle_events_mutex);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->idle_events_mutex);
for (guint i = 0; i < priv->idle_events->len; i++) {
GUsbContextIdleHelper *helper = g_ptr_array_index(priv->idle_events, i);
switch (helper->event) {
case LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED:
- g_usb_context_add_device (helper->context, helper->dev);
+ g_usb_context_add_device(helper->context, helper->dev);
break;
case LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT:
- g_usb_context_remove_device (helper->context, helper->dev);
+ g_usb_context_remove_device(helper->context, helper->dev);
break;
default:
break;
@@ -402,37 +386,37 @@ g_usb_context_idle_hotplug_cb (gpointer user_data)
}
/* all done */
- g_ptr_array_set_size (priv->idle_events, 0);
+ g_ptr_array_set_size(priv->idle_events, 0);
priv->idle_events_id = 0;
return FALSE;
}
/* this is run in the libusb thread */
static int
-g_usb_context_hotplug_cb (struct libusb_context *ctx,
- struct libusb_device *dev,
- libusb_hotplug_event event,
- void *user_data)
+g_usb_context_hotplug_cb(struct libusb_context *ctx,
+ struct libusb_device *dev,
+ libusb_hotplug_event event,
+ void *user_data)
{
- GUsbContext *context = G_USB_CONTEXT (user_data);
+ GUsbContext *context = G_USB_CONTEXT(user_data);
GUsbContextIdleHelper *helper;
GUsbContextPrivate *priv = context->priv;
- g_autoptr(GMutexLocker) locker = g_mutex_locker_new (&priv->idle_events_mutex);
+ g_autoptr(GMutexLocker) locker = g_mutex_locker_new(&priv->idle_events_mutex);
- helper = g_new0 (GUsbContextIdleHelper, 1);
- helper->context = g_object_ref (context);
- helper->dev = libusb_ref_device (dev);
+ helper = g_new0(GUsbContextIdleHelper, 1);
+ helper->context = g_object_ref(context);
+ helper->dev = libusb_ref_device(dev);
helper->event = event;
g_ptr_array_add(priv->idle_events, helper);
if (priv->idle_events_id == 0)
- priv->idle_events_id = g_idle_add (g_usb_context_idle_hotplug_cb, context);
+ priv->idle_events_id = g_idle_add(g_usb_context_idle_hotplug_cb, context);
return 0;
}
static void
-g_usb_context_rescan (GUsbContext *context)
+g_usb_context_rescan(GUsbContext *context)
{
GUsbContextPrivate *priv = context->priv;
libusb_device **dev_list = NULL;
@@ -440,40 +424,41 @@ g_usb_context_rescan (GUsbContext *context)
/* copy to a context so we can remove from the array */
for (guint i = 0; i < priv->devices->len; i++) {
- GUsbDevice *device = g_ptr_array_index (priv->devices, i);
- existing_devices = g_list_prepend (existing_devices, device);
+ GUsbDevice *device = g_ptr_array_index(priv->devices, i);
+ existing_devices = g_list_prepend(existing_devices, device);
}
/* look for any removed devices */
- libusb_get_device_list (priv->ctx, &dev_list);
+ libusb_get_device_list(priv->ctx, &dev_list);
for (GList *l = existing_devices; l != NULL; l = l->next) {
- GUsbDevice *device = G_USB_DEVICE (l->data);
+ GUsbDevice *device = G_USB_DEVICE(l->data);
gboolean found = FALSE;
for (guint i = 0; dev_list != NULL && dev_list[i] != NULL; i++) {
- if (libusb_get_bus_number (dev_list[i]) == g_usb_device_get_bus (device) &&
- libusb_get_device_address (dev_list[i]) == g_usb_device_get_address (device)) {
+ if (libusb_get_bus_number(dev_list[i]) == g_usb_device_get_bus(device) &&
+ libusb_get_device_address(dev_list[i]) ==
+ g_usb_device_get_address(device)) {
found = TRUE;
break;
}
}
if (!found) {
- g_usb_context_emit_device_remove (context, device);
- g_ptr_array_remove (priv->devices, device);
+ g_usb_context_emit_device_remove(context, device);
+ g_ptr_array_remove(priv->devices, device);
}
}
/* add any devices not yet added (duplicates will be filtered */
for (guint i = 0; dev_list != NULL && dev_list[i] != NULL; i++)
- g_usb_context_add_device (context, dev_list[i]);
+ g_usb_context_add_device(context, dev_list[i]);
- libusb_free_device_list (dev_list, 1);
+ libusb_free_device_list(dev_list, 1);
}
static gboolean
-g_usb_context_rescan_cb (gpointer user_data)
+g_usb_context_rescan_cb(gpointer user_data)
{
- GUsbContext *context = G_USB_CONTEXT (user_data);
- g_usb_context_rescan (context);
+ GUsbContext *context = G_USB_CONTEXT(user_data);
+ g_usb_context_rescan(context);
return TRUE;
}
@@ -489,14 +474,13 @@ g_usb_context_rescan_cb (gpointer user_data)
* Since: 0.2.5
**/
GMainContext *
-g_usb_context_get_main_context (GUsbContext *context)
+g_usb_context_get_main_context(GUsbContext *context)
{
GUsbContextPrivate *priv = context->priv;
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), NULL);
return priv->main_ctx;
}
-
/**
* g_usb_context_set_main_context:
* @context: a #GUsbContext
@@ -506,32 +490,30 @@ g_usb_context_get_main_context (GUsbContext *context)
* Since: 0.2.5
**/
void
-g_usb_context_set_main_context (GUsbContext *context,
- GMainContext *main_ctx)
+g_usb_context_set_main_context(GUsbContext *context, GMainContext *main_ctx)
{
GUsbContextPrivate *priv = context->priv;
- g_return_if_fail (G_USB_IS_CONTEXT (context));
+ g_return_if_fail(G_USB_IS_CONTEXT(context));
- if (main_ctx != priv->main_ctx){
- g_main_context_unref (priv->main_ctx);
- priv->main_ctx = g_main_context_ref (main_ctx);
+ if (main_ctx != priv->main_ctx) {
+ g_main_context_unref(priv->main_ctx);
+ priv->main_ctx = g_main_context_ref(main_ctx);
}
}
static void
-g_usb_context_ensure_rescan_timeout (GUsbContext *context)
+g_usb_context_ensure_rescan_timeout(GUsbContext *context)
{
GUsbContextPrivate *priv = context->priv;
if (priv->hotplug_poll_id > 0) {
- g_source_remove (priv->hotplug_poll_id);
+ g_source_remove(priv->hotplug_poll_id);
priv->hotplug_poll_id = 0;
}
if (priv->hotplug_poll_interval > 0) {
- priv->hotplug_poll_id = g_timeout_add (priv->hotplug_poll_interval,
- g_usb_context_rescan_cb,
- context);
+ priv->hotplug_poll_id =
+ g_timeout_add(priv->hotplug_poll_interval, g_usb_context_rescan_cb, context);
}
}
@@ -546,10 +528,10 @@ g_usb_context_ensure_rescan_timeout (GUsbContext *context)
* Since: 0.3.10
**/
guint
-g_usb_context_get_hotplug_poll_interval (GUsbContext *context)
+g_usb_context_get_hotplug_poll_interval(GUsbContext *context)
{
GUsbContextPrivate *priv = context->priv;
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), G_MAXUINT);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), G_MAXUINT);
return priv->hotplug_poll_id;
}
@@ -565,12 +547,11 @@ g_usb_context_get_hotplug_poll_interval (GUsbContext *context)
* Since: 0.3.10
**/
void
-g_usb_context_set_hotplug_poll_interval (GUsbContext *context,
- guint hotplug_poll_interval)
+g_usb_context_set_hotplug_poll_interval(GUsbContext *context, guint hotplug_poll_interval)
{
GUsbContextPrivate *priv = context->priv;
- g_return_if_fail (G_USB_IS_CONTEXT (context));
+ g_return_if_fail(G_USB_IS_CONTEXT(context));
/* same */
if (priv->hotplug_poll_interval == hotplug_poll_interval)
@@ -580,7 +561,7 @@ g_usb_context_set_hotplug_poll_interval (GUsbContext *context,
/* if already running then change the existing timeout */
if (priv->hotplug_poll_id > 0)
- g_usb_context_ensure_rescan_timeout (context);
+ g_usb_context_ensure_rescan_timeout(context);
}
/**
@@ -595,7 +576,7 @@ g_usb_context_set_hotplug_poll_interval (GUsbContext *context,
* Since: 0.2.2
**/
void
-g_usb_context_enumerate (GUsbContext *context)
+g_usb_context_enumerate(GUsbContext *context)
{
GUsbContextPrivate *priv = context->priv;
@@ -603,17 +584,19 @@ g_usb_context_enumerate (GUsbContext *context)
if (priv->done_enumerate)
return;
- g_usb_context_rescan (context);
- if (!libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
- g_debug ("platform does not do hotplug, using polling");
- g_usb_context_ensure_rescan_timeout (context);
+ g_usb_context_rescan(context);
+ if (!libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
+ g_debug("platform does not do hotplug, using polling");
+ g_usb_context_ensure_rescan_timeout(context);
}
priv->done_enumerate = TRUE;
/* emit device-added signals before returning */
for (guint i = 0; i < priv->devices->len; i++) {
- g_signal_emit (context, signals[DEVICE_ADDED_SIGNAL], 0,
- g_ptr_array_index (priv->devices, i));
+ g_signal_emit(context,
+ signals[DEVICE_ADDED_SIGNAL],
+ 0,
+ g_ptr_array_index(priv->devices, i));
}
/* any queued up hotplug events are queued as idle handlers */
@@ -630,7 +613,7 @@ g_usb_context_enumerate (GUsbContext *context)
* Since: 0.2.11
**/
void
-g_usb_context_set_flags (GUsbContext *context, GUsbContextFlags flags)
+g_usb_context_set_flags(GUsbContext *context, GUsbContextFlags flags)
{
context->priv->flags = flags;
}
@@ -646,89 +629,86 @@ g_usb_context_set_flags (GUsbContext *context, GUsbContextFlags flags)
* Since: 0.2.11
**/
GUsbContextFlags
-g_usb_context_get_flags (GUsbContext *context)
+g_usb_context_get_flags(GUsbContext *context)
{
return context->priv->flags;
}
static gpointer
-g_usb_context_event_thread_cb (gpointer data)
+g_usb_context_event_thread_cb(gpointer data)
{
- GUsbContext *context = G_USB_CONTEXT (data);
+ GUsbContext *context = G_USB_CONTEXT(data);
GUsbContextPrivate *priv = context->priv;
struct timeval tv = {
- .tv_usec = 0,
- .tv_sec = 2,
+ .tv_usec = 0,
+ .tv_sec = 2,
};
- while (g_atomic_int_get (&priv->thread_event_run) > 0)
- libusb_handle_events_timeout_completed (priv->ctx, &tv, NULL);
+ while (g_atomic_int_get(&priv->thread_event_run) > 0)
+ libusb_handle_events_timeout_completed(priv->ctx, &tv, NULL);
return NULL;
}
static void
-g_usb_context_init (GUsbContext *context)
+g_usb_context_init(GUsbContext *context)
{
GUsbContextPrivate *priv;
- priv = context->priv = g_usb_context_get_instance_private (context);
+ priv = context->priv = g_usb_context_get_instance_private(context);
priv->flags = G_USB_CONTEXT_FLAGS_NONE;
priv->hotplug_poll_interval = G_USB_CONTEXT_HOTPLUG_POLL_INTERVAL_DEFAULT;
- priv->devices = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
- priv->dict_usb_ids = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free);
- priv->dict_replug = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, NULL);
+ priv->devices = g_ptr_array_new_with_free_func((GDestroyNotify)g_object_unref);
+ priv->dict_usb_ids = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+ priv->dict_replug = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
/* to escape the thread into the mainloop */
g_mutex_init(&priv->idle_events_mutex);
- priv->idle_events = g_ptr_array_new_with_free_func ((GDestroyNotify) g_usb_context_idle_helper_free);
+ priv->idle_events =
+ g_ptr_array_new_with_free_func((GDestroyNotify)g_usb_context_idle_helper_free);
}
static gboolean
-g_usb_context_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
+g_usb_context_initable_init(GInitable *initable, GCancellable *cancellable, GError **error)
{
- GUsbContext *context = G_USB_CONTEXT (initable);
+ GUsbContext *context = G_USB_CONTEXT(initable);
GUsbContextPrivate *priv;
gint rc;
libusb_context *ctx;
priv = context->priv;
- rc = libusb_init (&ctx);
+ rc = libusb_init(&ctx);
if (rc < 0) {
- g_set_error (error,
- G_USB_CONTEXT_ERROR,
- G_USB_CONTEXT_ERROR_INTERNAL,
- "failed to init libusb: %s [%i]",
- g_usb_strerror (rc), rc);
+ g_set_error(error,
+ G_USB_CONTEXT_ERROR,
+ G_USB_CONTEXT_ERROR_INTERNAL,
+ "failed to init libusb: %s [%i]",
+ g_usb_strerror(rc),
+ rc);
return FALSE;
}
- priv->main_ctx = g_main_context_ref (g_main_context_default ());
+ priv->main_ctx = g_main_context_ref(g_main_context_default());
priv->ctx = ctx;
priv->thread_event_run = 1;
- priv->thread_event = g_thread_new ("GUsbEventThread",
- g_usb_context_event_thread_cb,
- context);
+ priv->thread_event =
+ g_thread_new("GUsbEventThread", g_usb_context_event_thread_cb, context);
/* watch for add/remove */
- if (libusb_has_capability (LIBUSB_CAP_HAS_HOTPLUG)) {
- rc = libusb_hotplug_register_callback (priv->ctx,
- LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
- LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
- 0,
- LIBUSB_HOTPLUG_MATCH_ANY,
- LIBUSB_HOTPLUG_MATCH_ANY,
- LIBUSB_HOTPLUG_MATCH_ANY,
- g_usb_context_hotplug_cb,
- context,
- &context->priv->hotplug_id);
+ if (libusb_has_capability(LIBUSB_CAP_HAS_HOTPLUG)) {
+ rc = libusb_hotplug_register_callback(priv->ctx,
+ LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED |
+ LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
+ 0,
+ LIBUSB_HOTPLUG_MATCH_ANY,
+ LIBUSB_HOTPLUG_MATCH_ANY,
+ LIBUSB_HOTPLUG_MATCH_ANY,
+ g_usb_context_hotplug_cb,
+ context,
+ &context->priv->hotplug_id);
if (rc != LIBUSB_SUCCESS) {
- g_warning ("Error creating a hotplug callback: %s",
- g_usb_strerror (rc));
+ g_warning("Error creating a hotplug callback: %s", g_usb_strerror(rc));
}
}
@@ -736,7 +716,7 @@ g_usb_context_initable_init (GInitable *initable,
}
static void
-g_usb_context_initable_iface_init (GInitableIface *iface)
+g_usb_context_initable_iface_init(GInitableIface *iface)
{
iface->init = g_usb_context_initable_init;
}
@@ -752,7 +732,7 @@ g_usb_context_initable_iface_init (GInitableIface *iface)
* Since: 0.1.0
**/
libusb_context *
-_g_usb_context_get_context (GUsbContext *context)
+_g_usb_context_get_context(GUsbContext *context)
{
return context->priv->ctx;
}
@@ -769,8 +749,7 @@ _g_usb_context_get_context (GUsbContext *context)
* Since: 0.1.0
**/
GUsbSource *
-g_usb_context_get_source (GUsbContext *context,
- GMainContext *main_ctx)
+g_usb_context_get_source(GUsbContext *context, GMainContext *main_ctx)
{
return NULL;
}
@@ -788,13 +767,12 @@ g_usb_context_get_source (GUsbContext *context,
* Since: 0.1.0
**/
void
-g_usb_context_set_debug (GUsbContext *context,
- GLogLevelFlags flags)
+g_usb_context_set_debug(GUsbContext *context, GLogLevelFlags flags)
{
GUsbContextPrivate *priv;
int debug_level;
- g_return_if_fail (G_USB_IS_CONTEXT (context));
+ g_return_if_fail(G_USB_IS_CONTEXT(context));
priv = context->priv;
@@ -810,12 +788,12 @@ g_usb_context_set_debug (GUsbContext *context,
if (debug_level != priv->debug_level) {
priv->debug_level = debug_level;
#ifdef HAVE_LIBUSB_SET_OPTION
- libusb_set_option (priv->ctx, LIBUSB_OPTION_LOG_LEVEL, debug_level);
+ libusb_set_option(priv->ctx, LIBUSB_OPTION_LOG_LEVEL, debug_level);
#else
- libusb_set_debug (priv->ctx, debug_level);
+ libusb_set_debug(priv->ctx, debug_level);
#endif
- g_object_notify_by_pspec (G_OBJECT (context), pspecs[PROP_DEBUG_LEVEL]);
+ g_object_notify_by_pspec(G_OBJECT(context), pspecs[PROP_DEBUG_LEVEL]);
}
}
@@ -833,31 +811,29 @@ g_usb_context_set_debug (GUsbContext *context,
* Since: 0.2.2
**/
GUsbDevice *
-g_usb_context_find_by_bus_address (GUsbContext *context,
- guint8 bus,
- guint8 address,
- GError **error)
+g_usb_context_find_by_bus_address(GUsbContext *context, guint8 bus, guint8 address, GError **error)
{
GUsbContextPrivate *priv;
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
priv = context->priv;
- g_usb_context_enumerate (context);
+ g_usb_context_enumerate(context);
for (guint i = 0; i < priv->devices->len; i++) {
- GUsbDevice *device = g_ptr_array_index (priv->devices, i);
- if (g_usb_device_get_bus (device) == bus &&
- g_usb_device_get_address (device) == address) {
- return g_object_ref (device);
+ GUsbDevice *device = g_ptr_array_index(priv->devices, i);
+ if (g_usb_device_get_bus(device) == bus &&
+ g_usb_device_get_address(device) == address) {
+ return g_object_ref(device);
}
}
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NO_DEVICE,
- "Failed to find device %04x:%04x",
- bus, address);
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NO_DEVICE,
+ "Failed to find device %04x:%04x",
+ bus,
+ address);
return NULL;
}
@@ -874,28 +850,26 @@ g_usb_context_find_by_bus_address (GUsbContext *context,
* Since: 0.2.4
**/
GUsbDevice *
-g_usb_context_find_by_platform_id (GUsbContext *context,
- const gchar *platform_id,
- GError **error)
+g_usb_context_find_by_platform_id(GUsbContext *context, const gchar *platform_id, GError **error)
{
GUsbContextPrivate *priv;
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
priv = context->priv;
- g_usb_context_enumerate (context);
+ g_usb_context_enumerate(context);
for (guint i = 0; i < priv->devices->len; i++) {
- GUsbDevice *device = g_ptr_array_index (priv->devices, i);
- if (g_strcmp0 (g_usb_device_get_platform_id (device), platform_id) == 0)
- return g_object_ref (device);
+ GUsbDevice *device = g_ptr_array_index(priv->devices, i);
+ if (g_strcmp0(g_usb_device_get_platform_id(device), platform_id) == 0)
+ return g_object_ref(device);
}
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NO_DEVICE,
- "Failed to find device %s",
- platform_id);
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NO_DEVICE,
+ "Failed to find device %s",
+ platform_id);
return NULL;
}
@@ -913,37 +887,33 @@ g_usb_context_find_by_platform_id (GUsbContext *context,
* Since: 0.2.2
**/
GUsbDevice *
-g_usb_context_find_by_vid_pid (GUsbContext *context,
- guint16 vid,
- guint16 pid,
- GError **error)
+g_usb_context_find_by_vid_pid(GUsbContext *context, guint16 vid, guint16 pid, GError **error)
{
GUsbContextPrivate *priv;
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
priv = context->priv;
- g_usb_context_enumerate (context);
+ g_usb_context_enumerate(context);
for (guint i = 0; i < priv->devices->len; i++) {
- GUsbDevice *device = g_ptr_array_index (priv->devices, i);
- if (g_usb_device_get_vid (device) == vid &&
- g_usb_device_get_pid (device) == pid) {
- return g_object_ref (device);
+ GUsbDevice *device = g_ptr_array_index(priv->devices, i);
+ if (g_usb_device_get_vid(device) == vid && g_usb_device_get_pid(device) == pid) {
+ return g_object_ref(device);
}
}
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NO_DEVICE,
- "Failed to find device %04x:%04x",
- vid, pid);
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NO_DEVICE,
+ "Failed to find device %04x:%04x",
+ vid,
+ pid);
return NULL;
}
static gboolean
-g_usb_context_load_usb_ids (GUsbContext *context,
- GError **error)
+g_usb_context_load_usb_ids(GUsbContext *context, GError **error)
{
guint16 pid;
guint16 vid = 0x0000;
@@ -951,14 +921,14 @@ g_usb_context_load_usb_ids (GUsbContext *context,
g_auto(GStrv) lines = NULL;
/* already loaded */
- if (g_hash_table_size (context->priv->dict_usb_ids) > 0)
+ if (g_hash_table_size(context->priv->dict_usb_ids) > 0)
return TRUE;
/* parse */
- if (!g_file_get_contents (USB_IDS, &data, NULL, error))
+ if (!g_file_get_contents(USB_IDS, &data, NULL, error))
return FALSE;
- lines = g_strsplit (data, "\n", -1);
+ lines = g_strsplit(data, "\n", -1);
for (guint i = 0; lines[i] != NULL; i++) {
if (lines[i][0] == '#')
continue;
@@ -969,22 +939,22 @@ g_usb_context_load_usb_ids (GUsbContext *context,
if (lines[i][0] != '\t') {
lines[i][4] = '\0';
- vid = g_ascii_strtoull (lines[i], NULL, 16);
+ vid = g_ascii_strtoull(lines[i], NULL, 16);
if (vid == 0)
break;
- g_hash_table_insert (context->priv->dict_usb_ids,
- g_strdup (lines[i]),
- g_strdup (lines[i] + 6));
+ g_hash_table_insert(context->priv->dict_usb_ids,
+ g_strdup(lines[i]),
+ g_strdup(lines[i] + 6));
} else {
if (vid == 0x0000)
break;
lines[i][5] = '\0';
- pid = g_ascii_strtoull (lines[i] + 1, NULL, 16);
- g_hash_table_insert (context->priv->dict_usb_ids,
- g_strdup_printf ("%04x:%04x", vid, pid),
- g_strdup (lines[i] + 7));
+ pid = g_ascii_strtoull(lines[i] + 1, NULL, 16);
+ g_hash_table_insert(context->priv->dict_usb_ids,
+ g_strdup_printf("%04x:%04x", vid, pid),
+ g_strdup(lines[i] + 7));
}
}
@@ -1004,28 +974,27 @@ g_usb_context_load_usb_ids (GUsbContext *context,
* Since: 0.1.5
**/
const gchar *
-_g_usb_context_lookup_vendor (GUsbContext *context,
- guint16 vid,
- GError **error)
+_g_usb_context_lookup_vendor(GUsbContext *context, guint16 vid, GError **error)
{
const gchar *tmp;
g_autofree gchar *key = NULL;
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
/* load */
- if (!g_usb_context_load_usb_ids (context, error))
+ if (!g_usb_context_load_usb_ids(context, error))
return NULL;
/* find */
- key = g_strdup_printf ("%04x", vid);
- tmp = g_hash_table_lookup (context->priv->dict_usb_ids, key);
+ key = g_strdup_printf("%04x", vid);
+ tmp = g_hash_table_lookup(context->priv->dict_usb_ids, key);
if (tmp == NULL) {
- g_set_error (error,
- G_USB_CONTEXT_ERROR,
- G_USB_CONTEXT_ERROR_INTERNAL,
- "failed to find vid %s", key);
+ g_set_error(error,
+ G_USB_CONTEXT_ERROR,
+ G_USB_CONTEXT_ERROR_INTERNAL,
+ "failed to find vid %s",
+ key);
return NULL;
}
@@ -1046,29 +1015,27 @@ _g_usb_context_lookup_vendor (GUsbContext *context,
* Since: 0.1.5
**/
const gchar *
-_g_usb_context_lookup_product (GUsbContext *context,
- guint16 vid,
- guint16 pid,
- GError **error)
+_g_usb_context_lookup_product(GUsbContext *context, guint16 vid, guint16 pid, GError **error)
{
const gchar *tmp;
g_autofree gchar *key = NULL;
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
/* load */
- if (!g_usb_context_load_usb_ids (context, error))
+ if (!g_usb_context_load_usb_ids(context, error))
return NULL;
/* find */
- key = g_strdup_printf ("%04x:%04x", vid, pid);
- tmp = g_hash_table_lookup (context->priv->dict_usb_ids, key);
+ key = g_strdup_printf("%04x:%04x", vid, pid);
+ tmp = g_hash_table_lookup(context->priv->dict_usb_ids, key);
if (tmp == NULL) {
- g_set_error (error,
- G_USB_CONTEXT_ERROR,
- G_USB_CONTEXT_ERROR_INTERNAL,
- "failed to find vid %s", key);
+ g_set_error(error,
+ G_USB_CONTEXT_ERROR,
+ G_USB_CONTEXT_ERROR_INTERNAL,
+ "failed to find vid %s",
+ key);
return NULL;
}
@@ -1084,21 +1051,21 @@ _g_usb_context_lookup_product (GUsbContext *context,
* Since: 0.2.2
**/
GPtrArray *
-g_usb_context_get_devices (GUsbContext *context)
+g_usb_context_get_devices(GUsbContext *context)
{
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), NULL);
- g_usb_context_enumerate (context);
+ g_usb_context_enumerate(context);
- return g_ptr_array_ref (context->priv->devices);
+ return g_ptr_array_ref(context->priv->devices);
}
static gboolean
-g_usb_context_replug_timeout_cb (gpointer user_data)
+g_usb_context_replug_timeout_cb(gpointer user_data)
{
- GUsbContextReplugHelper *replug_helper = (GUsbContextReplugHelper *) user_data;
+ GUsbContextReplugHelper *replug_helper = (GUsbContextReplugHelper *)user_data;
replug_helper->timeout_id = 0;
- g_main_loop_quit (replug_helper->loop);
+ g_main_loop_quit(replug_helper->loop);
return FALSE;
}
@@ -1122,46 +1089,44 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUsbContextReplugHelper, g_usb_context_replug_help
* Since: 0.2.9
**/
GUsbDevice *
-g_usb_context_wait_for_replug (GUsbContext *context,
- GUsbDevice *device,
- guint timeout_ms,
- GError **error)
+g_usb_context_wait_for_replug(GUsbContext *context,
+ GUsbDevice *device,
+ guint timeout_ms,
+ GError **error)
{
GUsbContextPrivate *priv = context->priv;
const gchar *platform_id;
g_autoptr(GUsbContextReplugHelper) replug_helper = NULL;
- g_return_val_if_fail (G_USB_IS_CONTEXT (context), NULL);
+ g_return_val_if_fail(G_USB_IS_CONTEXT(context), NULL);
/* create a helper */
- replug_helper = g_new0 (GUsbContextReplugHelper, 1);
- replug_helper->device = g_object_ref (device);
- replug_helper->loop = g_main_loop_new (priv->main_ctx, FALSE);
- replug_helper->timeout_id = g_timeout_add (timeout_ms,
- g_usb_context_replug_timeout_cb,
- replug_helper);
+ replug_helper = g_new0(GUsbContextReplugHelper, 1);
+ replug_helper->device = g_object_ref(device);
+ replug_helper->loop = g_main_loop_new(priv->main_ctx, FALSE);
+ replug_helper->timeout_id =
+ g_timeout_add(timeout_ms, g_usb_context_replug_timeout_cb, replug_helper);
/* register */
- platform_id = g_usb_device_get_platform_id (device);
- g_hash_table_insert (priv->dict_replug,
- g_strdup (platform_id), replug_helper);
+ platform_id = g_usb_device_get_platform_id(device);
+ g_hash_table_insert(priv->dict_replug, g_strdup(platform_id), replug_helper);
/* wait for timeout, or replug */
- g_main_loop_run (replug_helper->loop);
+ g_main_loop_run(replug_helper->loop);
/* unregister */
- g_hash_table_remove (priv->dict_replug, platform_id);
+ g_hash_table_remove(priv->dict_replug, platform_id);
/* so we timed out; emit the removal now */
if (replug_helper->timeout_id == 0) {
- g_usb_context_emit_device_remove (context, replug_helper->device);
- g_set_error_literal (error,
- G_USB_CONTEXT_ERROR,
- G_USB_CONTEXT_ERROR_INTERNAL,
- "request timed out");
+ g_usb_context_emit_device_remove(context, replug_helper->device);
+ g_set_error_literal(error,
+ G_USB_CONTEXT_ERROR,
+ G_USB_CONTEXT_ERROR_INTERNAL,
+ "request timed out");
return NULL;
}
- return g_object_ref (replug_helper->device);
+ return g_object_ref(replug_helper->device);
}
/**
@@ -1175,7 +1140,7 @@ g_usb_context_wait_for_replug (GUsbContext *context,
* Since: 0.1.0
**/
GUsbContext *
-g_usb_context_new (GError **error)
+g_usb_context_new(GError **error)
{
- return g_initable_new (G_USB_TYPE_CONTEXT, NULL, error, NULL);
+ return g_initable_new(G_USB_TYPE_CONTEXT, NULL, error, NULL);
}
diff --git a/gusb/gusb-context.h b/gusb/gusb-context.h
index af4a9ab..baf7a1f 100644
--- a/gusb/gusb-context.h
+++ b/gusb/gusb-context.h
@@ -13,28 +13,24 @@
G_BEGIN_DECLS
-#define G_USB_TYPE_CONTEXT (g_usb_context_get_type ())
-#define G_USB_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_USB_TYPE_CONTEXT, GUsbContext))
-#define G_USB_IS_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_USB_TYPE_CONTEXT))
-#define G_USB_CONTEXT_ERROR (g_usb_context_error_quark ())
-
-typedef struct _GUsbContextPrivate GUsbContextPrivate;
-typedef struct _GUsbContext GUsbContext;
-typedef struct _GUsbContextClass GUsbContextClass;
-
-struct _GUsbContext
-{
- GObject parent;
- GUsbContextPrivate *priv;
+#define G_USB_TYPE_CONTEXT (g_usb_context_get_type())
+#define G_USB_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), G_USB_TYPE_CONTEXT, GUsbContext))
+#define G_USB_IS_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), G_USB_TYPE_CONTEXT))
+#define G_USB_CONTEXT_ERROR (g_usb_context_error_quark())
+
+typedef struct _GUsbContextPrivate GUsbContextPrivate;
+typedef struct _GUsbContext GUsbContext;
+typedef struct _GUsbContextClass GUsbContextClass;
+
+struct _GUsbContext {
+ GObject parent;
+ GUsbContextPrivate *priv;
};
-struct _GUsbContextClass
-{
- GObjectClass parent_class;
- void (*device_added) (GUsbContext *context,
- GUsbDevice *device);
- void (*device_removed) (GUsbContext *context,
- GUsbDevice *device);
+struct _GUsbContextClass {
+ GObjectClass parent_class;
+ void (*device_added)(GUsbContext *context, GUsbDevice *device);
+ void (*device_removed)(GUsbContext *context, GUsbDevice *device);
/*< private >*/
/*
* If adding fields to this struct, remove corresponding
@@ -43,9 +39,7 @@ struct _GUsbContextClass
gchar _gusb_reserved[62];
};
-typedef enum {
- G_USB_CONTEXT_ERROR_INTERNAL
-} GUsbContextError;
+typedef enum { G_USB_CONTEXT_ERROR_INTERNAL } GUsbContextError;
/**
* GUsbContextFlags:
@@ -53,53 +47,57 @@ typedef enum {
* The flags to use for the context.
**/
typedef enum {
- G_USB_CONTEXT_FLAGS_NONE = 0,
- G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES = 1 << 0,
+ G_USB_CONTEXT_FLAGS_NONE = 0,
+ G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES = 1 << 0,
/*< private >*/
G_USB_CONTEXT_FLAGS_LAST
} GUsbContextFlags;
-GType g_usb_context_get_type (void);
-GQuark g_usb_context_error_quark (void);
+GType
+g_usb_context_get_type(void);
+GQuark
+g_usb_context_error_quark(void);
-GUsbContext *g_usb_context_new (GError **error);
+GUsbContext *
+g_usb_context_new(GError **error);
-void g_usb_context_set_flags (GUsbContext *context,
- GUsbContextFlags flags);
-GUsbContextFlags g_usb_context_get_flags (GUsbContext *context);
+void
+g_usb_context_set_flags(GUsbContext *context, GUsbContextFlags flags);
+GUsbContextFlags
+g_usb_context_get_flags(GUsbContext *context);
G_DEPRECATED
-GUsbSource *g_usb_context_get_source (GUsbContext *context,
- GMainContext *main_ctx);
-GMainContext *g_usb_context_get_main_context (GUsbContext *context);
-void g_usb_context_set_main_context (GUsbContext *context,
- GMainContext *main_ctx);
-guint g_usb_context_get_hotplug_poll_interval(GUsbContext *context);
-void g_usb_context_set_hotplug_poll_interval(GUsbContext *context,
- guint hotplug_poll_interval);
-
-void g_usb_context_enumerate (GUsbContext *context);
-
-void g_usb_context_set_debug (GUsbContext *context,
- GLogLevelFlags flags);
-GPtrArray *g_usb_context_get_devices (GUsbContext *context);
-
-GUsbDevice *g_usb_context_find_by_bus_address (GUsbContext *context,
- guint8 bus,
- guint8 address,
- GError **error);
-
-GUsbDevice *g_usb_context_find_by_vid_pid (GUsbContext *context,
- guint16 vid,
- guint16 pid,
- GError **error);
-GUsbDevice *g_usb_context_find_by_platform_id (GUsbContext *context,
- const gchar *platform_id,
- GError **error);
-
-GUsbDevice *g_usb_context_wait_for_replug (GUsbContext *context,
- GUsbDevice *device,
- guint timeout_ms,
- GError **error);
+GUsbSource *
+g_usb_context_get_source(GUsbContext *context, GMainContext *main_ctx);
+GMainContext *
+g_usb_context_get_main_context(GUsbContext *context);
+void
+g_usb_context_set_main_context(GUsbContext *context, GMainContext *main_ctx);
+guint
+g_usb_context_get_hotplug_poll_interval(GUsbContext *context);
+void
+g_usb_context_set_hotplug_poll_interval(GUsbContext *context, guint hotplug_poll_interval);
+
+void
+g_usb_context_enumerate(GUsbContext *context);
+
+void
+g_usb_context_set_debug(GUsbContext *context, GLogLevelFlags flags);
+GPtrArray *
+g_usb_context_get_devices(GUsbContext *context);
+
+GUsbDevice *
+g_usb_context_find_by_bus_address(GUsbContext *context, guint8 bus, guint8 address, GError **error);
+
+GUsbDevice *
+g_usb_context_find_by_vid_pid(GUsbContext *context, guint16 vid, guint16 pid, GError **error);
+GUsbDevice *
+g_usb_context_find_by_platform_id(GUsbContext *context, const gchar *platform_id, GError **error);
+
+GUsbDevice *
+g_usb_context_wait_for_replug(GUsbContext *context,
+ GUsbDevice *device,
+ guint timeout_ms,
+ GError **error);
G_END_DECLS
diff --git a/gusb/gusb-device-list.c b/gusb/gusb-device-list.c
index c350934..1ca9a20 100644
--- a/gusb/gusb-device-list.c
+++ b/gusb/gusb-device-list.c
@@ -15,109 +15,99 @@
#include "config.h"
-#include <string.h>
-#include <stdlib.h>
#include <libusb.h>
+#include <stdlib.h>
+#include <string.h>
#include "gusb-context-private.h"
#include "gusb-device-list.h"
#include "gusb-device-private.h"
-enum {
- PROP_0,
- PROP_CONTEXT
-};
+enum { PROP_0, PROP_CONTEXT };
-enum
-{
- DEVICE_ADDED_SIGNAL,
- DEVICE_REMOVED_SIGNAL,
- LAST_SIGNAL
-};
+enum { DEVICE_ADDED_SIGNAL, DEVICE_REMOVED_SIGNAL, LAST_SIGNAL };
struct _GUsbDeviceListPrivate {
GUsbContext *context;
};
-static guint signals[LAST_SIGNAL] = { 0 };
+static guint signals[LAST_SIGNAL] = {0};
-G_DEFINE_TYPE_WITH_PRIVATE (GUsbDeviceList, g_usb_device_list, G_TYPE_OBJECT);
+G_DEFINE_TYPE_WITH_PRIVATE(GUsbDeviceList, g_usb_device_list, G_TYPE_OBJECT);
static void
-g_usb_device_list_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+g_usb_device_list_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
- GUsbDeviceList *list = G_USB_DEVICE_LIST (object);
+ GUsbDeviceList *list = G_USB_DEVICE_LIST(object);
GUsbDeviceListPrivate *priv = list->priv;
switch (prop_id) {
case PROP_CONTEXT:
- g_value_set_object (value, priv->context);
+ g_value_set_object(value, priv->context);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
-g_usb_device_added_cb (GUsbContext *context,
- GUsbDevice *device,
- GUsbDeviceList *list)
+g_usb_device_added_cb(GUsbContext *context, GUsbDevice *device, GUsbDeviceList *list)
{
- g_signal_emit (list, signals[DEVICE_ADDED_SIGNAL], 0, device);
+ g_signal_emit(list, signals[DEVICE_ADDED_SIGNAL], 0, device);
}
static void
-g_usb_device_removed_cb (GUsbContext *context,
- GUsbDevice *device,
- GUsbDeviceList *list)
+g_usb_device_removed_cb(GUsbContext *context, GUsbDevice *device, GUsbDeviceList *list)
{
- g_signal_emit (list, signals[DEVICE_REMOVED_SIGNAL], 0, device);
+ g_signal_emit(list, signals[DEVICE_REMOVED_SIGNAL], 0, device);
}
static void
-g_usb_device_list_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+g_usb_device_list_set_property(GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GUsbDeviceList *list = G_USB_DEVICE_LIST (object);
+ GUsbDeviceList *list = G_USB_DEVICE_LIST(object);
GUsbDeviceListPrivate *priv = list->priv;
switch (prop_id) {
case PROP_CONTEXT:
- priv->context = g_value_get_object (value);
- g_signal_connect (priv->context, "device-added",
- G_CALLBACK (g_usb_device_added_cb), list);
- g_signal_connect (priv->context, "device-removed",
- G_CALLBACK (g_usb_device_removed_cb), list);
+ priv->context = g_value_get_object(value);
+ g_signal_connect(priv->context,
+ "device-added",
+ G_CALLBACK(g_usb_device_added_cb),
+ list);
+ g_signal_connect(priv->context,
+ "device-removed",
+ G_CALLBACK(g_usb_device_removed_cb),
+ list);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
-g_usb_device_list_class_init (GUsbDeviceListClass *klass)
+g_usb_device_list_class_init(GUsbDeviceListClass *klass)
{
GParamSpec *pspec;
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
- object_class->get_property = g_usb_device_list_get_property;
- object_class->set_property = g_usb_device_list_set_property;
+ object_class->get_property = g_usb_device_list_get_property;
+ object_class->set_property = g_usb_device_list_set_property;
/**
* GUsbDeviceList:context:
*/
- pspec = g_param_spec_object ("context", NULL, NULL,
- G_USB_TYPE_CONTEXT,
- G_PARAM_CONSTRUCT_ONLY|
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_CONTEXT, pspec);
+ pspec = g_param_spec_object("context",
+ NULL,
+ NULL,
+ G_USB_TYPE_CONTEXT,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
+ g_object_class_install_property(object_class, PROP_CONTEXT, pspec);
/**
* GUsbDeviceList::device-added:
@@ -126,16 +116,17 @@ g_usb_device_list_class_init (GUsbDeviceListClass *klass)
*
* This signal is emitted when a USB device is added.
**/
- signals[DEVICE_ADDED_SIGNAL] = g_signal_new ("device-added",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GUsbDeviceListClass, device_added),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1,
- G_USB_TYPE_DEVICE);
+ signals[DEVICE_ADDED_SIGNAL] =
+ g_signal_new("device-added",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(GUsbDeviceListClass, device_added),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ G_USB_TYPE_DEVICE);
/**
* GUsbDeviceList::device-removed:
@@ -144,22 +135,23 @@ g_usb_device_list_class_init (GUsbDeviceListClass *klass)
*
* This signal is emitted when a USB device is removed.
**/
- signals[DEVICE_REMOVED_SIGNAL] = g_signal_new ("device-removed",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GUsbDeviceListClass, device_removed),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1,
- G_USB_TYPE_DEVICE);
+ signals[DEVICE_REMOVED_SIGNAL] =
+ g_signal_new("device-removed",
+ G_TYPE_FROM_CLASS(klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET(GUsbDeviceListClass, device_removed),
+ NULL,
+ NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ G_USB_TYPE_DEVICE);
}
static void
-g_usb_device_list_init (GUsbDeviceList *list)
+g_usb_device_list_init(GUsbDeviceList *list)
{
- list->priv = g_usb_device_list_get_instance_private (list);
+ list->priv = g_usb_device_list_get_instance_private(list);
}
/**
@@ -171,11 +163,11 @@ g_usb_device_list_init (GUsbDeviceList *list)
* Since: 0.1.0
**/
GPtrArray *
-g_usb_device_list_get_devices (GUsbDeviceList *list)
+g_usb_device_list_get_devices(GUsbDeviceList *list)
{
- g_return_val_if_fail (G_USB_IS_DEVICE_LIST (list), NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE_LIST(list), NULL);
- return g_usb_context_get_devices (list->priv->context);
+ return g_usb_context_get_devices(list->priv->context);
}
/**
@@ -187,7 +179,7 @@ g_usb_device_list_get_devices (GUsbDeviceList *list)
* Since: 0.1.0
**/
void
-g_usb_device_list_coldplug (GUsbDeviceList *list)
+g_usb_device_list_coldplug(GUsbDeviceList *list)
{
return;
}
@@ -206,16 +198,15 @@ g_usb_device_list_coldplug (GUsbDeviceList *list)
* Since: 0.1.0
**/
GUsbDevice *
-g_usb_device_list_find_by_bus_address (GUsbDeviceList *list,
- guint8 bus,
- guint8 address,
- GError **error)
+g_usb_device_list_find_by_bus_address(GUsbDeviceList *list,
+ guint8 bus,
+ guint8 address,
+ GError **error)
{
- g_return_val_if_fail (G_USB_IS_DEVICE_LIST (list), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE_LIST(list), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
- return g_usb_context_find_by_bus_address (list->priv->context,
- bus, address, error);
+ return g_usb_context_find_by_bus_address(list->priv->context, bus, address, error);
}
/**
@@ -232,16 +223,12 @@ g_usb_device_list_find_by_bus_address (GUsbDeviceList *list,
* Since: 0.1.0
**/
GUsbDevice *
-g_usb_device_list_find_by_vid_pid (GUsbDeviceList *list,
- guint16 vid,
- guint16 pid,
- GError **error)
+g_usb_device_list_find_by_vid_pid(GUsbDeviceList *list, guint16 vid, guint16 pid, GError **error)
{
- g_return_val_if_fail (G_USB_IS_DEVICE_LIST (list), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE_LIST(list), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
- return g_usb_context_find_by_vid_pid (list->priv->context,
- vid, pid, error);
+ return g_usb_context_find_by_vid_pid(list->priv->context, vid, pid, error);
}
/**
@@ -258,7 +245,7 @@ g_usb_device_list_find_by_vid_pid (GUsbDeviceList *list,
* Since: 0.1.0
**/
GUsbDeviceList *
-g_usb_device_list_new (GUsbContext *context)
+g_usb_device_list_new(GUsbContext *context)
{
- return g_object_new (G_USB_TYPE_DEVICE_LIST, "context", context, NULL);
+ return g_object_new(G_USB_TYPE_DEVICE_LIST, "context", context, NULL);
}
diff --git a/gusb/gusb-device-list.h b/gusb/gusb-device-list.h
index 97edee3..d0297e9 100644
--- a/gusb/gusb-device-list.h
+++ b/gusb/gusb-device-list.h
@@ -12,28 +12,25 @@
G_BEGIN_DECLS
-#define G_USB_TYPE_DEVICE_LIST (g_usb_device_list_get_type ())
-#define G_USB_DEVICE_LIST(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_USB_TYPE_DEVICE_LIST, GUsbDeviceList))
-#define G_USB_IS_DEVICE_LIST(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_USB_TYPE_DEVICE_LIST))
+#define G_USB_TYPE_DEVICE_LIST (g_usb_device_list_get_type())
+#define G_USB_DEVICE_LIST(o) \
+ (G_TYPE_CHECK_INSTANCE_CAST((o), G_USB_TYPE_DEVICE_LIST, GUsbDeviceList))
+#define G_USB_IS_DEVICE_LIST(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), G_USB_TYPE_DEVICE_LIST))
-typedef struct _GUsbDeviceListPrivate GUsbDeviceListPrivate;
-typedef struct _GUsbDeviceList GUsbDeviceList;
-typedef struct _GUsbDeviceListClass GUsbDeviceListClass;
+typedef struct _GUsbDeviceListPrivate GUsbDeviceListPrivate;
+typedef struct _GUsbDeviceList GUsbDeviceList;
+typedef struct _GUsbDeviceListClass GUsbDeviceListClass;
-struct _GUsbDeviceList
-{
- GObject parent;
- GUsbDeviceListPrivate *priv;
+struct _GUsbDeviceList {
+ GObject parent;
+ GUsbDeviceListPrivate *priv;
};
-struct _GUsbDeviceListClass
-{
- GObjectClass parent_class;
+struct _GUsbDeviceListClass {
+ GObjectClass parent_class;
/* Signals */
- void (*device_added) (GUsbDeviceList *list,
- GUsbDevice *device);
- void (*device_removed) (GUsbDeviceList *list,
- GUsbDevice *device);
+ void (*device_added)(GUsbDeviceList *list, GUsbDevice *device);
+ void (*device_removed)(GUsbDeviceList *list, GUsbDevice *device);
/*< private >*/
/*
* If adding fields to this struct, remove corresponding
@@ -42,27 +39,30 @@ struct _GUsbDeviceListClass
gchar _gusb_reserved[64];
};
-GType g_usb_device_list_get_type (void);
+GType
+g_usb_device_list_get_type(void);
G_DEPRECATED_FOR(g_usb_context_new)
-GUsbDeviceList *g_usb_device_list_new (GUsbContext *context);
+GUsbDeviceList *
+g_usb_device_list_new(GUsbContext *context);
G_DEPRECATED
-void g_usb_device_list_coldplug (GUsbDeviceList *list);
+void
+g_usb_device_list_coldplug(GUsbDeviceList *list);
G_DEPRECATED_FOR(g_usb_context_get_devices)
-GPtrArray *g_usb_device_list_get_devices (GUsbDeviceList *list);
+GPtrArray *
+g_usb_device_list_get_devices(GUsbDeviceList *list);
G_DEPRECATED_FOR(g_usb_context_find_by_bus_address)
-GUsbDevice *g_usb_device_list_find_by_bus_address (GUsbDeviceList *list,
- guint8 bus,
- guint8 address,
- GError **error);
+GUsbDevice *
+g_usb_device_list_find_by_bus_address(GUsbDeviceList *list,
+ guint8 bus,
+ guint8 address,
+ GError **error);
G_DEPRECATED_FOR(g_usb_context_find_by_vid_pid)
-GUsbDevice *g_usb_device_list_find_by_vid_pid (GUsbDeviceList *list,
- guint16 vid,
- guint16 pid,
- GError **error);
+GUsbDevice *
+g_usb_device_list_find_by_vid_pid(GUsbDeviceList *list, guint16 vid, guint16 pid, GError **error);
G_END_DECLS
diff --git a/gusb/gusb-device-private.h b/gusb/gusb-device-private.h
index 5a313db..70cfec0 100644
--- a/gusb/gusb-device-private.h
+++ b/gusb/gusb-device-private.h
@@ -11,12 +11,12 @@
G_BEGIN_DECLS
-GUsbDevice *_g_usb_device_new (GUsbContext *context,
- libusb_device *device,
- GError **error);
+GUsbDevice *
+_g_usb_device_new(GUsbContext *context, libusb_device *device, GError **error);
-libusb_device *_g_usb_device_get_device (GUsbDevice *device);
-gboolean _g_usb_device_open_internal (GUsbDevice *device,
- GError **error);
+libusb_device *
+_g_usb_device_get_device(GUsbDevice *device);
+gboolean
+_g_usb_device_open_internal(GUsbDevice *device, GError **error);
G_END_DECLS
diff --git a/gusb/gusb-device.c b/gusb/gusb-device.c
index beec181..576b148 100644
--- a/gusb/gusb-device.c
+++ b/gusb/gusb-device.c
@@ -16,47 +16,45 @@
#include "config.h"
-#include <string.h>
-
#include <libusb.h>
+#include <string.h>
+#include "gusb-bos-descriptor-private.h"
#include "gusb-context-private.h"
-#include "gusb-util.h"
#include "gusb-device-private.h"
#include "gusb-interface-private.h"
-#include "gusb-bos-descriptor-private.h"
+#include "gusb-util.h"
/**
* GUsbDevicePrivate:
*
* Private #GUsbDevice data
**/
-struct _GUsbDevicePrivate
-{
- gchar *platform_id;
- GUsbContext *context;
- libusb_device *device;
- libusb_device_handle *handle;
+struct _GUsbDevicePrivate {
+ gchar *platform_id;
+ GUsbContext *context;
+ libusb_device *device;
+ libusb_device_handle *handle;
struct libusb_device_descriptor desc;
};
-enum {
- PROP_0,
- PROP_LIBUSB_DEVICE,
- PROP_CONTEXT,
- PROP_PLATFORM_ID,
- N_PROPERTIES
-};
+enum { PROP_0, PROP_LIBUSB_DEVICE, PROP_CONTEXT, PROP_PLATFORM_ID, N_PROPERTIES };
-static GParamSpec *pspecs[N_PROPERTIES] = { NULL, };
+static GParamSpec *pspecs[N_PROPERTIES] = {
+ NULL,
+};
-static void g_usb_device_initable_iface_init (GInitableIface *iface);
+static void
+g_usb_device_initable_iface_init(GInitableIface *iface);
-G_DEFINE_TYPE_WITH_CODE (GUsbDevice, g_usb_device, G_TYPE_OBJECT,
- G_ADD_PRIVATE (GUsbDevice)
- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
- g_usb_device_initable_iface_init))
+G_DEFINE_TYPE_WITH_CODE(GUsbDevice,
+ g_usb_device,
+ G_TYPE_OBJECT,
+ G_ADD_PRIVATE(GUsbDevice)
+ G_IMPLEMENT_INTERFACE(G_TYPE_INITABLE,
+ g_usb_device_initable_iface_init))
+/* clang-format off */
/**
* g_usb_device_error_quark:
*
@@ -65,90 +63,84 @@ G_DEFINE_TYPE_WITH_CODE (GUsbDevice, g_usb_device, G_TYPE_OBJECT,
* Since: 0.1.0
**/
G_DEFINE_QUARK (g-usb-device-error-quark, g_usb_device_error)
+/* clang-format on */
static void
-g_usb_device_finalize (GObject *object)
+g_usb_device_finalize(GObject *object)
{
- GUsbDevice *device = G_USB_DEVICE (object);
+ GUsbDevice *device = G_USB_DEVICE(object);
GUsbDevicePrivate *priv = device->priv;
- g_free (priv->platform_id);
+ g_free(priv->platform_id);
- G_OBJECT_CLASS (g_usb_device_parent_class)->finalize (object);
+ G_OBJECT_CLASS(g_usb_device_parent_class)->finalize(object);
}
static void
-g_usb_device_dispose (GObject *object)
+g_usb_device_dispose(GObject *object)
{
- GUsbDevice *device = G_USB_DEVICE (object);
+ GUsbDevice *device = G_USB_DEVICE(object);
GUsbDevicePrivate *priv = device->priv;
- g_clear_pointer (&priv->device, libusb_unref_device);
- g_clear_object (&priv->context);
+ g_clear_pointer(&priv->device, libusb_unref_device);
+ g_clear_object(&priv->context);
- G_OBJECT_CLASS (g_usb_device_parent_class)->dispose (object);
+ G_OBJECT_CLASS(g_usb_device_parent_class)->dispose(object);
}
static void
-g_usb_device_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+g_usb_device_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
- GUsbDevice *device = G_USB_DEVICE (object);
+ GUsbDevice *device = G_USB_DEVICE(object);
GUsbDevicePrivate *priv = device->priv;
switch (prop_id) {
case PROP_LIBUSB_DEVICE:
- g_value_set_pointer (value, priv->device);
+ g_value_set_pointer(value, priv->device);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
-set_libusb_device (GUsbDevice *device,
- struct libusb_device *dev)
+set_libusb_device(GUsbDevice *device, struct libusb_device *dev)
{
GUsbDevicePrivate *priv = device->priv;
- g_clear_pointer (&priv->device, libusb_unref_device);
+ g_clear_pointer(&priv->device, libusb_unref_device);
if (dev != NULL)
- priv->device = libusb_ref_device (dev);
+ priv->device = libusb_ref_device(dev);
}
static void
-g_usb_device_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+g_usb_device_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
- GUsbDevice *device = G_USB_DEVICE (object);
+ GUsbDevice *device = G_USB_DEVICE(object);
GUsbDevicePrivate *priv = device->priv;
switch (prop_id) {
case PROP_LIBUSB_DEVICE:
- set_libusb_device (device, g_value_get_pointer (value));
+ set_libusb_device(device, g_value_get_pointer(value));
break;
case PROP_CONTEXT:
- priv->context = g_value_dup_object (value);
+ priv->context = g_value_dup_object(value);
break;
case PROP_PLATFORM_ID:
- priv->platform_id = g_value_dup_string (value);
+ priv->platform_id = g_value_dup_string(value);
break;
default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
static void
-g_usb_device_constructed (GObject *object)
+g_usb_device_constructed(GObject *object)
{
- GUsbDevice *device = G_USB_DEVICE (object);
+ GUsbDevice *device = G_USB_DEVICE(object);
GUsbDevicePrivate *priv;
gint rc;
@@ -157,18 +149,17 @@ g_usb_device_constructed (GObject *object)
if (!priv->device)
g_error("constructed without a libusb_device");
- rc = libusb_get_device_descriptor (priv->device, &priv->desc);
+ rc = libusb_get_device_descriptor(priv->device, &priv->desc);
if (rc != LIBUSB_SUCCESS)
- g_warning ("Failed to get USB descriptor for device: %s",
- g_usb_strerror (rc));
+ g_warning("Failed to get USB descriptor for device: %s", g_usb_strerror(rc));
- G_OBJECT_CLASS (g_usb_device_parent_class)->constructed (object);
+ G_OBJECT_CLASS(g_usb_device_parent_class)->constructed(object);
}
static void
-g_usb_device_class_init (GUsbDeviceClass *klass)
+g_usb_device_class_init(GUsbDeviceClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->finalize = g_usb_device_finalize;
object_class->dispose = g_usb_device_dispose;
@@ -180,41 +171,42 @@ g_usb_device_class_init (GUsbDeviceClass *klass)
* GUsbDevice:libusb_device:
*/
pspecs[PROP_LIBUSB_DEVICE] =
- g_param_spec_pointer ("libusb-device", NULL, NULL,
- G_PARAM_CONSTRUCT_ONLY|
- G_PARAM_READWRITE);
+ g_param_spec_pointer("libusb-device",
+ NULL,
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
/**
* GUsbDevice:context:
*/
- pspecs[PROP_CONTEXT] =
- g_param_spec_object ("context", NULL, NULL,
- G_USB_TYPE_CONTEXT,
- G_PARAM_CONSTRUCT_ONLY|
- G_PARAM_WRITABLE);
+ pspecs[PROP_CONTEXT] = g_param_spec_object("context",
+ NULL,
+ NULL,
+ G_USB_TYPE_CONTEXT,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
/**
* GUsbDevice:platform-id:
*/
- pspecs[PROP_PLATFORM_ID] =
- g_param_spec_string ("platform-id", NULL, NULL,
- NULL,
- G_PARAM_CONSTRUCT_ONLY|
- G_PARAM_WRITABLE);
+ pspecs[PROP_PLATFORM_ID] = g_param_spec_string("platform-id",
+ NULL,
+ NULL,
+ NULL,
+ G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE);
- g_object_class_install_properties (object_class, N_PROPERTIES, pspecs);
+ g_object_class_install_properties(object_class, N_PROPERTIES, pspecs);
}
static void
-g_usb_device_init (GUsbDevice *device)
+g_usb_device_init(GUsbDevice *device)
{
- device->priv = g_usb_device_get_instance_private (device);
+ device->priv = g_usb_device_get_instance_private(device);
}
/* not defined in FreeBSD */
#ifndef HAVE_LIBUSB_GET_PARENT
static libusb_device *
-libusb_get_parent (libusb_device *dev)
+libusb_get_parent(libusb_device *dev)
{
return NULL;
}
@@ -223,67 +215,69 @@ libusb_get_parent (libusb_device *dev)
/* not defined in DragonFlyBSD */
#ifndef HAVE_LIBUSB_GET_PORT_NUMBER
static guint8
-libusb_get_port_number (libusb_device *dev)
+libusb_get_port_number(libusb_device *dev)
{
return 0xff;
}
#endif
static void
-g_usb_device_build_parent_port_number (GString *str, libusb_device *dev)
+g_usb_device_build_parent_port_number(GString *str, libusb_device *dev)
{
- libusb_device *parent = libusb_get_parent (dev);
+ libusb_device *parent = libusb_get_parent(dev);
if (parent != NULL)
- g_usb_device_build_parent_port_number (str, parent);
- g_string_append_printf (str, "%02x:", libusb_get_port_number (dev));
+ g_usb_device_build_parent_port_number(str, parent);
+ g_string_append_printf(str, "%02x:", libusb_get_port_number(dev));
}
static gchar *
-g_usb_device_build_platform_id (struct libusb_device *dev)
+g_usb_device_build_platform_id(struct libusb_device *dev)
{
GString *platform_id;
/* build a topology of the device */
- platform_id = g_string_new ("usb:");
- g_string_append_printf (platform_id, "%02x:", libusb_get_bus_number (dev));
- g_usb_device_build_parent_port_number (platform_id, dev);
- g_string_truncate (platform_id, platform_id->len - 1);
- return g_string_free (platform_id, FALSE);
+ platform_id = g_string_new("usb:");
+ g_string_append_printf(platform_id, "%02x:", libusb_get_bus_number(dev));
+ g_usb_device_build_parent_port_number(platform_id, dev);
+ g_string_truncate(platform_id, platform_id->len - 1);
+ return g_string_free(platform_id, FALSE);
}
static gboolean
-g_usb_device_initable_init (GInitable *initable,
- GCancellable *cancellable,
- GError **error)
+g_usb_device_initable_init(GInitable *initable, GCancellable *cancellable, GError **error)
{
- GUsbDevice *device = G_USB_DEVICE (initable);
+ GUsbDevice *device = G_USB_DEVICE(initable);
GUsbDevicePrivate *priv;
gint rc;
priv = device->priv;
if (priv->device == NULL) {
- g_set_error_literal (error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_INTERNAL,
- "Constructed without a libusb_device");
+ g_set_error_literal(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_INTERNAL,
+ "Constructed without a libusb_device");
return FALSE;
}
- rc = libusb_get_device_descriptor (priv->device, &priv->desc);
+ rc = libusb_get_device_descriptor(priv->device, &priv->desc);
if (rc != LIBUSB_SUCCESS) {
- g_set_error (error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_INTERNAL,
- "Failed to get USB descriptor for device: %s",
- g_usb_strerror (rc));
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_INTERNAL,
+ "Failed to get USB descriptor for device: %s",
+ g_usb_strerror(rc));
return FALSE;
}
/* this does not change on plug->unplug->plug */
- priv->platform_id = g_usb_device_build_platform_id (priv->device);
+ priv->platform_id = g_usb_device_build_platform_id(priv->device);
return TRUE;
}
static void
-g_usb_device_initable_iface_init (GInitableIface *iface)
+g_usb_device_initable_iface_init(GInitableIface *iface)
{
iface->init = g_usb_device_initable_init;
}
@@ -296,15 +290,16 @@ g_usb_device_initable_iface_init (GInitableIface *iface)
* Since: 0.1.0
**/
GUsbDevice *
-_g_usb_device_new (GUsbContext *context,
- libusb_device *device,
- GError **error)
+_g_usb_device_new(GUsbContext *context, libusb_device *device, GError **error)
{
- return g_initable_new (G_USB_TYPE_DEVICE,
- NULL, error,
- "context", context,
- "libusb-device", device,
- NULL);
+ return g_initable_new(G_USB_TYPE_DEVICE,
+ NULL,
+ error,
+ "context",
+ context,
+ "libusb-device",
+ device,
+ NULL);
}
/**
@@ -316,15 +311,13 @@ _g_usb_device_new (GUsbContext *context,
* Return value: The #libusb_device or %NULL. Do not unref this value.
**/
libusb_device *
-_g_usb_device_get_device (GUsbDevice *device)
+_g_usb_device_get_device(GUsbDevice *device)
{
return device->priv->device;
}
static gboolean
-g_usb_device_libusb_error_to_gerror (GUsbDevice *device,
- gint rc,
- GError **error)
+g_usb_device_libusb_error_to_gerror(GUsbDevice *device, gint rc, GError **error)
{
gint error_code = G_USB_DEVICE_ERROR_INTERNAL;
/* Put the rc in libusb's error enum so that gcc warns us if we're
@@ -363,60 +356,65 @@ g_usb_device_libusb_error_to_gerror (GUsbDevice *device,
break;
}
- g_set_error (error, G_USB_DEVICE_ERROR, error_code,
- "USB error on device %04x:%04x : %s [%i]",
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device),
- g_usb_strerror (rc), rc);
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ error_code,
+ "USB error on device %04x:%04x : %s [%i]",
+ g_usb_device_get_vid(device),
+ g_usb_device_get_pid(device),
+ g_usb_strerror(rc),
+ rc);
return FALSE;
}
static gboolean
-g_usb_device_not_open_error (GUsbDevice *device,
- GError **error)
-{
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_OPEN,
- "Device %04x:%04x has not been opened",
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device));
+g_usb_device_not_open_error(GUsbDevice *device, GError **error)
+{
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NOT_OPEN,
+ "Device %04x:%04x has not been opened",
+ g_usb_device_get_vid(device),
+ g_usb_device_get_pid(device));
return FALSE;
}
static void
-g_usb_device_async_not_open_error (GUsbDevice *device,
- GAsyncReadyCallback callback,
- gpointer user_data,
- gpointer source_tag)
-{
- g_task_report_new_error (device, callback, user_data, source_tag,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_OPEN,
- "Device %04x:%04x has not been opened",
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device));
+g_usb_device_async_not_open_error(GUsbDevice *device,
+ GAsyncReadyCallback callback,
+ gpointer user_data,
+ gpointer source_tag)
+{
+ g_task_report_new_error(device,
+ callback,
+ user_data,
+ source_tag,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NOT_OPEN,
+ "Device %04x:%04x has not been opened",
+ g_usb_device_get_vid(device),
+ g_usb_device_get_pid(device));
}
gboolean
-_g_usb_device_open_internal (GUsbDevice *device, GError **error)
+_g_usb_device_open_internal(GUsbDevice *device, GError **error)
{
gint rc;
if (device->priv->handle != NULL) {
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_ALREADY_OPEN,
- "Device %04x:%04x is already open",
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device));
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_ALREADY_OPEN,
+ "Device %04x:%04x is already open",
+ g_usb_device_get_vid(device),
+ g_usb_device_get_pid(device));
return FALSE;
}
/* open device */
- rc = libusb_open (device->priv->device, &device->priv->handle);
- return g_usb_device_libusb_error_to_gerror (device, rc, error);
+ rc = libusb_open(device->priv->device, &device->priv->handle);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
}
/**
@@ -433,17 +431,17 @@ _g_usb_device_open_internal (GUsbDevice *device, GError **error)
* Since: 0.1.0
**/
gboolean
-g_usb_device_open (GUsbDevice *device, GError **error)
+g_usb_device_open(GUsbDevice *device, GError **error)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
/* ignore */
- if (g_usb_context_get_flags (device->priv->context) & G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES)
+ if (g_usb_context_get_flags(device->priv->context) & G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES)
return TRUE;
/* open */
- return _g_usb_device_open_internal (device, error);
+ return _g_usb_device_open_internal(device, error);
}
/**
@@ -461,19 +459,19 @@ g_usb_device_open (GUsbDevice *device, GError **error)
* Since: 0.2.5
**/
guint8
-g_usb_device_get_custom_index (GUsbDevice *device,
- guint8 class_id,
- guint8 subclass_id,
- guint8 protocol_id,
- GError **error)
+g_usb_device_get_custom_index(GUsbDevice *device,
+ guint8 class_id,
+ guint8 subclass_id,
+ guint8 protocol_id,
+ GError **error)
{
const struct libusb_interface_descriptor *ifp;
gint rc;
guint8 idx = 0x00;
struct libusb_config_descriptor *config;
- rc = libusb_get_active_config_descriptor (device->priv->device, &config);
- if (!g_usb_device_libusb_error_to_gerror (device, rc, error))
+ rc = libusb_get_active_config_descriptor(device->priv->device, &config);
+ if (!g_usb_device_libusb_error_to_gerror(device, rc, error))
return 0x00;
/* find the right data */
@@ -491,15 +489,17 @@ g_usb_device_get_custom_index (GUsbDevice *device,
/* nothing matched */
if (idx == 0x00) {
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_SUPPORTED,
- "no vendor descriptor for class 0x%02x, "
- "subclass 0x%02x and protocol 0x%02x",
- class_id, subclass_id, protocol_id);
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NOT_SUPPORTED,
+ "no vendor descriptor for class 0x%02x, "
+ "subclass 0x%02x and protocol 0x%02x",
+ class_id,
+ subclass_id,
+ protocol_id);
}
- libusb_free_config_descriptor (config);
+ libusb_free_config_descriptor(config);
return idx;
}
@@ -521,22 +521,22 @@ g_usb_device_get_custom_index (GUsbDevice *device,
* Since: 0.2.8
**/
GUsbInterface *
-g_usb_device_get_interface (GUsbDevice *device,
- guint8 class_id,
- guint8 subclass_id,
- guint8 protocol_id,
- GError **error)
+g_usb_device_get_interface(GUsbDevice *device,
+ guint8 class_id,
+ guint8 subclass_id,
+ guint8 protocol_id,
+ GError **error)
{
const struct libusb_interface_descriptor *ifp;
gint rc;
GUsbInterface *interface = NULL;
struct libusb_config_descriptor *config;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
- rc = libusb_get_active_config_descriptor (device->priv->device, &config);
- if (!g_usb_device_libusb_error_to_gerror (device, rc, error))
+ rc = libusb_get_active_config_descriptor(device->priv->device, &config);
+ if (!g_usb_device_libusb_error_to_gerror(device, rc, error))
return NULL;
/* find the right data */
@@ -548,21 +548,23 @@ g_usb_device_get_interface (GUsbDevice *device,
continue;
if (ifp->bInterfaceProtocol != protocol_id)
continue;
- interface = _g_usb_interface_new (ifp);
+ interface = _g_usb_interface_new(ifp);
break;
}
/* nothing matched */
if (interface == NULL) {
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_SUPPORTED,
- "no interface for class 0x%02x, "
- "subclass 0x%02x and protocol 0x%02x",
- class_id, subclass_id, protocol_id);
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NOT_SUPPORTED,
+ "no interface for class 0x%02x, "
+ "subclass 0x%02x and protocol 0x%02x",
+ class_id,
+ subclass_id,
+ protocol_id);
}
- libusb_free_config_descriptor (config);
+ libusb_free_config_descriptor(config);
return interface;
}
@@ -573,37 +575,38 @@ g_usb_device_get_interface (GUsbDevice *device,
*
* Gets all the interfaces exported by the device.
*
- * Return value: (transfer container) (element-type GUsbInterface): an array of interfaces or %NULL for error
+ * Return value: (transfer container) (element-type GUsbInterface): an array of interfaces or %NULL
+ *for error
*
* Since: 0.2.8
**/
GPtrArray *
-g_usb_device_get_interfaces (GUsbDevice *device, GError **error)
+g_usb_device_get_interfaces(GUsbDevice *device, GError **error)
{
const struct libusb_interface_descriptor *ifp;
gint rc;
struct libusb_config_descriptor *config;
GPtrArray *array = NULL;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
- rc = libusb_get_active_config_descriptor (device->priv->device, &config);
- if (!g_usb_device_libusb_error_to_gerror (device, rc, error))
+ rc = libusb_get_active_config_descriptor(device->priv->device, &config);
+ if (!g_usb_device_libusb_error_to_gerror(device, rc, error))
return NULL;
/* get all interfaces */
- array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+ array = g_ptr_array_new_with_free_func((GDestroyNotify)g_object_unref);
for (guint i = 0; i < config->bNumInterfaces; i++) {
GUsbInterface *interface = NULL;
- for (guint j = 0; j < (guint) config->interface[i].num_altsetting; j++) {
+ for (guint j = 0; j < (guint)config->interface[i].num_altsetting; j++) {
ifp = &config->interface[i].altsetting[j];
- interface = _g_usb_interface_new (ifp);
- g_ptr_array_add (array, interface);
+ interface = _g_usb_interface_new(ifp);
+ g_ptr_array_add(array, interface);
}
}
- libusb_free_config_descriptor (config);
+ libusb_free_config_descriptor(config);
return array;
}
@@ -622,23 +625,21 @@ g_usb_device_get_interfaces (GUsbDevice *device, GError **error)
* Since: 0.4.0
**/
GUsbBosDescriptor *
-g_usb_device_get_bos_descriptor (GUsbDevice *device,
- guint8 capability,
- GError **error)
+g_usb_device_get_bos_descriptor(GUsbDevice *device, guint8 capability, GError **error)
{
gint rc;
guint8 num_device_caps;
GUsbBosDescriptor *bos_descriptor = NULL;
struct libusb_bos_descriptor *bos = NULL;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
- rc = libusb_get_bos_descriptor (device->priv->handle, &bos);
- if (!g_usb_device_libusb_error_to_gerror (device, rc, error))
+ rc = libusb_get_bos_descriptor(device->priv->handle, &bos);
+ if (!g_usb_device_libusb_error_to_gerror(device, rc, error))
return NULL;
- /* find the right data */
+ /* find the right data */
#ifdef __FreeBSD__
num_device_caps = bos->bNumDeviceCapabilities;
#else
@@ -647,21 +648,21 @@ g_usb_device_get_bos_descriptor (GUsbDevice *device,
for (guint i = 0; i < num_device_caps; i++) {
struct libusb_bos_dev_capability_descriptor *bos_cap = bos->dev_capability[i];
if (bos_cap->bDevCapabilityType == capability) {
- bos_descriptor = _g_usb_bos_descriptor_new (bos_cap);
+ bos_descriptor = _g_usb_bos_descriptor_new(bos_cap);
break;
}
}
/* nothing matched */
if (bos_descriptor == NULL) {
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_SUPPORTED,
- "no BOS descriptor for capability 0x%02x",
- capability);
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NOT_SUPPORTED,
+ "no BOS descriptor for capability 0x%02x",
+ capability);
}
- libusb_free_bos_descriptor (bos);
+ libusb_free_bos_descriptor(bos);
return bos_descriptor;
}
@@ -677,22 +678,22 @@ g_usb_device_get_bos_descriptor (GUsbDevice *device,
* Since: 0.4.0
**/
GPtrArray *
-g_usb_device_get_bos_descriptors (GUsbDevice *device, GError **error)
+g_usb_device_get_bos_descriptors(GUsbDevice *device, GError **error)
{
gint rc;
guint8 num_device_caps;
struct libusb_bos_descriptor *bos = NULL;
GPtrArray *array = NULL;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
- rc = libusb_get_bos_descriptor (device->priv->handle, &bos);
- if (!g_usb_device_libusb_error_to_gerror (device, rc, error))
+ rc = libusb_get_bos_descriptor(device->priv->handle, &bos);
+ if (!g_usb_device_libusb_error_to_gerror(device, rc, error))
return NULL;
/* get all BOS descriptors */
- array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
+ array = g_ptr_array_new_with_free_func((GDestroyNotify)g_object_unref);
#ifdef __FreeBSD__
num_device_caps = bos->bNumDeviceCapabilities;
#else
@@ -701,11 +702,11 @@ g_usb_device_get_bos_descriptors (GUsbDevice *device, GError **error)
for (guint i = 0; i < num_device_caps; i++) {
GUsbBosDescriptor *bos_descriptor = NULL;
struct libusb_bos_dev_capability_descriptor *bos_cap = bos->dev_capability[i];
- bos_descriptor = _g_usb_bos_descriptor_new (bos_cap);
- g_ptr_array_add (array, bos_descriptor);
+ bos_descriptor = _g_usb_bos_descriptor_new(bos_cap);
+ g_ptr_array_add(array, bos_descriptor);
}
- libusb_free_bos_descriptor (bos);
+ libusb_free_bos_descriptor(bos);
return array;
}
@@ -721,20 +722,19 @@ g_usb_device_get_bos_descriptors (GUsbDevice *device, GError **error)
* Since: 0.1.0
**/
gboolean
-g_usb_device_close (GUsbDevice *device,
- GError **error)
+g_usb_device_close(GUsbDevice *device, GError **error)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
/* ignore */
- if (g_usb_context_get_flags (device->priv->context) & G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES)
+ if (g_usb_context_get_flags(device->priv->context) & G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES)
return TRUE;
if (device->priv->handle == NULL)
- return g_usb_device_not_open_error (device, error);
+ return g_usb_device_not_open_error(device, error);
- libusb_close (device->priv->handle);
+ libusb_close(device->priv->handle);
device->priv->handle = NULL;
return TRUE;
}
@@ -757,20 +757,19 @@ g_usb_device_close (GUsbDevice *device,
* Since: 0.1.0
**/
gboolean
-g_usb_device_reset (GUsbDevice *device,
- GError **error)
+g_usb_device_reset(GUsbDevice *device, GError **error)
{
gint rc;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
if (device->priv->handle == NULL)
- return g_usb_device_not_open_error (device, error);
+ return g_usb_device_not_open_error(device, error);
- rc = libusb_reset_device (device->priv->handle);
+ rc = libusb_reset_device(device->priv->handle);
if (rc == LIBUSB_ERROR_NOT_FOUND)
return TRUE;
- return g_usb_device_libusb_error_to_gerror (device, rc, error);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
}
/**
@@ -787,23 +786,22 @@ g_usb_device_reset (GUsbDevice *device,
* Since: 0.1.0
**/
gint
-g_usb_device_get_configuration (GUsbDevice *device,
- GError **error)
+g_usb_device_get_configuration(GUsbDevice *device, GError **error)
{
gint rc;
int config;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), -1);
- g_return_val_if_fail (error == NULL || *error == NULL, -1);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), -1);
+ g_return_val_if_fail(error == NULL || *error == NULL, -1);
if (device->priv->handle == NULL) {
- g_usb_device_not_open_error (device, error);
+ g_usb_device_not_open_error(device, error);
return -1;
}
- rc = libusb_get_configuration (device->priv->handle, &config);
+ rc = libusb_get_configuration(device->priv->handle, &config);
if (rc != LIBUSB_SUCCESS) {
- g_usb_device_libusb_error_to_gerror (device, rc, error);
+ g_usb_device_libusb_error_to_gerror(device, rc, error);
return -1;
}
@@ -825,33 +823,28 @@ g_usb_device_get_configuration (GUsbDevice *device,
* Since: 0.1.0
**/
gboolean
-g_usb_device_set_configuration (GUsbDevice *device,
- gint configuration,
- GError **error)
+g_usb_device_set_configuration(GUsbDevice *device, gint configuration, GError **error)
{
gint rc;
gint config_tmp = 0;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
if (device->priv->handle == NULL)
- return g_usb_device_not_open_error (device, error);
+ return g_usb_device_not_open_error(device, error);
/* verify we've not already set the same configuration */
- rc = libusb_get_configuration (device->priv->handle,
- &config_tmp);
+ rc = libusb_get_configuration(device->priv->handle, &config_tmp);
if (rc != LIBUSB_SUCCESS) {
- return g_usb_device_libusb_error_to_gerror (device,
- rc,
- error);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
}
if (config_tmp == configuration)
return TRUE;
/* different, so change */
- rc = libusb_set_configuration (device->priv->handle, configuration);
- return g_usb_device_libusb_error_to_gerror (device, rc, error);
+ rc = libusb_set_configuration(device->priv->handle, configuration);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
}
/**
@@ -868,32 +861,29 @@ g_usb_device_set_configuration (GUsbDevice *device,
* Since: 0.1.0
**/
gboolean
-g_usb_device_claim_interface (GUsbDevice *device,
- gint interface,
- GUsbDeviceClaimInterfaceFlags flags,
- GError **error)
+g_usb_device_claim_interface(GUsbDevice *device,
+ gint interface,
+ GUsbDeviceClaimInterfaceFlags flags,
+ GError **error)
{
gint rc;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
if (device->priv->handle == NULL)
- return g_usb_device_not_open_error (device, error);
+ return g_usb_device_not_open_error(device, error);
if (flags & G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER) {
- rc = libusb_detach_kernel_driver (device->priv->handle,
- interface);
- if (rc != LIBUSB_SUCCESS &&
- rc != LIBUSB_ERROR_NOT_FOUND && /* No driver attached */
- rc != LIBUSB_ERROR_NOT_SUPPORTED && /* win32 */
+ rc = libusb_detach_kernel_driver(device->priv->handle, interface);
+ if (rc != LIBUSB_SUCCESS && rc != LIBUSB_ERROR_NOT_FOUND && /* No driver attached */
+ rc != LIBUSB_ERROR_NOT_SUPPORTED && /* win32 */
rc != LIBUSB_ERROR_BUSY /* driver rebound already */)
- return g_usb_device_libusb_error_to_gerror (device, rc,
- error);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
}
- rc = libusb_claim_interface (device->priv->handle, interface);
- return g_usb_device_libusb_error_to_gerror (device, rc, error);
+ rc = libusb_claim_interface(device->priv->handle, interface);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
}
/**
@@ -910,32 +900,29 @@ g_usb_device_claim_interface (GUsbDevice *device,
* Since: 0.1.0
**/
gboolean
-g_usb_device_release_interface (GUsbDevice *device,
- gint interface,
- GUsbDeviceClaimInterfaceFlags flags,
- GError **error)
+g_usb_device_release_interface(GUsbDevice *device,
+ gint interface,
+ GUsbDeviceClaimInterfaceFlags flags,
+ GError **error)
{
gint rc;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
if (device->priv->handle == NULL)
- return g_usb_device_not_open_error (device, error);
+ return g_usb_device_not_open_error(device, error);
- rc = libusb_release_interface (device->priv->handle, interface);
+ rc = libusb_release_interface(device->priv->handle, interface);
if (rc != LIBUSB_SUCCESS)
- return g_usb_device_libusb_error_to_gerror (device, rc, error);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
if (flags & G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER) {
- rc = libusb_attach_kernel_driver (device->priv->handle,
- interface);
- if (rc != LIBUSB_SUCCESS &&
- rc != LIBUSB_ERROR_NOT_FOUND && /* No driver attached */
- rc != LIBUSB_ERROR_NOT_SUPPORTED && /* win32 */
+ rc = libusb_attach_kernel_driver(device->priv->handle, interface);
+ if (rc != LIBUSB_SUCCESS && rc != LIBUSB_ERROR_NOT_FOUND && /* No driver attached */
+ rc != LIBUSB_ERROR_NOT_SUPPORTED && /* win32 */
rc != LIBUSB_ERROR_BUSY /* driver rebound already */)
- return g_usb_device_libusb_error_to_gerror (device, rc,
- error);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
}
return TRUE;
@@ -955,20 +942,19 @@ g_usb_device_release_interface (GUsbDevice *device,
* Since: 0.2.8
**/
gboolean
-g_usb_device_set_interface_alt (GUsbDevice *device, gint interface,
- guint8 alt, GError **error)
+g_usb_device_set_interface_alt(GUsbDevice *device, gint interface, guint8 alt, GError **error)
{
gint rc;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), FALSE);
- g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), FALSE);
+ g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
if (device->priv->handle == NULL)
- return g_usb_device_not_open_error (device, error);
+ return g_usb_device_not_open_error(device, error);
- rc = libusb_set_interface_alt_setting (device->priv->handle, interface, (gint) alt);
+ rc = libusb_set_interface_alt_setting(device->priv->handle, interface, (gint)alt);
if (rc != LIBUSB_SUCCESS)
- return g_usb_device_libusb_error_to_gerror (device, rc, error);
+ return g_usb_device_libusb_error_to_gerror(device, rc, error);
return TRUE;
}
@@ -986,30 +972,27 @@ g_usb_device_set_interface_alt (GUsbDevice *device, gint interface,
* Since: 0.1.0
**/
gchar *
-g_usb_device_get_string_descriptor (GUsbDevice *device,
- guint8 desc_index,
- GError **error)
+g_usb_device_get_string_descriptor(GUsbDevice *device, guint8 desc_index, GError **error)
{
gint rc;
/* libusb_get_string_descriptor_ascii returns max 128 bytes */
unsigned char buf[128];
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
if (device->priv->handle == NULL) {
- g_usb_device_not_open_error (device, error);
+ g_usb_device_not_open_error(device, error);
return NULL;
}
- rc = libusb_get_string_descriptor_ascii (device->priv->handle,
- desc_index, buf, sizeof(buf));
+ rc = libusb_get_string_descriptor_ascii(device->priv->handle, desc_index, buf, sizeof(buf));
if (rc < 0) {
- g_usb_device_libusb_error_to_gerror (device, rc, error);
+ g_usb_device_libusb_error_to_gerror(device, rc, error);
return NULL;
}
- return g_strdup ((const gchar *)buf);
+ return g_strdup((const gchar *)buf);
}
/**
@@ -1027,32 +1010,30 @@ g_usb_device_get_string_descriptor (GUsbDevice *device,
* Since: 0.3.8
**/
GBytes *
-g_usb_device_get_string_descriptor_bytes_full (GUsbDevice *device,
- guint8 desc_index,
- guint16 langid,
- gsize length,
- GError **error)
+g_usb_device_get_string_descriptor_bytes_full(GUsbDevice *device,
+ guint8 desc_index,
+ guint16 langid,
+ gsize length,
+ GError **error)
{
gint rc;
g_autofree guint8 *buf = g_malloc0(length);
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
- g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
+ g_return_val_if_fail(error == NULL || *error == NULL, NULL);
if (device->priv->handle == NULL) {
- g_usb_device_not_open_error (device, error);
+ g_usb_device_not_open_error(device, error);
return NULL;
}
- rc = libusb_get_string_descriptor (device->priv->handle,
- desc_index, langid,
- buf, length);
+ rc = libusb_get_string_descriptor(device->priv->handle, desc_index, langid, buf, length);
if (rc < 0) {
- g_usb_device_libusb_error_to_gerror (device, rc, error);
+ g_usb_device_libusb_error_to_gerror(device, rc, error);
return NULL;
}
- return g_bytes_new (buf, rc);
+ return g_bytes_new(buf, rc);
}
/**
@@ -1072,10 +1053,10 @@ g_usb_device_get_string_descriptor_bytes_full (GUsbDevice *device,
* Since: 0.3.6
**/
GBytes *
-g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
- guint8 desc_index,
- guint16 langid,
- GError **error)
+g_usb_device_get_string_descriptor_bytes(GUsbDevice *device,
+ guint8 desc_index,
+ guint16 langid,
+ GError **error)
{
return g_usb_device_get_string_descriptor_bytes_full(device,
desc_index,
@@ -1084,23 +1065,21 @@ g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
error);
}
-typedef gssize (GUsbDeviceTransferFinishFunc) (GUsbDevice *device, GAsyncResult *res, GError **error);
+typedef gssize(GUsbDeviceTransferFinishFunc)(GUsbDevice *device, GAsyncResult *res, GError **error);
typedef struct {
- GError **error;
- GMainContext *context;
- GMainLoop *loop;
- GUsbDeviceTransferFinishFunc *finish_func;
- gssize ret;
+ GError **error;
+ GMainContext *context;
+ GMainLoop *loop;
+ GUsbDeviceTransferFinishFunc *finish_func;
+ gssize ret;
} GUsbSyncHelper;
static void
-g_usb_device_sync_transfer_cb (GUsbDevice *device,
- GAsyncResult *res,
- GUsbSyncHelper *helper)
+g_usb_device_sync_transfer_cb(GUsbDevice *device, GAsyncResult *res, GUsbSyncHelper *helper)
{
- helper->ret = (*helper->finish_func) (device, res, helper->error);
- g_main_loop_quit (helper->loop);
+ helper->ret = (*helper->finish_func)(device, res, helper->error);
+ g_main_loop_quit(helper->loop);
}
/**
@@ -1129,46 +1108,46 @@ g_usb_device_sync_transfer_cb (GUsbDevice *device,
* Since: 0.1.0
**/
gboolean
-g_usb_device_control_transfer (GUsbDevice *device,
- GUsbDeviceDirection direction,
- GUsbDeviceRequestType request_type,
- GUsbDeviceRecipient recipient,
- guint8 request,
- guint16 value,
- guint16 idx,
- guint8 *data,
- gsize length,
- gsize *actual_length,
- guint timeout,
- GCancellable *cancellable,
- GError **error)
+g_usb_device_control_transfer(GUsbDevice *device,
+ GUsbDeviceDirection direction,
+ GUsbDeviceRequestType request_type,
+ GUsbDeviceRecipient recipient,
+ guint8 request,
+ guint16 value,
+ guint16 idx,
+ guint8 *data,
+ gsize length,
+ gsize *actual_length,
+ guint timeout,
+ GCancellable *cancellable,
+ GError **error)
{
GUsbSyncHelper helper;
helper.ret = -1;
- helper.context = g_usb_context_get_main_context (device->priv->context);
- helper.loop = g_main_loop_new (helper.context, FALSE);
+ helper.context = g_usb_context_get_main_context(device->priv->context);
+ helper.loop = g_main_loop_new(helper.context, FALSE);
helper.error = error;
helper.finish_func = g_usb_device_control_transfer_finish;
- g_usb_device_control_transfer_async (device,
- direction,
- request_type,
- recipient,
- request,
- value,
- idx,
- data,
- length,
- timeout,
- cancellable,
- (GAsyncReadyCallback) g_usb_device_sync_transfer_cb,
- &helper);
- g_main_loop_run (helper.loop);
- g_main_loop_unref (helper.loop);
+ g_usb_device_control_transfer_async(device,
+ direction,
+ request_type,
+ recipient,
+ request,
+ value,
+ idx,
+ data,
+ length,
+ timeout,
+ cancellable,
+ (GAsyncReadyCallback)g_usb_device_sync_transfer_cb,
+ &helper);
+ g_main_loop_run(helper.loop);
+ g_main_loop_unref(helper.loop);
if (actual_length != NULL)
- *actual_length = (gsize) helper.ret;
+ *actual_length = (gsize)helper.ret;
return helper.ret != -1;
}
@@ -1196,36 +1175,36 @@ g_usb_device_control_transfer (GUsbDevice *device,
* Since: 0.1.0
**/
gboolean
-g_usb_device_bulk_transfer (GUsbDevice *device,
- guint8 endpoint,
- guint8 *data,
- gsize length,
- gsize *actual_length,
- guint timeout,
- GCancellable *cancellable,
- GError **error)
+g_usb_device_bulk_transfer(GUsbDevice *device,
+ guint8 endpoint,
+ guint8 *data,
+ gsize length,
+ gsize *actual_length,
+ guint timeout,
+ GCancellable *cancellable,
+ GError **error)
{
GUsbSyncHelper helper;
helper.ret = -1;
- helper.context = g_usb_context_get_main_context (device->priv->context);
- helper.loop = g_main_loop_new (helper.context, FALSE);
+ helper.context = g_usb_context_get_main_context(device->priv->context);
+ helper.loop = g_main_loop_new(helper.context, FALSE);
helper.error = error;
helper.finish_func = g_usb_device_bulk_transfer_finish;
- g_usb_device_bulk_transfer_async (device,
- endpoint,
- data,
- length,
- timeout,
- cancellable,
- (GAsyncReadyCallback) g_usb_device_sync_transfer_cb,
- &helper);
- g_main_loop_run (helper.loop);
- g_main_loop_unref (helper.loop);
+ g_usb_device_bulk_transfer_async(device,
+ endpoint,
+ data,
+ length,
+ timeout,
+ cancellable,
+ (GAsyncReadyCallback)g_usb_device_sync_transfer_cb,
+ &helper);
+ g_main_loop_run(helper.loop);
+ g_main_loop_unref(helper.loop);
if (actual_length != NULL)
- *actual_length = (gsize) helper.ret;
+ *actual_length = (gsize)helper.ret;
return helper.ret != -1;
}
@@ -1253,33 +1232,33 @@ g_usb_device_bulk_transfer (GUsbDevice *device,
* Since: 0.1.0
**/
gboolean
-g_usb_device_interrupt_transfer (GUsbDevice *device,
- guint8 endpoint,
- guint8 *data,
- gsize length,
- gsize *actual_length,
- guint timeout,
- GCancellable *cancellable,
- GError **error)
+g_usb_device_interrupt_transfer(GUsbDevice *device,
+ guint8 endpoint,
+ guint8 *data,
+ gsize length,
+ gsize *actual_length,
+ guint timeout,
+ GCancellable *cancellable,
+ GError **error)
{
GUsbSyncHelper helper;
helper.ret = -1;
- helper.context = g_usb_context_get_main_context (device->priv->context);
- helper.loop = g_main_loop_new (helper.context, FALSE);
+ helper.context = g_usb_context_get_main_context(device->priv->context);
+ helper.loop = g_main_loop_new(helper.context, FALSE);
helper.error = error;
helper.finish_func = g_usb_device_interrupt_transfer_finish;
- g_usb_device_interrupt_transfer_async (device,
- endpoint,
- data,
- length,
- timeout,
- cancellable,
- (GAsyncReadyCallback) g_usb_device_sync_transfer_cb,
- &helper);
- g_main_loop_run (helper.loop);
- g_main_loop_unref (helper.loop);
+ g_usb_device_interrupt_transfer_async(device,
+ endpoint,
+ data,
+ length,
+ timeout,
+ cancellable,
+ (GAsyncReadyCallback)g_usb_device_sync_transfer_cb,
+ &helper);
+ g_main_loop_run(helper.loop);
+ g_main_loop_unref(helper.loop);
if (actual_length != NULL)
*actual_length = helper.ret;
@@ -1288,30 +1267,28 @@ g_usb_device_interrupt_transfer (GUsbDevice *device,
}
typedef struct {
- GCancellable *cancellable;
- gulong cancellable_id;
- struct libusb_transfer *transfer;
- guint8 *data; /* owned by the user */
- guint8 *data_raw; /* owned by the task */
+ GCancellable *cancellable;
+ gulong cancellable_id;
+ struct libusb_transfer *transfer;
+ guint8 *data; /* owned by the user */
+ guint8 *data_raw; /* owned by the task */
} GcmDeviceReq;
static void
-g_usb_device_req_free (GcmDeviceReq *req)
+g_usb_device_req_free(GcmDeviceReq *req)
{
- g_free (req->data_raw);
+ g_free(req->data_raw);
if (req->cancellable_id > 0) {
- g_cancellable_disconnect (req->cancellable,
- req->cancellable_id);
- g_object_unref (req->cancellable);
+ g_cancellable_disconnect(req->cancellable, req->cancellable_id);
+ g_object_unref(req->cancellable);
}
- libusb_free_transfer (req->transfer);
- g_slice_free (GcmDeviceReq, req);
+ libusb_free_transfer(req->transfer);
+ g_slice_free(GcmDeviceReq, req);
}
static gboolean
-g_usb_device_libusb_status_to_gerror (gint status,
- GError **error)
+g_usb_device_libusb_status_to_gerror(gint status, GError **error)
{
gboolean ret = FALSE;
@@ -1320,96 +1297,95 @@ g_usb_device_libusb_status_to_gerror (gint status,
ret = TRUE;
break;
case LIBUSB_TRANSFER_ERROR:
- g_set_error_literal (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_FAILED,
- "transfer failed");
+ g_set_error_literal(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_FAILED,
+ "transfer failed");
break;
case LIBUSB_TRANSFER_TIMED_OUT:
- g_set_error_literal (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_TIMED_OUT,
- "transfer timed out");
+ g_set_error_literal(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_TIMED_OUT,
+ "transfer timed out");
break;
case LIBUSB_TRANSFER_CANCELLED:
- g_set_error_literal (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_CANCELLED,
- "transfer cancelled");
+ g_set_error_literal(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_CANCELLED,
+ "transfer cancelled");
break;
case LIBUSB_TRANSFER_STALL:
- g_set_error_literal (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_SUPPORTED,
- "endpoint stalled or request not supported");
+ g_set_error_literal(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NOT_SUPPORTED,
+ "endpoint stalled or request not supported");
break;
case LIBUSB_TRANSFER_NO_DEVICE:
- g_set_error_literal (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NO_DEVICE,
- "device was disconnected");
+ g_set_error_literal(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_NO_DEVICE,
+ "device was disconnected");
break;
case LIBUSB_TRANSFER_OVERFLOW:
- g_set_error_literal (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_INTERNAL,
- "device sent more data than requested");
+ g_set_error_literal(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_INTERNAL,
+ "device sent more data than requested");
break;
default:
- g_set_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_INTERNAL,
- "unknown status [%i]", status);
+ g_set_error(error,
+ G_USB_DEVICE_ERROR,
+ G_USB_DEVICE_ERROR_INTERNAL,
+ "unknown status [%i]",
+ status);
}
return ret;
}
static void
-g_usb_device_async_transfer_cb (struct libusb_transfer *transfer)
+g_usb_device_async_transfer_cb(struct libusb_transfer *transfer)
{
GTask *task = transfer->user_data;
gboolean ret;
GError *error = NULL;
/* did request fail? */
- ret = g_usb_device_libusb_status_to_gerror (transfer->status, &error);
+ ret = g_usb_device_libusb_status_to_gerror(transfer->status, &error);
if (!ret) {
- g_task_return_error (task, error);
+ g_task_return_error(task, error);
} else {
- g_task_return_int (task, transfer->actual_length);
+ g_task_return_int(task, transfer->actual_length);
}
- g_object_unref (task);
+ g_object_unref(task);
}
static void
-g_usb_device_cancelled_cb (GCancellable *cancellable,
- GcmDeviceReq *req)
+g_usb_device_cancelled_cb(GCancellable *cancellable, GcmDeviceReq *req)
{
- libusb_cancel_transfer (req->transfer);
+ libusb_cancel_transfer(req->transfer);
}
static void
-g_usb_device_control_transfer_cb (struct libusb_transfer *transfer)
+g_usb_device_control_transfer_cb(struct libusb_transfer *transfer)
{
GTask *task = transfer->user_data;
- GcmDeviceReq *req = g_task_get_task_data (task);
+ GcmDeviceReq *req = g_task_get_task_data(task);
gboolean ret;
GError *error = NULL;
/* did request fail? */
- ret = g_usb_device_libusb_status_to_gerror (transfer->status,
- &error);
+ ret = g_usb_device_libusb_status_to_gerror(transfer->status, &error);
if (!ret) {
- g_task_return_error (task, error);
+ g_task_return_error(task, error);
} else {
- memmove (req->data,
- transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE,
- (gsize) transfer->actual_length);
- g_task_return_int (task, transfer->actual_length);
+ memmove(req->data,
+ transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE,
+ (gsize)transfer->actual_length);
+ g_task_return_int(task, transfer->actual_length);
}
- g_object_unref (task);
+ g_object_unref(task);
}
/**
@@ -1430,19 +1406,19 @@ g_usb_device_control_transfer_cb (struct libusb_transfer *transfer)
* Since: 0.1.0
**/
void
-g_usb_device_control_transfer_async (GUsbDevice *device,
- GUsbDeviceDirection direction,
- GUsbDeviceRequestType request_type,
- GUsbDeviceRecipient recipient,
- guint8 request,
- guint16 value,
- guint16 idx,
- guint8 *data,
- gsize length,
- guint timeout,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+g_usb_device_control_transfer_async(GUsbDevice *device,
+ GUsbDeviceDirection direction,
+ GUsbDeviceRequestType request_type,
+ GUsbDeviceRecipient recipient,
+ guint8 request,
+ guint16 value,
+ guint16 idx,
+ guint8 *data,
+ gsize length,
+ guint timeout,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GTask *task;
GcmDeviceReq *req;
@@ -1450,23 +1426,25 @@ g_usb_device_control_transfer_async (GUsbDevice *device,
guint8 request_type_raw = 0;
GError *error = NULL;
- g_return_if_fail (G_USB_IS_DEVICE (device));
+ g_return_if_fail(G_USB_IS_DEVICE(device));
if (device->priv->handle == NULL) {
- g_usb_device_async_not_open_error (device, callback, user_data,
- g_usb_device_control_transfer_async);
+ g_usb_device_async_not_open_error(device,
+ callback,
+ user_data,
+ g_usb_device_control_transfer_async);
return;
}
- req = g_slice_new0 (GcmDeviceReq);
- req->transfer = libusb_alloc_transfer (0);
+ req = g_slice_new0(GcmDeviceReq);
+ req->transfer = libusb_alloc_transfer(0);
req->data = data;
- task = g_task_new (device, cancellable, callback, user_data);
- g_task_set_task_data (task, req, (GDestroyNotify)g_usb_device_req_free);
+ task = g_task_new(device, cancellable, callback, user_data);
+ g_task_set_task_data(task, req, (GDestroyNotify)g_usb_device_req_free);
- if (g_task_return_error_if_cancelled (task)) {
- g_object_unref (task);
+ if (g_task_return_error_if_cancelled(task)) {
+ g_object_unref(task);
return;
}
@@ -1476,36 +1454,35 @@ g_usb_device_control_transfer_async (GUsbDevice *device,
request_type_raw |= (request_type << 5);
request_type_raw |= recipient;
- req->data_raw = g_malloc0 (length + LIBUSB_CONTROL_SETUP_SIZE);
- memmove (req->data_raw + LIBUSB_CONTROL_SETUP_SIZE, data, length);
+ req->data_raw = g_malloc0(length + LIBUSB_CONTROL_SETUP_SIZE);
+ memmove(req->data_raw + LIBUSB_CONTROL_SETUP_SIZE, data, length);
/* fill in setup packet */
- libusb_fill_control_setup (req->data_raw, request_type_raw,
- request, value, idx, length);
+ libusb_fill_control_setup(req->data_raw, request_type_raw, request, value, idx, length);
/* fill in transfer details */
- libusb_fill_control_transfer (req->transfer,
- device->priv->handle,
- req->data_raw,
- g_usb_device_control_transfer_cb,
- task,
- timeout);
+ libusb_fill_control_transfer(req->transfer,
+ device->priv->handle,
+ req->data_raw,
+ g_usb_device_control_transfer_cb,
+ task,
+ timeout);
/* submit transfer */
- rc = libusb_submit_transfer (req->transfer);
+ rc = libusb_submit_transfer(req->transfer);
if (rc < 0) {
- g_usb_device_libusb_error_to_gerror (device, rc, &error);
- g_task_return_error (task, error);
- g_object_unref (task);
+ g_usb_device_libusb_error_to_gerror(device, rc, &error);
+ g_task_return_error(task, error);
+ g_object_unref(task);
}
/* setup cancellation after submission */
if (cancellable != NULL) {
- req->cancellable = g_object_ref (cancellable);
- req->cancellable_id = g_cancellable_connect (req->cancellable,
- G_CALLBACK (g_usb_device_cancelled_cb),
- req,
- NULL);
+ req->cancellable = g_object_ref(cancellable);
+ req->cancellable_id = g_cancellable_connect(req->cancellable,
+ G_CALLBACK(g_usb_device_cancelled_cb),
+ req,
+ NULL);
}
}
@@ -1522,15 +1499,13 @@ g_usb_device_control_transfer_async (GUsbDevice *device,
* Since: 0.1.0
**/
gssize
-g_usb_device_control_transfer_finish (GUsbDevice *device,
- GAsyncResult *res,
- GError **error)
+g_usb_device_control_transfer_finish(GUsbDevice *device, GAsyncResult *res, GError **error)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), -1);
- g_return_val_if_fail (g_task_is_valid (res, device), -1);
- g_return_val_if_fail (error == NULL || *error == NULL, -1);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), -1);
+ g_return_val_if_fail(g_task_is_valid(res, device), -1);
+ g_return_val_if_fail(error == NULL || *error == NULL, -1);
- return g_task_propagate_int (G_TASK (res), error);
+ return g_task_propagate_int(G_TASK(res), error);
}
/**
@@ -1552,64 +1527,66 @@ g_usb_device_control_transfer_finish (GUsbDevice *device,
* Since: 0.1.0
**/
void
-g_usb_device_bulk_transfer_async (GUsbDevice *device,
- guint8 endpoint,
- guint8 *data,
- gsize length,
- guint timeout,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+g_usb_device_bulk_transfer_async(GUsbDevice *device,
+ guint8 endpoint,
+ guint8 *data,
+ gsize length,
+ guint timeout,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GTask *task;
GcmDeviceReq *req;
gint rc;
GError *error = NULL;
- g_return_if_fail (G_USB_IS_DEVICE (device));
+ g_return_if_fail(G_USB_IS_DEVICE(device));
if (device->priv->handle == NULL) {
- g_usb_device_async_not_open_error (device, callback, user_data,
- g_usb_device_bulk_transfer_async);
+ g_usb_device_async_not_open_error(device,
+ callback,
+ user_data,
+ g_usb_device_bulk_transfer_async);
return;
}
- req = g_slice_new0 (GcmDeviceReq);
- req->transfer = libusb_alloc_transfer (0);
+ req = g_slice_new0(GcmDeviceReq);
+ req->transfer = libusb_alloc_transfer(0);
- task = g_task_new (device, cancellable, callback, user_data);
- g_task_set_task_data (task, req, (GDestroyNotify)g_usb_device_req_free);
+ task = g_task_new(device, cancellable, callback, user_data);
+ g_task_set_task_data(task, req, (GDestroyNotify)g_usb_device_req_free);
- if (g_task_return_error_if_cancelled (task)) {
- g_object_unref (task);
+ if (g_task_return_error_if_cancelled(task)) {
+ g_object_unref(task);
return;
}
/* fill in transfer details */
- libusb_fill_bulk_transfer (req->transfer,
- device->priv->handle,
- endpoint,
- data,
- length,
- g_usb_device_async_transfer_cb,
- task,
- timeout);
+ libusb_fill_bulk_transfer(req->transfer,
+ device->priv->handle,
+ endpoint,
+ data,
+ length,
+ g_usb_device_async_transfer_cb,
+ task,
+ timeout);
/* submit transfer */
- rc = libusb_submit_transfer (req->transfer);
+ rc = libusb_submit_transfer(req->transfer);
if (rc < 0) {
- g_usb_device_libusb_error_to_gerror (device, rc, &error);
- g_task_return_error (task, error);
- g_object_unref (task);
+ g_usb_device_libusb_error_to_gerror(device, rc, &error);
+ g_task_return_error(task, error);
+ g_object_unref(task);
}
/* setup cancellation after submission */
if (cancellable != NULL) {
- req->cancellable = g_object_ref (cancellable);
- req->cancellable_id = g_cancellable_connect (req->cancellable,
- G_CALLBACK (g_usb_device_cancelled_cb),
- req,
- NULL);
+ req->cancellable = g_object_ref(cancellable);
+ req->cancellable_id = g_cancellable_connect(req->cancellable,
+ G_CALLBACK(g_usb_device_cancelled_cb),
+ req,
+ NULL);
}
}
@@ -1626,15 +1603,13 @@ g_usb_device_bulk_transfer_async (GUsbDevice *device,
* Since: 0.1.0
**/
gssize
-g_usb_device_bulk_transfer_finish (GUsbDevice *device,
- GAsyncResult *res,
- GError **error)
+g_usb_device_bulk_transfer_finish(GUsbDevice *device, GAsyncResult *res, GError **error)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), -1);
- g_return_val_if_fail (g_task_is_valid (res, device), -1);
- g_return_val_if_fail (error == NULL || *error == NULL, -1);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), -1);
+ g_return_val_if_fail(g_task_is_valid(res, device), -1);
+ g_return_val_if_fail(error == NULL || *error == NULL, -1);
- return g_task_propagate_int (G_TASK (res), error);
+ return g_task_propagate_int(G_TASK(res), error);
}
/**
@@ -1656,64 +1631,66 @@ g_usb_device_bulk_transfer_finish (GUsbDevice *device,
* Since: 0.1.0
**/
void
-g_usb_device_interrupt_transfer_async (GUsbDevice *device,
- guint8 endpoint,
- guint8 *data,
- gsize length,
- guint timeout,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data)
+g_usb_device_interrupt_transfer_async(GUsbDevice *device,
+ guint8 endpoint,
+ guint8 *data,
+ gsize length,
+ guint timeout,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
{
GTask *task;
GcmDeviceReq *req;
GError *error = NULL;
gint rc;
- g_return_if_fail (G_USB_IS_DEVICE (device));
+ g_return_if_fail(G_USB_IS_DEVICE(device));
if (device->priv->handle == NULL) {
- g_usb_device_async_not_open_error (device, callback, user_data,
- g_usb_device_interrupt_transfer_async);
+ g_usb_device_async_not_open_error(device,
+ callback,
+ user_data,
+ g_usb_device_interrupt_transfer_async);
return;
}
- req = g_slice_new0 (GcmDeviceReq);
- req->transfer = libusb_alloc_transfer (0);
+ req = g_slice_new0(GcmDeviceReq);
+ req->transfer = libusb_alloc_transfer(0);
- task = g_task_new (device, cancellable, callback, user_data);
- g_task_set_task_data (task, req, (GDestroyNotify)g_usb_device_req_free);
+ task = g_task_new(device, cancellable, callback, user_data);
+ g_task_set_task_data(task, req, (GDestroyNotify)g_usb_device_req_free);
- if (g_task_return_error_if_cancelled (task)) {
- g_object_unref (task);
+ if (g_task_return_error_if_cancelled(task)) {
+ g_object_unref(task);
return;
}
/* fill in transfer details */
- libusb_fill_interrupt_transfer (req->transfer,
- device->priv->handle,
- endpoint,
- data,
- length,
- g_usb_device_async_transfer_cb,
- task,
- timeout);
+ libusb_fill_interrupt_transfer(req->transfer,
+ device->priv->handle,
+ endpoint,
+ data,
+ length,
+ g_usb_device_async_transfer_cb,
+ task,
+ timeout);
/* submit transfer */
- rc = libusb_submit_transfer (req->transfer);
+ rc = libusb_submit_transfer(req->transfer);
if (rc < 0) {
- g_usb_device_libusb_error_to_gerror (device, rc, &error);
- g_task_return_error (task, error);
- g_object_unref (task);
+ g_usb_device_libusb_error_to_gerror(device, rc, &error);
+ g_task_return_error(task, error);
+ g_object_unref(task);
}
/* setup cancellation after submission */
if (cancellable != NULL) {
- req->cancellable = g_object_ref (cancellable);
- req->cancellable_id = g_cancellable_connect (req->cancellable,
- G_CALLBACK (g_usb_device_cancelled_cb),
- req,
- NULL);
+ req->cancellable = g_object_ref(cancellable);
+ req->cancellable_id = g_cancellable_connect(req->cancellable,
+ G_CALLBACK(g_usb_device_cancelled_cb),
+ req,
+ NULL);
}
}
@@ -1730,15 +1707,13 @@ g_usb_device_interrupt_transfer_async (GUsbDevice *device,
* Since: 0.1.0
**/
gssize
-g_usb_device_interrupt_transfer_finish (GUsbDevice *device,
- GAsyncResult *res,
- GError **error)
+g_usb_device_interrupt_transfer_finish(GUsbDevice *device, GAsyncResult *res, GError **error)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), -1);
- g_return_val_if_fail (g_task_is_valid (res, device), -1);
- g_return_val_if_fail (error == NULL || *error == NULL, -1);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), -1);
+ g_return_val_if_fail(g_task_is_valid(res, device), -1);
+ g_return_val_if_fail(error == NULL || *error == NULL, -1);
- return g_task_propagate_int (G_TASK (res), error);
+ return g_task_propagate_int(G_TASK(res), error);
}
/**
@@ -1755,9 +1730,9 @@ g_usb_device_interrupt_transfer_finish (GUsbDevice *device,
* Since: 0.1.1
**/
const gchar *
-g_usb_device_get_platform_id (GUsbDevice *device)
+g_usb_device_get_platform_id(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
return device->priv->platform_id;
}
@@ -1773,19 +1748,19 @@ g_usb_device_get_platform_id (GUsbDevice *device)
* Since: 0.2.4
**/
GUsbDevice *
-g_usb_device_get_parent (GUsbDevice *device)
+g_usb_device_get_parent(GUsbDevice *device)
{
GUsbDevicePrivate *priv = device->priv;
libusb_device *parent;
- parent = libusb_get_parent (priv->device);
+ parent = libusb_get_parent(priv->device);
if (parent == NULL)
return NULL;
- return g_usb_context_find_by_bus_address (priv->context,
- libusb_get_bus_number (parent),
- libusb_get_device_address (parent),
- NULL);
+ return g_usb_context_find_by_bus_address(priv->context,
+ libusb_get_bus_number(parent),
+ libusb_get_device_address(parent),
+ NULL);
}
/**
@@ -1799,7 +1774,7 @@ g_usb_device_get_parent (GUsbDevice *device)
* Since: 0.2.4
**/
GPtrArray *
-g_usb_device_get_children (GUsbDevice *device)
+g_usb_device_get_children(GUsbDevice *device)
{
GPtrArray *children;
GUsbDevice *device_tmp;
@@ -1807,12 +1782,12 @@ g_usb_device_get_children (GUsbDevice *device)
g_autoptr(GPtrArray) devices = NULL;
/* find any devices that have @device as a parent */
- children = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
- devices = g_usb_context_get_devices (priv->context);
+ children = g_ptr_array_new_with_free_func((GDestroyNotify)g_object_unref);
+ devices = g_usb_context_get_devices(priv->context);
for (guint i = 0; i < devices->len; i++) {
- device_tmp = g_ptr_array_index (devices, i);
- if (priv->device == libusb_get_parent (device_tmp->priv->device))
- g_ptr_array_add (children, g_object_ref (device_tmp));
+ device_tmp = g_ptr_array_index(devices, i);
+ if (priv->device == libusb_get_parent(device_tmp->priv->device))
+ g_ptr_array_add(children, g_object_ref(device_tmp));
}
return children;
@@ -1829,11 +1804,11 @@ g_usb_device_get_children (GUsbDevice *device)
* Since: 0.1.0
**/
guint8
-g_usb_device_get_bus (GUsbDevice *device)
+g_usb_device_get_bus(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
- return libusb_get_bus_number (device->priv->device);
+ return libusb_get_bus_number(device->priv->device);
}
/**
@@ -1847,11 +1822,11 @@ g_usb_device_get_bus (GUsbDevice *device)
* Since: 0.1.0
**/
guint8
-g_usb_device_get_address (GUsbDevice *device)
+g_usb_device_get_address(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
- return libusb_get_device_address (device->priv->device);
+ return libusb_get_device_address(device->priv->device);
}
/**
@@ -1865,10 +1840,10 @@ g_usb_device_get_address (GUsbDevice *device)
* Since: 0.2.4
**/
guint8
-g_usb_device_get_port_number (GUsbDevice *device)
+g_usb_device_get_port_number(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
- return libusb_get_port_number (device->priv->device);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
+ return libusb_get_port_number(device->priv->device);
}
/**
@@ -1882,9 +1857,9 @@ g_usb_device_get_port_number (GUsbDevice *device)
* Since: 0.1.0
**/
guint16
-g_usb_device_get_vid (GUsbDevice *device)
+g_usb_device_get_vid(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.idVendor;
}
@@ -1900,9 +1875,9 @@ g_usb_device_get_vid (GUsbDevice *device)
* Since: 0.1.0
**/
guint16
-g_usb_device_get_pid (GUsbDevice *device)
+g_usb_device_get_pid(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.idProduct;
}
@@ -1918,9 +1893,9 @@ g_usb_device_get_pid (GUsbDevice *device)
* Since: 0.2.8
**/
guint16
-g_usb_device_get_release (GUsbDevice *device)
+g_usb_device_get_release(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.bcdDevice;
}
@@ -1937,9 +1912,9 @@ g_usb_device_get_release (GUsbDevice *device)
* Since: 0.3.1
**/
guint16
-g_usb_device_get_spec (GUsbDevice *device)
+g_usb_device_get_spec(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.bcdUSB;
}
@@ -1955,12 +1930,12 @@ g_usb_device_get_spec (GUsbDevice *device)
* Since: 0.2.4
**/
const gchar *
-g_usb_device_get_vid_as_str (GUsbDevice *device)
+g_usb_device_get_vid_as_str(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
- return _g_usb_context_lookup_vendor (device->priv->context,
- device->priv->desc.idVendor,
- NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
+ return _g_usb_context_lookup_vendor(device->priv->context,
+ device->priv->desc.idVendor,
+ NULL);
}
/**
@@ -1974,13 +1949,13 @@ g_usb_device_get_vid_as_str (GUsbDevice *device)
* Since: 0.2.4
**/
const gchar *
-g_usb_device_get_pid_as_str (GUsbDevice *device)
+g_usb_device_get_pid_as_str(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), NULL);
- return _g_usb_context_lookup_product (device->priv->context,
- device->priv->desc.idVendor,
- device->priv->desc.idProduct,
- NULL);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), NULL);
+ return _g_usb_context_lookup_product(device->priv->context,
+ device->priv->desc.idVendor,
+ device->priv->desc.idProduct,
+ NULL);
}
/**
@@ -1995,24 +1970,23 @@ g_usb_device_get_pid_as_str (GUsbDevice *device)
* Since: 0.3.5
**/
guint8
-g_usb_device_get_configuration_index (GUsbDevice *device)
+g_usb_device_get_configuration_index(GUsbDevice *device)
{
struct libusb_config_descriptor *config;
gint rc;
guint8 index;
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
- rc = libusb_get_active_config_descriptor (device->priv->device, &config);
- g_return_val_if_fail (rc == 0, 0);
+ rc = libusb_get_active_config_descriptor(device->priv->device, &config);
+ g_return_val_if_fail(rc == 0, 0);
index = config->iConfiguration;
- libusb_free_config_descriptor (config);
+ libusb_free_config_descriptor(config);
return index;
}
-
/**
* g_usb_device_get_manufacturer_index:
* @device: a #GUsbDevice
@@ -2024,9 +1998,9 @@ g_usb_device_get_configuration_index (GUsbDevice *device)
* Since: 0.1.0
**/
guint8
-g_usb_device_get_manufacturer_index (GUsbDevice *device)
+g_usb_device_get_manufacturer_index(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.iManufacturer;
}
@@ -2042,9 +2016,9 @@ g_usb_device_get_manufacturer_index (GUsbDevice *device)
* Since: 0.1.7
**/
guint8
-g_usb_device_get_device_class (GUsbDevice *device)
+g_usb_device_get_device_class(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.bDeviceClass;
}
@@ -2061,9 +2035,9 @@ g_usb_device_get_device_class (GUsbDevice *device)
* Since: 0.2.4
**/
guint8
-g_usb_device_get_device_subclass (GUsbDevice *device)
+g_usb_device_get_device_subclass(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.bDeviceSubClass;
}
@@ -2080,9 +2054,9 @@ g_usb_device_get_device_subclass (GUsbDevice *device)
* Since: 0.2.4
**/
guint8
-g_usb_device_get_device_protocol (GUsbDevice *device)
+g_usb_device_get_device_protocol(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.bDeviceProtocol;
}
@@ -2098,9 +2072,9 @@ g_usb_device_get_device_protocol (GUsbDevice *device)
* Since: 0.1.0
**/
guint8
-g_usb_device_get_product_index (GUsbDevice *device)
+g_usb_device_get_product_index(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.iProduct;
}
@@ -2116,9 +2090,9 @@ g_usb_device_get_product_index (GUsbDevice *device)
* Since: 0.1.0
**/
guint8
-g_usb_device_get_serial_number_index (GUsbDevice *device)
+g_usb_device_get_serial_number_index(GUsbDevice *device)
{
- g_return_val_if_fail (G_USB_IS_DEVICE (device), 0);
+ g_return_val_if_fail(G_USB_IS_DEVICE(device), 0);
return device->priv->desc.iSerialNumber;
}
diff --git a/gusb/gusb-device.h b/gusb/gusb-device.h
index a4f6140..633af23 100644
--- a/gusb/gusb-device.h
+++ b/gusb/gusb-device.h
@@ -9,21 +9,20 @@
#pragma once
#include <gio/gio.h>
-
-#include <gusb/gusb-util.h>
-#include <gusb/gusb-interface.h>
#include <gusb/gusb-bos-descriptor.h>
+#include <gusb/gusb-interface.h>
+#include <gusb/gusb-util.h>
G_BEGIN_DECLS
-#define G_USB_TYPE_DEVICE (g_usb_device_get_type ())
-#define G_USB_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_USB_TYPE_DEVICE, GUsbDevice))
-#define G_USB_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_USB_TYPE_DEVICE))
-#define G_USB_DEVICE_ERROR (g_usb_device_error_quark ())
+#define G_USB_TYPE_DEVICE (g_usb_device_get_type())
+#define G_USB_DEVICE(o) (G_TYPE_CHECK_INSTANCE_CAST((o), G_USB_TYPE_DEVICE, GUsbDevice))
+#define G_USB_IS_DEVICE(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), G_USB_TYPE_DEVICE))
+#define G_USB_DEVICE_ERROR (g_usb_device_error_quark())
-typedef struct _GUsbDevicePrivate GUsbDevicePrivate;
-typedef struct _GUsbDevice GUsbDevice;
-typedef struct _GUsbDeviceClass GUsbDeviceClass;
+typedef struct _GUsbDevicePrivate GUsbDevicePrivate;
+typedef struct _GUsbDevice GUsbDevice;
+typedef struct _GUsbDeviceClass GUsbDeviceClass;
/**
* GUsbDeviceDirection:
@@ -85,8 +84,8 @@ typedef enum {
* g_usb_device_release_interface methods flags parameters.
**/
typedef enum {
- G_USB_DEVICE_CLAIM_INTERFACE_NONE = 0,
- G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER = 1 << 0,
+ G_USB_DEVICE_CLAIM_INTERFACE_NONE = 0,
+ G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER = 1 << 0,
} GUsbDeviceClaimInterfaceFlags;
/**
@@ -95,49 +94,46 @@ typedef enum {
* The USB device class.
**/
typedef enum {
- G_USB_DEVICE_CLASS_INTERFACE_DESC = 0x00,
- G_USB_DEVICE_CLASS_AUDIO = 0x01,
- G_USB_DEVICE_CLASS_COMMUNICATIONS = 0x02,
- G_USB_DEVICE_CLASS_HID = 0x03,
- G_USB_DEVICE_CLASS_PHYSICAL = 0x05,
- G_USB_DEVICE_CLASS_IMAGE = 0x06,
- G_USB_DEVICE_CLASS_PRINTER = 0x07,
- G_USB_DEVICE_CLASS_MASS_STORAGE = 0x08,
- G_USB_DEVICE_CLASS_HUB = 0x09,
- G_USB_DEVICE_CLASS_CDC_DATA = 0x0a,
- G_USB_DEVICE_CLASS_SMART_CARD = 0x0b,
- G_USB_DEVICE_CLASS_CONTENT_SECURITY = 0x0d,
- G_USB_DEVICE_CLASS_VIDEO = 0x0e,
- G_USB_DEVICE_CLASS_PERSONAL_HEALTHCARE = 0x0f,
- G_USB_DEVICE_CLASS_AUDIO_VIDEO = 0x10,
- G_USB_DEVICE_CLASS_BILLBOARD = 0x11,
- G_USB_DEVICE_CLASS_DIAGNOSTIC = 0xdc,
- G_USB_DEVICE_CLASS_WIRELESS_CONTROLLER = 0xe0,
- G_USB_DEVICE_CLASS_MISCELLANEOUS = 0xef,
- G_USB_DEVICE_CLASS_APPLICATION_SPECIFIC = 0xfe,
- G_USB_DEVICE_CLASS_VENDOR_SPECIFIC = 0xff
+ G_USB_DEVICE_CLASS_INTERFACE_DESC = 0x00,
+ G_USB_DEVICE_CLASS_AUDIO = 0x01,
+ G_USB_DEVICE_CLASS_COMMUNICATIONS = 0x02,
+ G_USB_DEVICE_CLASS_HID = 0x03,
+ G_USB_DEVICE_CLASS_PHYSICAL = 0x05,
+ G_USB_DEVICE_CLASS_IMAGE = 0x06,
+ G_USB_DEVICE_CLASS_PRINTER = 0x07,
+ G_USB_DEVICE_CLASS_MASS_STORAGE = 0x08,
+ G_USB_DEVICE_CLASS_HUB = 0x09,
+ G_USB_DEVICE_CLASS_CDC_DATA = 0x0a,
+ G_USB_DEVICE_CLASS_SMART_CARD = 0x0b,
+ G_USB_DEVICE_CLASS_CONTENT_SECURITY = 0x0d,
+ G_USB_DEVICE_CLASS_VIDEO = 0x0e,
+ G_USB_DEVICE_CLASS_PERSONAL_HEALTHCARE = 0x0f,
+ G_USB_DEVICE_CLASS_AUDIO_VIDEO = 0x10,
+ G_USB_DEVICE_CLASS_BILLBOARD = 0x11,
+ G_USB_DEVICE_CLASS_DIAGNOSTIC = 0xdc,
+ G_USB_DEVICE_CLASS_WIRELESS_CONTROLLER = 0xe0,
+ G_USB_DEVICE_CLASS_MISCELLANEOUS = 0xef,
+ G_USB_DEVICE_CLASS_APPLICATION_SPECIFIC = 0xfe,
+ G_USB_DEVICE_CLASS_VENDOR_SPECIFIC = 0xff
} GUsbDeviceClassCode;
-
/**
* GUsbDeviceLangid:
*
* The USB language ID.
**/
typedef enum {
- G_USB_DEVICE_LANGID_INVALID = 0x0000,
- G_USB_DEVICE_LANGID_ENGLISH_UNITED_STATES = 0x0409,
+ G_USB_DEVICE_LANGID_INVALID = 0x0000,
+ G_USB_DEVICE_LANGID_ENGLISH_UNITED_STATES = 0x0409,
} GUsbDeviceLangid;
-struct _GUsbDevice
-{
- GObject parent;
- GUsbDevicePrivate *priv;
+struct _GUsbDevice {
+ GObject parent;
+ GUsbDevicePrivate *priv;
};
-struct _GUsbDeviceClass
-{
- GObjectClass parent_class;
+struct _GUsbDeviceClass {
+ GObjectClass parent_class;
/*< private >*/
/*
* If adding fields to this struct, remove corresponding
@@ -146,165 +142,190 @@ struct _GUsbDeviceClass
gchar _gusb_reserved[64];
};
-GType g_usb_device_get_type (void);
-GQuark g_usb_device_error_quark (void);
-
-const gchar *g_usb_device_get_platform_id (GUsbDevice *device);
-GUsbDevice *g_usb_device_get_parent (GUsbDevice *device);
-GPtrArray *g_usb_device_get_children (GUsbDevice *device);
-
-guint8 g_usb_device_get_bus (GUsbDevice *device);
-guint8 g_usb_device_get_address (GUsbDevice *device);
-guint8 g_usb_device_get_port_number (GUsbDevice *device);
-
-guint16 g_usb_device_get_vid (GUsbDevice *device);
-guint16 g_usb_device_get_pid (GUsbDevice *device);
-guint16 g_usb_device_get_release (GUsbDevice *device);
-guint16 g_usb_device_get_spec (GUsbDevice *device);
-const gchar *g_usb_device_get_vid_as_str (GUsbDevice *device);
-const gchar *g_usb_device_get_pid_as_str (GUsbDevice *device);
-guint8 g_usb_device_get_device_class (GUsbDevice *device);
-guint8 g_usb_device_get_device_subclass (GUsbDevice *device);
-guint8 g_usb_device_get_device_protocol (GUsbDevice *device);
-
-guint8 g_usb_device_get_configuration_index (GUsbDevice *device);
-guint8 g_usb_device_get_manufacturer_index (GUsbDevice *device);
-guint8 g_usb_device_get_product_index (GUsbDevice *device);
-guint8 g_usb_device_get_serial_number_index (GUsbDevice *device);
-guint8 g_usb_device_get_custom_index (GUsbDevice *device,
- guint8 class_id,
- guint8 subclass_id,
- guint8 protocol_id,
- GError **error);
-
-GUsbInterface *g_usb_device_get_interface (GUsbDevice *device,
- guint8 class_id,
- guint8 subclass_id,
- guint8 protocol_id,
- GError **error);
-GPtrArray *g_usb_device_get_interfaces (GUsbDevice *device,
- GError **error);
-
-GPtrArray *g_usb_device_get_bos_descriptors(GUsbDevice *device,
- GError **error);
-GUsbBosDescriptor *g_usb_device_get_bos_descriptor(GUsbDevice *device,
- guint8 capability,
- GError **error);
-
-gboolean g_usb_device_open (GUsbDevice *device,
- GError **error);
-gboolean g_usb_device_close (GUsbDevice *device,
- GError **error);
-
-gboolean g_usb_device_reset (GUsbDevice *device,
- GError **error);
-
-gint g_usb_device_get_configuration (GUsbDevice *device,
- GError **error);
-gboolean g_usb_device_set_configuration (GUsbDevice *device,
- gint configuration,
- GError **error);
-
-gboolean g_usb_device_claim_interface (GUsbDevice *device,
- gint interface,
- GUsbDeviceClaimInterfaceFlags flags,
- GError **error);
-gboolean g_usb_device_release_interface (GUsbDevice *device,
- gint interface,
- GUsbDeviceClaimInterfaceFlags flags,
- GError **error);
-gboolean g_usb_device_set_interface_alt (GUsbDevice *device,
- gint interface,
- guint8 alt,
- GError **error);
-
-gchar *g_usb_device_get_string_descriptor (GUsbDevice *device,
- guint8 desc_index,
- GError **error);
-GBytes *g_usb_device_get_string_descriptor_bytes (GUsbDevice *device,
- guint8 desc_index,
- guint16 langid,
- GError **error);
-GBytes *g_usb_device_get_string_descriptor_bytes_full (GUsbDevice *device,
- guint8 desc_index,
- guint16 langid,
- gsize length,
- GError **error);
+GType
+g_usb_device_get_type(void);
+GQuark
+g_usb_device_error_quark(void);
+
+const gchar *
+g_usb_device_get_platform_id(GUsbDevice *device);
+GUsbDevice *
+g_usb_device_get_parent(GUsbDevice *device);
+GPtrArray *
+g_usb_device_get_children(GUsbDevice *device);
+
+guint8
+g_usb_device_get_bus(GUsbDevice *device);
+guint8
+g_usb_device_get_address(GUsbDevice *device);
+guint8
+g_usb_device_get_port_number(GUsbDevice *device);
+
+guint16
+g_usb_device_get_vid(GUsbDevice *device);
+guint16
+g_usb_device_get_pid(GUsbDevice *device);
+guint16
+g_usb_device_get_release(GUsbDevice *device);
+guint16
+g_usb_device_get_spec(GUsbDevice *device);
+const gchar *
+g_usb_device_get_vid_as_str(GUsbDevice *device);
+const gchar *
+g_usb_device_get_pid_as_str(GUsbDevice *device);
+guint8
+g_usb_device_get_device_class(GUsbDevice *device);
+guint8
+g_usb_device_get_device_subclass(GUsbDevice *device);
+guint8
+g_usb_device_get_device_protocol(GUsbDevice *device);
+
+guint8
+g_usb_device_get_configuration_index(GUsbDevice *device);
+guint8
+g_usb_device_get_manufacturer_index(GUsbDevice *device);
+guint8
+g_usb_device_get_product_index(GUsbDevice *device);
+guint8
+g_usb_device_get_serial_number_index(GUsbDevice *device);
+guint8
+g_usb_device_get_custom_index(GUsbDevice *device,
+ guint8 class_id,
+ guint8 subclass_id,
+ guint8 protocol_id,
+ GError **error);
+
+GUsbInterface *
+g_usb_device_get_interface(GUsbDevice *device,
+ guint8 class_id,
+ guint8 subclass_id,
+ guint8 protocol_id,
+ GError **error);
+GPtrArray *
+g_usb_device_get_interfaces(GUsbDevice *device, GError **error);
+
+GPtrArray *
+g_usb_device_get_bos_descriptors(GUsbDevice *device, GError **error);
+GUsbBosDescriptor *
+g_usb_device_get_bos_descriptor(GUsbDevice *device, guint8 capability, GError **error);
+
+gboolean
+g_usb_device_open(GUsbDevice *device, GError **error);
+gboolean
+g_usb_device_close(GUsbDevice *device, GError **error);
+
+gboolean
+g_usb_device_reset(GUsbDevice *device, GError **error);
+
+gint
+g_usb_device_get_configuration(GUsbDevice *device, GError **error);
+gboolean
+g_usb_device_set_configuration(GUsbDevice *device, gint configuration, GError **error);
+
+gboolean
+g_usb_device_claim_interface(GUsbDevice *device,
+ gint interface,
+ GUsbDeviceClaimInterfaceFlags flags,
+ GError **error);
+gboolean
+g_usb_device_release_interface(GUsbDevice *device,
+ gint interface,
+ GUsbDeviceClaimInterfaceFlags flags,
+ GError **error);
+gboolean
+g_usb_device_set_interface_alt(GUsbDevice *device, gint interface, guint8 alt, GError **error);
+
+gchar *
+g_usb_device_get_string_descriptor(GUsbDevice *device, guint8 desc_index, GError **error);
+GBytes *
+g_usb_device_get_string_descriptor_bytes(GUsbDevice *device,
+ guint8 desc_index,
+ guint16 langid,
+ GError **error);
+GBytes *
+g_usb_device_get_string_descriptor_bytes_full(GUsbDevice *device,
+ guint8 desc_index,
+ guint16 langid,
+ gsize length,
+ GError **error);
/* sync -- TODO: use GCancellable and GUsbSource */
-gboolean g_usb_device_control_transfer (GUsbDevice *device,
- GUsbDeviceDirection direction,
- GUsbDeviceRequestType request_type,
- GUsbDeviceRecipient recipient,
- guint8 request,
- guint16 value,
- guint16 idx,
- guint8 *data,
- gsize length,
- gsize *actual_length,
- guint timeout,
- GCancellable *cancellable,
- GError **error);
-
-gboolean g_usb_device_bulk_transfer (GUsbDevice *device,
- guint8 endpoint,
- guint8 *data,
- gsize length,
- gsize *actual_length,
- guint timeout,
- GCancellable *cancellable,
- GError **error);
-
-gboolean g_usb_device_interrupt_transfer (GUsbDevice *device,
- guint8 endpoint,
- guint8 *data,
- gsize length,
- gsize *actual_length,
- guint timeout,
- GCancellable *cancellable,
- GError **error);
+gboolean
+g_usb_device_control_transfer(GUsbDevice *device,
+ GUsbDeviceDirection direction,
+ GUsbDeviceRequestType request_type,
+ GUsbDeviceRecipient recipient,
+ guint8 request,
+ guint16 value,
+ guint16 idx,
+ guint8 *data,
+ gsize length,
+ gsize *actual_length,
+ guint timeout,
+ GCancellable *cancellable,
+ GError **error);
+
+gboolean
+g_usb_device_bulk_transfer(GUsbDevice *device,
+ guint8 endpoint,
+ guint8 *data,
+ gsize length,
+ gsize *actual_length,
+ guint timeout,
+ GCancellable *cancellable,
+ GError **error);
+
+gboolean
+g_usb_device_interrupt_transfer(GUsbDevice *device,
+ guint8 endpoint,
+ guint8 *data,
+ gsize length,
+ gsize *actual_length,
+ guint timeout,
+ GCancellable *cancellable,
+ GError **error);
/* async */
-void g_usb_device_control_transfer_async (GUsbDevice *device,
- GUsbDeviceDirection direction,
- GUsbDeviceRequestType request_type,
- GUsbDeviceRecipient recipient,
- guint8 request,
- guint16 value,
- guint16 idx,
- guint8 *data,
- gsize length,
- guint timeout,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gssize g_usb_device_control_transfer_finish (GUsbDevice *device,
- GAsyncResult *res,
- GError **error);
-
-void g_usb_device_bulk_transfer_async (GUsbDevice *device,
- guint8 endpoint,
- guint8 *data,
- gsize length,
- guint timeout,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gssize g_usb_device_bulk_transfer_finish (GUsbDevice *device,
- GAsyncResult *res,
- GError **error);
-
-void g_usb_device_interrupt_transfer_async (GUsbDevice *device,
- guint8 endpoint,
- guint8 *data,
- gsize length,
- guint timeout,
- GCancellable *cancellable,
- GAsyncReadyCallback callback,
- gpointer user_data);
-gssize g_usb_device_interrupt_transfer_finish (GUsbDevice *device,
- GAsyncResult *res,
- GError **error);
+void
+g_usb_device_control_transfer_async(GUsbDevice *device,
+ GUsbDeviceDirection direction,
+ GUsbDeviceRequestType request_type,
+ GUsbDeviceRecipient recipient,
+ guint8 request,
+ guint16 value,
+ guint16 idx,
+ guint8 *data,
+ gsize length,
+ guint timeout,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gssize
+g_usb_device_control_transfer_finish(GUsbDevice *device, GAsyncResult *res, GError **error);
+
+void
+g_usb_device_bulk_transfer_async(GUsbDevice *device,
+ guint8 endpoint,
+ guint8 *data,
+ gsize length,
+ guint timeout,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gssize
+g_usb_device_bulk_transfer_finish(GUsbDevice *device, GAsyncResult *res, GError **error);
+
+void
+g_usb_device_interrupt_transfer_async(GUsbDevice *device,
+ guint8 endpoint,
+ guint8 *data,
+ gsize length,
+ guint timeout,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gssize
+g_usb_device_interrupt_transfer_finish(GUsbDevice *device, GAsyncResult *res, GError **error);
G_END_DECLS
diff --git a/gusb/gusb-endpoint-private.h b/gusb/gusb-endpoint-private.h
index 2646bb9..05bf860 100644
--- a/gusb/gusb-endpoint-private.h
+++ b/gusb/gusb-endpoint-private.h
@@ -7,12 +7,12 @@
#pragma once
-#include <libusb.h>
-
#include <gusb/gusb-endpoint.h>
+#include <libusb.h>
G_BEGIN_DECLS
-GUsbEndpoint *_g_usb_endpoint_new (const struct libusb_endpoint_descriptor *endpoint);
+GUsbEndpoint *
+_g_usb_endpoint_new(const struct libusb_endpoint_descriptor *endpoint);
G_END_DECLS
diff --git a/gusb/gusb-endpoint.c b/gusb/gusb-endpoint.c
index 4758398..ce2b298 100644
--- a/gusb/gusb-endpoint.c
+++ b/gusb/gusb-endpoint.c
@@ -21,36 +21,35 @@
#include "gusb-endpoint-private.h"
-struct _GUsbEndpoint
-{
+struct _GUsbEndpoint {
GObject parent_instance;
struct libusb_endpoint_descriptor endpoint_descriptor;
GBytes *extra;
};
-G_DEFINE_TYPE (GUsbEndpoint, g_usb_endpoint, G_TYPE_OBJECT)
+G_DEFINE_TYPE(GUsbEndpoint, g_usb_endpoint, G_TYPE_OBJECT)
static void
-g_usb_endpoint_finalize (GObject *object)
+g_usb_endpoint_finalize(GObject *object)
{
- GUsbEndpoint *endpoint = G_USB_ENDPOINT (object);
+ GUsbEndpoint *endpoint = G_USB_ENDPOINT(object);
- g_bytes_unref (endpoint->extra);
+ g_bytes_unref(endpoint->extra);
- G_OBJECT_CLASS (g_usb_endpoint_parent_class)->finalize (object);
+ G_OBJECT_CLASS(g_usb_endpoint_parent_class)->finalize(object);
}
static void
-g_usb_endpoint_class_init (GUsbEndpointClass *klass)
+g_usb_endpoint_class_init(GUsbEndpointClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->finalize = g_usb_endpoint_finalize;
}
static void
-g_usb_endpoint_init (GUsbEndpoint *endpoint)
+g_usb_endpoint_init(GUsbEndpoint *endpoint)
{
}
@@ -62,18 +61,19 @@ g_usb_endpoint_init (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
GUsbEndpoint *
-_g_usb_endpoint_new (const struct libusb_endpoint_descriptor *endpoint_descriptor)
+_g_usb_endpoint_new(const struct libusb_endpoint_descriptor *endpoint_descriptor)
{
GUsbEndpoint *endpoint;
- endpoint = g_object_new (G_USB_TYPE_ENDPOINT, NULL);
+ endpoint = g_object_new(G_USB_TYPE_ENDPOINT, NULL);
/* copy the data */
- memcpy (&endpoint->endpoint_descriptor,
- endpoint_descriptor,
- sizeof (struct libusb_endpoint_descriptor));
- endpoint->extra = g_bytes_new (endpoint_descriptor->extra, endpoint_descriptor->extra_length);
+ memcpy(&endpoint->endpoint_descriptor,
+ endpoint_descriptor,
+ sizeof(struct libusb_endpoint_descriptor));
+ endpoint->extra =
+ g_bytes_new(endpoint_descriptor->extra, endpoint_descriptor->extra_length);
- return G_USB_ENDPOINT (endpoint);
+ return G_USB_ENDPOINT(endpoint);
}
/**
@@ -87,9 +87,9 @@ _g_usb_endpoint_new (const struct libusb_endpoint_descriptor *endpoint_descripto
* Since: 0.3.3
**/
guint8
-g_usb_endpoint_get_kind (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_kind(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0);
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), 0);
return endpoint->endpoint_descriptor.bDescriptorType;
}
@@ -104,9 +104,9 @@ g_usb_endpoint_get_kind (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
guint16
-g_usb_endpoint_get_maximum_packet_size (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_maximum_packet_size(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0);
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), 0);
return endpoint->endpoint_descriptor.wMaxPacketSize;
}
@@ -121,9 +121,9 @@ g_usb_endpoint_get_maximum_packet_size (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
guint8
-g_usb_endpoint_get_polling_interval (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_polling_interval(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0);
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), 0);
return endpoint->endpoint_descriptor.bInterval;
}
@@ -138,9 +138,9 @@ g_usb_endpoint_get_polling_interval (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
guint8
-g_usb_endpoint_get_refresh (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_refresh(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0);
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), 0);
return endpoint->endpoint_descriptor.bRefresh;
}
@@ -155,9 +155,9 @@ g_usb_endpoint_get_refresh (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
guint8
-g_usb_endpoint_get_synch_address (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_synch_address(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0);
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), 0);
return endpoint->endpoint_descriptor.bSynchAddress;
}
@@ -172,9 +172,9 @@ g_usb_endpoint_get_synch_address (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
guint8
-g_usb_endpoint_get_address (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_address(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0);
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), 0);
return endpoint->endpoint_descriptor.bEndpointAddress;
}
@@ -189,9 +189,9 @@ g_usb_endpoint_get_address (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
guint8
-g_usb_endpoint_get_number (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_number(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0);
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), 0);
return (endpoint->endpoint_descriptor.bEndpointAddress) & 0xf;
}
@@ -206,12 +206,12 @@ g_usb_endpoint_get_number (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
GUsbDeviceDirection
-g_usb_endpoint_get_direction (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_direction(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), 0);
- return (endpoint->endpoint_descriptor.bEndpointAddress & 0x80) ?
- G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST :
- G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE;
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), 0);
+ return (endpoint->endpoint_descriptor.bEndpointAddress & 0x80)
+ ? G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST
+ : G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE;
}
/**
@@ -225,8 +225,8 @@ g_usb_endpoint_get_direction (GUsbEndpoint *endpoint)
* Since: 0.3.3
**/
GBytes *
-g_usb_endpoint_get_extra (GUsbEndpoint *endpoint)
+g_usb_endpoint_get_extra(GUsbEndpoint *endpoint)
{
- g_return_val_if_fail (G_USB_IS_ENDPOINT (endpoint), NULL);
+ g_return_val_if_fail(G_USB_IS_ENDPOINT(endpoint), NULL);
return endpoint->extra;
}
diff --git a/gusb/gusb-endpoint.h b/gusb/gusb-endpoint.h
index 0feb6e4..cc9119b 100644
--- a/gusb/gusb-endpoint.h
+++ b/gusb/gusb-endpoint.h
@@ -11,17 +11,26 @@
G_BEGIN_DECLS
-#define G_USB_TYPE_ENDPOINT (g_usb_endpoint_get_type ())
-G_DECLARE_FINAL_TYPE (GUsbEndpoint, g_usb_endpoint, G_USB, ENDPOINT, GObject)
+#define G_USB_TYPE_ENDPOINT (g_usb_endpoint_get_type())
+G_DECLARE_FINAL_TYPE(GUsbEndpoint, g_usb_endpoint, G_USB, ENDPOINT, GObject)
-guint8 g_usb_endpoint_get_kind (GUsbEndpoint *endpoint);
-guint16 g_usb_endpoint_get_maximum_packet_size (GUsbEndpoint *endpoint);
-guint8 g_usb_endpoint_get_polling_interval (GUsbEndpoint *endpoint);
-guint8 g_usb_endpoint_get_refresh (GUsbEndpoint *endpoint);
-guint8 g_usb_endpoint_get_synch_address (GUsbEndpoint *endpoint);
-guint8 g_usb_endpoint_get_address (GUsbEndpoint *endpoint);
-guint8 g_usb_endpoint_get_number (GUsbEndpoint *endpoint);
-GUsbDeviceDirection g_usb_endpoint_get_direction (GUsbEndpoint *endpoint);
-GBytes * g_usb_endpoint_get_extra (GUsbEndpoint *endpoint);
+guint8
+g_usb_endpoint_get_kind(GUsbEndpoint *endpoint);
+guint16
+g_usb_endpoint_get_maximum_packet_size(GUsbEndpoint *endpoint);
+guint8
+g_usb_endpoint_get_polling_interval(GUsbEndpoint *endpoint);
+guint8
+g_usb_endpoint_get_refresh(GUsbEndpoint *endpoint);
+guint8
+g_usb_endpoint_get_synch_address(GUsbEndpoint *endpoint);
+guint8
+g_usb_endpoint_get_address(GUsbEndpoint *endpoint);
+guint8
+g_usb_endpoint_get_number(GUsbEndpoint *endpoint);
+GUsbDeviceDirection
+g_usb_endpoint_get_direction(GUsbEndpoint *endpoint);
+GBytes *
+g_usb_endpoint_get_extra(GUsbEndpoint *endpoint);
G_END_DECLS
diff --git a/gusb/gusb-interface-private.h b/gusb/gusb-interface-private.h
index 7e5c992..7efd171 100644
--- a/gusb/gusb-interface-private.h
+++ b/gusb/gusb-interface-private.h
@@ -7,12 +7,12 @@
#pragma once
-#include <libusb.h>
-
#include <gusb/gusb-interface.h>
+#include <libusb.h>
G_BEGIN_DECLS
-GUsbInterface *_g_usb_interface_new (const struct libusb_interface_descriptor *iface);
+GUsbInterface *
+_g_usb_interface_new(const struct libusb_interface_descriptor *iface);
G_END_DECLS
diff --git a/gusb/gusb-interface.c b/gusb/gusb-interface.c
index bbc4db7..086580a 100644
--- a/gusb/gusb-interface.c
+++ b/gusb/gusb-interface.c
@@ -20,11 +20,10 @@
#include <string.h>
-#include "gusb-interface-private.h"
#include "gusb-endpoint-private.h"
+#include "gusb-interface-private.h"
-struct _GUsbInterface
-{
+struct _GUsbInterface {
GObject parent_instance;
struct libusb_interface_descriptor iface;
@@ -33,29 +32,29 @@ struct _GUsbInterface
GPtrArray *endpoints;
};
-G_DEFINE_TYPE (GUsbInterface, g_usb_interface, G_TYPE_OBJECT)
+G_DEFINE_TYPE(GUsbInterface, g_usb_interface, G_TYPE_OBJECT)
static void
-g_usb_interface_finalize (GObject *object)
+g_usb_interface_finalize(GObject *object)
{
- GUsbInterface *interface = G_USB_INTERFACE (object);
+ GUsbInterface *interface = G_USB_INTERFACE(object);
- g_bytes_unref (interface->extra);
- g_ptr_array_unref (interface->endpoints);
+ g_bytes_unref(interface->extra);
+ g_ptr_array_unref(interface->endpoints);
- G_OBJECT_CLASS (g_usb_interface_parent_class)->finalize (object);
+ G_OBJECT_CLASS(g_usb_interface_parent_class)->finalize(object);
}
static void
-g_usb_interface_class_init (GUsbInterfaceClass *klass)
+g_usb_interface_class_init(GUsbInterfaceClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS(klass);
object_class->finalize = g_usb_interface_finalize;
}
static void
-g_usb_interface_init (GUsbInterface *interface)
+g_usb_interface_init(GUsbInterface *interface)
{
}
@@ -67,22 +66,20 @@ g_usb_interface_init (GUsbInterface *interface)
* Since: 0.2.8
**/
GUsbInterface *
-_g_usb_interface_new (const struct libusb_interface_descriptor *iface)
+_g_usb_interface_new(const struct libusb_interface_descriptor *iface)
{
GUsbInterface *interface;
- interface = g_object_new (G_USB_TYPE_INTERFACE, NULL);
+ interface = g_object_new(G_USB_TYPE_INTERFACE, NULL);
/* copy the data */
- memcpy (&interface->iface,
- iface,
- sizeof (struct libusb_interface_descriptor));
- interface->extra = g_bytes_new (iface->extra, iface->extra_length);
+ memcpy(&interface->iface, iface, sizeof(struct libusb_interface_descriptor));
+ interface->extra = g_bytes_new(iface->extra, iface->extra_length);
- interface->endpoints = g_ptr_array_new_with_free_func (g_object_unref);
+ interface->endpoints = g_ptr_array_new_with_free_func(g_object_unref);
for (guint i = 0; i < iface->bNumEndpoints; i++)
- g_ptr_array_add (interface->endpoints, _g_usb_endpoint_new (&iface->endpoint[i]));
+ g_ptr_array_add(interface->endpoints, _g_usb_endpoint_new(&iface->endpoint[i]));
- return G_USB_INTERFACE (interface);
+ return G_USB_INTERFACE(interface);
}
/**
@@ -96,9 +93,9 @@ _g_usb_interface_new (const struct libusb_interface_descriptor *iface)
* Since: 0.2.8
**/
guint8
-g_usb_interface_get_length (GUsbInterface *interface)
+g_usb_interface_get_length(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), 0);
return interface->iface.bLength;
}
@@ -113,9 +110,9 @@ g_usb_interface_get_length (GUsbInterface *interface)
* Since: 0.2.8
**/
guint8
-g_usb_interface_get_kind (GUsbInterface *interface)
+g_usb_interface_get_kind(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), 0);
return interface->iface.bDescriptorType;
}
@@ -130,9 +127,9 @@ g_usb_interface_get_kind (GUsbInterface *interface)
* Since: 0.2.8
**/
guint8
-g_usb_interface_get_number (GUsbInterface *interface)
+g_usb_interface_get_number(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), 0);
return interface->iface.bInterfaceNumber;
}
@@ -147,9 +144,9 @@ g_usb_interface_get_number (GUsbInterface *interface)
* Since: 0.2.8
**/
guint8
-g_usb_interface_get_alternate (GUsbInterface *interface)
+g_usb_interface_get_alternate(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), 0);
return interface->iface.bAlternateSetting;
}
@@ -164,9 +161,9 @@ g_usb_interface_get_alternate (GUsbInterface *interface)
* Since: 0.2.8
**/
guint8
-g_usb_interface_get_class (GUsbInterface *interface)
+g_usb_interface_get_class(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), 0);
return interface->iface.bInterfaceClass;
}
@@ -182,9 +179,9 @@ g_usb_interface_get_class (GUsbInterface *interface)
* Since: 0.2.8
**/
guint8
-g_usb_interface_get_subclass (GUsbInterface *interface)
+g_usb_interface_get_subclass(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), 0);
return interface->iface.bInterfaceSubClass;
}
@@ -200,9 +197,9 @@ g_usb_interface_get_subclass (GUsbInterface *interface)
* Since: 0.2.8
**/
guint8
-g_usb_interface_get_protocol (GUsbInterface *interface)
+g_usb_interface_get_protocol(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), 0);
return interface->iface.bInterfaceProtocol;
}
@@ -217,9 +214,9 @@ g_usb_interface_get_protocol (GUsbInterface *interface)
* Since: 0.2.8
**/
guint8
-g_usb_interface_get_index (GUsbInterface *interface)
+g_usb_interface_get_index(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), 0);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), 0);
return interface->iface.iInterface;
}
@@ -234,9 +231,9 @@ g_usb_interface_get_index (GUsbInterface *interface)
* Since: 0.2.8
**/
GBytes *
-g_usb_interface_get_extra (GUsbInterface *interface)
+g_usb_interface_get_extra(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), NULL);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), NULL);
return interface->extra;
}
@@ -246,13 +243,14 @@ g_usb_interface_get_extra (GUsbInterface *interface)
*
* Gets interface endpoints.
*
- * Return value: (transfer container) (element-type GUsbEndpoint): an array of endpoints, or %NULL on failure
+ * Return value: (transfer container) (element-type GUsbEndpoint): an array of endpoints, or %NULL
+ *on failure
*
* Since: 0.3.3
**/
GPtrArray *
-g_usb_interface_get_endpoints (GUsbInterface *interface)
+g_usb_interface_get_endpoints(GUsbInterface *interface)
{
- g_return_val_if_fail (G_USB_IS_INTERFACE (interface), NULL);
- return g_ptr_array_ref (interface->endpoints);
+ g_return_val_if_fail(G_USB_IS_INTERFACE(interface), NULL);
+ return g_ptr_array_ref(interface->endpoints);
}
diff --git a/gusb/gusb-interface.h b/gusb/gusb-interface.h
index 0e1ca36..c1c13f0 100644
--- a/gusb/gusb-interface.h
+++ b/gusb/gusb-interface.h
@@ -12,18 +12,28 @@
G_BEGIN_DECLS
-#define G_USB_TYPE_INTERFACE (g_usb_interface_get_type ())
-G_DECLARE_FINAL_TYPE (GUsbInterface, g_usb_interface, G_USB, INTERFACE, GObject)
+#define G_USB_TYPE_INTERFACE (g_usb_interface_get_type())
+G_DECLARE_FINAL_TYPE(GUsbInterface, g_usb_interface, G_USB, INTERFACE, GObject)
-guint8 g_usb_interface_get_length (GUsbInterface *interface);
-guint8 g_usb_interface_get_kind (GUsbInterface *interface);
-guint8 g_usb_interface_get_number (GUsbInterface *interface);
-guint8 g_usb_interface_get_alternate (GUsbInterface *interface);
-guint8 g_usb_interface_get_class (GUsbInterface *interface);
-guint8 g_usb_interface_get_subclass (GUsbInterface *interface);
-guint8 g_usb_interface_get_protocol (GUsbInterface *interface);
-guint8 g_usb_interface_get_index (GUsbInterface *interface);
-GBytes *g_usb_interface_get_extra (GUsbInterface *interface);
-GPtrArray *g_usb_interface_get_endpoints (GUsbInterface *interface);
+guint8
+g_usb_interface_get_length(GUsbInterface *interface);
+guint8
+g_usb_interface_get_kind(GUsbInterface *interface);
+guint8
+g_usb_interface_get_number(GUsbInterface *interface);
+guint8
+g_usb_interface_get_alternate(GUsbInterface *interface);
+guint8
+g_usb_interface_get_class(GUsbInterface *interface);
+guint8
+g_usb_interface_get_subclass(GUsbInterface *interface);
+guint8
+g_usb_interface_get_protocol(GUsbInterface *interface);
+guint8
+g_usb_interface_get_index(GUsbInterface *interface);
+GBytes *
+g_usb_interface_get_extra(GUsbInterface *interface);
+GPtrArray *
+g_usb_interface_get_endpoints(GUsbInterface *interface);
G_END_DECLS
diff --git a/gusb/gusb-private.h b/gusb/gusb-private.h
index 95ffacf..1490726 100644
--- a/gusb/gusb-private.h
+++ b/gusb/gusb-private.h
@@ -9,8 +9,8 @@
#define __GUSB_INSIDE__
-#include <gusb/gusb.h>
#include <gusb/gusb-context-private.h>
#include <gusb/gusb-device-private.h>
+#include <gusb/gusb.h>
#undef __GUSB_INSIDE__
diff --git a/gusb/gusb-self-test.c b/gusb/gusb-self-test.c
index f078e1e..903770b 100644
--- a/gusb/gusb-self-test.c
+++ b/gusb/gusb-self-test.c
@@ -11,7 +11,7 @@
#include "gusb-context-private.h"
static void
-gusb_device_func (void)
+gusb_device_func(void)
{
GUsbDevice *device;
g_autoptr(GError) error = NULL;
@@ -19,46 +19,46 @@ gusb_device_func (void)
g_autoptr(GUsbContext) ctx = NULL;
#ifdef __FreeBSD__
- g_test_skip ("Root hubs on FreeBSD have vid and pid set to zero");
+ g_test_skip("Root hubs on FreeBSD have vid and pid set to zero");
return;
#endif
- ctx = g_usb_context_new (&error);
- g_assert_no_error (error);
- g_assert (ctx != NULL);
+ ctx = g_usb_context_new(&error);
+ g_assert_no_error(error);
+ g_assert(ctx != NULL);
- g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR);
+ g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR);
- array = g_usb_context_get_devices (ctx);
- g_assert (array != NULL);
- g_assert_cmpint (array->len, >, 0);
- device = G_USB_DEVICE (g_ptr_array_index (array, 0));
+ array = g_usb_context_get_devices(ctx);
+ g_assert(array != NULL);
+ g_assert_cmpint(array->len, >, 0);
+ device = G_USB_DEVICE(g_ptr_array_index(array, 0));
- g_assert_cmpint (g_usb_device_get_vid (device), >, 0x0000);
- g_assert_cmpint (g_usb_device_get_pid (device), >, 0x0000);
+ g_assert_cmpint(g_usb_device_get_vid(device), >, 0x0000);
+ g_assert_cmpint(g_usb_device_get_pid(device), >, 0x0000);
}
static void
-gusb_context_lookup_func (void)
+gusb_context_lookup_func(void)
{
GError *error = NULL;
const gchar *tmp;
g_autoptr(GUsbContext) ctx = NULL;
- ctx = g_usb_context_new (&error);
- g_assert_no_error (error);
- g_assert (ctx != NULL);
+ ctx = g_usb_context_new(&error);
+ g_assert_no_error(error);
+ g_assert(ctx != NULL);
- tmp = _g_usb_context_lookup_vendor (ctx, 0x04d8, &error);
- g_assert_no_error (error);
- g_assert_cmpstr (tmp, ==, "Microchip Technology, Inc.");
- tmp = _g_usb_context_lookup_product (ctx, 0x04d8, 0xf8da, &error);
- g_assert_no_error (error);
- g_assert_cmpstr (tmp, ==, "Hughski Ltd. ColorHug");
+ tmp = _g_usb_context_lookup_vendor(ctx, 0x04d8, &error);
+ g_assert_no_error(error);
+ g_assert_cmpstr(tmp, ==, "Microchip Technology, Inc.");
+ tmp = _g_usb_context_lookup_product(ctx, 0x04d8, 0xf8da, &error);
+ g_assert_no_error(error);
+ g_assert_cmpstr(tmp, ==, "Hughski Ltd. ColorHug");
}
static void
-gusb_context_func (void)
+gusb_context_func(void)
{
GPtrArray *array;
guint old_number_of_devices;
@@ -68,250 +68,225 @@ gusb_context_func (void)
g_autoptr(GUsbContext) ctx = NULL;
#ifdef __FreeBSD__
- g_test_skip ("Root hubs on FreeBSD have vid and pid set to zero");
+ g_test_skip("Root hubs on FreeBSD have vid and pid set to zero");
return;
#endif
- ctx = g_usb_context_new (&error);
- g_assert_no_error (error);
- g_assert (ctx != NULL);
+ ctx = g_usb_context_new(&error);
+ g_assert_no_error(error);
+ g_assert(ctx != NULL);
- g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR);
+ g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR);
/* coldplug, and ensure we got some devices */
- array = g_usb_context_get_devices (ctx);
- g_assert (array != NULL);
- g_assert_cmpint (array->len, >, 0);
+ array = g_usb_context_get_devices(ctx);
+ g_assert(array != NULL);
+ g_assert_cmpint(array->len, >, 0);
old_number_of_devices = array->len;
/* Print a list (also exercising various bits of g_usb_device) */
- g_print ("\n");
+ g_print("\n");
for (guint i = 0; i < array->len; i++) {
g_autofree gchar *manufacturer = NULL;
g_autofree gchar *product = NULL;
- device = G_USB_DEVICE (g_ptr_array_index (array, i));
+ device = G_USB_DEVICE(g_ptr_array_index(array, i));
- g_assert_cmpint (g_usb_device_get_vid (device), >, 0x0000);
- g_assert_cmpint (g_usb_device_get_pid (device), >, 0x0000);
+ g_assert_cmpint(g_usb_device_get_vid(device), >, 0x0000);
+ g_assert_cmpint(g_usb_device_get_pid(device), >, 0x0000);
/* Needed for g_usb_device_get_string_descriptor below,
not error checked to allow running basic tests without
needing r/w rights on /dev/bus/usb nodes */
- g_usb_context_set_debug (ctx, 0);
- g_usb_device_open (device, NULL);
- g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR);
+ g_usb_context_set_debug(ctx, 0);
+ g_usb_device_open(device, NULL);
+ g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR);
/* We don't error check these as not all devices have these
(and the device_open may have failed). */
- manufacturer = g_usb_device_get_string_descriptor (device,
- g_usb_device_get_manufacturer_index (device),
- NULL);
- product = g_usb_device_get_string_descriptor (device,
- g_usb_device_get_product_index (device),
- NULL);
-
- g_usb_device_close (device, NULL);
-
- g_print ("Found %04x:%04x, %s %s\n",
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device),
- manufacturer ? manufacturer : "",
- product ? product : "");
+ manufacturer =
+ g_usb_device_get_string_descriptor(device,
+ g_usb_device_get_manufacturer_index(device),
+ NULL);
+ product = g_usb_device_get_string_descriptor(device,
+ g_usb_device_get_product_index(device),
+ NULL);
+
+ g_usb_device_close(device, NULL);
+
+ g_print("Found %04x:%04x, %s %s\n",
+ g_usb_device_get_vid(device),
+ g_usb_device_get_pid(device),
+ manufacturer ? manufacturer : "",
+ product ? product : "");
}
- g_ptr_array_unref (array);
+ g_ptr_array_unref(array);
/* coldplug again, and ensure we did not duplicate devices */
- array = g_usb_context_get_devices (ctx);
- g_assert (array != NULL);
- g_assert_cmpint (array->len, ==, old_number_of_devices);
- device = G_USB_DEVICE (g_ptr_array_index (array, 0));
- bus = g_usb_device_get_bus (device);
- address = g_usb_device_get_address (device);
- g_ptr_array_unref (array);
+ array = g_usb_context_get_devices(ctx);
+ g_assert(array != NULL);
+ g_assert_cmpint(array->len, ==, old_number_of_devices);
+ device = G_USB_DEVICE(g_ptr_array_index(array, 0));
+ bus = g_usb_device_get_bus(device);
+ address = g_usb_device_get_address(device);
+ g_ptr_array_unref(array);
/* ensure we can search for the same device */
- device = g_usb_context_find_by_bus_address (ctx,
- bus,
- address,
- &error);
- g_assert_no_error (error);
- g_assert (device != NULL);
- g_assert_cmpint (bus, ==, g_usb_device_get_bus (device));
- g_assert_cmpint (address, ==, g_usb_device_get_address (device));
- g_object_unref (device);
+ device = g_usb_context_find_by_bus_address(ctx, bus, address, &error);
+ g_assert_no_error(error);
+ g_assert(device != NULL);
+ g_assert_cmpint(bus, ==, g_usb_device_get_bus(device));
+ g_assert_cmpint(address, ==, g_usb_device_get_address(device));
+ g_object_unref(device);
/* get a device that can't exist */
- device = g_usb_context_find_by_vid_pid (ctx,
- 0xffff,
- 0xffff,
- &error);
- g_assert_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NO_DEVICE);
- g_assert (device == NULL);
+ device = g_usb_context_find_by_vid_pid(ctx, 0xffff, 0xffff, &error);
+ g_assert_error(error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_NO_DEVICE);
+ g_assert(device == NULL);
}
static void
-gusb_device_huey_func (void)
+gusb_device_huey_func(void)
{
gboolean ret;
GCancellable *cancellable = NULL;
- const gchar request[8] = { 0x0e, 'G', 'r', 'M', 'b', 'k', 'e', 'd' };
+ const gchar request[8] = {0x0e, 'G', 'r', 'M', 'b', 'k', 'e', 'd'};
g_autoptr(GError) error = NULL;
g_autoptr(GUsbContext) ctx = NULL;
g_autoptr(GUsbDevice) device = NULL;
- ctx = g_usb_context_new (&error);
- g_assert_no_error (error);
- g_assert (ctx != NULL);
+ ctx = g_usb_context_new(&error);
+ g_assert_no_error(error);
+ g_assert(ctx != NULL);
- g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR);
+ g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR);
/* coldplug, and get the huey */
- device = g_usb_context_find_by_vid_pid (ctx,
- 0x0971,
- 0x2005,
- &error);
- if (device == NULL &&
- error->domain == G_USB_DEVICE_ERROR &&
+ device = g_usb_context_find_by_vid_pid(ctx, 0x0971, 0x2005, &error);
+ if (device == NULL && error->domain == G_USB_DEVICE_ERROR &&
error->code == G_USB_DEVICE_ERROR_NO_DEVICE) {
- g_print ("No device detected!\n");
+ g_print("No device detected!\n");
return;
}
- g_assert_no_error (error);
- g_assert (device != NULL);
+ g_assert_no_error(error);
+ g_assert(device != NULL);
/* close not opened */
- ret = g_usb_device_close (device, &error);
- g_assert_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_OPEN);
- g_assert (!ret);
- g_clear_error (&error);
+ ret = g_usb_device_close(device, &error);
+ g_assert_error(error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_NOT_OPEN);
+ g_assert(!ret);
+ g_clear_error(&error);
/* open */
- ret = g_usb_device_open (device, &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_open(device, &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* open opened */
- ret = g_usb_device_open (device, &error);
- g_assert_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_ALREADY_OPEN);
- g_assert (!ret);
- g_clear_error (&error);
+ ret = g_usb_device_open(device, &error);
+ g_assert_error(error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_ALREADY_OPEN);
+ g_assert(!ret);
+ g_clear_error(&error);
/* claim interface 0 */
- ret = g_usb_device_claim_interface (device, 0x00,
- G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
- &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_claim_interface(device,
+ 0x00,
+ G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
+ &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* do a request (unlock) */
- ret = g_usb_device_control_transfer (device,
- G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
- G_USB_DEVICE_REQUEST_TYPE_CLASS,
- G_USB_DEVICE_RECIPIENT_INTERFACE,
- 0x09, /* request */
- 0x0200, /* value */
- 0, /* index */
- (guint8*) request,
- 8,
- NULL,
- 2000,
- cancellable,
- &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_control_transfer(device,
+ G_USB_DEVICE_DIRECTION_HOST_TO_DEVICE,
+ G_USB_DEVICE_REQUEST_TYPE_CLASS,
+ G_USB_DEVICE_RECIPIENT_INTERFACE,
+ 0x09, /* request */
+ 0x0200, /* value */
+ 0, /* index */
+ (guint8 *)request,
+ 8,
+ NULL,
+ 2000,
+ cancellable,
+ &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* do a request we know is going to fail */
- ret = g_usb_device_control_transfer (device,
- G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST,
- G_USB_DEVICE_REQUEST_TYPE_CLASS,
- G_USB_DEVICE_RECIPIENT_INTERFACE,
- 0x09, /* request */
- 0x0200, /* value */
- 0, /* index */
- (guint8*) request,
- 8,
- NULL,
- 2000,
- cancellable,
- &error);
- g_assert_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_SUPPORTED);
- g_assert (!ret);
- g_clear_error (&error);
+ ret = g_usb_device_control_transfer(device,
+ G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST,
+ G_USB_DEVICE_REQUEST_TYPE_CLASS,
+ G_USB_DEVICE_RECIPIENT_INTERFACE,
+ 0x09, /* request */
+ 0x0200, /* value */
+ 0, /* index */
+ (guint8 *)request,
+ 8,
+ NULL,
+ 2000,
+ cancellable,
+ &error);
+ g_assert_error(error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_NOT_SUPPORTED);
+ g_assert(!ret);
+ g_clear_error(&error);
/* release interface 0 */
- ret = g_usb_device_release_interface (device, 0x00,
- G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
- &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_release_interface(device,
+ 0x00,
+ G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
+ &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* close */
- ret = g_usb_device_close (device, &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_close(device, &error);
+ g_assert_no_error(error);
+ g_assert(ret);
}
typedef struct {
- guint8 *buffer;
- guint buffer_len;
- GMainLoop *loop;
+ guint8 *buffer;
+ guint buffer_len;
+ GMainLoop *loop;
} GUsbDeviceAsyncHelper;
-
static void
-g_usb_device_print_data (const gchar *title,
- const guchar *data,
- gsize length)
+g_usb_device_print_data(const gchar *title, const guchar *data, gsize length)
{
- if (g_strcmp0 (title, "request") == 0)
- g_print ("%c[%dm", 0x1B, 31);
- if (g_strcmp0 (title, "reply") == 0)
- g_print ("%c[%dm", 0x1B, 34);
- g_print ("%s\t", title);
-
- for (guint i = 0; i< length; i++) {
- g_print ("%02x [%c]\t",
- data[i],
- g_ascii_isprint (data[i]) ? data[i] : '?');
+ if (g_strcmp0(title, "request") == 0)
+ g_print("%c[%dm", 0x1B, 31);
+ if (g_strcmp0(title, "reply") == 0)
+ g_print("%c[%dm", 0x1B, 34);
+ g_print("%s\t", title);
+
+ for (guint i = 0; i < length; i++) {
+ g_print("%02x [%c]\t", data[i], g_ascii_isprint(data[i]) ? data[i] : '?');
}
- g_print ("%c[%dm\n", 0x1B, 0);
+ g_print("%c[%dm\n", 0x1B, 0);
}
static void
-g_usb_test_button_pressed_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
+g_usb_test_button_pressed_cb(GObject *source_object, GAsyncResult *res, gpointer user_data)
{
gboolean ret;
- GUsbDeviceAsyncHelper *helper = (GUsbDeviceAsyncHelper *) user_data;
+ GUsbDeviceAsyncHelper *helper = (GUsbDeviceAsyncHelper *)user_data;
g_autoptr(GError) error = NULL;
- ret = g_usb_device_interrupt_transfer_finish (G_USB_DEVICE (source_object),
- res, &error);
+ ret = g_usb_device_interrupt_transfer_finish(G_USB_DEVICE(source_object), res, &error);
if (!ret) {
- g_error ("%s", error->message);
+ g_error("%s", error->message);
return;
}
- g_usb_device_print_data ("button press",
- helper->buffer,
- helper->buffer_len);
- g_main_loop_quit (helper->loop);
- g_free (helper->buffer);
+ g_usb_device_print_data("button press", helper->buffer, helper->buffer_len);
+ g_main_loop_quit(helper->loop);
+ g_free(helper->buffer);
}
static void
-gusb_device_munki_func (void)
+gusb_device_munki_func(void)
{
gboolean ret;
GCancellable *cancellable = NULL;
@@ -321,122 +296,114 @@ gusb_device_munki_func (void)
g_autoptr(GUsbContext) ctx = NULL;
g_autoptr(GUsbDevice) device = NULL;
- ctx = g_usb_context_new (&error);
- g_assert_no_error (error);
- g_assert (ctx != NULL);
+ ctx = g_usb_context_new(&error);
+ g_assert_no_error(error);
+ g_assert(ctx != NULL);
- g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR);
+ g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR);
/* coldplug, and get the ColorMunki */
- device = g_usb_context_find_by_vid_pid (ctx,
- 0x0971,
- 0x2007,
- &error);
- if (device == NULL &&
- error->domain == G_USB_DEVICE_ERROR &&
+ device = g_usb_context_find_by_vid_pid(ctx, 0x0971, 0x2007, &error);
+ if (device == NULL && error->domain == G_USB_DEVICE_ERROR &&
error->code == G_USB_DEVICE_ERROR_NO_DEVICE) {
- g_print ("No device detected!\n");
+ g_print("No device detected!\n");
return;
}
- g_assert_no_error (error);
- g_assert (device != NULL);
+ g_assert_no_error(error);
+ g_assert(device != NULL);
/* close not opened */
- ret = g_usb_device_close (device, &error);
- g_assert_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_NOT_OPEN);
- g_assert (!ret);
- g_clear_error (&error);
+ ret = g_usb_device_close(device, &error);
+ g_assert_error(error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_NOT_OPEN);
+ g_assert(!ret);
+ g_clear_error(&error);
/* open */
- ret = g_usb_device_open (device, &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_open(device, &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* open opened */
- ret = g_usb_device_open (device, &error);
- g_assert_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_ALREADY_OPEN);
- g_assert (!ret);
- g_clear_error (&error);
+ ret = g_usb_device_open(device, &error);
+ g_assert_error(error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_ALREADY_OPEN);
+ g_assert(!ret);
+ g_clear_error(&error);
/* claim interface 0 */
- ret = g_usb_device_claim_interface (device, 0x00,
- G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
- &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_claim_interface(device,
+ 0x00,
+ G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
+ &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* do a request (get chip id) */
- ret = g_usb_device_control_transfer (device,
- G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST,
- G_USB_DEVICE_REQUEST_TYPE_VENDOR,
- G_USB_DEVICE_RECIPIENT_DEVICE,
- 0x86, /* request */
- 0x0000, /* value */
- 0, /* index */
- (guint8*) request,
- 24,
- NULL,
- 2000,
- cancellable,
- &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_control_transfer(device,
+ G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST,
+ G_USB_DEVICE_REQUEST_TYPE_VENDOR,
+ G_USB_DEVICE_RECIPIENT_DEVICE,
+ 0x86, /* request */
+ 0x0000, /* value */
+ 0, /* index */
+ (guint8 *)request,
+ 24,
+ NULL,
+ 2000,
+ cancellable,
+ &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* do a request we know is going to fail */
- ret = g_usb_device_control_transfer (device,
- G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST,
- G_USB_DEVICE_REQUEST_TYPE_CLASS,
- G_USB_DEVICE_RECIPIENT_INTERFACE,
- 0x00, /* request */
- 0x0200, /* value */
- 0, /* index */
- (guint8*) request,
- 8,
- NULL,
- 100,
- cancellable,
- &error);
- g_assert_error (error,
- G_USB_DEVICE_ERROR,
- G_USB_DEVICE_ERROR_TIMED_OUT);
- g_assert (!ret);
- g_clear_error (&error);
+ ret = g_usb_device_control_transfer(device,
+ G_USB_DEVICE_DIRECTION_DEVICE_TO_HOST,
+ G_USB_DEVICE_REQUEST_TYPE_CLASS,
+ G_USB_DEVICE_RECIPIENT_INTERFACE,
+ 0x00, /* request */
+ 0x0200, /* value */
+ 0, /* index */
+ (guint8 *)request,
+ 8,
+ NULL,
+ 100,
+ cancellable,
+ &error);
+ g_assert_error(error, G_USB_DEVICE_ERROR, G_USB_DEVICE_ERROR_TIMED_OUT);
+ g_assert(!ret);
+ g_clear_error(&error);
/* do async read of button event */
- helper = g_slice_new0 (GUsbDeviceAsyncHelper);
+ helper = g_slice_new0(GUsbDeviceAsyncHelper);
helper->buffer_len = 8;
- helper->buffer = g_new0 (guint8, helper->buffer_len);
- helper->loop = g_main_loop_new (NULL, FALSE);
- g_usb_device_interrupt_transfer_async (device,
- 0x83,
- helper->buffer,
- 8,
- 30*1000,
- cancellable, /* TODO; use GCancellable */
- g_usb_test_button_pressed_cb,
- helper);
- g_main_loop_run (helper->loop);
- g_main_loop_unref (helper->loop);
+ helper->buffer = g_new0(guint8, helper->buffer_len);
+ helper->loop = g_main_loop_new(NULL, FALSE);
+ g_usb_device_interrupt_transfer_async(device,
+ 0x83,
+ helper->buffer,
+ 8,
+ 30 * 1000,
+ cancellable, /* TODO; use GCancellable */
+ g_usb_test_button_pressed_cb,
+ helper);
+ g_main_loop_run(helper->loop);
+ g_main_loop_unref(helper->loop);
/* release interface 0 */
- ret = g_usb_device_release_interface (device, 0x00,
- G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
- &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_release_interface(device,
+ 0x00,
+ G_USB_DEVICE_CLAIM_INTERFACE_BIND_KERNEL_DRIVER,
+ &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* close */
- ret = g_usb_device_close (device, &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_close(device, &error);
+ g_assert_no_error(error);
+ g_assert(ret);
}
static void
-gusb_device_ch2_func (void)
+gusb_device_ch2_func(void)
{
gboolean ret;
guint8 idx;
@@ -445,66 +412,62 @@ gusb_device_ch2_func (void)
g_autoptr(GUsbContext) ctx = NULL;
g_autoptr(GUsbDevice) device = NULL;
- ctx = g_usb_context_new (&error);
- g_assert_no_error (error);
- g_assert (ctx != NULL);
+ ctx = g_usb_context_new(&error);
+ g_assert_no_error(error);
+ g_assert(ctx != NULL);
- g_usb_context_set_debug (ctx, G_LOG_LEVEL_ERROR);
+ g_usb_context_set_debug(ctx, G_LOG_LEVEL_ERROR);
/* coldplug, and get the ColorHug */
- device = g_usb_context_find_by_vid_pid (ctx,
- 0x273f,
- 0x1004,
- &error);
- if (device == NULL &&
- error->domain == G_USB_DEVICE_ERROR &&
+ device = g_usb_context_find_by_vid_pid(ctx, 0x273f, 0x1004, &error);
+ if (device == NULL && error->domain == G_USB_DEVICE_ERROR &&
error->code == G_USB_DEVICE_ERROR_NO_DEVICE) {
- g_print ("No device detected!\n");
+ g_print("No device detected!\n");
return;
}
- g_assert_no_error (error);
- g_assert (device != NULL);
+ g_assert_no_error(error);
+ g_assert(device != NULL);
/* open */
- ret = g_usb_device_open (device, &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_open(device, &error);
+ g_assert_no_error(error);
+ g_assert(ret);
/* get vendor data */
- idx = g_usb_device_get_custom_index (device,
- G_USB_DEVICE_CLASS_VENDOR_SPECIFIC,
- 'F', 'W', &error);
- g_assert_no_error (error);
- g_assert_cmpint (idx, ==, 3);
+ idx = g_usb_device_get_custom_index(device,
+ G_USB_DEVICE_CLASS_VENDOR_SPECIFIC,
+ 'F',
+ 'W',
+ &error);
+ g_assert_no_error(error);
+ g_assert_cmpint(idx, ==, 3);
/* get the firmware version */
- tmp = g_usb_device_get_string_descriptor (device, idx, &error);
- g_assert_no_error (error);
- g_assert_cmpstr (tmp, ==, "2.0.3");
+ tmp = g_usb_device_get_string_descriptor(device, idx, &error);
+ g_assert_no_error(error);
+ g_assert_cmpstr(tmp, ==, "2.0.3");
/* close */
- ret = g_usb_device_close (device, &error);
- g_assert_no_error (error);
- g_assert (ret);
+ ret = g_usb_device_close(device, &error);
+ g_assert_no_error(error);
+ g_assert(ret);
}
int
-main (int argc,
- char **argv)
+main(int argc, char **argv)
{
- g_test_init (&argc, &argv, NULL);
+ g_test_init(&argc, &argv, NULL);
/* only critical and error are fatal */
- g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
+ g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
/* tests go here */
- g_test_add_func ("/gusb/context", gusb_context_func);
- g_test_add_func ("/gusb/context{lookup}", gusb_context_lookup_func);
- g_test_add_func ("/gusb/device", gusb_device_func);
- g_test_add_func ("/gusb/device[huey]", gusb_device_huey_func);
- g_test_add_func ("/gusb/device[munki]", gusb_device_munki_func);
- g_test_add_func ("/gusb/device[colorhug2]", gusb_device_ch2_func);
-
- return g_test_run ();
+ g_test_add_func("/gusb/context", gusb_context_func);
+ g_test_add_func("/gusb/context{lookup}", gusb_context_lookup_func);
+ g_test_add_func("/gusb/device", gusb_device_func);
+ g_test_add_func("/gusb/device[huey]", gusb_device_huey_func);
+ g_test_add_func("/gusb/device[munki]", gusb_device_munki_func);
+ g_test_add_func("/gusb/device[colorhug2]", gusb_device_ch2_func);
+
+ return g_test_run();
}
-
diff --git a/gusb/gusb-source.c b/gusb/gusb-source.c
index 4cfb826..51502e0 100644
--- a/gusb/gusb-source.c
+++ b/gusb/gusb-source.c
@@ -26,11 +26,11 @@
* Since: 0.1.0
**/
GQuark
-g_usb_source_error_quark (void)
+g_usb_source_error_quark(void)
{
static GQuark quark = 0;
if (!quark)
- quark = g_quark_from_static_string ("g_usb_source_error");
+ quark = g_quark_from_static_string("g_usb_source_error");
return quark;
}
@@ -46,10 +46,10 @@ g_usb_source_error_quark (void)
* Since: 0.1.0
**/
void
-g_usb_source_set_callback (GUsbSource *source,
- GSourceFunc func,
- gpointer data,
- GDestroyNotify notify)
+g_usb_source_set_callback(GUsbSource *source,
+ GSourceFunc func,
+ gpointer data,
+ GDestroyNotify notify)
{
- g_source_set_callback ((GSource *)source, func, data, notify);
+ g_source_set_callback((GSource *)source, func, data, notify);
}
diff --git a/gusb/gusb-source.h b/gusb/gusb-source.h
index 2c2b8bb..a6a7a81 100644
--- a/gusb/gusb-source.h
+++ b/gusb/gusb-source.h
@@ -12,7 +12,7 @@
G_BEGIN_DECLS
-#define G_USB_SOURCE_ERROR (g_usb_source_error_quark ())
+#define G_USB_SOURCE_ERROR (g_usb_source_error_quark())
typedef struct _GUsbSource GUsbSource;
@@ -21,17 +21,17 @@ typedef struct _GUsbSource GUsbSource;
*
* The error code.
**/
-typedef enum {
- G_USB_SOURCE_ERROR_INTERNAL
-} GUsbSourceError;
+typedef enum { G_USB_SOURCE_ERROR_INTERNAL } GUsbSourceError;
G_DEPRECATED_FOR(g_usb_context_error_quark)
-GQuark g_usb_source_error_quark (void);
+GQuark
+g_usb_source_error_quark(void);
G_DEPRECATED
-void g_usb_source_set_callback (GUsbSource *source,
- GSourceFunc func,
- gpointer data,
- GDestroyNotify notify);
+void
+g_usb_source_set_callback(GUsbSource *source,
+ GSourceFunc func,
+ gpointer data,
+ GDestroyNotify notify);
G_END_DECLS
diff --git a/gusb/gusb-umockdev-test.c b/gusb/gusb-umockdev-test.c
index b659187..e1b7714 100644
--- a/gusb/gusb-umockdev-test.c
+++ b/gusb/gusb-umockdev-test.c
@@ -7,16 +7,16 @@
*/
#include <glib.h>
-#include <unistd.h>
#include <string.h>
+#include <unistd.h>
#include "gusb.h"
-
#include "umockdev.h"
-#define UNUSED_DATA __attribute__ ((unused)) gconstpointer unused_data
+#define UNUSED_DATA __attribute__((unused)) gconstpointer unused_data
-/* avoid leak reports inside assertions; leaking stuff on assertion failures does not matter in tests */
+/* avoid leak reports inside assertions; leaking stuff on assertion failures does not matter in
+ * tests */
#if !defined(__clang__)
#pragma GCC diagnostic ignored "-Wanalyzer-malloc-leak"
#pragma GCC diagnostic ignored "-Wanalyzer-file-leak"
@@ -28,77 +28,79 @@ typedef struct {
} UMockdevTestbedFixture;
static void
-test_fixture_setup (UMockdevTestbedFixture *fixture, UNUSED_DATA)
+test_fixture_setup(UMockdevTestbedFixture *fixture, UNUSED_DATA)
{
- fixture->testbed = umockdev_testbed_new ();
- g_assert (fixture->testbed != NULL);
+ fixture->testbed = umockdev_testbed_new();
+ g_assert(fixture->testbed != NULL);
}
static void
-test_fixture_setup_empty (UMockdevTestbedFixture *fixture, UNUSED_DATA)
+test_fixture_setup_empty(UMockdevTestbedFixture *fixture, UNUSED_DATA)
{
- test_fixture_setup (fixture, NULL);
- fixture->ctx = g_usb_context_new (NULL);
+ test_fixture_setup(fixture, NULL);
+ fixture->ctx = g_usb_context_new(NULL);
}
static void
-test_fixture_teardown (UMockdevTestbedFixture *fixture, UNUSED_DATA)
+test_fixture_teardown(UMockdevTestbedFixture *fixture, UNUSED_DATA)
{
/* break context -> device -> context cycle */
if (fixture->ctx)
- g_object_run_dispose (G_OBJECT (fixture->ctx));
- g_clear_object (&fixture->ctx);
- g_clear_object (&fixture->testbed);
+ g_object_run_dispose(G_OBJECT(fixture->ctx));
+ g_clear_object(&fixture->ctx);
+ g_clear_object(&fixture->testbed);
/* running the mainloop is needed to ensure everything is cleaned up */
- while (g_main_context_iteration (NULL, FALSE)) { }
+ while (g_main_context_iteration(NULL, FALSE)) {
+ }
}
static void
-test_fixture_add_canon (UMockdevTestbedFixture *fixture)
+test_fixture_add_canon(UMockdevTestbedFixture *fixture)
{
/* NOTE: there is no device file, so cannot be opened */
/* NOTE: add_device would not create a file, needed for device emulation */
/* XXX: racy, see https://github.com/martinpitt/umockdev/issues/173 */
- umockdev_testbed_add_from_string (fixture->testbed,
- "P: /devices/usb1\n"
- "N: bus/usb/001/001\n"
- "E: SUBSYSTEM=usb\n"
- "E: DRIVER=usb\n"
- "E: BUSNUM=001\n"
- "E: DEVNUM=001\n"
- "E: DEVNAME=/dev/bus/usb/001/001\n"
- "E: DEVTYPE=usb_device\n"
- "A: bConfigurationValue=1\\n\n"
- "A: busnum=1\\n\n"
- "A: devnum=1\\n\n"
- "A: bConfigurationValue=1\\n\n"
- "A: speed=480\\n\n"
- /* descriptor from a Canon PowerShot SX200; VID 04a9 PID 31c0 */
- "H: descriptors="
- "1201000200000040a904c03102000102"
- "030109022700010100c0010904000003"
- "06010100070581020002000705020200"
- "020007058303080009\n",
- NULL);
+ umockdev_testbed_add_from_string(
+ fixture->testbed,
+ "P: /devices/usb1\n"
+ "N: bus/usb/001/001\n"
+ "E: SUBSYSTEM=usb\n"
+ "E: DRIVER=usb\n"
+ "E: BUSNUM=001\n"
+ "E: DEVNUM=001\n"
+ "E: DEVNAME=/dev/bus/usb/001/001\n"
+ "E: DEVTYPE=usb_device\n"
+ "A: bConfigurationValue=1\\n\n"
+ "A: busnum=1\\n\n"
+ "A: devnum=1\\n\n"
+ "A: bConfigurationValue=1\\n\n"
+ "A: speed=480\\n\n"
+ /* descriptor from a Canon PowerShot SX200; VID 04a9 PID 31c0 */
+ "H: descriptors="
+ "1201000200000040a904c03102000102"
+ "030109022700010100c0010904000003"
+ "06010100070581020002000705020200"
+ "020007058303080009\n",
+ NULL);
}
static void
-test_ctx_enumerate (UMockdevTestbedFixture *fixture, UNUSED_DATA)
+test_ctx_enumerate(UMockdevTestbedFixture *fixture, UNUSED_DATA)
{
g_autoptr(GPtrArray) devices = NULL;
- test_fixture_add_canon (fixture);
+ test_fixture_add_canon(fixture);
- g_usb_context_enumerate (fixture->ctx);
+ g_usb_context_enumerate(fixture->ctx);
- devices = g_usb_context_get_devices (fixture->ctx);
- g_assert_cmpint (devices->len, ==, 1);
+ devices = g_usb_context_get_devices(fixture->ctx);
+ g_assert_cmpint(devices->len, ==, 1);
}
static void
-count_hotplug_event_cb (GUsbContext *context, GUsbDevice *device, gpointer user_data)
+count_hotplug_event_cb(GUsbContext *context, GUsbDevice *device, gpointer user_data)
{
int *counter = user_data;
@@ -106,74 +108,76 @@ count_hotplug_event_cb (GUsbContext *context, GUsbDevice *device, gpointer user_
}
static void
-test_ctx_hotplug (UMockdevTestbedFixture *fixture, UNUSED_DATA)
+test_ctx_hotplug(UMockdevTestbedFixture *fixture, UNUSED_DATA)
{
g_autoptr(GPtrArray) devices = NULL;
gint events = 0;
- g_signal_connect (fixture->ctx, "device-added", G_CALLBACK (count_hotplug_event_cb), &events);
+ g_signal_connect(fixture->ctx, "device-added", G_CALLBACK(count_hotplug_event_cb), &events);
- g_usb_context_enumerate (fixture->ctx);
+ g_usb_context_enumerate(fixture->ctx);
- devices = g_usb_context_get_devices (fixture->ctx);
- g_assert_cmpint (devices->len, ==, 0);
- g_assert_cmpint (events, ==, 0);
- g_clear_pointer (&devices, g_ptr_array_unref);
+ devices = g_usb_context_get_devices(fixture->ctx);
+ g_assert_cmpint(devices->len, ==, 0);
+ g_assert_cmpint(events, ==, 0);
+ g_clear_pointer(&devices, g_ptr_array_unref);
- test_fixture_add_canon (fixture);
+ test_fixture_add_canon(fixture);
/* ensure the event was processed by helper thread */
- g_usleep (G_USEC_PER_SEC / 2);
+ g_usleep(G_USEC_PER_SEC / 2);
/* still not returned (and no event fired) */
- devices = g_usb_context_get_devices (fixture->ctx);
- g_assert_cmpint (devices->len, ==, 0);
- g_assert_cmpint (events, ==, 0);
- g_clear_pointer (&devices, g_ptr_array_unref);
+ devices = g_usb_context_get_devices(fixture->ctx);
+ g_assert_cmpint(devices->len, ==, 0);
+ g_assert_cmpint(events, ==, 0);
+ g_clear_pointer(&devices, g_ptr_array_unref);
/* run mainloop, which causes the event to be processed */
- while (g_main_context_iteration (NULL, FALSE)) { }
+ while (g_main_context_iteration(NULL, FALSE)) {
+ }
- devices = g_usb_context_get_devices (fixture->ctx);
- g_assert_cmpint (events, ==, 1);
- g_assert_cmpint (devices->len, ==, 1);
- g_clear_pointer (&devices, g_ptr_array_unref);
+ devices = g_usb_context_get_devices(fixture->ctx);
+ g_assert_cmpint(events, ==, 1);
+ g_assert_cmpint(devices->len, ==, 1);
+ g_clear_pointer(&devices, g_ptr_array_unref);
}
static void
-test_ctx_hotplug_dispose (UMockdevTestbedFixture *fixture, UNUSED_DATA)
+test_ctx_hotplug_dispose(UMockdevTestbedFixture *fixture, UNUSED_DATA)
{
g_autoptr(GPtrArray) devices = NULL;
gint events = 0;
- g_signal_connect (fixture->ctx, "device-added", G_CALLBACK (count_hotplug_event_cb), &events);
+ g_signal_connect(fixture->ctx, "device-added", G_CALLBACK(count_hotplug_event_cb), &events);
- g_usb_context_enumerate (fixture->ctx);
- devices = g_usb_context_get_devices (fixture->ctx);
- g_assert_cmpint (devices->len, ==, 0);
- g_assert_cmpint (events, ==, 0);
- g_clear_pointer (&devices, g_ptr_array_unref);
+ g_usb_context_enumerate(fixture->ctx);
+ devices = g_usb_context_get_devices(fixture->ctx);
+ g_assert_cmpint(devices->len, ==, 0);
+ g_assert_cmpint(events, ==, 0);
+ g_clear_pointer(&devices, g_ptr_array_unref);
- test_fixture_add_canon (fixture);
+ test_fixture_add_canon(fixture);
/* ensure the event was processed by helper thread */
- g_usleep (G_USEC_PER_SEC / 2);
+ g_usleep(G_USEC_PER_SEC / 2);
/* still not returned (and no event fired) */
- g_usb_context_enumerate (fixture->ctx);
- devices = g_usb_context_get_devices (fixture->ctx);
- g_assert_cmpint (devices->len, ==, 0);
- g_assert_cmpint (events, ==, 0);
- g_clear_pointer (&devices, g_ptr_array_unref);
+ g_usb_context_enumerate(fixture->ctx);
+ devices = g_usb_context_get_devices(fixture->ctx);
+ g_assert_cmpint(devices->len, ==, 0);
+ g_assert_cmpint(events, ==, 0);
+ g_clear_pointer(&devices, g_ptr_array_unref);
/* idle handler is pending, we dispose our context reference */
- g_object_run_dispose (G_OBJECT (fixture->ctx));
+ g_object_run_dispose(G_OBJECT(fixture->ctx));
/* run mainloop, which causes the event to be processed */
- while (g_main_context_iteration (NULL, FALSE)) { }
+ while (g_main_context_iteration(NULL, FALSE)) {
+ }
/* but no signal is fired */
- g_assert_cmpint (events, ==, 0);
+ g_assert_cmpint(events, ==, 0);
- g_clear_object (&fixture->ctx);
+ g_clear_object(&fixture->ctx);
}
int
@@ -181,20 +185,26 @@ main(int argc, char **argv)
{
g_test_init(&argc, &argv, NULL);
- g_test_add("/gusb/ctx/enumerate", UMockdevTestbedFixture, NULL,
- test_fixture_setup_empty,
- test_ctx_enumerate,
- test_fixture_teardown);
-
- g_test_add("/gusb/ctx/hotplug", UMockdevTestbedFixture, NULL,
- test_fixture_setup_empty,
- test_ctx_hotplug,
- test_fixture_teardown);
-
- g_test_add("/gusb/ctx/hotplug-dispose", UMockdevTestbedFixture, NULL,
- test_fixture_setup_empty,
- test_ctx_hotplug_dispose,
- test_fixture_teardown);
+ g_test_add("/gusb/ctx/enumerate",
+ UMockdevTestbedFixture,
+ NULL,
+ test_fixture_setup_empty,
+ test_ctx_enumerate,
+ test_fixture_teardown);
+
+ g_test_add("/gusb/ctx/hotplug",
+ UMockdevTestbedFixture,
+ NULL,
+ test_fixture_setup_empty,
+ test_ctx_hotplug,
+ test_fixture_teardown);
+
+ g_test_add("/gusb/ctx/hotplug-dispose",
+ UMockdevTestbedFixture,
+ NULL,
+ test_fixture_setup_empty,
+ test_ctx_hotplug_dispose,
+ test_fixture_teardown);
return g_test_run();
}
diff --git a/gusb/gusb-util.c b/gusb/gusb-util.c
index 4ca830d..0456e52 100644
--- a/gusb/gusb-util.c
+++ b/gusb/gusb-util.c
@@ -22,7 +22,7 @@
* Since: 0.1.0
**/
const gchar *
-g_usb_strerror (gint error_code)
+g_usb_strerror(gint error_code)
{
- return libusb_strerror (error_code);
+ return libusb_strerror(error_code);
}
diff --git a/gusb/gusb-util.h b/gusb/gusb-util.h
index 23664f5..ed26eb3 100644
--- a/gusb/gusb-util.h
+++ b/gusb/gusb-util.h
@@ -11,6 +11,7 @@
G_BEGIN_DECLS
-const gchar *g_usb_strerror (gint error_code);
+const gchar *
+g_usb_strerror(gint error_code);
G_END_DECLS
diff --git a/gusb/gusb-version.c b/gusb/gusb-version.c
index 8ae4315..e4630f8 100644
--- a/gusb/gusb-version.c
+++ b/gusb/gusb-version.c
@@ -19,9 +19,8 @@
* Since: 0.3.1
**/
const gchar *
-g_usb_version_string (void)
+g_usb_version_string(void)
{
- return G_STRINGIFY(G_USB_MAJOR_VERSION) "."
- G_STRINGIFY(G_USB_MINOR_VERSION) "."
- G_STRINGIFY(G_USB_MICRO_VERSION);
+ return G_STRINGIFY(G_USB_MAJOR_VERSION) "." G_STRINGIFY(
+ G_USB_MINOR_VERSION) "." G_STRINGIFY(G_USB_MICRO_VERSION);
}
diff --git a/gusb/gusb.h b/gusb/gusb.h
index d8ffea0..928d50a 100644
--- a/gusb/gusb.h
+++ b/gusb/gusb.h
@@ -10,14 +10,14 @@
#define __GUSB_INSIDE__
#include <gusb/gusb-autocleanups.h>
-#include <gusb/gusb-context.h>
-#include <gusb/gusb-interface.h>
#include <gusb/gusb-bos-descriptor.h>
+#include <gusb/gusb-context.h>
+#include <gusb/gusb-device-list.h>
+#include <gusb/gusb-device.h>
#include <gusb/gusb-endpoint.h>
+#include <gusb/gusb-interface.h>
#include <gusb/gusb-source.h>
-#include <gusb/gusb-device.h>
-#include <gusb/gusb-device-list.h>
-#include <gusb/gusb-version.h>
#include <gusb/gusb-util.h>
+#include <gusb/gusb-version.h>
#undef __GUSB_INSIDE__
diff --git a/tools/gusb-main.c b/tools/gusb-main.c
index 8caad29..8cfd4d1 100644
--- a/tools/gusb-main.c
+++ b/tools/gusb-main.c
@@ -13,362 +13,362 @@
#include <string.h>
static void
-gusb_log_ignore_cb (const gchar *log_domain, GLogLevelFlags log_level,
- const gchar *message, gpointer user_data)
+gusb_log_ignore_cb(const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
{
}
static void
-gusb_log_handler_cb (const gchar *log_domain, GLogLevelFlags log_level,
- const gchar *message, gpointer user_data)
+gusb_log_handler_cb(const gchar *log_domain,
+ GLogLevelFlags log_level,
+ const gchar *message,
+ gpointer user_data)
{
gchar str_time[255];
time_t the_time;
/* header always in green */
- time (&the_time);
- strftime (str_time, 254, "%H:%M:%S", localtime (&the_time));
- g_print ("%c[%dmTI:%s\t", 0x1B, 32, str_time);
+ time(&the_time);
+ strftime(str_time, 254, "%H:%M:%S", localtime(&the_time));
+ g_print("%c[%dmTI:%s\t", 0x1B, 32, str_time);
/* critical is also in red */
- if (log_level == G_LOG_LEVEL_CRITICAL ||
- log_level == G_LOG_LEVEL_WARNING ||
+ if (log_level == G_LOG_LEVEL_CRITICAL || log_level == G_LOG_LEVEL_WARNING ||
log_level == G_LOG_LEVEL_ERROR) {
- g_print ("%c[%dm%s\n%c[%dm", 0x1B, 31, message, 0x1B, 0);
+ g_print("%c[%dm%s\n%c[%dm", 0x1B, 31, message, 0x1B, 0);
} else {
/* debug in blue */
- g_print ("%c[%dm%s\n%c[%dm", 0x1B, 34, message, 0x1B, 0);
+ g_print("%c[%dm%s\n%c[%dm", 0x1B, 34, message, 0x1B, 0);
}
}
typedef struct {
- GOptionContext *context;
- GUsbContext *usb_ctx;
- GPtrArray *cmd_array;
+ GOptionContext *context;
+ GUsbContext *usb_ctx;
+ GPtrArray *cmd_array;
} GUsbCmdPrivate;
-typedef gboolean (*GUsbCmdPrivateCb) (GUsbCmdPrivate *cmd,
- gchar **values,
- GError **error);
+typedef gboolean (*GUsbCmdPrivateCb)(GUsbCmdPrivate *cmd, gchar **values, GError **error);
typedef struct {
- gchar *name;
- gchar *description;
- GUsbCmdPrivateCb callback;
+ gchar *name;
+ gchar *description;
+ GUsbCmdPrivateCb callback;
} GUsbCmdItem;
static void
-gusb_cmd_item_free (GUsbCmdItem *item)
+gusb_cmd_item_free(GUsbCmdItem *item)
{
- g_free (item->name);
- g_free (item->description);
- g_slice_free (GUsbCmdItem, item);
+ g_free(item->name);
+ g_free(item->description);
+ g_slice_free(GUsbCmdItem, item);
}
/*
* gusb_sort_command_name_cb:
*/
static gint
-gusb_sort_command_name_cb (GUsbCmdItem **item1, GUsbCmdItem **item2)
+gusb_sort_command_name_cb(GUsbCmdItem **item1, GUsbCmdItem **item2)
{
- return g_strcmp0 ((*item1)->name, (*item2)->name);
+ return g_strcmp0((*item1)->name, (*item2)->name);
}
static void
-gusb_cmd_add (GPtrArray *array, const gchar *name, const gchar *description, GUsbCmdPrivateCb callback)
+gusb_cmd_add(GPtrArray *array,
+ const gchar *name,
+ const gchar *description,
+ GUsbCmdPrivateCb callback)
{
- g_auto(GStrv) names = g_strsplit (name, ",", -1);
+ g_auto(GStrv) names = g_strsplit(name, ",", -1);
for (guint i = 0; names[i] != NULL; i++) {
- GUsbCmdItem *item = g_slice_new0 (GUsbCmdItem);
- item->name = g_strdup (names[i]);
+ GUsbCmdItem *item = g_slice_new0(GUsbCmdItem);
+ item->name = g_strdup(names[i]);
if (i == 0) {
- item->description = g_strdup (description);
+ item->description = g_strdup(description);
} else {
/* TRANSLATORS: this is a command alias */
- item->description = g_strdup_printf ("Alias to %s",
- names[0]);
+ item->description = g_strdup_printf("Alias to %s", names[0]);
}
item->callback = callback;
- g_ptr_array_add (array, item);
+ g_ptr_array_add(array, item);
}
}
static gchar *
-gusb_cmd_get_descriptions (GPtrArray *array)
+gusb_cmd_get_descriptions(GPtrArray *array)
{
guint len;
guint max_len = 19;
g_autoptr(GString) string = NULL;
/* print each command */
- string = g_string_new ("");
+ string = g_string_new("");
for (guint i = 0; i < array->len; i++) {
- GUsbCmdItem *item = g_ptr_array_index (array, i);
- g_string_append (string, " ");
- g_string_append (string, item->name);
- g_string_append (string, " ");
- len = strlen (item->name);
- for (guint j = len; j < max_len+2; j++)
- g_string_append_c (string, ' ');
- g_string_append (string, item->description);
- g_string_append_c (string, '\n');
+ GUsbCmdItem *item = g_ptr_array_index(array, i);
+ g_string_append(string, " ");
+ g_string_append(string, item->name);
+ g_string_append(string, " ");
+ len = strlen(item->name);
+ for (guint j = len; j < max_len + 2; j++)
+ g_string_append_c(string, ' ');
+ g_string_append(string, item->description);
+ g_string_append_c(string, '\n');
}
/* remove trailing newline */
if (string->len > 0)
- g_string_set_size (string, string->len - 1);
+ g_string_set_size(string, string->len - 1);
- return g_string_free (g_steal_pointer(&string), FALSE);
+ return g_string_free(g_steal_pointer(&string), FALSE);
}
static void
-gusb_main_device_open (GUsbDevice *device)
+gusb_main_device_open(GUsbDevice *device)
{
guint8 idx;
g_autoptr(GError) error = NULL;
/* open */
- if (!g_usb_device_open (device, &error)) {
- g_print ("failed to open: %s\n", error->message);
+ if (!g_usb_device_open(device, &error)) {
+ g_print("failed to open: %s\n", error->message);
return;
}
/* print info we can only get whilst open */
- idx = g_usb_device_get_product_index (device);
+ idx = g_usb_device_get_product_index(device);
if (idx != 0x00) {
- g_autofree gchar *product = g_usb_device_get_string_descriptor (device, idx, &error);
+ g_autofree gchar *product = g_usb_device_get_string_descriptor(device, idx, &error);
if (product == NULL) {
- g_print ("failed to get string desc: %s\n", error->message);
+ g_print("failed to get string desc: %s\n", error->message);
return;
}
- g_print ("product: %s\n", product);
+ g_print("product: %s\n", product);
}
}
static void
-gusb_device_list_added_cb (GUsbContext *context,
- GUsbDevice *device,
- gpointer user_data)
+gusb_device_list_added_cb(GUsbContext *context, GUsbDevice *device, gpointer user_data)
{
- g_print ("device %s added %x:%x\n",
- g_usb_device_get_platform_id (device),
- g_usb_device_get_bus (device),
- g_usb_device_get_address (device));
- gusb_main_device_open (device);
+ g_print("device %s added %x:%x\n",
+ g_usb_device_get_platform_id(device),
+ g_usb_device_get_bus(device),
+ g_usb_device_get_address(device));
+ gusb_main_device_open(device);
}
static void
-gusb_device_list_removed_cb (GUsbContext *context,
- GUsbDevice *device,
- gpointer user_data)
+gusb_device_list_removed_cb(GUsbContext *context, GUsbDevice *device, gpointer user_data)
{
- g_print ("device %s removed %x:%x\n",
- g_usb_device_get_platform_id (device),
- g_usb_device_get_bus (device),
- g_usb_device_get_address (device));
+ g_print("device %s removed %x:%x\n",
+ g_usb_device_get_platform_id(device),
+ g_usb_device_get_bus(device),
+ g_usb_device_get_address(device));
}
static gint
-gusb_devices_sort_by_platform_id_cb (gconstpointer a, gconstpointer b)
+gusb_devices_sort_by_platform_id_cb(gconstpointer a, gconstpointer b)
{
- GUsbDevice *device_a = *((GUsbDevice **) a);
- GUsbDevice *device_b = *((GUsbDevice **) b);
- return g_strcmp0 (g_usb_device_get_platform_id (device_a),
- g_usb_device_get_platform_id (device_b));
+ GUsbDevice *device_a = *((GUsbDevice **)a);
+ GUsbDevice *device_b = *((GUsbDevice **)b);
+ return g_strcmp0(g_usb_device_get_platform_id(device_a),
+ g_usb_device_get_platform_id(device_b));
}
static gboolean
-moo_cb (GNode *node, gpointer data)
+gusb_cmd_show_cb(GNode *node, gpointer data)
{
- GUsbDevice *device = G_USB_DEVICE (node->data);
+ GUsbDevice *device = G_USB_DEVICE(node->data);
const gchar *tmp;
g_autofree gchar *product = NULL;
g_autofree gchar *vendor = NULL;
g_autoptr(GString) str = NULL;
if (device == NULL) {
- g_print ("Root Device\n");
+ g_print("Root Device\n");
return FALSE;
}
/* indent */
- str = g_string_new ("");
+ str = g_string_new("");
for (GNode *n = node; n->data != NULL; n = n->parent)
- g_string_append (str, " ");
+ g_string_append(str, " ");
/* add bus:address */
- g_string_append_printf (str, "%02x:%02x [%04x:%04x]",
- g_usb_device_get_bus (device),
- g_usb_device_get_address (device),
- g_usb_device_get_vid (device),
- g_usb_device_get_pid (device));
+ g_string_append_printf(str,
+ "%02x:%02x [%04x:%04x]",
+ g_usb_device_get_bus(device),
+ g_usb_device_get_address(device),
+ g_usb_device_get_vid(device),
+ g_usb_device_get_pid(device));
/* pad */
for (guint i = str->len; i < 30; i++)
- g_string_append (str, " ");
+ g_string_append(str, " ");
/* We don't error check these as not all devices have these
(and the device_open may have failed). */
- g_usb_device_open (device, NULL);
- vendor = g_usb_device_get_string_descriptor (device,
- g_usb_device_get_manufacturer_index (device),
- NULL);
- product = g_usb_device_get_string_descriptor (device,
- g_usb_device_get_product_index (device),
- NULL);
+ g_usb_device_open(device, NULL);
+ vendor = g_usb_device_get_string_descriptor(device,
+ g_usb_device_get_manufacturer_index(device),
+ NULL);
+ product = g_usb_device_get_string_descriptor(device,
+ g_usb_device_get_product_index(device),
+ NULL);
/* lookup from usb.ids */
if (vendor == NULL) {
- tmp = g_usb_device_get_vid_as_str (device);
+ tmp = g_usb_device_get_vid_as_str(device);
if (tmp != NULL)
- vendor = g_strdup (tmp);
+ vendor = g_strdup(tmp);
}
if (product == NULL) {
- tmp = g_usb_device_get_pid_as_str (device);
+ tmp = g_usb_device_get_pid_as_str(device);
if (tmp != NULL)
- product = g_strdup (tmp);
+ product = g_strdup(tmp);
}
/* a hub */
- if (g_usb_device_get_device_class (device) == 0x09 && product == NULL) {
- product = g_strdup ("USB HUB");
+ if (g_usb_device_get_device_class(device) == 0x09 && product == NULL) {
+ product = g_strdup("USB HUB");
}
/* fall back to the VID/PID */
if (product == NULL)
- product = g_strdup ("Unknown");
+ product = g_strdup("Unknown");
if (vendor == NULL)
- vendor = g_strdup ("Unknown");
+ vendor = g_strdup("Unknown");
/* add bus:address */
- g_string_append_printf (str, "%s - %s", vendor, product);
+ g_string_append_printf(str, "%s - %s", vendor, product);
- g_print ("%s\n", str->str);
+ g_print("%s\n", str->str);
return FALSE;
}
static gboolean
-gusb_cmd_show (GUsbCmdPrivate *priv, gchar **values, GError **error)
+gusb_cmd_show(GUsbCmdPrivate *priv, gchar **values, GError **error)
{
g_autoptr(GNode) node = NULL;
g_autoptr(GPtrArray) devices = NULL;
/* sort */
- devices = g_usb_context_get_devices (priv->usb_ctx);
- g_ptr_array_sort (devices, gusb_devices_sort_by_platform_id_cb);
+ devices = g_usb_context_get_devices(priv->usb_ctx);
+ g_ptr_array_sort(devices, gusb_devices_sort_by_platform_id_cb);
/* make a tree of the devices */
- node = g_node_new (NULL);
+ node = g_node_new(NULL);
for (guint i = 0; i < devices->len; i++) {
GNode *n;
- GUsbDevice *device = g_ptr_array_index (devices, i);
- GUsbDevice *parent = g_usb_device_get_parent (device);
+ GUsbDevice *device = g_ptr_array_index(devices, i);
+ GUsbDevice *parent = g_usb_device_get_parent(device);
if (parent == NULL) {
- g_node_append_data (node, device);
+ g_node_append_data(node, device);
continue;
}
- n = g_node_find (node, G_PRE_ORDER, G_TRAVERSE_ALL, parent);
+ n = g_node_find(node, G_PRE_ORDER, G_TRAVERSE_ALL, parent);
if (n == NULL) {
- g_set_error (error, 1, 0,
- "no parent node for %s",
- g_usb_device_get_platform_id (device));
+ g_set_error(error,
+ 1,
+ 0,
+ "no parent node for %s",
+ g_usb_device_get_platform_id(device));
return FALSE;
}
- g_node_append_data (n, device);
-
+ g_node_append_data(n, device);
}
- g_node_traverse (node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, moo_cb, priv);
+ g_node_traverse(node, G_PRE_ORDER, G_TRAVERSE_ALL, -1, gusb_cmd_show_cb, priv);
return TRUE;
}
static gboolean
-gusb_cmd_watch (GUsbCmdPrivate *priv, gchar **values, GError **error)
+gusb_cmd_watch(GUsbCmdPrivate *priv, gchar **values, GError **error)
{
g_autoptr(GMainLoop) loop = NULL;
g_autoptr(GPtrArray) devices = NULL;
- devices = g_usb_context_get_devices (priv->usb_ctx);
+ devices = g_usb_context_get_devices(priv->usb_ctx);
for (guint i = 0; i < devices->len; i++) {
- GUsbDevice *device = g_ptr_array_index (devices, i);
- g_print ("device %s already present %x:%x\n",
- g_usb_device_get_platform_id (device),
- g_usb_device_get_bus (device),
- g_usb_device_get_address (device));
- gusb_main_device_open (device);
+ GUsbDevice *device = g_ptr_array_index(devices, i);
+ g_print("device %s already present %x:%x\n",
+ g_usb_device_get_platform_id(device),
+ g_usb_device_get_bus(device),
+ g_usb_device_get_address(device));
+ gusb_main_device_open(device);
}
- loop = g_main_loop_new (NULL, FALSE);
- g_signal_connect (priv->usb_ctx, "device-added",
- G_CALLBACK (gusb_device_list_added_cb),
- priv);
- g_signal_connect (priv->usb_ctx, "device-removed",
- G_CALLBACK (gusb_device_list_removed_cb),
- priv);
- g_main_loop_run (loop);
+ loop = g_main_loop_new(NULL, FALSE);
+ g_signal_connect(priv->usb_ctx,
+ "device-added",
+ G_CALLBACK(gusb_device_list_added_cb),
+ priv);
+ g_signal_connect(priv->usb_ctx,
+ "device-removed",
+ G_CALLBACK(gusb_device_list_removed_cb),
+ priv);
+ g_main_loop_run(loop);
return TRUE;
}
static gboolean
-gusb_cmd_replug (GUsbCmdPrivate *priv, gchar **values, GError **error)
+gusb_cmd_replug(GUsbCmdPrivate *priv, gchar **values, GError **error)
{
guint16 vid, pid;
g_autoptr(GUsbDevice) device = NULL;
g_autoptr(GUsbDevice) device_new = NULL;
/* check args */
- if (g_strv_length (values) != 2) {
- g_set_error_literal (error, 1, 0,
- "no VID:PID specified");
+ if (g_strv_length(values) != 2) {
+ g_set_error_literal(error, 1, 0, "no VID:PID specified");
return FALSE;
}
/* get vid:pid */
- vid = g_ascii_strtoull (values[0], NULL, 16);
- pid = g_ascii_strtoull (values[1], NULL, 16);
- device = g_usb_context_find_by_vid_pid (priv->usb_ctx,
- vid, pid, error);
+ vid = g_ascii_strtoull(values[0], NULL, 16);
+ pid = g_ascii_strtoull(values[1], NULL, 16);
+ device = g_usb_context_find_by_vid_pid(priv->usb_ctx, vid, pid, error);
if (device == NULL)
return FALSE;
/* watch for debugging */
- g_signal_connect (priv->usb_ctx, "device-added",
- G_CALLBACK (gusb_device_list_added_cb),
- priv);
- g_signal_connect (priv->usb_ctx, "device-removed",
- G_CALLBACK (gusb_device_list_removed_cb),
- priv);
+ g_signal_connect(priv->usb_ctx,
+ "device-added",
+ G_CALLBACK(gusb_device_list_added_cb),
+ priv);
+ g_signal_connect(priv->usb_ctx,
+ "device-removed",
+ G_CALLBACK(gusb_device_list_removed_cb),
+ priv);
/* wait for replug */
- device_new = g_usb_context_wait_for_replug (priv->usb_ctx,
- device,
- 5000,
- error);
+ device_new = g_usb_context_wait_for_replug(priv->usb_ctx, device, 5000, error);
return device_new != NULL;
}
static gboolean
-gusb_cmd_run (GUsbCmdPrivate *priv, const gchar *command, gchar **values, GError **error)
+gusb_cmd_run(GUsbCmdPrivate *priv, const gchar *command, gchar **values, GError **error)
{
- g_autoptr(GString) string = g_string_new (NULL);
+ g_autoptr(GString) string = g_string_new(NULL);
/* find command */
for (guint i = 0; i < priv->cmd_array->len; i++) {
- GUsbCmdItem *item = g_ptr_array_index (priv->cmd_array, i);
- if (g_strcmp0 (item->name, command) == 0) {
- return item->callback (priv, values, error);
+ GUsbCmdItem *item = g_ptr_array_index(priv->cmd_array, i);
+ if (g_strcmp0(item->name, command) == 0) {
+ return item->callback(priv, values, error);
}
}
/* TRANSLATORS: error message */
- g_string_append_printf (string, "%s\n", "Command not found, valid commands are:");
+ g_string_append_printf(string, "%s\n", "Command not found, valid commands are:");
for (guint i = 0; i < priv->cmd_array->len; i++) {
- GUsbCmdItem *item = g_ptr_array_index (priv->cmd_array, i);
- g_string_append_printf (string, " * %s\n", item->name);
+ GUsbCmdItem *item = g_ptr_array_index(priv->cmd_array, i);
+ g_string_append_printf(string, " * %s\n", item->name);
}
- g_set_error_literal (error, 1, 0, string->str);
+ g_set_error_literal(error, 1, 0, string->str);
return FALSE;
}
@@ -376,17 +376,17 @@ static void
gusb_cmd_private_free(GUsbCmdPrivate *priv)
{
if (priv->cmd_array != NULL)
- g_ptr_array_unref (priv->cmd_array);
+ g_ptr_array_unref(priv->cmd_array);
if (priv->usb_ctx != NULL)
- g_object_unref (priv->usb_ctx);
- g_option_context_free (priv->context);
- g_slice_free (GUsbCmdPrivate, priv);
+ g_object_unref(priv->usb_ctx);
+ g_option_context_free(priv->context);
+ g_slice_free(GUsbCmdPrivate, priv);
}
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GUsbCmdPrivate, gusb_cmd_private_free)
int
-main (int argc, char *argv[])
+main(int argc, char *argv[])
{
gboolean verbose = FALSE;
g_autofree gchar *cmd_descriptions = NULL;
@@ -394,75 +394,67 @@ main (int argc, char *argv[])
g_autoptr(GError) error = NULL;
g_autoptr(GUsbCmdPrivate) priv = NULL;
- const GOptionEntry options[] = {
- { "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose,
- "Show extra debugging information", NULL },
- { NULL}
- };
+ const GOptionEntry options[] = {{"verbose",
+ 'v',
+ 0,
+ G_OPTION_ARG_NONE,
+ &verbose,
+ "Show extra debugging information",
+ NULL},
+ {NULL}};
- setlocale (LC_ALL, "");
+ setlocale(LC_ALL, "");
/* create helper object */
- priv = g_slice_new0 (GUsbCmdPrivate);
- priv->context = g_option_context_new ("GUSB Console Program");
- g_option_context_add_main_entries (priv->context, options, NULL);
- if (!g_option_context_parse (priv->context, &argc, &argv, &error)) {
- g_printerr ("Failed to parse arguments: %s\n", error->message);
+ priv = g_slice_new0(GUsbCmdPrivate);
+ priv->context = g_option_context_new("GUSB Console Program");
+ g_option_context_add_main_entries(priv->context, options, NULL);
+ if (!g_option_context_parse(priv->context, &argc, &argv, &error)) {
+ g_printerr("Failed to parse arguments: %s\n", error->message);
return 2;
}
/* verbose? */
if (verbose) {
- g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
- g_log_set_handler ("GUsb", G_LOG_LEVEL_ERROR |
- G_LOG_LEVEL_CRITICAL |
- G_LOG_LEVEL_DEBUG |
- G_LOG_LEVEL_WARNING,
- gusb_log_handler_cb, NULL);
+ g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
+ g_log_set_handler("GUsb",
+ G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_DEBUG |
+ G_LOG_LEVEL_WARNING,
+ gusb_log_handler_cb,
+ NULL);
} else {
/* hide all debugging */
- g_log_set_fatal_mask (NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
- g_log_set_handler ("GUsb", G_LOG_LEVEL_DEBUG,
- gusb_log_ignore_cb, NULL);
+ g_log_set_fatal_mask(NULL, G_LOG_LEVEL_ERROR | G_LOG_LEVEL_CRITICAL);
+ g_log_set_handler("GUsb", G_LOG_LEVEL_DEBUG, gusb_log_ignore_cb, NULL);
}
/* GUsbContext */
- priv->usb_ctx = g_usb_context_new (NULL);
- g_usb_context_set_flags (priv->usb_ctx, G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES);
+ priv->usb_ctx = g_usb_context_new(NULL);
+ g_usb_context_set_flags(priv->usb_ctx, G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES);
/* add commands */
- priv->cmd_array = g_ptr_array_new_with_free_func ((GDestroyNotify) gusb_cmd_item_free);
- gusb_cmd_add (priv->cmd_array,
- "show",
- "Show currently connected devices",
- gusb_cmd_show);
- gusb_cmd_add (priv->cmd_array,
- "watch",
- "Watch devices as they come and go",
- gusb_cmd_watch);
- gusb_cmd_add (priv->cmd_array,
- "replug",
- "Watch a device as it reconnects",
- gusb_cmd_replug);
+ priv->cmd_array = g_ptr_array_new_with_free_func((GDestroyNotify)gusb_cmd_item_free);
+ gusb_cmd_add(priv->cmd_array, "show", "Show currently connected devices", gusb_cmd_show);
+ gusb_cmd_add(priv->cmd_array, "watch", "Watch devices as they come and go", gusb_cmd_watch);
+ gusb_cmd_add(priv->cmd_array, "replug", "Watch a device as it reconnects", gusb_cmd_replug);
/* sort by command name */
- g_ptr_array_sort (priv->cmd_array,
- (GCompareFunc) gusb_sort_command_name_cb);
+ g_ptr_array_sort(priv->cmd_array, (GCompareFunc)gusb_sort_command_name_cb);
/* get a list of the commands */
- cmd_descriptions = gusb_cmd_get_descriptions (priv->cmd_array);
- g_option_context_set_summary (priv->context, cmd_descriptions);
+ cmd_descriptions = gusb_cmd_get_descriptions(priv->cmd_array);
+ g_option_context_set_summary(priv->context, cmd_descriptions);
/* nothing specified */
if (argc < 2) {
- options_help = g_option_context_get_help (priv->context, TRUE, NULL);
- g_print ("%s", options_help);
+ options_help = g_option_context_get_help(priv->context, TRUE, NULL);
+ g_print("%s", options_help);
return 1;
}
/* run the specified command */
- if (!gusb_cmd_run (priv, argv[1], (gchar**) &argv[2], &error)) {
- g_print ("%s\n", error->message);
+ if (!gusb_cmd_run(priv, argv[1], (gchar **)&argv[2], &error)) {
+ g_print("%s\n", error->message);
return 1;
}