Anklang-0.3.0.dev712+gdc4e642f anklang-0.3.0.dev712+gdc4e642f
ASE — Anklang Sound Engine (C++)

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

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

#include "loop.hh"

Inheritance diagram for Ase::Loop:
[legend]

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 >
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 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
 

Detailed Description

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

Definition at line 76 of file loop.hh.

Member Typedef Documentation

◆ BoolSlot

Definition at line 86 of file loop.hh.

◆ BPfdSlot

Definition at line 88 of file loop.hh.

◆ DispatcherSlot

Definition at line 89 of file loop.hh.

◆ SigchldSlot

Definition at line 91 of file loop.hh.

◆ USignalSlot

Definition at line 90 of file loop.hh.

◆ VoidSlot

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

Definition at line 85 of file loop.hh.

◆ VPfdSlot

Definition at line 87 of file loop.hh.

Constructor & Destructor Documentation

◆ Loop()

Ase::Loop::Loop ( )
explicitprotected

Definition at line 69 of file loop.cc.

◆ ~Loop()

Ase::Loop::~Loop ( )
protectedvirtual

Definition at line 70 of file loop.cc.

Member Function Documentation

◆ add() [1/2]

template<class Coroutine >
requires IsAwaitable<std::invoke_result_t<Coroutine>>
LoopID Ase::Loop::add ( Coroutine &&  func,
LoopPriority  priority 
)

Definition at line 331 of file loop.hh.

◆ add() [2/2]

template<IsLoopCallback Func>
LoopID Ase::Loop::add ( Func &&  func,
std::chrono::milliseconds  interval = std::chrono::milliseconds (0),
LoopPriority  priority = LoopPriority::NORMAL 
)

Definition at line 322 of file loop.hh.

◆ add_source()

virtual LoopID Ase::Loop::add_source ( LoopSourceP  loop_source,
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().

◆ cancel() [1/2]

virtual void Ase::Loop::cancel ( LoopID *  idp)
pure virtual

Cancel a source by id if present and resets the id.

Implemented in Ase::LoopImpl.

◆ cancel() [2/2]

virtual void Ase::Loop::cancel ( LoopID  id)
pure virtual

Cancel a source and remove it from the loop.

Implemented in Ase::LoopImpl.

Referenced by Ase::LoopSource::loop_remove().

◆ current()

LoopP Ase::Loop::current ( )
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.

Definition at line 306 of file loop.cc.

◆ delay()

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.

◆ destroy_loop()

virtual void Ase::Loop::destroy_loop ( )
protectedpure virtual

Implemented in Ase::LoopImpl.

◆ exec_dispatcher()

LoopID Ase::Loop::exec_dispatcher ( const DispatcherSlot sl,
LoopPriority  priority = LoopPriority::NORMAL 
)

Definition at line 302 of file loop.hh.

◆ exec_io_handler()

template<class BoolVoidPollFunctor >
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().

◆ exec_once()

virtual bool Ase::Loop::exec_once ( uint  delay_ms,
LoopID *  once_id,
const VoidSlot vfunc,
LoopPriority  priority = LoopPriority::NORMAL 
)
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.

◆ exec_sigchld()

virtual LoopID Ase::Loop::exec_sigchld ( int64_t  pid,
const SigchldSlot vfunc,
LoopPriority  priority = LoopPriority::NORMAL 
)
pure virtual

Execute a signal callback for prepare, check, dispatch.

Implemented in Ase::LoopImpl.

◆ exec_usignal()

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().

◆ finishable()

virtual bool Ase::Loop::finishable ( )
pure virtual

Indicates wether this loop has no primary sources left to process.

Implemented in Ase::LoopImpl.

◆ has_primary()

virtual bool Ase::Loop::has_primary ( void  )
pure virtual

Indicates whether loop contains primary sources.

Implemented in Ase::LoopImpl.

◆ has_quit()

virtual bool Ase::Loop::has_quit ( )
pure virtual

Check if quit() has been called.

Implemented in Ase::LoopImpl.

◆ iterate()

virtual bool Ase::Loop::iterate ( bool  block)
pure virtual

Perform one loop iteration and return whether more iterations are needed.

Implemented in Ase::LoopImpl.

◆ iterate_pending()

virtual void Ase::Loop::iterate_pending ( )
pure virtual

Call iterate() until no immediate dispatching is needed.

Implemented in Ase::LoopImpl.

◆ make_promise() [1/2]

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().

◆ make_promise() [2/2]

template<typename Result >
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().

◆ pending()

virtual bool Ase::Loop::pending ( )
pure virtual

Check if iterate() needs to be called for dispatching.

Implemented in Ase::LoopImpl.

◆ quit()

virtual void Ase::Loop::quit ( int  quit_code = 0)
pure virtual

Cause run() to return with quit_code.

Implemented in Ase::LoopImpl.

◆ run()

virtual int Ase::Loop::run ( )
pure virtual

Run loop iterations until a call to quit() or finishable becomes true.

Implemented in Ase::LoopImpl.

◆ running()

virtual bool Ase::Loop::running ( )
pure virtual

Indicates if quit() has been called already.

Implemented in Ase::LoopImpl.

◆ set_g_main_context()

virtual bool Ase::Loop::set_g_main_context ( GlibGMainContext *  glib_main_context)
pure virtual

Set context to integrate with a GLib GMainContext loop.

Implemented in Ase::LoopImpl.

◆ wakeup()

virtual void Ase::Loop::wakeup ( )
pure virtual

Wakeup loop from polling.

Implemented in Ase::LoopImpl.

Friends And Related Symbol Documentation

◆ LoopImpl

friend class LoopImpl
friend

Definition at line 78 of file loop.hh.


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