libsigrok  unreleased development snapshot
sigrok hardware access and backend library
Functions
Input modules

Input file/data module handling. More...

Functions

const struct sr_input_module ** sr_input_list (void)
 Returns a NULL-terminated list of all available input modules. More...
 
const char * sr_input_id_get (const struct sr_input_module *imod)
 Returns the specified input module's ID. More...
 
const char * sr_input_name_get (const struct sr_input_module *imod)
 Returns the specified input module's name. More...
 
const char * sr_input_description_get (const struct sr_input_module *imod)
 Returns the specified input module's description. More...
 
const char *const * sr_input_extensions_get (const struct sr_input_module *imod)
 Returns the specified input module's file extensions typical for the file format, as a NULL terminated array, or returns a NULL pointer if there is no preferred extension. More...
 
const struct sr_input_module * sr_input_find (const char *id)
 Return the input module with the specified ID, or NULL if no module with that id is found. More...
 
const struct sr_option ** sr_input_options_get (const struct sr_input_module *imod)
 Returns a NULL-terminated array of struct sr_option, or NULL if the module takes no options. More...
 
void sr_input_options_free (const struct sr_option **options)
 After a call to sr_input_options_get(), this function cleans up all resources returned by that call. More...
 
struct sr_input * sr_input_new (const struct sr_input_module *imod, GHashTable *options)
 Create a new input instance using the specified input module. More...
 
int sr_input_scan_buffer (GString *buf, const struct sr_input **in)
 Try to find an input module that can parse the given buffer. More...
 
int sr_input_scan_file (const char *filename, const struct sr_input **in)
 Try to find an input module that can parse the given file. More...
 
const struct sr_input_module * sr_input_module_get (const struct sr_input *in)
 Return the input instance's module "class". More...
 
struct sr_dev_inst * sr_input_dev_inst_get (const struct sr_input *in)
 Return the input instance's (virtual) device instance. More...
 
int sr_input_send (const struct sr_input *in, GString *buf)
 Send data to the specified input instance. More...
 
int sr_input_end (const struct sr_input *in)
 Signal the input module no more data will come. More...
 
int sr_input_reset (const struct sr_input *in_ro)
 Reset the input module's input handling structures. More...
 
void sr_input_free (const struct sr_input *in)
 Free the specified input instance and all associated resources. More...
 

Detailed Description

Input file/data module handling.

libsigrok can process acquisition data in several different ways. Aside from acquiring data from a hardware device, it can also take it from a file in various formats (binary, CSV, VCD, and so on).

Like all libsigrok data handling, processing is done in a streaming manner: input should be supplied a chunk at a time. This way anything that processes data can do so in real time, without the user having to wait for the whole thing to be finished.

Every input module is "pluggable", meaning it's handled as being separate from the main libsigrok, but linked in to it statically. To keep things modular and separate like this, functions within an input module should be declared static, with only the respective 'struct sr_input_module' being exported for use into the wider libsigrok namespace.

Function Documentation

const char* sr_input_description_get ( const struct sr_input_module *  imod)

Returns the specified input module's description.

Since
0.4.0

Definition at line 143 of file input.c.

struct sr_dev_inst* sr_input_dev_inst_get ( const struct sr_input *  in)

Return the input instance's (virtual) device instance.

This can be used to find out the number of channels and other information.

If the device instance has not yet been fully populated by the input module, NULL is returned. This indicates the module needs more data to identify the number of channels and so on.

Since
0.4.0

Definition at line 571 of file input.c.

int sr_input_end ( const struct sr_input *  in)

Signal the input module no more data will come.

This will cause the module to process any data it may have buffered. The SR_DF_END packet will also typically be sent at this time.

Since
0.4.0

Definition at line 610 of file input.c.

const char* const* sr_input_extensions_get ( const struct sr_input_module *  imod)

Returns the specified input module's file extensions typical for the file format, as a NULL terminated array, or returns a NULL pointer if there is no preferred extension.

Note
these are a suggestions only.
Since
0.4.0

Definition at line 161 of file input.c.

const struct sr_input_module* sr_input_find ( const char *  id)

Return the input module with the specified ID, or NULL if no module with that id is found.

Since
0.4.0

Definition at line 178 of file input.c.

void sr_input_free ( const struct sr_input *  in)

Free the specified input instance and all associated resources.

