Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
Ase::EventLoop Class Reference

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

#include "loop.hh"

Inheritance diagram for Ase::EventLoop:
[legend]

Classes

struct  QuickPfdArray
 

Public Types

typedef std::function< void(void)> VoidSlot
 
typedef std::function< bool(void)> BoolSlot
 
typedef std::function< void(PollFD &)> VPfdSlot
 
typedef std::function< bool(PollFD &)> BPfdSlot
 
typedef std::function< bool(const LoopState &)> DispatcherSlot
 
typedef std::function< bool(int8)> USignalSlot
 
typedef std::function< void(int, int)> SigchldSlot
 

Public Member Functions

void wakeup ()
 Wakeup loop from polling.
 
uint add (EventSourceP loop_source, int priority=PRIORITY_NORMAL)
 Adds a new source to the loop with custom priority.
 
void remove (uint id)
 Removes a source from loop, the source must be present.
 
bool try_remove (uint id)
 Tries to remove a source, returns if successfull.
 
bool clear_source (uint *id_pointer)
 Remove source if id_pointer and *id_pointer are valid.
 
void destroy_loop (void)
 
bool has_primary (void)
 Indicates whether loop contains primary sources.
 
bool flag_primary (bool on)
 
MainLoopmain_loop () const
 Get the main loop for this loop.
 
template<class BoolVoidFunctor >
uint exec_now (BoolVoidFunctor &&bvf)
 Execute a callback as primary source with priority "now" (highest), returning true repeats callback.
 
template<class BoolVoidFunctor >
uint exec_callback (BoolVoidFunctor &&bvf, int priority=PRIORITY_NORMAL)
 Execute a callback at user defined priority returning true repeats callback.
 
template<class BoolVoidFunctor >
uint exec_idle (BoolVoidFunctor &&bvf)
 Execute a callback with priority "idle", returning true repeats callback.
 
uint exec_dispatcher (const DispatcherSlot &sl, int priority=PRIORITY_NORMAL)
 
uint exec_usignal (int8 signum, const USignalSlot &sl, int priority=PRIORITY_NOW -1)
 Execute a single dispatcher callback for prepare, check, dispatch.
 
uint exec_sigchld (int64_t pid, const SigchldSlot &vfunc, int priority=PRIORITY_NORMAL)
 Execute a signal callback for prepare, check, dispatch.
 
bool exec_once (uint delay_ms, uint *once_id, const VoidSlot &vfunc, int priority=PRIORITY_NORMAL)
 Execute a callback once on SIGCHLD for pid.
 
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.
 
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.
 
- Public Member Functions inherited from std::enable_shared_from_this< EventLoop >
enable_shared_from_this (T... args)
 
operator= (T... args)
 
shared_from_this (T... args)
 
weak_from_this (T... args)
 
~enable_shared_from_this (T... args)
 

Static Public Attributes

static const int16 PRIORITY_CEILING
 Internal upper limit, don't use.
 
static const int16 PRIORITY_NOW
 Most important, used for immediate async execution.
 
static const int16 PRIORITY_ASCENT
 Threshold for priorization across different loops.
 
static const int16 PRIORITY_HIGH
 Very important, used for timers or IO handlers.
 
static const int16 PRIORITY_NEXT
 Important, used for async operations and callbacks.
 
static const int16 PRIORITY_NORMAL
 Normal importantance, GUI event processing, RPC.
 
static const int16 PRIORITY_UPDATE
 Mildly important, used for GUI updates or user information.
 
static const int16 PRIORITY_IDLE
 Mildly important, used for background tasks.
 
static const int16 PRIORITY_LOW
 Unimportant, used when everything else done.
 

Protected Types

typedef std::vector< EventSourcePSourceList
 

Protected Member Functions

 EventLoop (MainLoop &)
 
EventSourcePfind_first_L ()
 
EventSourcePfind_source_L (uint id)
 
bool has_primary_L (void)
 
void remove_source_Lm (EventSourceP source)
 
void kill_sources_Lm (void)
 
void unpoll_sources_U ()
 
void collect_sources_Lm (LoopState &)
 
bool prepare_sources_Lm (LoopState &, QuickPfdArray &)
 
bool check_sources_Lm (LoopState &, const QuickPfdArray &)
 
void dispatch_source_Lm (LoopState &)
 

Protected Attributes

MainLoopmain_loop_
 
SourceList sources_
 
std::vector< EventSourcePpoll_sources_
 
int16 dispatch_priority_
 
bool primary_
 

Friends

class MainLoop
 

Detailed Description

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

Definition at line 57 of file loop.hh.

Member Typedef Documentation

