ble_gatt_client
|
set of function to manage the epool loop More...
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <sys/signalfd.h>
#include <sys/timerfd.h>
#include <sys/epoll.h>
#include "mainloop.h"
Go to the source code of this file.
Data Structures | |
struct | mainloop_data |
mainloop file descriptor event data structure More... | |
struct | timeout_data |
struct | signal_data |
Macros | |
#define | MAX_EPOLL_EVENTS 10 |
#define | MAX_MAINLOOP_ENTRIES 128 |
Functions | |
void | mainloop_init (void) |
void | mainloop_quit (void) |
void | mainloop_exit_success (void) |
void | mainloop_exit_failure (void) |
static void | signal_callback (int fd, uint32_t events, void *user_data) |
int | mainloop_run (void) |
int | mainloop_add_fd (int fd, uint32_t events, mainloop_event_func callback, void *user_data, mainloop_destroy_func destroy) |
int | mainloop_modify_fd (int fd, uint32_t events) |
int | mainloop_remove_fd (int fd) |
static void | timeout_destroy (void *user_data) |
static void | timeout_callback (int fd, uint32_t events, void *user_data) |
static int | timeout_set (int fd, unsigned int msec) |
int | mainloop_add_timeout (unsigned int msec, mainloop_timeout_func callback, void *user_data, mainloop_destroy_func destroy) |
int | mainloop_modify_timeout (int id, unsigned int msec) |
int | mainloop_remove_timeout (int id) |
int | mainloop_set_signal (sigset_t *mask, mainloop_signal_func callback, void *user_data, mainloop_destroy_func destroy) |
Variables | |
static int | epoll_fd |
static int | epoll_terminate |
static int | exit_status |
static struct mainloop_data * | mainloop_list [MAX_MAINLOOP_ENTRIES] |
array of file descriptor event stub More... | |
static struct signal_data * | signal_data |
set of function to manage the epool loop
Definition in file mainloop.c.
#define MAX_EPOLL_EVENTS 10 |
Definition at line 50 of file mainloop.c.
#define MAX_MAINLOOP_ENTRIES 128 |
Definition at line 72 of file mainloop.c.
Referenced by mainloop_add_fd(), mainloop_init(), mainloop_modify_fd(), mainloop_remove_fd(), and mainloop_run().
int mainloop_add_fd | ( | int | fd, |
uint32_t | events, | ||
mainloop_event_func | callback, | ||
void * | user_data, | ||
mainloop_destroy_func | destroy | ||
) |
trigger an event to be processed by the mainloop_run function and create a mainloop_list entry
fd | "file descriptor" source of the event (socket) |
events | event flags EPOOL type like EPOLLIN, EPOLLOUT... |
callback | function to call back by the event processor |
user_data | associated data |
destroy | management function to unallocate user_data |
Definition at line 252 of file mainloop.c.
References mainloop_data::callback, mainloop_data::destroy, epoll_fd, mainloop_data::events, mainloop_data::fd, MAX_MAINLOOP_ENTRIES, and mainloop_data::user_data.
Referenced by io_new(), main(), mainloop_add_timeout(), and mainloop_run().
int mainloop_add_timeout | ( | unsigned int | msec, |
mainloop_timeout_func | callback, | ||
void * | user_data, | ||
mainloop_destroy_func | destroy | ||
) |
Definition at line 388 of file mainloop.c.
References timeout_data::callback, timeout_data::destroy, timeout_data::fd, mainloop_add_fd(), timeout_callback(), timeout_destroy(), timeout_set(), and timeout_data::user_data.
void mainloop_exit_failure | ( | void | ) |
set exit_status to EXIT_FAILURE set epoll_terminate to 1 (mainloop_run exit looping)
Definition at line 135 of file mainloop.c.
References epoll_terminate, and exit_status.
void mainloop_exit_success | ( | void | ) |
set exit_status to EXIT_SUCCESS set epoll_terminate to 1 (mainloop_run exit looping)
Definition at line 125 of file mainloop.c.
References epoll_terminate, and exit_status.
void mainloop_init | ( | void | ) |
create the epoll resource (epoll_fd global variable) initialize mainloop_list (global variable) event table set epoll_terminate to 0 (mainloop_run looping)
Definition at line 101 of file mainloop.c.
References epoll_fd, epoll_terminate, and MAX_MAINLOOP_ENTRIES.
Referenced by main().
int mainloop_modify_fd | ( | int | fd, |
uint32_t | events | ||
) |
trigger an epoll event for an existing mainloop socket (exisiting mainloop_list[fd]) epool event "events" = events, "data.ptr" = mainloop_list[fd]
fd | socket |
events | EPOLL event like EPOLLIN, EPOLLOUT... |
Definition at line 296 of file mainloop.c.
References epoll_fd, mainloop_data::events, mainloop_data::fd, and MAX_MAINLOOP_ENTRIES.
Referenced by io_callback(), io_set_disconnect_handler(), io_set_read_handler(), io_set_write_handler(), and mainloop_modify_timeout().
int mainloop_modify_timeout | ( | int | id, |
unsigned int | msec | ||
) |
Definition at line 429 of file mainloop.c.
References mainloop_modify_fd(), and timeout_set().
void mainloop_quit | ( | void | ) |
set epoll_terminate to 1 (mainloop_run exit looping)
Definition at line 116 of file mainloop.c.
References epoll_terminate.
Referenced by att_disconnect_cb(), cmd_quit(), prompt_read_cb(), signal_callback(), and signal_cb().
int mainloop_remove_fd | ( | int | fd | ) |
Definition at line 322 of file mainloop.c.
References mainloop_data::destroy, epoll_fd, mainloop_data::fd, MAX_MAINLOOP_ENTRIES, and mainloop_data::user_data.
Referenced by io_callback(), io_destroy(), mainloop_remove_timeout(), and mainloop_run().
int mainloop_remove_timeout | ( | int | id | ) |
Definition at line 442 of file mainloop.c.
References mainloop_remove_fd().
int mainloop_run | ( | void | ) |
main loop wait for epoll events to exit the loop, set epoll_terminate to a <>0 value
Definition at line 174 of file mainloop.c.
References mainloop_data::callback, mainloop_data::destroy, signal_data::destroy, epoll_fd, epoll_terminate, exit_status, mainloop_data::fd, signal_data::fd, mainloop_add_fd(), mainloop_remove_fd(), signal_data::mask, MAX_MAINLOOP_ENTRIES, signal_callback(), mainloop_data::user_data, and signal_data::user_data.
Referenced by main().
int mainloop_set_signal | ( | sigset_t * | mask, |
mainloop_signal_func | callback, | ||
void * | user_data, | ||
mainloop_destroy_func | destroy | ||
) |
set mainloop signal handler (signal_data) usally SIGINT and SIGTERM handler signal_data is a global variable
mask | events to filter |
callback | function call triggered by filtered events prototype callback(int signum, void *user_data) |
user_data | user data to pass to callback |
destroy | user data storage management |
Definition at line 457 of file mainloop.c.
References signal_data::callback, signal_data::destroy, signal_data::fd, signal_data::mask, and signal_data::user_data.
Referenced by main().
|
static |
fd | |
events | |
user_data |
Definition at line 147 of file mainloop.c.
References signal_data::callback, mainloop_quit(), and signal_data::user_data.
Referenced by mainloop_run().
|
static |
Definition at line 357 of file mainloop.c.
References timeout_data::callback, timeout_data::fd, and timeout_data::user_data.
Referenced by mainloop_add_timeout().
|
static |
Definition at line 346 of file mainloop.c.
References timeout_data::destroy, timeout_data::fd, and timeout_data::user_data.
Referenced by mainloop_add_timeout().
|
inlinestatic |
Definition at line 374 of file mainloop.c.
Referenced by mainloop_add_timeout(), and mainloop_modify_timeout().
|
static |
Definition at line 52 of file mainloop.c.
Referenced by mainloop_add_fd(), mainloop_init(), mainloop_modify_fd(), mainloop_remove_fd(), and mainloop_run().
|
static |
Definition at line 53 of file mainloop.c.
Referenced by mainloop_exit_failure(), mainloop_exit_success(), mainloop_init(), mainloop_quit(), and mainloop_run().
|
static |
Definition at line 54 of file mainloop.c.
Referenced by mainloop_exit_failure(), mainloop_exit_success(), and mainloop_run().
|
static |
array of file descriptor event stub
Definition at line 77 of file mainloop.c.
|
static |
Definition at line 94 of file mainloop.c.