Since
0.4.0

Definition at line 675 of file input.c.

const char* sr_input_id_get ( const struct sr_input_module *  imod)

Returns the specified input module's ID.

Since
0.4.0

Definition at line 113 of file input.c.

const struct sr_input_module** sr_input_list ( void  )

Returns a NULL-terminated list of all available input modules.

Since
0.4.0

Definition at line 103 of file input.c.

Referenced by sr_buildinfo_scpi_backends_get().

+ Here is the caller graph for this function:

const struct sr_input_module* sr_input_module_get ( const struct sr_input *  in)

Return the input instance's module "class".

This can be used to find out which input module handles a specific input file. This is especially useful when an application did not create the input stream by specifying an input module, but instead some shortcut or convenience wrapper did.

Since
0.6.0

Definition at line 553 of file input.c.

const char* sr_input_name_get ( const struct sr_input_module *  imod)

Returns the specified input module's name.

Since
0.4.0

Definition at line 128 of file input.c.

struct sr_input* sr_input_new ( const struct sr_input_module *  imod,
GHashTable *  options 
)

Create a new input instance using the specified input module.

This function is used when a client wants to use a specific input module to parse a stream. No effort is made to identify the format.

Parameters
imodThe input module to use. Must not be NULL.
optionsGHashTable consisting of keys corresponding with the module options id field. The values should be GVariant pointers with sunk references, of the same GVariantType as the option's default value.
Since
0.4.0

Definition at line 261 of file input.c.

References sr_option::def, sr_option::id, and SR_OK.

Referenced by sr_input_scan_buffer(), and sr_input_scan_file().

+ Here is the caller graph for this function:

void sr_input_options_free ( const struct sr_option **  options)

After a call to sr_input_options_get(), this function cleans up all resources returned by that call.

Since
0.4.0

Definition at line 226 of file input.c.

References sr_option::def, and sr_option::values.

const struct sr_option** sr_input_options_get ( const struct sr_input_module *  imod)

Returns a NULL-terminated array of struct sr_option, or NULL if the module takes no options.

Each call to this function must be followed by a call to sr_input_options_free().

Since
0.4.0

Definition at line 199 of file input.c.

References sr_option::id.

int sr_input_reset ( const struct sr_input *  in_ro)

Reset the input module's input handling structures.

Causes the input module to reset its internal state so that we can re-send the input data from the beginning without having to re-create the entire input module.

Since
0.5.0

Definition at line 625 of file input.c.

References SR_ERR_ARG, and SR_OK.

int sr_input_scan_buffer ( GString *  buf,
const struct sr_input **  in 
)

Try to find an input module that can parse the given buffer.

The buffer must contain enough of the beginning of the file for the input modules to find a match. This is format-dependent. When magic strings get checked, 128 bytes normally could be enough. Note that some formats try to parse larger header sections, and benefit from seeing a larger scope.

If an input module is found, an instance is created into *in. Otherwise, *in contains NULL. When multiple input moduless claim support for the format, the one with highest confidence takes precedence. Applications will see at most one input module spec.

If an instance is created, it has the given buffer used for scanning already submitted to it, to be processed before more data is sent. This allows a frontend to submit an initial chunk of a non-seekable stream, such as stdin, without having to keep it around and submit it again later.

Definition at line 370 of file input.c.

References SR_ERR, SR_ERR_DATA, sr_input_new(), and SR_OK.

+ Here is the call graph for this function:

int sr_input_scan_file ( const char *  filename,
const struct sr_input **  in 
)

Try to find an input module that can parse the given file.

If an input module is found, an instance is created into *in. Otherwise, *in contains NULL. When multiple input moduless claim support for the format, the one with highest confidence takes precedence. Applications will see at most one input module spec.

Definition at line 448 of file input.c.

References SR_ERR, SR_ERR_ARG, sr_input_new(), and SR_OK.

+ Here is the call graph for this function:

int sr_input_send ( const struct sr_input *  in,
GString *  buf 
)

Send data to the specified input instance.

When an input module instance is created with sr_input_new(), this function is used to feed data to the instance.

As enough data gets fed into this function to completely populate the device instance associated with this input instance, this is guaranteed to return the moment it's ready. This gives the caller the chance to examine the device instance, attach session callbacks and so on.

Since
0.4.0

Definition at line 593 of file input.c.