Anklang C++ API 0.0.0
Loading...
Searching...
No Matches
EventLoop

#include "loop.hh"

Inheritance diagram for EventLoop:
[legend]

Classes

struct QuickPfdArray

Public Types

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

Public Member Functions

uintadd (EventSourceP loop_source, int priority=PRIORITY_NORMAL)
boolclear_source (uint *id_pointer)
voiddestroy_loop (void)
template<class BoolVoidFunctor >
uintexec_callback (BoolVoidFunctor &&bvf, int priority=PRIORITY_NORMAL)
uintexec_dispatcher (const DispatcherSlot &sl, int priority=PRIORITY_NORMAL)
template<class BoolVoidFunctor >
uintexec_idle (BoolVoidFunctor &&bvf)
template<class BoolVoidPollFunctor >
uintexec_io_handler (BoolVoidPollFunctor &&bvf, int fd, const String &mode, int priority=PRIORITY_NORMAL)
template<class BoolVoidFunctor >
uintexec_now (BoolVoidFunctor &&bvf)
boolexec_once (uint delay_ms, uint *once_id, const VoidSlot &vfunc, int priority=PRIORITY_NORMAL)
template<class BoolVoidFunctor >
uintexec_timer (BoolVoidFunctor &&bvf, uint delay_ms, int64 repeat_ms=-1, int priority=PRIORITY_NORMAL)
uintexec_usignal (int8 signum, const USignalSlot &sl, int priority=PRIORITY_NOW -1)
boolflag_primary (bool on)
boolhas_primary (void)
MainLoop *main_loop () const
voidremove (uint id)
booltry_remove (uint id)
voidwakeup ()

Static Public Attributes

static const int16PRIORITY_ASCENT
static const int16PRIORITY_CEILING
static const int16PRIORITY_HIGH
static const int16PRIORITY_IDLE
static const int16PRIORITY_LOW
static const int16PRIORITY_NEXT
static const int16PRIORITY_NORMAL
static const int16PRIORITY_NOW
static const int16PRIORITY_UPDATE

Protected Types

typedef std::vector< EventSourceP >SourceList

Protected Member Functions

boolcheck_sources_Lm (LoopState &, const QuickPfdArray &)
voidcollect_sources_Lm (LoopState &)
voiddispatch_source_Lm (LoopState &)
EventLoop (MainLoop &)
EventSourceP &find_first_L ()
EventSourceP &find_source_L (uint id)
boolhas_primary_L (void)
voidkill_sources_Lm (void)
boolprepare_sources_Lm (LoopState &, QuickPfdArray &)
voidremove_source_Lm (EventSourceP source)
voidunpoll_sources_U ()
virtual~EventLoop ()

Protected Attributes

int16dispatch_priority_
MainLoop *main_loop_
std::vector< EventSourceP >poll_sources_
boolprimary_
SourceListsources_

Detailed Description

Loop object, polling for events and executing callbacks in accordance.

Member Typedef Documentation

SourceList

typedef std::vector<EventSourceP> SourceList
protected

VoidSlot

typedef std::function<void (void)> VoidSlot

BoolSlot

typedef std::function<bool (void)> BoolSlot

VPfdSlot

typedef std::function<void (PollFD&)> VPfdSlot

BPfdSlot

typedef std::function<bool (PollFD&)> BPfdSlot

DispatcherSlot

typedef std::function<bool (const LoopState&)> DispatcherSlot

USignalSlot

typedef std::function<bool (int8)> USignalSlot

Constructor & Destructor Documentation

EventLoop()

EventLoop ( MainLoop & main)
explicitprotected

~EventLoop()

~EventLoop ( )
protectedvirtual

Member Function Documentation

find_first_L()

EventSourceP & find_first_L ( )
protected

find_source_L()

EventSourceP & find_source_L ( uint id)
protected

has_primary_L()

bool has_primary_L ( void )
protected

remove_source_Lm()

void remove_source_Lm ( EventSourceP source)
protected

kill_sources_Lm()

void kill_sources_Lm ( void )
protected

unpoll_sources_U()

void unpoll_sources_U ( )
protected

collect_sources_Lm()

void collect_sources_Lm ( LoopState & state)
protected

prepare_sources_Lm()

bool prepare_sources_Lm ( LoopState & state,
QuickPfdArray & pfda
)
protected

check_sources_Lm()

bool check_sources_Lm ( LoopState & state,
const QuickPfdArray & pfda
)
protected

