|
Anklang-0.3.0.dev551+gad1415e2 anklang-0.3.0.dev551+gad1415e2
ASE — Anklang Sound Engine (C++)
« « « Anklang Documentation |
Loop object, polling for events and executing callbacks in accordance. More...
#include "loop.hh"
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. | |
| void | remove (uint *idp) |
| Removes a source by id if present, resets id. | |
| 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) |
| Remove all sources from a loop and prevent any further execution. | |
| bool | has_primary (void) |
| Indicates whether loop contains primary sources. | |
| bool | flag_primary (bool on) |
| MainLoop * | main_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 > | |
| T | enable_shared_from_this (T... args) |
| T | operator= (T... args) |
| T | shared_from_this (T... args) |
| T | weak_from_this (T... args) |
| T | ~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< EventSourceP > | SourceList |
Protected Member Functions | |
| EventLoop (MainLoop &) | |
| EventSourceP & | find_first_L () |
| EventSourceP & | find_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 | |
| MainLoop * | main_loop_ |
| SourceList | sources_ |
| std::vector< EventSourceP > | poll_sources_ |
| int16 | dispatch_priority_ |
| bool | primary_ |
Friends | |
| class | MainLoop |
Loop object, polling for events and executing callbacks in accordance.
| typedef std::function<bool (void)> Ase::EventLoop::BoolSlot |
| typedef std::function<bool (PollFD&)> Ase::EventLoop::BPfdSlot |
| typedef std::function<bool (const LoopState&)> Ase::EventLoop::DispatcherSlot |
| typedef std::function<void (int,int)> Ase::EventLoop::SigchldSlot |
|
protected |
| typedef std::function<bool (int8)> Ase::EventLoop::USignalSlot |
| typedef std::function<void (void)> Ase::EventLoop::VoidSlot |
| typedef std::function<void (PollFD&)> Ase::EventLoop::VPfdSlot |
|
explicitprotected |
| 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().
|
protected |
Remove source if id_pointer and *id_pointer are valid.
Definition at line 258 of file loop.cc.
References return_unless, and try_remove().
Referenced by exec_once().
|
protected |
| 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 342 of file loop.cc.
References assert_return, and Ase::MainLoop::mutex().
|
protected |
| uint Ase::EventLoop::exec_callback | ( | BoolVoidFunctor && | bvf, |
| int | priority = PRIORITY_NORMAL |
||
| ) |
| uint Ase::EventLoop::exec_dispatcher | ( | const DispatcherSlot & | sl, |
| int | priority = PRIORITY_NORMAL |
||
| ) |
| uint Ase::EventLoop::exec_idle | ( | BoolVoidFunctor && | bvf | ) |
Execute a callback with priority "idle", returning true repeats callback.
Definition at line 354 of file loop.hh.
References add(), and PRIORITY_IDLE.
| uint Ase::EventLoop::exec_io_handler | ( | BoolVoidPollFunctor && | bvf, |
| int | fd, | ||
| const String & | mode, | ||
| int | priority = PRIORITY_NORMAL |
||
| ) |
| uint Ase::EventLoop::exec_now | ( | BoolVoidFunctor && | bvf | ) |
Execute a callback as primary source with priority "now" (highest), returning true repeats callback.
Definition at line 336 of file loop.hh.
References add(), and PRIORITY_NOW.
| 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 274 of file loop.cc.
References assert_return, clear_source(), Ase::MainLoop::mutex(), PRIORITY_CEILING, std::vector::push_back(), and wakeup().
| uint Ase::EventLoop::exec_sigchld | ( | int64_t | pid, |
| const SigchldSlot & | vfunc, | ||
| int | priority = PRIORITY_NORMAL |
||
| ) |
| uint Ase::EventLoop::exec_timer | ( | BoolVoidFunctor && | bvf, |
| uint | delay_ms, | ||
| int64 | repeat_ms = -1, |
||
| int | priority = PRIORITY_NORMAL |
||
| ) |
| uint Ase::EventLoop::exec_usignal | ( | int8 | signum, |
| const USignalSlot & | sl, | ||
| int | priority = PRIORITY_NOW -1 |
||
| ) |
|
protected |
|
protected |
| bool Ase::EventLoop::has_primary | ( | void | ) |
Indicates whether loop contains primary sources.
Definition at line 172 of file loop.cc.
References Ase::MainLoop::mutex().
| 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().
|
protected |
| void Ase::EventLoop::remove | ( | uint * | idp | ) |
Removes a source by id if present, resets id.
Definition at line 248 of file loop.cc.
References try_remove().
| void Ase::EventLoop::remove | ( | uint | id | ) |
Removes a source from loop, the source must be present.
Definition at line 267 of file loop.cc.
References try_remove().
|
protected |
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(), remove(), and remove().
| void Ase::EventLoop::wakeup | ( | ) |
Wakeup loop from polling.
Definition at line 356 of file loop.cc.
Referenced by add(), exec_once(), Ase::MainLoop::quit(), and try_remove().
|
protected |
|
static |
|
static |
Internal upper limit, don't use.
Definition at line 88 of file loop.hh.
Referenced by add(), and exec_once().
|
static |
|
static |
Mildly important, used for background tasks.
Definition at line 95 of file loop.hh.
Referenced by exec_idle().
|
static |
|
static |
|
static |
|
static |
Most important, used for immediate async execution.
Definition at line 89 of file loop.hh.
Referenced by exec_now().
|
static |
|
protected |