Instrument Neutral Distributed Interface INDI  2.0.2
Classes | Macros | Typedefs | Functions
eventloop.c File Reference
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include "eventloop.h"

Go to the source code of this file.

Classes

struct  CB
 
struct  TF
 
struct  WP
 
struct  Immediate
 

Macros

#define EPOCHDT(tp)   /* ms from epoch to timeval *tp */ (((tp)->tv_usec) / 1000.0 + ((tp)->tv_sec) * 1000.0)
 

Typedefs

typedef struct TF TF
 
typedef struct Immediate Immediate
 
typedef void() IE_CBF(int readfiledes, void *userpointer)
 Signature of a callback. More...
 
typedef void() IE_TCF(void *userpointer)
 Signature of a timeout caller. More...
 
typedef void() IE_WPF(void *userpointer)
 Signature of a work procedure function. More...
 

Functions

void eventLoop ()
 Main calls this when ready to hand over control. More...
 
int deferLoop (int maxms, int *flagp)
 
int deferLoop0 (int maxms, int *flagp)
 
int addCallback (int fd, CBF *fp, void *ud)
 
void rmCallback (int cid)
 
int addTimer (int ms, TCF *fp, void *ud)
 
int addPeriodicTimer (int ms, TCF *fp, void *ud)
 
void rmTimer (int timer_id)
 
int remainingTimer (int timer_id)
 
int64_t nsecsRemainingTimer (int timer_id)
 
int addWorkProc (WPF *fp, void *ud)
 
void rmWorkProc (int wid)
 
void addImmediateWork (TCF *fp, void *ud)
 
int IEAddCallback (int readfiledes, IE_CBF *fp, void *p)
 Register a new callback, fp, to be called with userpointer as argument when readfiledes is ready. More...
 
void IERmCallback (int callbackid)
 Remove a callback function. More...
 
int IEAddTimer (int millisecs, IE_TCF *fp, void *p)
 Register a new single-shot timer function, fp, to be called with ud as argument after ms. More...
 
int IEAddPeriodicTimer (int millisecs, IE_TCF *fp, void *p)
 Register a new periodic timer function, fp, to be called with ud as argument after ms. More...
 
int IERemainingTimer (int timerid)
 Returns the timer's remaining value in milliseconds left until the timeout. More...
 
int64_t IENSecsRemainingTimer (int timerid)
 
void IERmTimer (int timerid)
 Remove the timer with the given timerid, as returned from IEAddTimer() or IEAddPeriodicTimer(). More...
 
int IEAddWorkProc (IE_WPF *fp, void *p)
 Add a new work procedure, fp, to be called with ud when nothing else to do. More...
 
void IERmWorkProc (int workprocid)
 Remove a work procedure. More...
 
int IEDeferLoop (int maxms, int *flagp)
 wait in-line for a flag to set, presumably by another event function More...
 
int IEDeferLoop0 (int maxms, int *flagp)
 

Macro Definition Documentation

◆ EPOCHDT

#define EPOCHDT (   tp)    /* ms from epoch to timeval *tp */ (((tp)->tv_usec) / 1000.0 + ((tp)->tv_sec) * 1000.0)

Definition at line 78 of file eventloop.c.

Typedef Documentation

◆ IE_CBF

IE_CBF

Signature of a callback.

Definition at line 568 of file eventloop.c.

◆ IE_TCF

IE_TCF

Signature of a timeout caller.

Definition at line 569 of file eventloop.c.

◆ IE_WPF

IE_WPF

Signature of a work procedure function.

Definition at line 570 of file eventloop.c.

◆ Immediate

typedef struct Immediate Immediate

◆ TF

typedef struct TF TF

Function Documentation

◆ addCallback()

int addCallback ( int  fd,
CBF fp,
void *  ud 
)

Register a new callback, fp, to be called with ud as argument when fd is ready.

Parameters
fdfile descriptor.
fpa pointer to the callback function.
uda pointer to be passed to the callback function when called.
Returns
a unique callback id for use with rmCallback().

Definition at line 161 of file eventloop.c.

◆ addImmediateWork()

void addImmediateWork ( TCF fp,
void *  ud 
)

Register a given function to be called once after the current loop

Parameters
fpa pointer to the callback function.
uda pointer to be passed to the callback function when called.

Definition at line 524 of file eventloop.c.

◆ addPeriodicTimer()

int addPeriodicTimer ( int  ms,
TCF fp,
void *  ud 
)

Register a new periodic timer function, fp, to be called with ud as argument after ms.

Parameters
mstimer period in milliseconds.
fpa pointer to the callback function.
uda pointer to be passed to the callback function when called.
Returns
a unique id for use with rmTimer().

Definition at line 253 of file eventloop.c.

◆ addTimer()

int addTimer ( int  ms,
TCF fp,
void *  ud 
)

Register a new single-shot timer function, fp, to be called with ud as argument after ms.

Parameters
mstimer period in milliseconds.
fpa pointer to the callback function.
uda pointer to be passed to the callback function when called.
Returns
a unique id for use with rmTimer().

Definition at line 248 of file eventloop.c.

◆ addWorkProc()

int addWorkProc ( WPF fp,
void *  ud 
)

