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

« « « Anklang Documentation
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
Ase::MainLoop Class Reference

An EventLoop implementation that offers public API for running the loop. More...

#include "loop.hh"

Inheritance diagram for Ase::MainLoop:
[legend]

Public Member Functions

int run ()
 Run loop iterations until a call to quit() or finishable becomes true.
 
bool running ()
 Indicates if quit() has been called already.
 
bool finishable ()
 Indicates wether this loop has no primary sources left to process.
 
void quit (int quit_code=0)
 Cause run() to return with quit_code.
 
bool pending ()
 Check if iterate() needs to be called for dispatching.
 
bool iterate (bool block)
 Perform one loop iteration and return whether more iterations are needed.
 
void iterate_pending ()
 Call iterate() until no immediate dispatching is needed.
 
EventLoopP create_sub_loop ()
 Creates a new event loop that is run as part of this main loop.
 
std::mutexmutex ()
 Provide access to the mutex associated with this main loop.
 
bool set_g_main_context (GlibGMainContext *glib_main_context)
 Set context to integrate with a GLib GMainContext loop.
 
- Public Member Functions inherited from Ase::EventLoop
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 Member Functions

static MainLoopP create ()
 Create a MainLoop shared pointer handle.
 

Friends

class EventLoop
 
class SubLoop
 

Additional Inherited Members

- Public Types inherited from Ase::EventLoop
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
 
- Static Public Attributes inherited from Ase::EventLoop
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 inherited from Ase::EventLoop
typedef std::vector< EventSourcePSourceList
 
- Protected Member Functions inherited from Ase::EventLoop
 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 inherited from Ase::EventLoop
MainLoopmain_loop_
 
SourceList sources_
 
std::vector< EventSourcePpoll_sources_
 
int16 dispatch_priority_
 
bool primary_
 

Detailed Description

An EventLoop implementation that offers public API for running the loop.

Definition at line 133 of file loop.hh.

Member Function Documentation

◆ create()

MainLoopP Ase::MainLoop::create ( )
static

Create a MainLoop shared pointer handle.

Create a new main loop object, users can run or iterate this loop directly. Note that MainLoop objects have special lifetime semantics that keep them alive until they are explicitely destroyed with destroy_loop().

Definition at line 369 of file loop.cc.

References Ase::EventLoop::main_loop(), and mutex().

◆ create_sub_loop()

EventLoopP Ase::MainLoop::create_sub_loop ( )

Creates a new event loop that is run as part of this main loop.

Definition at line 896 of file loop.cc.

References mutex().

◆ finishable()

bool Ase::MainLoop::finishable ( )

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

Definition at line 480 of file loop.cc.

◆ iterate()

bool Ase::MainLoop::iterate ( bool  may_block)

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

Parameters
may_blockIf true, iterate() will wait for events occour.

MainLoop::iterate() is the heart of the main event loop. For loop iteration, all event sources are polled for incoming events. Then dispatchable sources are picked one per iteration and dispatched in round-robin fashion. If no sources need immediate dispatching and may_block is true, iterate() will wait for events to become available.

Returns
Whether more sources need immediate dispatching.

Definition at line 497 of file loop.cc.

◆ iterate_pending()

void Ase::MainLoop::iterate_pending ( )

Call iterate() until no immediate dispatching is needed.

Definition at line 510 of file loop.cc.

References ISLIKELY.

◆ mutex()

std::mutex & Ase::MainLoop::mutex ( )

Provide access to the mutex associated with this main loop.

Definition at line 163 of file loop.hh.

Referenced by Ase::EventLoop::add(), create(), create_sub_loop(), Ase::EventLoop::destroy_loop(), Ase::EventLoop::exec_once(), Ase::EventLoop::has_primary(), and Ase::EventLoop::try_remove().

◆ pending()

bool Ase::MainLoop::pending ( )

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

Definition at line 524 of file loop.cc.

◆ quit()

void Ase::MainLoop::quit ( int  quit_code = 0)

Cause run() to return with quit_code.

Definition at line 459 of file loop.cc.

References Ase::EventLoop::wakeup().

◆ run()

int Ase::MainLoop::run ( )

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

Definition at line 436 of file loop.cc.

References ISLIKELY.

◆ running()

bool Ase::MainLoop::running ( )

Indicates if quit() has been called already.

Definition at line 452 of file loop.cc.

◆ set_g_main_context()

bool Ase::MainLoop::set_g_main_context ( GlibGMainContext *  glib_main_context)

Set context to integrate with a GLib GMainContext loop.

Definition at line 533 of file loop.cc.

Friends And Related Symbol Documentation

◆ EventLoop

friend class EventLoop
friend

Definition at line 135 of file loop.hh.

◆ SubLoop

friend class SubLoop
friend

Definition at line 136 of file loop.hh.


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