Skip to content

Commit c9add98

Browse files
committed
Reduce the debugging level when emulating firmware
1 parent 28b4d05 commit c9add98

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

gusb/gusb-context-private.h

+2
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ const gchar *
1919
_g_usb_context_lookup_vendor(GUsbContext *self, guint16 vid, GError **error);
2020
const gchar *
2121
_g_usb_context_lookup_product(GUsbContext *self, guint16 vid, guint16 pid, GError **error);
22+
gboolean
23+
_g_usb_context_has_flag(GUsbContext *self, GUsbContextFlags flags);
2224

2325
G_END_DECLS

gusb/gusb-context.c

+7
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,13 @@ g_usb_context_get_flags(GUsbContext *self)
826826
return priv->flags;
827827
}
828828

829+
gboolean
830+
_g_usb_context_has_flag(GUsbContext *self, GUsbContextFlags flag)
831+
{
832+
GUsbContextPrivate *priv = GET_PRIVATE(self);
833+
return (priv->flags & flag) > 0;
834+
}
835+
829836
static gpointer
830837
g_usb_context_event_thread_cb(gpointer data)
831838
{

gusb/gusb-context.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ typedef enum {
4242
G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES = 1 << 0,
4343
G_USB_CONTEXT_FLAGS_SAVE_EVENTS = 1 << 1,
4444
G_USB_CONTEXT_FLAGS_SAVE_REMOVED_DEVICES = 1 << 2,
45+
G_USB_CONTEXT_FLAGS_DEBUG = 1 << 3,
4546
/*< private >*/
4647
G_USB_CONTEXT_FLAGS_LAST
4748
} GUsbContextFlags;

gusb/gusb-device.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,8 @@ _g_usb_device_save(GUsbDevice *self, JsonBuilder *json_builder, GError **error)
404404
/* array of BOS descriptors */
405405
bos_descriptors = g_usb_device_get_bos_descriptors(self, &error_bos);
406406
if (bos_descriptors == NULL) {
407-
g_debug("%s", error_bos->message);
407+
if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG))
408+
g_debug("%s", error_bos->message);
408409
} else if (bos_descriptors->len > 0) {
409410
json_builder_set_member_name(json_builder, "UsbBosDescriptors");
410411
json_builder_begin_array(json_builder);
@@ -419,7 +420,8 @@ _g_usb_device_save(GUsbDevice *self, JsonBuilder *json_builder, GError **error)
419420
/* array of interfaces */
420421
interfaces = g_usb_device_get_interfaces(self, &error_interfaces);
421422
if (interfaces == NULL) {
422-
g_debug("%s", error_interfaces->message);
423+
if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG))
424+
g_debug("%s", error_interfaces->message);
423425
} else if (interfaces->len > 0) {
424426
json_builder_set_member_name(json_builder, "UsbInterfaces");
425427
json_builder_begin_array(json_builder);
@@ -829,7 +831,8 @@ g_usb_device_load_event(GUsbDevice *self, const gchar *id)
829831
for (guint i = priv->event_idx; i < priv->events->len; i++) {
830832
GUsbDeviceEvent *event = g_ptr_array_index(priv->events, i);
831833
if (g_strcmp0(g_usb_device_event_get_id(event), id) == 0) {
832-
g_debug("found in-order %s at position %u", id, i);
834+
if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG))
835+
g_debug("found in-order %s at position %u", id, i);
833836
priv->event_idx = i + 1;
834837
return event;
835838
}
@@ -839,7 +842,8 @@ g_usb_device_load_event(GUsbDevice *self, const gchar *id)
839842
for (guint i = 0; i < priv->events->len; i++) {
840843
GUsbDeviceEvent *event = g_ptr_array_index(priv->events, i);
841844
if (g_strcmp0(g_usb_device_event_get_id(event), id) == 0) {
842-
g_debug("found out-of-order %s at position %u", id, i);
845+
if (_g_usb_context_has_flag(priv->context, G_USB_CONTEXT_FLAGS_DEBUG))
846+
g_debug("found out-of-order %s at position %u", id, i);
843847
return event;
844848
}
845849
}

tools/gusb-main.c

+2
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,8 @@ main(int argc, char *argv[])
519519
priv->usb_ctx = g_usb_context_new(NULL);
520520
if (save_events)
521521
context_flags |= G_USB_CONTEXT_FLAGS_SAVE_EVENTS;
522+
if (verbose)
523+
context_flags |= G_USB_CONTEXT_FLAGS_DEBUG;
522524
g_usb_context_set_flags(priv->usb_ctx, context_flags);
523525

524526
/* add commands */

0 commit comments

Comments
 (0)