|
Anklang-0.3.0.dev712+gdc4e642f anklang-0.3.0.dev712+gdc4e642f
ASE — Anklang Sound Engine (C++)
« « « Anklang Documentation |
Loop object, polling for events and executing callbacks in accordance. More...
#include "loop.hh"
Classes | |
| struct | Promise |
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 | |
| virtual void | wakeup ()=0 |
| Wakeup loop from polling. | |
| virtual LoopID | add_source (LoopSourceP loop_source, LoopPriority priority=LoopPriority::NORMAL)=0 |
| Adds a new source to the loop with custom priority. | |
| virtual void | cancel (LoopID id)=0 |
| Cancel a source and remove it from the loop. | |
| virtual void | cancel (LoopID *idp)=0 |
| Cancel a source by id if present and resets the id. | |
| virtual bool | has_primary (void)=0 |
| Indicates whether loop contains primary sources. | |
| LoopID | exec_dispatcher (const DispatcherSlot &sl, LoopPriority priority=LoopPriority::NORMAL) |
| LoopID | exec_usignal (int8 signum, const USignalSlot &sl, LoopPriority priority=LoopPriority::USIGNAL) |
| Execute a single dispatcher callback for prepare, check, dispatch. | |
| virtual LoopID | exec_sigchld (int64_t pid, const SigchldSlot &vfunc, LoopPriority priority=LoopPriority::NORMAL)=0 |
| Execute a signal callback for prepare, check, dispatch. | |
| virtual bool | exec_once (uint delay_ms, LoopID *once_id, const VoidSlot &vfunc, LoopPriority priority=LoopPriority::NORMAL)=0 |
Execute a callback once on SIGCHLD for pid. | |
| template<IsLoopCallback Func> | |
| LoopID | add (Func &&func, std::chrono::milliseconds interval=std::chrono::milliseconds(0), LoopPriority priority=LoopPriority::NORMAL) |
| template<IsLoopCallback Func> requires IsAwaitable<std::invoke_result_t<Coroutine>> | |
| LoopID | add (Func &&func, LoopPriority priority) |
|
template<class Coroutine > requires IsAwaitable<std::invoke_result_t<Coroutine>> | |
| LoopID | add (Coroutine &&coroutine, LoopPriority priority=LoopPriority::NORMAL) |
| template<class BoolVoidPollFunctor > | |
| LoopID | exec_io_handler (BoolVoidPollFunctor &&bvf, int fd, const String &mode, LoopPriority priority=LoopPriority::NORMAL) |
| Execute a callback after polling for mode on fd, returning true repeats callback. | |
| virtual int | run ()=0 |
| Run loop iterations until a call to quit() or finishable becomes true. | |
| virtual bool | running ()=0 |
| Indicates if quit() has been called already. | |
| virtual bool | finishable ()=0 |
| Indicates wether this loop has no primary sources left to process. | |
| virtual void | quit (int quit_code=0)=0 |
| Cause run() to return with quit_code. | |
| virtual bool | pending ()=0 |
| Check if iterate() needs to be called for dispatching. | |
| virtual bool | iterate (bool block)=0 |
| Perform one loop iteration and return whether more iterations are needed. | |
| virtual void | iterate_pending ()=0 |
| Call iterate() until no immediate dispatching is needed. | |
| virtual bool | set_g_main_context (GlibGMainContext *glib_main_context)=0 |
| Set context to integrate with a GLib GMainContext loop. | |
| virtual bool | has_quit ()=0 |
| Check if quit() has been called. | |
| template<typename Result > | |
| std::shared_ptr< Promise< Result > > | make_promise (const std::function< void(std::function< void(Result)>)> &executor) |
| Create promise and immediately run executor. | |
| std::shared_ptr< Promise< void > > | make_promise (const std::function< void(std::function< void()>)> &executor) |
| Create promise and immediately run executor. | |
| std::shared_ptr< Promise< uint64_t > > | delay (std::chrono::milliseconds ms) |
Create a promise that resolves after ms milliseconds and returns the elapsed delay. | |
Public Member Functions inherited from std::enable_shared_from_this< Loop > | |
| 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 Member Functions | |
| static LoopP | current () |
| Return the thread-local singleton loop, created on first call. | |
Protected Member Functions | |
| virtual void | destroy_loop ()=0 |
Friends | |
| class | LoopImpl |
Loop object, polling for events and executing callbacks in accordance.
| typedef std::function<bool (void)> Ase::Loop::BoolSlot |
| typedef std::function<bool (PollFD&)> Ase::Loop::BPfdSlot |
| typedef std::function<bool (const LoopState&)> Ase::Loop::DispatcherSlot |
| typedef std::function<void (int,int)> Ase::Loop::SigchldSlot |
| typedef std::function<bool (int8)> Ase::Loop::USignalSlot |
| typedef std::function<void (void)> Ase::Loop::VoidSlot |
| typedef std::function<void (PollFD&)> Ase::Loop::VPfdSlot |
| LoopID Ase::Loop::add | ( | Coroutine && | func, |
| LoopPriority | priority | ||
| ) |
| LoopID Ase::Loop::add | ( | Func && | func, |
| std::chrono::milliseconds | interval = std::chrono::milliseconds (0), |
||
| LoopPriority | priority = LoopPriority::NORMAL |
||
| ) |
|
pure virtual |
Adds a new source to the loop with custom priority.
Implemented in Ase::LoopImpl.
Referenced by exec_io_handler(), and exec_usignal().
|
pure virtual |
Cancel a source by id if present and resets the id.
Implemented in Ase::LoopImpl.
|
pure virtual |
Cancel a source and remove it from the loop.
Implemented in Ase::LoopImpl.
Referenced by Ase::LoopSource::loop_remove().
|
static |
Return the thread-local singleton loop, created on first call.
Each thread gets its own independent loop instance that lives for the duration of the thread. The loop is created lazily on first access and is kept alive by the thread_local storage. Calling current() from different threads returns different loop instances; calling it multiple times from the same thread always returns the same instance.
| std::shared_ptr< Loop::Promise< uint64_t > > Ase::Loop::delay | ( | std::chrono::milliseconds | ms | ) |
Create a promise that resolves after ms milliseconds and returns the elapsed delay.
Definition at line 314 of file loop.cc.
References std::chrono::steady_clock::now(), and uint64_t.
|
protectedpure virtual |
Implemented in Ase::LoopImpl.
| LoopID Ase::Loop::exec_dispatcher | ( | const DispatcherSlot & | sl, |
| LoopPriority | priority = LoopPriority::NORMAL |
||
| ) |
| LoopID Ase::Loop::exec_io_handler | ( | BoolVoidPollFunctor && | bvf, |
| int | fd, | ||
| const String & | mode, | ||
| LoopPriority | priority = LoopPriority::NORMAL |
||
| ) |
Execute a callback after polling for mode on fd, returning true repeats callback.
Definition at line 314 of file loop.hh.
References add_source().
|
pure virtual |
Execute a callback once on SIGCHLD for pid.
Execute a callback once, re-schedules the callback if 0 != *once_id.
Implemented in Ase::LoopImpl.
|
pure virtual |
Execute a signal callback for prepare, check, dispatch.
Implemented in Ase::LoopImpl.
| LoopID Ase::Loop::exec_usignal | ( | int8 | signum, |
| const USignalSlot & | sl, | ||
| LoopPriority | priority = LoopPriority::USIGNAL |
||
| ) |
Execute a single dispatcher callback for prepare, check, dispatch.
Definition at line 308 of file loop.hh.
References add_source().
|
pure virtual |
Indicates wether this loop has no primary sources left to process.
Implemented in Ase::LoopImpl.
|
pure virtual |
Indicates whether loop contains primary sources.
Implemented in Ase::LoopImpl.
|
pure virtual |
Check if quit() has been called.
Implemented in Ase::LoopImpl.
Perform one loop iteration and return whether more iterations are needed.
Implemented in Ase::LoopImpl.
|
pure virtual |
Call iterate() until no immediate dispatching is needed.
Implemented in Ase::LoopImpl.
| std::shared_ptr< Loop::Promise< void > > Ase::Loop::make_promise | ( | const std::function< void(std::function< void()>)> & | executor | ) |
Create promise and immediately run executor.
Definition at line 487 of file loop.hh.
References std::current_exception().
| std::shared_ptr< Loop::Promise< Result > > Ase::Loop::make_promise | ( | const std::function< void(std::function< void(Result)>)> & | executor | ) |
Create promise and immediately run executor.
Definition at line 470 of file loop.hh.
References std::current_exception().
|
pure virtual |
Check if iterate() needs to be called for dispatching.
Implemented in Ase::LoopImpl.
|
pure virtual |
Cause run() to return with quit_code.
Implemented in Ase::LoopImpl.
|
pure virtual |
Run loop iterations until a call to quit() or finishable becomes true.
Implemented in Ase::LoopImpl.
|
pure virtual |
Indicates if quit() has been called already.
Implemented in Ase::LoopImpl.
|
pure virtual |
Set context to integrate with a GLib GMainContext loop.
Implemented in Ase::LoopImpl.
|
pure virtual |
Wakeup loop from polling.
Implemented in Ase::LoopImpl.