Instrument Neutral Distributed Interface INDI  1.9.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"
#include "indidevapi.h"

Go to the source code of this file.

Classes

struct  CB
 
struct  TF
 
struct  WP
 

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
 

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)
 
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)
 
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 79 of file eventloop.c.

Typedef Documentation

◆ 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.

◆ 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 515 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 530 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 525 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 550 of file eventloop.c.

◆ IEDeferLoop()

int IEDeferLoop ( int  maxms,
int *  flagp 
)

Definition at line 560 of file eventloop.c.

◆ IEDeferLoop0()

int IEDeferLoop0 ( int  maxms,
int *  flagp 
)

Definition at line 565 of file eventloop.c.

◆ IENSecsRemainingTimer()

int64_t IENSecsRemainingTimer ( int  timerid)

Definition at line 540 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 535 of file eventloop.c.

◆ IERmCallback()

void IERmCallback ( int  callbackid)

Remove a callback function.

Parameters
callbackidthe callback ID returned from IEAddCallback()

Definition at line 520 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 545 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 555 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.