Skip to content

Commit

Permalink
Reduce the debugging level when emulating firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsie committed Jan 27, 2023
1 parent 28b4d05 commit c9add98
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gusb/gusb-context-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ const gchar *
_g_usb_context_lookup_vendor(GUsbContext *self, guint16 vid, GError **error);
const gchar *
_g_usb_context_lookup_product(GUsbContext *self, guint16 vid, guint16 pid, GError **error);
gboolean
_g_usb_context_has_flag(GUsbContext *self, GUsbContextFlags flags);

G_END_DECLS
7 changes: 7 additions & 0 deletions gusb/gusb-context.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,13 @@ g_usb_context_get_flags(GUsbContext *self)
return priv->flags;
}

gboolean
_g_usb_context_has_flag(GUsbContext *self, GUsbContextFlags flag)
{
GUsbContextPrivate *priv = GET_PRIVATE(self);
return (priv->flags & flag) > 0;
}

static gpointer
g_usb_context_event_thread_cb(gpointer data)
{
Expand Down
1 change: 1 addition & 0 deletions gusb/gusb-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef enum {
G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES = 1 << 0,
G_USB_CONTEXT_FLAGS_SAVE_EVENTS = 1 << 1,
G_USB_CONTEXT_FLAGS_SAVE_REMOVED_DEVICES = 1 << 2,
G_USB_CONTEXT_FLAGS_DEBUG = 1 << 3,
/*< private >*/
G_USB_CONTEXT_FLAGS_LAST
} GUsbContextFlags;
Expand Down
12 changes: 8 additions & 4 deletions gusb/gusb-device.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ _g_usb_device_save(GUsbDevice *self, JsonBuilder *json_builder, GError **error)
/* array of BOS descriptors */
bos_descriptors = g_usb_device_get_bos_descriptors(self, &error_bos);
if (bos_descriptors == NULL) {
g_debug("%s", error_bos->message);
if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG))
g_debug("%s", error_bos->message);
} else if (bos_descriptors->len > 0) {
json_builder_set_member_name(json_builder, "UsbBosDescriptors");
json_builder_begin_array(json_builder);
Expand All @@ -419,7 +420,8 @@ _g_usb_device_save(GUsbDevice *self, JsonBuilder *json_builder, GError **error)
/* array of interfaces */
interfaces = g_usb_device_get_interfaces(self, &error_interfaces);
if (interfaces == NULL) {
g_debug("%s", error_interfaces->message);
if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG))
g_debug("%s", error_interfaces->message);
} else if (interfaces->len > 0) {
json_builder_set_member_name(json_builder, "UsbInterfaces");
json_builder_begin_array(json_builder);
Expand Down Expand Up @@ -829,7 +831,8 @@ g_usb_device_load_event(GUsbDevice *self, const gchar *id)
for (guint i = priv->event_idx; i < priv->events->len; i++) {
GUsbDeviceEvent *event = g_ptr_array_index(priv->events, i);
if (g_strcmp0(g_usb_device_event_get_id(event), id) == 0) {
g_debug("found in-order %s at position %u", id, i);
if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG))
g_debug("found in-order %s at position %u", id, i);
priv->event_idx = i + 1;
return event;
}
Expand All @@ -839,7 +842,8 @@ g_usb_device_load_event(GUsbDevice *self, const gchar *id)
for (guint i = 0; i < priv->events->len; i++) {
GUsbDeviceEvent *event = g_ptr_array_index(priv->events, i);
if (g_strcmp0(g_usb_device_event_get_id(event), id) == 0) {
g_debug("found out-of-order %s at position %u", id, i);
if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG))
g_debug("found out-of-order %s at position %u", id, i);
return event;
}
}
Expand Down
2 changes: 2 additions & 0 deletions tools/gusb-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,8 @@ main(int argc, char *argv[])
priv->usb_ctx = g_usb_context_new(NULL);
if (save_events)
context_flags |= G_USB_CONTEXT_FLAGS_SAVE_EVENTS;
if (verbose)
context_flags |= G_USB_CONTEXT_FLAGS_DEBUG;
g_usb_context_set_flags(priv->usb_ctx, context_flags);

/* add commands */
Expand Down

0 comments on commit c9add98

Please sign in to comment.