◆ BoolSlot

Definition at line 82 of file loop.hh.

◆ BPfdSlot

Definition at line 84 of file loop.hh.

◆ DispatcherSlot

Definition at line 85 of file loop.hh.

◆ SigchldSlot

Definition at line 87 of file loop.hh.

◆ SourceList

Definition at line 62 of file loop.hh.

◆ USignalSlot

Definition at line 86 of file loop.hh.

◆ VoidSlot

Definition at line 81 of file loop.hh.

◆ VPfdSlot

Definition at line 83 of file loop.hh.

Constructor & Destructor Documentation

◆ EventLoop()

Ase::EventLoop::EventLoop ( MainLoop main)
explicitprotected

Definition at line 129 of file loop.cc.

◆ ~EventLoop()

Ase::EventLoop::~EventLoop ( )
protectedvirtual

Definition at line 137 of file loop.cc.

Member Function Documentation

◆ add()

uint Ase::EventLoop::add ( EventSourceP  loop_source,
int  priority = PRIORITY_NORMAL 
)

Adds a new source to the loop with custom priority.

Definition at line 198 of file loop.cc.

References assert_return, Ase::MainLoop::mutex(), PRIORITY_CEILING, std::vector::push_back(), and wakeup().

Referenced by exec_callback(), exec_idle(), exec_io_handler(), exec_now(), exec_sigchld(), exec_timer(), and exec_usignal().

◆ check_sources_Lm()

bool Ase::EventLoop::check_sources_Lm ( LoopState state,
const QuickPfdArray pfda 
)
protected

Definition at line 679 of file loop.cc.

◆ clear_source()

bool Ase::EventLoop::clear_source ( uint id_pointer)

Remove source if id_pointer and *id_pointer are valid.

Definition at line 248 of file loop.cc.

References return_unless, and try_remove().

Referenced by exec_once().

◆ collect_sources_Lm()

void Ase::EventLoop::collect_sources_Lm ( LoopState state)
protected

Definition at line 592 of file loop.cc.

◆ destroy_loop()

void Ase::EventLoop::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.

Definition at line 332 of file loop.cc.

References assert_return, and Ase::MainLoop::mutex().

◆ dispatch_source_Lm()

void Ase::EventLoop::dispatch_source_Lm ( LoopState state)
protected

Definition at line 716 of file loop.cc.

◆ exec_callback()

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

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

Definition at line 345 of file loop.hh.

References add().

◆ exec_dispatcher()

uint Ase::EventLoop::exec_dispatcher ( const DispatcherSlot sl,
int  priority = PRIORITY_NORMAL 
)

Definition at line 361 of file loop.hh.

◆ exec_idle()

template<class BoolVoidFunctor >
uint Ase::EventLoop::exec_idle ( BoolVoidFunctor &&  bvf)

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

Definition at line 353 of file loop.hh.

References add(), and PRIORITY_IDLE.

◆ exec_io_handler()

template<class BoolVoidPollFunctor >
uint Ase::EventLoop::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.

Definition at line 387 of file loop.hh.

References add().

◆ exec_now()

template<class BoolVoidFunctor >
uint Ase::EventLoop::exec_now ( BoolVoidFunctor &&  bvf)

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

Definition at line 335 of file loop.hh.

References add(), and PRIORITY_NOW.

◆ exec_once()

bool Ase::EventLoop::exec_once ( uint  delay_ms,
uint once_id,
const VoidSlot vfunc,
int  priority = PRIORITY_NORMAL 
)

Execute a callback once on SIGCHLD for pid.

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

Definition at line 264 of file loop.cc.

References assert_return, clear_source(), Ase::MainLoop::mutex(), PRIORITY_CEILING, std::vector::push_back(), and wakeup().

◆ exec_sigchld()

uint Ase::EventLoop::exec_sigchld ( int64_t  pid,
const SigchldSlot vfunc,
int  priority = PRIORITY_NORMAL 
)

Execute a signal callback for prepare, check, dispatch.

Definition at line 373 of file loop.hh.

References add().

◆ exec_timer()

template<class BoolVoidFunctor >
uint Ase::EventLoop::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.

Definition at line 379 of file loop.hh.

References add().

◆ exec_usignal()

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

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

Definition at line 367 of file loop.hh.

References add().

◆ find_first_L()

EventSourceP & Ase::EventLoop::find_first_L ( )
protected

Definition at line 144 of file loop.cc.

◆ find_source_L()

EventSourceP & Ase::EventLoop::find_source_L ( uint  id)
protected

Definition at line 151 of file loop.cc.

◆ flag_primary()

bool Ase::EventLoop::flag_primary ( bool  on)

