GUsbContext

GUsbContext — Per-thread instance integration for libusb

Functions

Types and Values

Description

This object is used to get a context that is thread safe.

Functions

g_usb_context_error_quark ()

GQuark
g_usb_context_error_quark (void);

Returns

Our personal error quark.

Since: 0.1.0


g_usb_context_new ()

GUsbContext *
g_usb_context_new (GError **error);

Creates a new context for accessing USB devices.

Parameters

error

a GError, or NULL

 

Returns

a new GUsbContext object or NULL on error.

Since: 0.1.0


g_usb_context_set_flags ()

void
g_usb_context_set_flags (GUsbContext *self,
                         GUsbContextFlags flags);

Sets the flags to use for the context. These should be set before g_usb_context_enumerate() is called.

Parameters

self

a GUsbContext

 

flags

some GUsbContextFlags, e.g. G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES

 

Since: 0.2.11


g_usb_context_get_flags ()

GUsbContextFlags
g_usb_context_get_flags (GUsbContext *self);

Sets the flags to use for the context.

Parameters

self

a GUsbContext

 

Returns

the GUsbContextFlags, e.g. G_USB_CONTEXT_FLAGS_AUTO_OPEN_DEVICES

Since: 0.2.11


g_usb_context_get_source ()

GUsbSource *
g_usb_context_get_source (GUsbContext *self,
                          GMainContext *main_ctx);

g_usb_context_get_source is deprecated and should not be used in newly-written code.

This function does nothing.

Parameters

self

a GUsbContext

 

main_ctx

a GMainContext, or NULL

 

Returns

the GUsbSource.

[transfer none]

Since: 0.1.0


g_usb_context_get_main_context ()

GMainContext *
g_usb_context_get_main_context (GUsbContext *self);

Gets the internal GMainContext to use for synchronous methods. By default the value is set to the value of g_main_context_default()

Parameters

self

a GUsbContext

 

Returns

the GMainContext.

[transfer none]

Since: 0.2.5


g_usb_context_set_main_context ()

void
g_usb_context_set_main_context (GUsbContext *self,
                                GMainContext *main_ctx);

Sets the internal GMainContext to use for synchronous methods.

Parameters

self

a GUsbContext

 

Since: 0.2.5


g_usb_context_get_hotplug_poll_interval ()

guint
g_usb_context_get_hotplug_poll_interval
                               (GUsbContext *self);

Gets the poll interval for platforms like Windows that do not support LIBUSB_CAP_HAS_HOTPLUG.

Parameters

self

a GUsbContext

 

Returns

interval in ms

Since: 0.3.10


g_usb_context_set_hotplug_poll_interval ()

void
g_usb_context_set_hotplug_poll_interval
                               (GUsbContext *self,
                                guint hotplug_poll_interval);

Sets the poll interval for platforms like Windows that do not support LIBUSB_CAP_HAS_HOTPLUG. This defaults to 1000ms and can be changed before or after g_usb_context_enumerate() has been called.

Parameters

self

a GUsbContext

 

hotplug_poll_interval

the interval in ms

 

Since: 0.3.10


g_usb_context_enumerate ()

void
g_usb_context_enumerate (GUsbContext *self);

Enumerates all the USB devices and adds them to the context.

You only need to call this function once, and any subsequent calls are silently ignored.

Parameters

self

a GUsbContext

 

Since: 0.2.2


g_usb_context_load ()

gboolean
g_usb_context_load (GUsbContext *self,
                    JsonObject *json_object,
                    GError **error);

Loads the context from a JSON object.

Parameters

context

a GUsbContext

 

json_object

a JsonObject

 

error

a GError, or NULL

 

Returns

TRUE on success

Since: 0.4.0


g_usb_context_save ()

gboolean
g_usb_context_save (GUsbContext *self,
                    JsonBuilder *json_builder,
                    GError **error);

Saves the context to an existing JSON builder.

Parameters

context

a GUsbContext

 

json_builder

a JsonBuilder

 

error

a GError, or NULL

 

Returns

TRUE on success

Since: 0.4.0


g_usb_context_set_debug ()

void
g_usb_context_set_debug (GUsbContext *self,
                         GLogLevelFlags flags);

Sets the debug flags which control what is logged to the console.

Using G_LOG_LEVEL_INFO will output to standard out, and everything else logs to standard error.

Parameters

self

a GUsbContext

 

flags

a GLogLevelFlags such as G_LOG_LEVEL_ERROR | G_LOG_LEVEL_INFO, or 0

 

Since: 0.1.0


g_usb_context_get_devices ()

GPtrArray *
g_usb_context_get_devices (GUsbContext *self);

Parameters

self

a GUsbContext

 

Returns

a new GPtrArray of GUsbDevice's.

[transfer full][element-type GUsbDevice]

Since: 0.2.2


g_usb_context_find_by_bus_address ()

GUsbDevice *
g_usb_context_find_by_bus_address (GUsbContext *self,
                                   guint8 bus,
                                   guint8 address,
                                   GError **error);

Finds a device based on its bus and address values.

Parameters

self

a GUsbContext

 

bus

a bus number

 

address

a bus address

 

error

A GError or NULL

 

Returns

a new GUsbDevice, or NULL if not found.

[transfer full]

Since: 0.2.2


g_usb_context_find_by_vid_pid ()

GUsbDevice *
g_usb_context_find_by_vid_pid (GUsbContext *self,
                               guint16 vid,
                               guint16 pid,
                               GError **error);

Finds a device based on its bus and address values.

Parameters

self

a GUsbContext

 

vid

a vendor ID

 

pid

a product ID

 

error

A GError or NULL

 

Returns

a new GUsbDevice, or NULL if not found.

[transfer full]

Since: 0.2.2


g_usb_context_find_by_platform_id ()

GUsbDevice *
g_usb_context_find_by_platform_id (GUsbContext *self,
                                   const gchar *platform_id,
                                   GError **error);

Finds a device based on its platform id value.

Parameters

self

a GUsbContext

 

platform_id

a platform id, e.g. "usb:00:03:03:02"

 

error

A GError or NULL

 

Returns

a new GUsbDevice, or NULL if not found.

[transfer full]

Since: 0.2.4


g_usb_context_wait_for_replug ()

GUsbDevice *
g_usb_context_wait_for_replug (GUsbContext *self,
                               GUsbDevice *device,
                               guint timeout_ms,
                               GError **error);

Waits for the device to be replugged. It may come back with a different VID:PID.

Warning: This is synchronous and blocks until the device comes back or the timeout triggers.

Parameters

self

a GUsbContext

 

device

a GUsbDevice

 

timeout_ms

timeout to wait

 

error

A GError or NULL

 

Returns

a new GUsbDevice, or NULL for invalid.

[transfer full]

Since: 0.2.9

Types and Values

G_USB_TYPE_CONTEXT

#define G_USB_TYPE_CONTEXT  (g_usb_context_get_type())

G_USB_CONTEXT_ERROR

#define G_USB_CONTEXT_ERROR (g_usb_context_error_quark())

struct GUsbContextClass

struct GUsbContextClass {
	GObjectClass parent_class;
	void (*device_added)(GUsbContext *self, GUsbDevice *device);
	void (*device_removed)(GUsbContext *self, GUsbDevice *device);
};

enum GUsbContextFlags

The flags to use for the context.

Members

G_USB_CONTEXT_ERROR_INTERNAL

   

GUsbContext

typedef struct _GUsbContext GUsbContext;