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

Go to the source code of this file.

Data Structures

struct  source
 

Functions

SR_API struct sr_sessionsr_session_new (void)
 Create a new session. More...
 
SR_API int sr_session_destroy (void)
 Destroy the current session. More...
 
SR_API int sr_session_dev_remove_all (void)
 Remove all the devices from the current session. More...
 
SR_API int sr_session_dev_add (struct sr_dev *dev)
 Add a device to the current session. More...
 
SR_API int sr_session_datafeed_callback_remove_all (void)
 Remove all datafeed callbacks in the current session. More...
 
SR_API int sr_session_datafeed_callback_add (sr_datafeed_callback_t cb)
 Add a datafeed callback to the current session. More...
 
SR_API int sr_session_start (void)
 Start a session. More...
 
SR_API int sr_session_run (void)
 Run the session. More...
 
SR_API int sr_session_halt (void)
 Halt the current session. More...
 
SR_API int sr_session_stop (void)
 Stop the current session. More...
 
SR_PRIV int sr_session_send (struct sr_dev *dev, struct sr_datafeed_packet *packet)
 Send a packet to whatever is listening on the datafeed bus. More...
 
SR_API int sr_session_source_add (int fd, int events, int timeout, sr_receive_data_callback_t cb, void *cb_data)
 TODO. More...
 
SR_API int sr_session_source_remove (int fd)
 Remove the source belonging to the specified file descriptor. More...
 

Variables

SR_PRIV GIOChannel channels [2]
 
struct sr_sessionsession
 

Function Documentation

SR_API int sr_session_datafeed_callback_add ( sr_datafeed_callback_t  cb)

Add a datafeed callback to the current session.

Parameters
cbFunction to call when a chunk of data is received. Must not be NULL.
Returns
SR_OK upon success, SR_ERR_BUG if no session exists.

Definition at line 187 of file session.c.

References sr_session::datafeed_callbacks, sr_err(), SR_ERR_ARG, SR_ERR_BUG, and SR_OK.

Here is the call graph for this function:

SR_API int sr_session_datafeed_callback_remove_all ( void  )

Remove all datafeed callbacks in the current session.

Returns
SR_OK upon success, SR_ERR_BUG if no session exists.

Definition at line 166 of file session.c.

References sr_session::datafeed_callbacks, sr_err(), SR_ERR_BUG, and SR_OK.

Here is the call graph for this function:

SR_API int sr_session_destroy ( void  )

Destroy the current session.

This frees up all memory used by the session.

Returns
SR_OK upon success, SR_ERR_BUG if no session exists.

Definition at line 72 of file session.c.

References sr_session::devs, sr_err(), SR_ERR_BUG, and SR_OK.

Here is the call graph for this function:

SR_API int sr_session_dev_add ( struct sr_dev dev)

Add a device to the current session.

Parameters
devThe device to add to the current session. Must not be NULL. Also, dev->driver and dev->driver->dev_open must not be NULL.
Returns
SR_OK upon success, SR_ERR_ARG upon invalid arguments.

Definition at line 121 of file session.c.

References sr_dev_driver::dev_open, sr_session::devs, sr_dev::driver, sr_dev::driver_index, sr_dbg(), sr_err(), SR_ERR_ARG, SR_ERR_BUG, and SR_OK.

Referenced by sr_session_load().

Here is the call graph for this function:

SR_API int sr_session_dev_remove_all ( void  )

Remove all the devices from the current session.

TODO?

The session itself (i.e., the struct sr_session) is not free'd and still exists after this function returns.

Returns
SR_OK upon success, SR_ERR_BUG if no session exists.

Definition at line 100 of file session.c.

References sr_session::devs, sr_err(), SR_ERR_BUG, and SR_OK.

Here is the call graph for this function:

SR_API int sr_session_halt ( void  )

Halt the current session.

This requests the current session be stopped as soon as possible, for example on receiving an SR_DF_END packet.