dispatch_source_Lm()

void dispatch_source_Lm ( LoopState & state)
protected

wakeup()

void wakeup ( )

Wakeup loop from polling.

add()

uint add ( EventSourceP loop_source,
int priority = PRIORITY_NORMAL
)

Adds a new source to the loop with custom priority.

remove()

void remove ( uint id)

Removes a source from loop, the source must be present.

try_remove()

bool try_remove ( uint id)

Tries to remove a source, returns if successfull.

clear_source()

bool clear_source ( uint * id_pointer)

Remove source if `id_pointer` and `*id_pointer` are valid.

destroy_loop()

void destroy_loop ( void )

Remove all sources from a loop and prevent any further execution. The destroy_loop() method removes all sources from a loop and in case of a sub EventLoop (see create_sub_loop()) removes it from its associated main loop. Calling destroy_loop() on a main loop also calls destroy_loop() for all its sub loops. Note that MainLoop objects are artificially kept alive until MainLoop::destroy_loop() is called, so calling destroy_loop() is mandatory for MainLoop objects to prevent object leaks. This method must be called only once on a loop.

has_primary()

bool has_primary ( void )

Indicates whether loop contains primary sources.

flag_primary()

bool flag_primary ( bool on)

main_loop()

MainLoop * main_loop ( ) const

Get the main loop for this loop.

exec_now()

template<class BoolVoidFunctor >
uint exec_now ( BoolVoidFunctor && bvf)

Execute a callback as primary source with priority "now" (highest), returning true repeats callback.

exec_callback()

template<class BoolVoidFunctor >
uint exec_callback ( BoolVoidFunctor && bvf,
int priority = PRIORITY_NORMAL
)

Execute a callback at user defined priority returning true repeats callback.

exec_idle()

template<class BoolVoidFunctor >
uint exec_idle ( BoolVoidFunctor && bvf)

Execute a callback with priority "idle", returning true repeats callback.

exec_dispatcher()

uint exec_dispatcher ( const DispatcherSlot & sl,
int priority = PRIORITY_NORMAL
)

exec_usignal()

uint exec_usignal ( int8 signum,
const USignalSlot & sl,
int priority = PRIORITY_NOW -1
)

Execute a single dispatcher callback for prepare, check, dispatch.

exec_once()

bool exec_once ( uint delay_ms,
uint * once_id,
const VoidSlot & vfunc,
int priority = PRIORITY_NORMAL
)

Execute a signal callback for prepare, check, dispatch.

Execute a callback once, re-schedules the callback if `0 != *once_id`.

exec_timer()

template<class BoolVoidFunctor >
uint exec_timer ( BoolVoidFunctor && bvf,
uint delay_ms,
int64 repeat_ms = -1,
int priority = PRIORITY_NORMAL
)

Execute a callback after a specified timeout with adjustable initial timeout, returning true repeats callback.

exec_io_handler()

template<class BoolVoidPollFunctor >
uint exec_io_handler ( BoolVoidPollFunctor && bvf,
int fd,
const String & mode,
int priority = PRIORITY_NORMAL
)

Execute a callback after polling for mode on fd, returning true repeats callback.

Member Data Documentation

main_loop_

MainLoop* main_loop_
protected

sources_

SourceList sources_
protected

poll_sources_

std::vector<EventSourceP> poll_sources_
protected

dispatch_priority_

int16 dispatch_priority_
protected

primary_

bool primary_
protected

PRIORITY_CEILING

const int16 PRIORITY_CEILING
static

Internal upper limit, don't use.

PRIORITY_NOW

const int16 PRIORITY_NOW
static

Most important, used for immediate async execution.

PRIORITY_ASCENT

const int16 PRIORITY_ASCENT
static

Threshold for priorization across different loops.

PRIORITY_HIGH

const int16 PRIORITY_HIGH
static

Very important, used for timers or IO handlers.

PRIORITY_NEXT

const int16 PRIORITY_NEXT
static

Important, used for async operations and callbacks.

PRIORITY_NORMAL

const int16 PRIORITY_NORMAL
static

Normal importantance, GUI event processing, RPC.

PRIORITY_UPDATE

const int16 PRIORITY_UPDATE
static

Mildly important, used for GUI updates or user information.

PRIORITY_IDLE

const int16 PRIORITY_IDLE
static

Mildly important, used for background tasks.

PRIORITY_LOW

const int16 PRIORITY_LOW
static

Unimportant, used when everything else done.