libsigrok  0.4.0
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 (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...
 
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...
 
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 127 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 519 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 556 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 145 of file input.c.

const struct sr_input_module* sr_input_find ( 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 162 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 567 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 97 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 87 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 112 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 245 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 210 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 183 of file input.c.

References sr_option::id.

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, but 128 bytes is normally enough.

If an input module is found, an instance is created into *in. Otherwise, *in contains NULL.

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 350 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.

Definition at line 417 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 541 of file input.c.