ble_gatt_client
|
#include <signal.h>
#include <sys/epoll.h>
Go to the source code of this file.
Typedefs | |
typedef void(* | mainloop_destroy_func )(void *user_data) |
typedef void(* | mainloop_event_func )(int fd, uint32_t events, void *user_data) |
typedef void(* | mainloop_timeout_func )(int id, void *user_data) |
typedef void(* | mainloop_signal_func )(int signum, void *user_data) |
Functions | |
void | mainloop_init (void) |
void | mainloop_quit (void) |
void | mainloop_exit_success (void) |
void | mainloop_exit_failure (void) |
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) |
int | mainloop_add_timeout (unsigned int msec, mainloop_timeout_func callback, void *user_data, mainloop_destroy_func destroy) |
int | mainloop_modify_timeout (int fd, 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) |
typedef void(* mainloop_destroy_func)(void *user_data) |
Definition at line 28 of file mainloop.h.
typedef void(* mainloop_event_func)(int fd, uint32_t events, void *user_data) |
Definition at line 30 of file mainloop.h.
typedef void(* mainloop_signal_func)(int signum, void *user_data) |
Definition at line 32 of file mainloop.h.
typedef void(* mainloop_timeout_func)(int id, void *user_data) |
Definition at line 31 of file mainloop.h.
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 | fd, |
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().