Definition at line 179 of file loop.cc.

◆ has_primary()

bool Ase::EventLoop::has_primary ( void  )

Indicates whether loop contains primary sources.

Definition at line 172 of file loop.cc.

References Ase::MainLoop::mutex().

◆ has_primary_L()

bool Ase::EventLoop::has_primary_L ( void  )
protected

Definition at line 161 of file loop.cc.

◆ kill_sources_Lm()

void Ase::EventLoop::kill_sources_Lm ( void  )
protected

Definition at line 306 of file loop.cc.

◆ main_loop()

MainLoop * Ase::EventLoop::main_loop ( ) const

Get the main loop for this loop.

Definition at line 190 of file loop.cc.

Referenced by Ase::MainLoop::create(), and Ase::EventSource::main_loop().

◆ prepare_sources_Lm()

bool Ase::EventLoop::prepare_sources_Lm ( LoopState state,
QuickPfdArray pfda 
)
protected

Definition at line 639 of file loop.cc.

◆ remove()

void Ase::EventLoop::remove ( uint  id)

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

Definition at line 257 of file loop.cc.

References try_remove().

◆ remove_source_Lm()

void Ase::EventLoop::remove_source_Lm ( EventSourceP  source)
protected

Definition at line 217 of file loop.cc.

◆ try_remove()

bool Ase::EventLoop::try_remove ( uint  id)

Tries to remove a source, returns if successfull.

Definition at line 234 of file loop.cc.

References Ase::MainLoop::mutex(), and wakeup().

Referenced by clear_source(), Ase::EventSource::loop_remove(), and remove().

◆ unpoll_sources_U()

void Ase::EventLoop::unpoll_sources_U ( )
protected

Definition at line 585 of file loop.cc.

◆ wakeup()

void Ase::EventLoop::wakeup ( )

Wakeup loop from polling.

Definition at line 346 of file loop.cc.

Referenced by add(), exec_once(), Ase::MainLoop::quit(), and try_remove().

Friends And Related Symbol Documentation

◆ MainLoop

friend class MainLoop
friend

Definition at line 60 of file loop.hh.

Member Data Documentation

◆ dispatch_priority_

int16 Ase::EventLoop::dispatch_priority_
protected

Definition at line 66 of file loop.hh.

◆ main_loop_

MainLoop* Ase::EventLoop::main_loop_
protected

Definition at line 63 of file loop.hh.

◆ poll_sources_

std::vector<EventSourceP> Ase::EventLoop::poll_sources_
protected

Definition at line 65 of file loop.hh.

◆ primary_

bool Ase::EventLoop::primary_
protected

Definition at line 67 of file loop.hh.

◆ PRIORITY_ASCENT

const int16 Ase::EventLoop::PRIORITY_ASCENT
static

Threshold for priorization across different loops.

Definition at line 90 of file loop.hh.

◆ PRIORITY_CEILING

const int16 Ase::EventLoop::PRIORITY_CEILING
static

Internal upper limit, don't use.

Definition at line 88 of file loop.hh.

Referenced by add(), and exec_once().

◆ PRIORITY_HIGH

const int16 Ase::EventLoop::PRIORITY_HIGH
static

Very important, used for timers or IO handlers.

Definition at line 91 of file loop.hh.

◆ PRIORITY_IDLE

const int16 Ase::EventLoop::PRIORITY_IDLE
static

Mildly important, used for background tasks.

Definition at line 95 of file loop.hh.

Referenced by exec_idle().

◆ PRIORITY_LOW

const int16 Ase::EventLoop::PRIORITY_LOW
static

Unimportant, used when everything else done.

Definition at line 96 of file loop.hh.

◆ PRIORITY_NEXT

const int16 Ase::EventLoop::PRIORITY_NEXT
static

Important, used for async operations and callbacks.

Definition at line 92 of file loop.hh.

◆ PRIORITY_NORMAL

const int16 Ase::EventLoop::PRIORITY_NORMAL
static

Normal importantance, GUI event processing, RPC.

Definition at line 93 of file loop.hh.

◆ PRIORITY_NOW

const int16 Ase::EventLoop::PRIORITY_NOW
static

Most important, used for immediate async execution.

Definition at line 89 of file loop.hh.

Referenced by exec_now().

◆ PRIORITY_UPDATE

const int16 Ase::EventLoop::PRIORITY_UPDATE
static

Mildly important, used for GUI updates or user information.

Definition at line 94 of file loop.hh.

◆ sources_

SourceList Ase::EventLoop::sources_
protected

Definition at line 64 of file loop.hh.


The documentation for this class was generated from the following files: