#include "loop.hh"
Public Member Functions | |
EventLoopP | create_sub_loop () |
bool | finishable () |
bool | iterate (bool block) |
void | iterate_pending () |
std::mutex & | mutex () |
bool | pending () |
void | quit (int quit_code=0) |
int | run () |
bool | running () |
bool | set_g_main_context (GlibGMainContext *glib_main_context) |
![]() | |
uint | add (EventSourceP loop_source, int priority=PRIORITY_NORMAL) |
bool | clear_source (uint *id_pointer) |
void | destroy_loop (void) |
template<class BoolVoidFunctor > | |
uint | exec_callback (BoolVoidFunctor &&bvf, int priority=PRIORITY_NORMAL) |
uint | exec_dispatcher (const DispatcherSlot &sl, int priority=PRIORITY_NORMAL) |
template<class BoolVoidFunctor > | |
uint | exec_idle (BoolVoidFunctor &&bvf) |
template<class BoolVoidPollFunctor > | |
uint | exec_io_handler (BoolVoidPollFunctor &&bvf, int fd, const String &mode, int priority=PRIORITY_NORMAL) |
template<class BoolVoidFunctor > | |
uint | exec_now (BoolVoidFunctor &&bvf) |
bool | exec_once (uint delay_ms, uint *once_id, const VoidSlot &vfunc, int priority=PRIORITY_NORMAL) |
template<class BoolVoidFunctor > | |
uint | exec_timer (BoolVoidFunctor &&bvf, uint delay_ms, int64 repeat_ms=-1, int priority=PRIORITY_NORMAL) |
uint | exec_usignal (int8 signum, const USignalSlot &sl, int priority=PRIORITY_NOW -1) |
bool | flag_primary (bool on) |
bool | has_primary (void) |
MainLoop * | main_loop () const |
void | remove (uint id) |
bool | try_remove (uint id) |
void | wakeup () |
Static Public Member Functions | |
static MainLoopP | create () |
Additional Inherited Members | |
![]() | |
typedef std::function< bool(void)> | BoolSlot |
typedef std::function< bool(PollFD &)> | BPfdSlot |
typedef std::function< bool(const LoopState &)> | DispatcherSlot |
typedef std::function< bool(int8)> | USignalSlot |
typedef std::function< void(void)> | VoidSlot |
typedef std::function< void(PollFD &)> | VPfdSlot |
![]() | |
static const int16 | PRIORITY_ASCENT |
static const int16 | PRIORITY_CEILING |
static const int16 | PRIORITY_HIGH |
static const int16 | PRIORITY_IDLE |
static const int16 | PRIORITY_LOW |
static const int16 | PRIORITY_NEXT |
static const int16 | PRIORITY_NORMAL |
static const int16 | PRIORITY_NOW |
static const int16 | PRIORITY_UPDATE |
![]() | |
typedef std::vector< EventSourceP > | SourceList |
![]() | |
bool | check_sources_Lm (LoopState &, const QuickPfdArray &) |
void | collect_sources_Lm (LoopState &) |
void | dispatch_source_Lm (LoopState &) |
EventLoop (MainLoop &) | |
EventSourceP & | find_first_L () |
EventSourceP & | find_source_L (uint id) |
bool | has_primary_L (void) |
void | kill_sources_Lm (void) |
bool | prepare_sources_Lm (LoopState &, QuickPfdArray &) |
void | remove_source_Lm (EventSourceP source) |
void | unpoll_sources_U () |
virtual | ~EventLoop () |
![]() | |
int16 | dispatch_priority_ |
MainLoop * | main_loop_ |
std::vector< EventSourceP > | poll_sources_ |
bool | primary_ |
SourceList | sources_ |
An EventLoop implementation that offers public API for running the loop.
int run | ( | ) |
Run loop iterations until a call to quit() or finishable becomes true.
bool running | ( | ) |
Indicates if quit() has been called already.
bool finishable | ( | ) |
Indicates wether this loop has no primary sources left to process.
void quit | ( | int | quit_code = 0 | ) |
Cause run() to return with quit_code.
bool pending | ( | ) |
Check if iterate() needs to be called for dispatching.
bool iterate | ( | bool | may_block | ) |
Perform one loop iteration and return whether more iterations are needed.
may_block | If true, iterate() will wait for events occour. |
MainLoop::iterate() is the heart of the main event loop. For loop iteration, all event sources are polled for incoming events. Then dispatchable sources are picked one per iteration and dispatched in round-robin fashion. If no sources need immediate dispatching and may_block is true, iterate() will wait for events to become available.
void iterate_pending | ( | ) |
Call iterate() until no immediate dispatching is needed.
EventLoopP create_sub_loop | ( | ) |
Creates a new event loop that is run as part of this main loop.
std::mutex & mutex | ( | ) |
Provide access to the mutex associated with this main loop.
|
static |
Create a MainLoop shared pointer handle.
Create a new main loop object, users can run or iterate this loop directly. Note that MainLoop objects have special lifetime semantics that keep them alive until they are explicitely destroyed with destroy_loop().
bool set_g_main_context | ( | GlibGMainContext * | glib_main_context | ) |
Set context to integrate with a GLib GMainContext loop.