The VisAO Camera
fifoutils.c File Reference

Definitions for linux fifo utilities. More...

#include "fifoutils.h"
#include "time.h"
#include "sys/time.h"

Go to the source code of this file.

Functions

double get_currt ()
 Returns time since the Unix epoch in double precision seconds. More...
 
int init_fifo_channel (fifo_channel *fc)
 Initializes the fifo_channel structure. More...
 
int setup_fifo_channel (fifo_channel *fc, size_t buffsz)
 Allocate the server_response buffer. More...
 
int set_fifo_channel (fifo_channel *fc, const char *fin, const char *fout, int(*inp_hand)(fifo_channel *), void *adata)
 Set the details of the fifo_channel. More...
 
int create_fifos (fifo_channel *fc)
 Creates the fifos if they don't already exist. More...
 
int open_fifo_channel_in (fifo_channel *fc)
 Opens the input fifo channel for async reading with an exculsive lock. More...
 
int open_fifo_channel_in_nolock (fifo_channel *fc)
 Opens the input fifo channel for async reading without an exculsive lock. More...
 
int open_fifo_channel_out (fifo_channel *fc)
 Opens the output fifo channel for non-blocking writing with an exclusive lock. More...
 
int open_fifo_channel_out_nolock (fifo_channel *fc)
 Opens the output fifo channel for non-blocking writing without an exclusive lock. More...
 
int write_fifo_channel (fifo_channel *fc, const char *com, int comlen)
 Write data to the output channel. More...
 
int write_fifo_channel_seqmsg (fifo_channel *fc, const char *com, int comlen, char *seqmsg)
 Write data to the output channel, including a sequence message. More...
 
int read_fifo_channel (fifo_channel *fc)
 Read data from the input fifo channel. More...
 
int check_if_in_locked (fifo_channel *fc)
 Checks if the output fifo of the channel is locked. More...
 
int init_fifo_list (fifo_list *fl)
 Initialize the fifo_list. More...
 
int setup_fifo_list (fifo_list *fl, int nch)
 Setup a fifo_list. More...
 
int set_fifo_list_channel (fifo_list *fl, int nch, int buffsz, const char *fin, const char *fout, int(*inp_hand)(fifo_channel *), void *adata)
 Set the details of one channel in the list. More...
 
int connect_fifo_list (fifo_list *fl)
 Open each fifo in the list, with exclusive lock on the input fifo. More...
 
int connect_fifo_list_nolock (fifo_list *fl)
 Open each fifo in the list, without exclusive locks. More...
 
int init_fifo_list_pending_reads (fifo_list *fl)
 Populates the fd_to_fifo_ch_index array.
 
void catch_fifo_response_list (int signum __attribute__((unused)))
 
int set_fifo_list_rtsig (fifo_list *fl)
 Change from SIGIO to real time signals.
 
void catch_fifo_pending_reads (int signum __attribute__((unused)), siginfo_t *siginf, void *ucont __attribute__((unused)))
 
void catch_fifo_standard_sigio (int signum __attribute__((unused)))
 
int fifo_list_do_pending_read (fifo_list *fl)
 Runs through the pending reads, dispatching each handler in turn.
 
int ropen_async (char *fname, int nolock)
 Open a file for non-blocking asynchronous reads. More...
 
int wopen_nonblock (char *fname, int nolock)
 Open a file for non-blocking writes. More...
 

Detailed Description

Author
Jared R. Males

Definition in file fifoutils.c.

Function Documentation

double get_currt ( )

Uses clock_gettime, CLOCK_REALTIME, and the attendant timespec, so it has precision of nanoseconds.

Definition at line 23 of file fifoutils.c.

int init_fifo_channel ( fifo_channel *  fc)

All members are set to zero by this init. Should be called every time a fifo_channel is created.

Parameters
fcis a pointer the fifo_channel to initialize
Return values
0on success (always)

Definition at line 31 of file fifoutils.c.

Referenced by setup_fifo_list().

int setup_fifo_channel ( fifo_channel *  fc,
size_t  buffsz 
)

Checks if buffer is non-zero and free's it if it is - so you must call init_fifo_channel before setup.

Parameters
fcis a pointer the fifo_channel to initialize
buffszis the size of the server_response buffer to allocate
Return values
0on success
-1on failure

Definition at line 47 of file fifoutils.c.

References ERRMSG.

Referenced by set_fifo_list_channel().

int set_fifo_channel ( fifo_channel *  fc,
const char *  fin,
const char *  fout,
int(*)(fifo_channel *)  inp_hand,
void *  adata 
)

Allocates and assigns the file name strings, you must call init_fifo_channel before using this function. Also installs the handler pointer. This function calls create_fifos, thus creating them if they don't already exist. This function does not actually open the fifos.

Parameters
fcis a pointer the fifo_channel to initialize
finis the file name of the input fifo
foutis the file name of the output fifo
inp_handis a pointer to the input handler function for this channel
adataa pointer to auxiliary data.
Return values
0on success
-1on failure

Definition at line 63 of file fifoutils.c.

References create_fifos(), and ERRMSG.

Referenced by set_fifo_list_channel().

int create_fifos ( fifo_channel *  fc)
Parameters
fcis a pointer the fifo_channel to initialize
Return values
0on success
-1on failure (check errno)

Definition at line 92 of file fifoutils.c.

References ERRMSG.

Referenced by set_fifo_channel().

int open_fifo_channel_in ( fifo_channel *  fc)

Clears the fifo, ignoring any pending input, so open before listening for SIGIO

Parameters
fcis a pointer the fifo_channel to initialize
Return values
0on success
-1on failure

Definition at line 119 of file fifoutils.c.

References ERRMSG, and ropen_async().

Referenced by connect_fifo_list().

int open_fifo_channel_in_nolock ( fifo_channel *  fc)

Clears the fifo, ignoring any pending input, so open before listening for SIGIO

Parameters
fcis a pointer the fifo_channel to initialize
Return values
0on success
-1on failure

Definition at line 144 of file fifoutils.c.

References ERRMSG, and ropen_async().

Referenced by connect_fifo_list_nolock().

int open_fifo_channel_out ( fifo_channel *  fc)
Parameters
fcis a pointer the fifo_channel to initialize
Return values
0on success
-1on failure

Definition at line 166 of file fifoutils.c.

References ERRMSG, and wopen_nonblock().

int open_fifo_channel_out_nolock ( fifo_channel *  fc)
Parameters
fcis a pointer the fifo_channel to initialize
Return values
0on success
-1on failure

Definition at line 180 of file fifoutils.c.

References ERRMSG, and wopen_nonblock().

Referenced by connect_fifo_list(), and connect_fifo_list_nolock().

int write_fifo_channel ( fifo_channel *  fc,
const char *  com,
int  comlen 
)
Parameters
fcis a pointer the fifo_channel to initialize
comthe buffer to write
comlenlength of the buffer
Return values
nbytesthe number of bytes written, on success
-1on failure

Definition at line 194 of file fifoutils.c.

References ERRMSG, and RWBUFF_SZ.

Referenced by VisAO::com_auto_handler(), VisAO::com_local_handler(), VisAO::com_remote_handler(), VisAO::com_script_handler(), VisAO::read_diofifo(), and VisAO::framegrabber< dataT >::send_ping().

int write_fifo_channel_seqmsg ( fifo_channel *  fc,
const char *  com,
int  comlen,
char *  seqmsg 
)
Parameters
fcis a pointer the fifo_channel to initialize
comthe buffer to write
comlenlength of the buffer
seqmsgthe 6 byte sequence message.
Return values
nbytesthe number of bytes written, on success
-1on failure

Definition at line 218 of file fifoutils.c.

References ERRMSG, and RWBUFF_SZ.

Referenced by VisAO::VisAOApp_base::write_fifo_channel().

int read_fifo_channel ( fifo_channel *  fc)
int check_if_in_locked ( fifo_channel *  fc)

Normally a process obtains an exclusive lock on the input of its fifo channels. That is it wants to be the only process which can receive commands on that channel. This function checks for the presence of such a lock on the output fifo of a channel, as a way to test if anybody is listening. This can be used to prevent writing to a fifo that isn't being read. See VisApp_base::write_fifo_channel for an example.

Parameters
fcthe relevant fifo_channel
Return values
0if there is not lock
1if there is a lock

Definition at line 316 of file fifoutils.c.

int init_fifo_list ( fifo_list fl)

All members set to 0.

Parameters
flis a pointer to the fifo_list to initialize
Return values
0on success (always)

Definition at line 341 of file fifoutils.c.

References fifo_list::fds, fifo_list::fifo_ch, fifo_list::maxfile, fifo_list::nchan, fifo_list::rq_sz, and fifo_list::RTSIGIO_overflow.

Referenced by VisAO::VisAOApp_base::VisAOApp_base().

int setup_fifo_list ( fifo_list fl,
int  nch 
)

Allocates the fifo_ch array, then initializes each fifo_channel

Parameters
flis a pointer to the initialized fifo_list to setup
nchis the number of channels in the list
Return values
0on success
-1on failure

Definition at line 354 of file fifoutils.c.

References ERRMSG, fifo_list::fifo_ch, init_fifo_channel(), and fifo_list::nchan.

Referenced by VisAO::framegrabber< dataT >::Create(), and VisAO::VisAOApp_base::setup_fifo_list().

int set_fifo_list_channel ( fifo_list fl,
int  nch,
int  buffsz,
const char *  fin,
const char *  fout,
int(*)(fifo_channel *)  inp_hand,
void *  adata 
)

First calls setup_fifo_channel Then calls set_fifo_channel

Parameters
flis a pointer to the initialized fifo_list to setup
nchis the channel number to set
buffszis the size of the server_reponse buvver for this channel
finis the file name of the input fifo
foutis the file name of the output fifo
inp_handis a pointer to the input handler function for this channel
adataa pointer to auxiliary data.
Return values
0on success
-1on failure

Definition at line 373 of file fifoutils.c.

References fifo_list::fifo_ch, set_fifo_channel(), and setup_fifo_channel().

Referenced by VisAO::framegrabber< dataT >::Create(), VisAO::reconstructor::Create(), VisAO::JoeCtrl::Create(), VisAO::CCD47Ctrl::init_VisAOApp(), VisAO::FocusMotorCtrl::initapp(), VisAO::VisAOApp_base::setup_baseApp(), and VisAO::dioserver::setup_dioserver().

int connect_fifo_list ( fifo_list fl)

The input channel is locked so that no other process will intercept communications intended for the calling process. Output fifos are not locked, as multiple processes could conceivable write to the same channel (e.g. a ping or watchdog). Both channels can't be locked, as then nobody could establish a connection.

Parameters
flis a pointer to the initialized fifo_list to setup
Return values
0on success
-1on failure

Definition at line 379 of file fifoutils.c.

References ERRMSG, ERRMSG_SZ, fifo_list::fds, fifo_list::fifo_ch, init_fifo_list_pending_reads(), fifo_list::maxfile, fifo_list::nchan, open_fifo_channel_in(), and open_fifo_channel_out_nolock().

Referenced by VisAO::VisAOApp_base::connect_fifo_list().

int connect_fifo_list_nolock ( fifo_list fl)
Parameters
flis a pointer to the initialized fifo_list to setup
Return values
0on success
-1on failure

Definition at line 415 of file fifoutils.c.

References ERRMSG, ERRMSG_SZ, fifo_list::fds, fifo_list::fifo_ch, init_fifo_list_pending_reads(), fifo_list::maxfile, fifo_list::nchan, open_fifo_channel_in_nolock(), and open_fifo_channel_out_nolock().

Referenced by VisAO::VisAOApp_base::connect_fifo_list_nolock().

int ropen_async ( char *  fname,
int  nolock 
)

The nolock parameter controls whether or not to attempt an exclusive lock.

Parameters
fnameis the name of the file to open
nolockif 0 attempt to get an exclusive lock (WRLCK) and close file if rejected. if 1 do not lock.
Return values
>0(the file descriptor) on success
0on failure
-1on failure to lock

Definition at line 607 of file fifoutils.c.

References ERRMSG, and ERRMSG_SZ.

Referenced by open_fifo_channel_in(), and open_fifo_channel_in_nolock().

int wopen_nonblock ( char *  fname,
int  nolock 
)

The nolock parameter controls whether or not to attempt an exclusive lock.

Parameters
fnameis the name of the file to open
nolockif 0 attempt to get an exclusive lock (WRLCK) and close file if rejected. if 1 do not lock.
Return values
>0(the file descriptor) on success
0on failure
-1on failure to lock

Definition at line 649 of file fifoutils.c.

References ERRMSG, and ERRMSG_SZ.

Referenced by open_fifo_channel_out(), open_fifo_channel_out_nolock(), and VisAO::VisAOApp_base::write_fifo_channel().