Returns
SR_OK upon success, SR_ERR_BUG if no session exists.

Definition at line 347 of file session.c.

References sr_session::running, sr_err(), SR_ERR_BUG, sr_info(), and SR_OK.

Here is the call graph for this function:

SR_API struct sr_session* sr_session_new ( void  )

Create a new session.

TODO: Should it use the file-global "session" variable or take an argument? The same question applies to all the other session functions.

Returns
A pointer to the newly allocated session, or NULL upon errors.

Definition at line 55 of file session.c.

References session, and sr_err().

Referenced by sr_session_load().

Here is the call graph for this function:

SR_API int sr_session_run ( void  )

Run the session.

TODO: Various error checks etc.

Returns
SR_OK upon success, SR_ERR_BUG upon errors.

Definition at line 308 of file session.c.

References source::cb, sr_session::devs, sr_session::running, sr_err(), SR_ERR_BUG, sr_info(), and SR_OK.

Here is the call graph for this function:

SR_PRIV int sr_session_send ( struct sr_dev dev,
struct sr_datafeed_packet packet 
)

Send a packet to whatever is listening on the datafeed bus.

Hardware drivers use this to send a data packet to the frontend.

Parameters
devTODO.
packetThe datafeed packet to send to the session bus.
Returns
SR_OK upon success, SR_ERR_ARG upon invalid arguments.

Definition at line 435 of file session.c.

References sr_session::datafeed_callbacks, sr_err(), SR_ERR_ARG, SR_LOG_DBG, sr_log_loglevel_get(), and SR_OK.

Here is the call graph for this function:

SR_API int sr_session_source_add ( int  fd,
int  events,
int  timeout,
sr_receive_data_callback_t  cb,
void *  cb_data 
)

TODO.

TODO: More error checks etc.

Parameters
fdTODO.
eventsTODO.
timeoutTODO.
cbCallback function to add. Must not be NULL.
cb_dataData for the callback function. Can be NULL.
Returns
SR_OK upon success, SR_ERR_ARG upon invalid arguments, or SR_ERR_MALLOC upon memory allocation errors.

Definition at line 476 of file session.c.

References source::cb, source::cb_data, source::events, source::fd, sr_err(), SR_ERR_ARG, SR_ERR_MALLOC, SR_OK, and source::timeout.

Referenced by sr_source_add().

Here is the call graph for this function:

SR_API int sr_session_source_remove ( int  fd)

Remove the source belonging to the specified file descriptor.

TODO: More error checks.

Parameters
fdTODO.
Returns
SR_OK upon success, SR_ERR_ARG upon invalid arguments, or SR_ERR_MALLOC upon memory allocation errors, SR_ERR_BUG upon internal errors.

Definition at line 526 of file session.c.

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

Referenced by sr_source_remove().

Here is the call graph for this function:

SR_API int sr_session_start ( void  )

Start a session.

There can only be one session at a time.

Returns
SR_OK upon success, SR_ERR upon errors.

Definition at line 262 of file session.c.

References sr_dev_driver::dev_acquisition_start, sr_session::devs, sr_dev::driver, sr_dev::driver_index, sr_err(), SR_ERR_BUG, sr_info(), and SR_OK.

Here is the call graph for this function:

SR_API int sr_session_stop ( void  )

Stop the current session.

The current session is stopped immediately, with all acquisition sessions being stopped and hardware drivers cleaned up.

Returns
SR_OK upon success, SR_ERR_BUG if no session exists.

Definition at line 368 of file session.c.

References sr_dev_driver::cleanup, sr_dev_driver::dev_acquisition_stop, sr_session::devs, sr_dev::driver, sr_dev::driver_index, sr_session::running, sr_err(), SR_ERR_BUG, sr_info(), and SR_OK.

Here is the call graph for this function:

Variable Documentation

SR_PRIV GIOChannel channels[2]

Definition at line 67 of file demo.c.

struct sr_session* session

Definition at line 41 of file session.c.

Referenced by sr_session_new().