eXpand your USB potential
Data Structures | Typedefs | Enumerations | Functions
Library initialization/deinitialization

This page details how to initialize and deinitialize libusbx. More...

Data Structures

struct  libusb_version
 Structure providing the version of the libusbx runtime. More...

Typedefs

typedef struct libusb_context libusb_context
 Structure representing a libusbx session.

Enumerations

enum  libusb_log_level {
  LIBUSB_LOG_LEVEL_NONE = 0, LIBUSB_LOG_LEVEL_ERROR, LIBUSB_LOG_LEVEL_WARNING, LIBUSB_LOG_LEVEL_INFO,
  LIBUSB_LOG_LEVEL_DEBUG
}
 Log message levels. More...

Functions

void libusb_set_debug (libusb_context *ctx, int level)
 Set log message verbosity.
int libusb_init (libusb_context **context)
 Initialize libusb.
void libusb_exit (struct libusb_context *ctx)
 Deinitialize libusb.

Detailed Description

This page details how to initialize and deinitialize libusbx.

Initialization must be performed before using any libusbx functionality, and similarly you must not call any libusbx functions after deinitialization.


Typedef Documentation

Structure representing a libusbx session.

The concept of individual libusbx sessions allows for your program to use two libraries (or dynamically load two modules) which both independently use libusb. This will prevent interference between the individual libusbx users - for example libusb_set_debug() will not affect the other user of the library, and libusb_exit() will not destroy resources that the other user is still using.

Sessions are created by libusb_init() and destroyed through libusb_exit(). If your application is guaranteed to only ever include a single libusbx user (i.e. you), you do not have to worry about contexts: pass NULL in every function call where a context is required. The default context will be used.

For more information, see Contexts.


Enumeration Type Documentation

Log message levels.

  • LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default)
  • LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr
  • LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr
  • LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stdout, warning and error messages are printed to stderr
  • LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stdout, warnings and errors to stderr

Function Documentation

void libusb_set_debug ( libusb_context ctx,
int  level 
)

Set log message verbosity.

The default level is LIBUSB_LOG_LEVEL_NONE, which means no messages are ever printed. If you choose to increase the message verbosity level, ensure that your application does not close the stdout/stderr file descriptors.

You are advised to use level LIBUSB_LOG_LEVEL_WARNING. libusbx is conservative with its message logging and most of the time, will only log messages that explain error conditions and other oddities. This will help you debug your software.

If the LIBUSB_DEBUG environment variable was set when libusbx was initialized, this function does nothing: the message verbosity is fixed to the value in the environment variable.

If libusbx was compiled without any message logging, this function does nothing: you'll never get any messages.

If libusbx was compiled with verbose debug message logging, this function does nothing: you'll always get messages from all levels.

Parameters:
ctxthe context to operate on, or NULL for the default context
leveldebug level to set
int libusb_init ( libusb_context **  context)

Initialize libusb.

This function must be called before calling any other libusbx function.

If you do not provide an output location for a context pointer, a default context will be created. If there was already a default context, it will be reused (and nothing will be initialized/reinitialized).

Parameters:
contextOptional output location for context pointer. Only valid on return code 0.
Returns:
0 on success, or a LIBUSB_ERROR code on failure
See also:
contexts
void libusb_exit ( struct libusb_context ctx)

Deinitialize libusb.

Should be called after closing all open devices and before your application terminates.

Parameters:
ctxthe context to deinitialize, or NULL for the default context