libsigrok
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Functions
datastore.c File Reference
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <glib.h>
#include "sigrok.h"
#include "sigrok-internal.h"
Include dependency graph for datastore.c:

Go to the source code of this file.

Functions

SR_API int sr_datastore_new (int unitsize, struct sr_datastore **ds)
 Create a new datastore with the specified unit size. More...
 
SR_API int sr_datastore_destroy (struct sr_datastore *ds)
 Destroy the specified datastore and free the memory used by it. More...
 
SR_API int sr_datastore_put (struct sr_datastore *ds, void *data, unsigned int length, int in_unitsize, const int *probelist)
 Append some data to the specified datastore. More...
 

Function Documentation

SR_API int sr_datastore_destroy ( struct sr_datastore ds)

Destroy the specified datastore and free the memory used by it.

This will free the memory used by the data in the datastore's 'chunklist', by the chunklist data structure itself, and by the datastore struct.

Parameters
dsThe datastore to destroy.
Returns
SR_OK upon success, SR_ERR_ARG upon invalid arguments.

Definition at line 86 of file datastore.c.

References sr_datastore::chunklist, sr_err(), SR_ERR_ARG, and SR_OK.

Here is the call graph for this function:

SR_API int sr_datastore_new ( int  unitsize,
struct sr_datastore **  ds 
)

Create a new datastore with the specified unit size.

The unit size is fixed once the datastore is created, and cannot be changed later on, neither can data be added to the datastore with different unit sizes later.

It is the caller's responsibility to free the allocated memory of the datastore via the sr_datastore_destroy() function, if no longer needed.

TODO: Unitsize should probably be unsigned int or uint32_t or similar. TODO: This function should have a 'chunksize' parameter, and struct sr_datastore a 'chunksize' field.

Parameters
unitsizeThe unit size (>= 1) to be used for this datastore.
dsPointer to a variable which will hold the newly created datastore structure.
Returns
SR_OK upon success, SR_ERR_MALLOC upon memory allocation errors, or SR_ERR_ARG upon invalid arguments. If something other than SR_OK is returned, the value of 'ds' is undefined.

Definition at line 51 of file datastore.c.

References sr_err(), SR_ERR_ARG, SR_ERR_MALLOC, and SR_OK.

Here is the call graph for this function:

SR_API int sr_datastore_put ( struct sr_datastore ds,
void *  data,
unsigned int  length,
int  in_unitsize,
const int *  probelist 
)

Append some data to the specified datastore.

TODO: More elaborate function description.

TODO: This function should use the (not yet available) 'chunksize' field of struct sr_datastore (instead of hardcoding DATASTORE_CHUNKSIZE). TODO: in_unitsize and probelist are unused? TODO: A few of the parameters can be const. TODO: Ideally, 'ds' should be unmodified upon errors.

Parameters
dsPointer to the datastore which shall receive the data. Must not be NULL.
dataPointer to the memory buffer containing the data to add. Must not be NULL. TODO: Data format?
lengthLength of the data to add (in number of bytes). TODO: Should 0 be allowed as length?
in_unitsizeThe unit size (>= 1) of the input data.
probelistPointer to a list of integers (probe numbers). The probe numbers in this list are 1-based, i.e. the first probe is expected to be numbered 1 (not 0!). Must not be NULL.
Returns
SR_OK upon success, SR_ERR_MALLOC upon memory allocation errors, or SR_ERR_ARG upon invalid arguments. If something other than SR_OK is returned, the value/state of 'ds' is undefined.

Definition at line 130 of file datastore.c.

References sr_datastore::chunklist, sr_datastore::ds_unitsize, sr_datastore::num_units, sr_err(), SR_ERR_ARG, SR_ERR_MALLOC, and SR_OK.

Here is the call graph for this function: