Declarations for linux fifo utilities. More...
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/stat.h>
#include "profileutils.h"
Go to the source code of this file.
Classes | |
struct | fifo_channel |
The basic fifo_channel structure. More... | |
struct | fifo_list |
A structure to hold a list of fifo_channels. More... | |
Macros | |
#define | MAX_FNAME_SZ 256 |
The maximum allowed filename length. | |
#define | RWBUFF_SZ 256 |
The size of the i/o buffer. | |
#define | ERRMSG_SZ 256 |
The size of the errmsg buffers. | |
#define | ERRMSG(msg) fprintf(stderr, "%s (%s line %i)\n", msg,__FILE__,__LINE__) |
Error reporting macro. If not using the function __error_message(msg) then use stderr. | |
#define | RTSIGIO (SIGRTMIN+4) |
#define | RTSIGIGN (SIGRTMIN+5) |
#define | RTSIGPING (SIGRTMIN+6) |
Functions | |
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) |
A SIGIO handler, which uses global_fifo_list to call the appropriate handler. More... | |
int | set_fifo_list_rtsig (fifo_list *fl) |
Change from SIGIO to real time signals. | |
void | catch_fifo_pending_reads (int signum, siginfo_t *siginf, void *ucont) |
A handler for a R/T SIGIO, which just updates the pending reads meta data but does no actual signal handling. | |
void | catch_fifo_standard_sigio (int signum) |
A handler for normal SIGIO when we should have gotten the R/T SIGIO, implying signal queue overflow. | |
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... | |
double | get_currt () |
Returns time since the Unix epoch in double precision seconds. More... | |
Variables | |
fifo_list * | global_fifo_list |
The global fifo_list, for signal handling. | |
Definition in file fifoutils.h.
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.
fc | is a pointer the fifo_channel to initialize |
0 | on success (always) |
Definition at line 31 of file fifoutils.c.
Referenced by setup_fifo_list().
Checks if buffer is non-zero and free's it if it is - so you must call init_fifo_channel before setup.
fc | is a pointer the fifo_channel to initialize |
buffsz | is the size of the server_response buffer to allocate |
0 | on success |
-1 | on 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.
fc | is a pointer the fifo_channel to initialize |
fin | is the file name of the input fifo |
fout | is the file name of the output fifo |
inp_hand | is a pointer to the input handler function for this channel |
adata | a pointer to auxiliary data. |
0 | on success |
-1 | on 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 | ) |
fc | is a pointer the fifo_channel to initialize |
0 | on success |
-1 | on 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
fc | is a pointer the fifo_channel to initialize |
0 | on success |
-1 | on 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
fc | is a pointer the fifo_channel to initialize |
0 | on success |
-1 | on 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 | ) |
fc | is a pointer the fifo_channel to initialize |
0 | on success |
-1 | on failure |
Definition at line 166 of file fifoutils.c.
References ERRMSG, and wopen_nonblock().
int open_fifo_channel_out_nolock | ( | fifo_channel * | fc | ) |
fc | is a pointer the fifo_channel to initialize |
0 | on success |
-1 | on failure |
Definition at line 180 of file fifoutils.c.
References ERRMSG, and wopen_nonblock().
Referenced by connect_fifo_list(), and connect_fifo_list_nolock().
fc | is a pointer the fifo_channel to initialize |
com | the buffer to write |
comlen | length of the buffer |
nbytes | the number of bytes written, on success |
-1 | on 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().
fc | is a pointer the fifo_channel to initialize |
com | the buffer to write |
comlen | length of the buffer |
seqmsg | the 6 byte sequence message. |
nbytes | the number of bytes written, on success |
-1 | on 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 | ) |
fc | is a pointer the fifo_channel to initialize |
0 | on success |
1 | if read not complete before filling __fifo_channel::server_response. |
Definition at line 246 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::VisAOApp_base::get_fifo_channel_response(), VisAO::read_diofifo(), VisAO::frameselector::Run(), VisAO::reconstructor::Run(), VisAO::frameserver::send_frame(), and VisAO::JoeCtrl::TestCCD47CtrlLink().
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.
fc | the relevant fifo_channel |
0 | if there is not lock |
1 | if there is a lock |
Definition at line 316 of file fifoutils.c.
All members set to 0.
fl | is a pointer to the fifo_list to initialize |
0 | on 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().
Allocates the fifo_ch array, then initializes each fifo_channel
fl | is a pointer to the initialized fifo_list to setup |
nch | is the number of channels in the list |
0 | on success |
-1 | on 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
fl | is a pointer to the initialized fifo_list to setup |
nch | is the channel number to set |
buffsz | is the size of the server_reponse buvver for this channel |
fin | is the file name of the input fifo |
fout | is the file name of the output fifo |
inp_hand | is a pointer to the input handler function for this channel |
adata | a pointer to auxiliary data. |
0 | on success |
-1 | on 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().
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.
fl | is a pointer to the initialized fifo_list to setup |
0 | on success |
-1 | on 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().
fl | is a pointer to the initialized fifo_list to setup |
0 | on success |
-1 | on 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().
void catch_fifo_response_list | ( | int | signum | ) |
This means you must define global_fifo_list and point it at your fifo_list or this will segfault.
Referenced by VisAO::VisAOApp_base::check_fifo_list_RTpending(), and VisAO::VisAOApp_base::setup_sigio().
The nolock parameter controls whether or not to attempt an exclusive lock.
fname | is the name of the file to open |
nolock | if 0 attempt to get an exclusive lock (WRLCK) and close file if rejected. if 1 do not lock. |
>0 | (the file descriptor) on success |
0 | on failure |
-1 | on 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().
The nolock parameter controls whether or not to attempt an exclusive lock.
fname | is the name of the file to open |
nolock | if 0 attempt to get an exclusive lock (WRLCK) and close file if rejected. if 1 do not lock. |
>0 | (the file descriptor) on success |
0 | on failure |
-1 | on 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().
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.