Add a new work procedure, fp, to be called with ud when nothing else to do.

Parameters
fpa pointer to the work procedure callback function.
uda pointer to be passed to the callback function when called.
Returns
a unique id for use with rmWorkProc().

Definition at line 329 of file eventloop.c.

◆ deferLoop()

int deferLoop ( int  maxms,
int *  flagp 
)

Definition at line 118 of file eventloop.c.

◆ deferLoop0()

int deferLoop0 ( int  maxms,
int *  flagp 
)

Definition at line 141 of file eventloop.c.

◆ eventLoop()

void eventLoop ( )

Main calls this when ready to hand over control.

Definition at line 105 of file eventloop.c.

◆ IEAddCallback()

int IEAddCallback ( int  readfiledes,
IE_CBF fp,
void *  userpointer 
)

Register a new callback, fp, to be called with userpointer as argument when readfiledes is ready.

Parameters
readfiledesfile descriptor.
fpa pointer to the callback function.
userpointera pointer to be passed to the callback function when called.
Returns
a unique callback id for use with IERmCallback().

Definition at line 572 of file eventloop.c.

◆ IEAddPeriodicTimer()

int IEAddPeriodicTimer ( int  millisecs,
IE_TCF fp,
void *  userpointer 
)

Register a new periodic timer function, fp, to be called with ud as argument after ms.

Parameters
millisecstimer period in milliseconds.
fpa pointer to the callback function.
userpointera pointer to be passed to the callback function when called.
Returns
a unique id for use with IERmTimer().

Definition at line 587 of file eventloop.c.

◆ IEAddTimer()

int IEAddTimer ( int  millisecs,
IE_TCF fp,
void *  userpointer 
)

Register a new single-shot timer function, fp, to be called with ud as argument after ms.

Parameters
millisecstimer period in milliseconds.
fpa pointer to the callback function.
userpointera pointer to be passed to the callback function when called.
Returns
a unique id for use with IERmTimer().

Definition at line 582 of file eventloop.c.

◆ IEAddWorkProc()

int IEAddWorkProc ( IE_WPF fp,
void *  userpointer 
)

Add a new work procedure, fp, to be called with ud when nothing else to do.

Parameters
fpa pointer to the work procedure callback function.
userpointera pointer to be passed to the callback function when called.
Returns
a unique id for use with IERmWorkProc().

Definition at line 607 of file eventloop.c.

◆ IEDeferLoop()

int IEDeferLoop ( int  maxms,
int *  flagp 
)

wait in-line for a flag to set, presumably by another event function

Definition at line 617 of file eventloop.c.

◆ IEDeferLoop0()

int IEDeferLoop0 ( int  maxms,
int *  flagp 
)

Definition at line 622 of file eventloop.c.

◆ IENSecsRemainingTimer()

int64_t IENSecsRemainingTimer ( int  timerid)

Definition at line 597 of file eventloop.c.

◆ IERemainingTimer()

int IERemainingTimer ( int  timerid)

Returns the timer's remaining value in milliseconds left until the timeout.

Parameters
timeridthe timer callback ID returned from IEAddTimer() or IEAddPeriodicTimer()
Returns
If the timer not exists, the returned value will be -1.

Definition at line 592 of file eventloop.c.

◆ IERmCallback()

void IERmCallback ( int  callbackid)

Remove a callback function.

Parameters
callbackidthe callback ID returned from IEAddCallback()

Definition at line 577 of file eventloop.c.

◆ IERmTimer()

void IERmTimer ( int  timerid)

Remove the timer with the given timerid, as returned from IEAddTimer() or IEAddPeriodicTimer().

Parameters
timeridthe timer callback ID returned from IEAddTimer() or IEAddPeriodicTimer().

Definition at line 602 of file eventloop.c.

◆ IERmWorkProc()

void IERmWorkProc ( int  workprocid)

Remove a work procedure.

Parameters
workprocidThe unique ID for the work procedure to be removed.

Definition at line 612 of file eventloop.c.

◆ nsecsRemainingTimer()

int64_t nsecsRemainingTimer ( int  timer_id)

Definition at line 320 of file eventloop.c.

◆ remainingTimer()

int remainingTimer ( int  tid)

Returns the timer's remaining value in milliseconds left until the timeout.

Parameters
tidthe timer callback ID returned from addTimer() or addPeriodicTimer()
Returns
If the timer not exists, the returned value will be -1.

Definition at line 311 of file eventloop.c.

◆ rmCallback()

void rmCallback ( int  cid)

Remove a callback function.

Parameters
cidthe callback ID returned from addCallback().

Definition at line 189 of file eventloop.c.

◆ rmTimer()

void rmTimer ( int  tid)

Remove the timer with the given id, as returned from addTimer() or addPeriodicTimer().

Parameters
tidthe timer callback ID returned from addTimer() or addPeriodicTimer().

Definition at line 286 of file eventloop.c.

◆ rmWorkProc()

void rmWorkProc ( int  wid)

Remove the work procedure with the given id, as returned from addWorkProc().

Parameters
widthe work procedure callback ID returned from addWorkProc().

Definition at line 356 of file eventloop.c.