Anklang C++ API 0.0.0
Loading...
Searching...
No Matches
MainLoop

#include "loop.hh"

Inheritance diagram for MainLoop:
[legend]

Public Member Functions

EventLoopPcreate_sub_loop ()
boolfinishable ()
booliterate (bool block)
voiditerate_pending ()
std::mutex &mutex ()
boolpending ()
voidquit (int quit_code=0)
intrun ()
boolrunning ()
boolset_g_main_context (GlibGMainContext *glib_main_context)
- Public Member Functions inherited from EventLoop
uintadd (EventSourceP loop_source, int priority=PRIORITY_NORMAL)
boolclear_source (uint *id_pointer)
voiddestroy_loop (void)
template<class BoolVoidFunctor >
uintexec_callback (BoolVoidFunctor &&bvf, int priority=PRIORITY_NORMAL)
uintexec_dispatcher (const DispatcherSlot &sl, int priority=PRIORITY_NORMAL)
template<class BoolVoidFunctor >
uintexec_idle (BoolVoidFunctor &&bvf)
template<class BoolVoidPollFunctor >
uintexec_io_handler (BoolVoidPollFunctor &&bvf, int fd, const String &mode, int priority=PRIORITY_NORMAL)
template<class BoolVoidFunctor >
uintexec_now (BoolVoidFunctor &&bvf)
boolexec_once (uint delay_ms, uint *once_id, const VoidSlot &vfunc, int priority=PRIORITY_NORMAL)
template<class BoolVoidFunctor >
uintexec_timer (BoolVoidFunctor &&bvf, uint delay_ms, int64 repeat_ms=-1, int priority=PRIORITY_NORMAL)
uintexec_usignal (int8 signum, const USignalSlot &sl, int priority=PRIORITY_NOW -1)
boolflag_primary (bool on)
boolhas_primary (void)
MainLoop *main_loop () const
voidremove (uint id)
booltry_remove (uint id)
voidwakeup ()

Static Public Member Functions

static MainLoopPcreate ()

Additional Inherited Members

- Public Types inherited from EventLoop
typedef std::function< bool(void)>BoolSlot
typedef std::function< bool(PollFD &)>BPfdSlot
typedef std::function< bool(const LoopState &)>DispatcherSlot
typedef std::function< bool(int8)>USignalSlot
typedef std::function< void(void)>VoidSlot
typedef std::function< void(PollFD &)>VPfdSlot
- Static Public Attributes inherited from EventLoop
static const int16PRIORITY_ASCENT
static const int16PRIORITY_CEILING
static const int16PRIORITY_HIGH
static const int16PRIORITY_IDLE
static const int16PRIORITY_LOW
static const int16PRIORITY_NEXT
static const int16PRIORITY_NORMAL
static const int16PRIORITY_NOW
static const int16PRIORITY_UPDATE
- Protected Types inherited from EventLoop
typedef std::vector< EventSourceP >SourceList
- Protected Member Functions inherited from EventLoop
boolcheck_sources_Lm (LoopState &, const QuickPfdArray &)
voidcollect_sources_Lm (LoopState &)
voiddispatch_source_Lm (LoopState &)
EventLoop (MainLoop &)
EventSourceP &find_first_L ()
EventSourceP &find_source_L (uint id)
boolhas_primary_L (void)
voidkill_sources_Lm (void)
boolprepare_sources_Lm (LoopState &, QuickPfdArray &)
voidremove_source_Lm (EventSourceP source)
voidunpoll_sources_U ()
virtual~EventLoop ()
- Protected Attributes inherited from EventLoop
int16dispatch_priority_
MainLoop *main_loop_
std::vector< EventSourceP >poll_sources_
boolprimary_
SourceListsources_

Detailed Description

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

Member Function Documentation

run()

int run ( )

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

running()

bool running ( )

Indicates if quit() has been called already.

finishable()

bool finishable ( )

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

quit()

void quit ( int quit_code = 0)

Cause run() to return with quit_code.

pending()

bool pending ( )

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

iterate()

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

iterate_pending()

void iterate_pending ( )

Call iterate() until no immediate dispatching is needed.

create_sub_loop()

EventLoopP create_sub_loop ( )

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

mutex()

std::mutex & mutex ( )

Provide access to the mutex associated with this main loop.

create()

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

set_g_main_context()

bool set_g_main_context ( GlibGMainContext * glib_main_context)

Set context to integrate with a GLib GMainContext loop.