Skip to content

Class Ase::MainLoop

ClassList > Ase > MainLoop

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

  • #include <loop.hh>

Inherits the following classes: Ase::EventLoop

Public Types inherited from Ase::EventLoop

See Ase::EventLoop

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

Public Static Attributes inherited from Ase::EventLoop

See Ase::EventLoop

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

Public Functions

Type Name
EventLoopP create_sub_loop ()
Creates a new event loop that is run as part of this main loop.
bool finishable ()
Indicates wether this loop has no primary sources left to process.
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.
std::mutex & mutex ()
Provide access to the mutex associated with this main loop.
bool pending ()
Check if iterate() needs to be called for dispatching.
void quit (int quit_code=0)
Cause run() to return with__quit_code .
int run ()
Run loop iterations until a call to quit() or finishable becomes true.
bool running ()
Indicates if quit() has been called already.
bool set_g_main_context (GlibGMainContext * glib_main_context)
Set context to integrate with a GLib GMainContext loop.

Public Functions inherited from Ase::EventLoop

See Ase::EventLoop

Type Name
uint add (EventSourceP loop_source, int priority=PRIORITY_NORMAL)
Adds a new source to the loop with custom priority.
bool clear_source (uint * id_pointer)
Remove source if id_pointer and*id_pointer are valid.
void destroy_loop (void)
uint exec_callback (BoolVoidFunctor && bvf, int priority=PRIORITY_NORMAL)
Execute a callback at user defined priority returning true repeats callback.
uint exec_dispatcher (const DispatcherSlot & sl, int priority=PRIORITY_NORMAL)
uint exec_idle (BoolVoidFunctor && bvf)
Execute a callback with priority "idle", returning true repeats callback.
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.
uint exec_now (BoolVoidFunctor && bvf)
Execute a callback as primary source with priority "now" (highest), returning true repeats callback.
bool exec_once (uint delay_ms, uint * once_id, const VoidSlot & vfunc, int priority=PRIORITY_NORMAL)
Execute a signal callback for prepare, check, dispatch.
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.
uint exec_usignal (int8 signum, const USignalSlot & sl, int priority=PRIORITY_NOW -1)
Execute a single dispatcher callback for prepare, check, dispatch.
bool flag_primary (bool on)
bool has_primary (void)
Indicates whether loop contains primary sources.
MainLoop * main_loop () const
Get the main loop for this loop.
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.
void wakeup ()
Wakeup loop from polling.

Public Static Functions

Type Name
MainLoopP create ()
Create a MainLoop shared pointer handle.

Protected Types inherited from Ase::EventLoop

See Ase::EventLoop

Type Name
typedef std::vector< EventSourceP > SourceList

Protected Attributes inherited from Ase::EventLoop

See Ase::EventLoop

Type Name
int16 dispatch_priority_
MainLoop * main_loop_
std::vector< EventSourceP > poll_sources_
bool primary_
SourceList sources_

Protected Functions inherited from Ase::EventLoop

See Ase::EventLoop

Type Name
EventLoop (MainLoop & main)
bool check_sources_Lm (LoopState & state, const QuickPfdArray & pfda)
void collect_sources_Lm (LoopState & state)
void dispatch_source_Lm (LoopState & state)
EventSourceP & find_first_L ()
EventSourceP & find_source_L (uint id)
bool has_primary_L (void)
void kill_sources_Lm (void)
bool prepare_sources_Lm (LoopState & state, QuickPfdArray & pfda)
void remove_source_Lm (EventSourceP source)
void unpoll_sources_U ()
virtual ~EventLoop ()

Public Functions Documentation

function create_sub_loop

EventLoopP Ase::MainLoop::create_sub_loop () 

function finishable

bool Ase::MainLoop::finishable () 

function iterate

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

bool Ase::MainLoop::iterate (
    bool block
) 

Parameters:

  • may_block If 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.


function iterate_pending

void Ase::MainLoop::iterate_pending () 

function mutex

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

function pending

bool Ase::MainLoop::pending () 

function quit

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

function run

int Ase::MainLoop::run () 

function running

bool Ase::MainLoop::running () 

function set_g_main_context

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

Public Static Functions Documentation

function create

Create a MainLoop shared pointer handle.

static MainLoopP Ase::MainLoop::create () 

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



The documentation for this class was generated from the following file /__w/anklang/anklang/ase/loop.hh