CliXoN
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
Macros | Functions | Variables
clixon_event.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/time.h>
#include "clixon_queue.h"
#include "clixon_log.h"
#include "clixon_err.h"
#include "clixon_event.h"

Macros

#define EVENT_STRLEN   32
 

Functions

int clicon_exit_set (void)
 
int clicon_exit_get (void)
 
int event_reg_fd (int fd, int(*fn)(int, void *), void *arg, char *str)
 
int event_unreg_fd (int s, int(*fn)(int, void *))
 
int event_reg_timeout (struct timeval t, int(*fn)(int, void *), void *arg, char *str)
 
int event_unreg_timeout (int(*fn)(int, void *), void *arg)
 
int event_loop (void)
 
int event_exit (void)
 

Variables

static struct event_data * ee = NULL
 
static struct event_data * ee_timers = NULL
 
static int _ee_unreg = 0
 
static int _clicon_exit = 0
 

Macro Definition Documentation

#define EVENT_STRLEN   32

Function Documentation

int clicon_exit_get ( void  )

Get the status of global exit variable, usually set by signal handlers

int clicon_exit_set ( void  )

For signal handlers: instead of doing exit, set a global variable to exit Status is then checked in event_loop. Note it maybe would be better to do use on a handle basis, bit a signal handler is global

int event_exit ( void  )
int event_loop ( void  )

Dispatch file descriptor events (and timeouts) by invoking callbacks. There is an issue with fairness that timeouts may take over all events One could try to poll the file descriptors after a timeout?

int event_reg_fd ( int  fd,
int(*)(int, void *)  fn,
void *  arg,
char *  str 
)

Register a callback function to be called on input on a file descriptor.

Parameters
[in]fdFile descriptor
[in]fnFunction to call when input available on fd
[in]argArgument to function fn
[in]strDescribing string for logging
int fn(int fd, void *arg){
}
event_reg_fd(fd, fn, (void*)42, "call fn on input on fd");
int event_reg_timeout ( struct timeval  t,
int(*)(int, void *)  fn,
void *  arg,
char *  str 
)

Call a callback function at an absolute time

Parameters
[in]tAbsolute (not relative!) timestamp when callback is called
[in]fnFunction to call at time t
[in]argArgument to function fn
[in]strDescribing string for logging
int fn(int d, void *arg){
struct timeval t, t1;
gettimeofday(&t, NULL);
t1.tv_sec = 1; t1.tv_usec = 0;
timeradd(&t, &t1, &t);
event_reg_timeout(t, fn, NULL, "call every second");
}

Note that the timestamp is an absolute timestamp, not relative. Note also that the callback is not periodic, you need to make a new registration for each period, see example above. Note also that the first argument to fn is a dummy, just to get the same signatute as for file-descriptor callbacks.

See Also
event_reg_fd
event_unreg_timeout
int event_unreg_fd ( int  s,
int(*)(int, void *)  fn 
)

Deregister a file descriptor callback

Parameters
[in]sFile descriptor
[in]fnFunction to call when input available on fd Note: deregister when exactly function and socket match, not argument
See Also
event_reg_fd
event_unreg_timeout
int event_unreg_timeout ( int(*)(int, void *)  fn,
void *  arg 
)

Deregister a timeout callback as previosly registered by event_reg_timeout() Note: deregister when exactly function and function arguments match, not time. So you cannot have same function and argument callback on different timeouts. This is a little different from event_unreg_fd.

Parameters
[in]fnFunction to call at time t
[in]argArgument to function fn
See Also
event_reg_timeout
event_unreg_fd

Variable Documentation

int _clicon_exit = 0
static
int _ee_unreg = 0
static
struct event_data* ee = NULL
static
struct event_data* ee_timers = NULL
static