Skip to content

Class Ase::EventLoop

ClassList > Ase > EventLoop

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

  • #include <loop.hh>

Inherits the following classes: std::enable_shared_from_this< EventLoop >

Inherited by the following classes: Ase::MainLoop, Ase::SubLoop

Classes

Type Name
struct QuickPfdArray

Public Types

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

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

Protected Types

Type Name
typedef std::vector< EventSourceP > SourceList

Protected Attributes

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

Protected Functions

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

typedef BPfdSlot

typedef std::function<bool (PollFD&)> Ase::EventLoop::BPfdSlot;

typedef BoolSlot

typedef std::function<bool (void)> Ase::EventLoop::BoolSlot;

typedef DispatcherSlot

typedef std::function<bool (const LoopState&)> Ase::EventLoop::DispatcherSlot;

typedef USignalSlot

typedef std::function<bool (int8)> Ase::EventLoop::USignalSlot;

typedef VPfdSlot

typedef std::function<void (PollFD&)> Ase::EventLoop::VPfdSlot;

typedef VoidSlot

typedef std::function<void (void)> Ase::EventLoop::VoidSlot;

Public Static Attributes Documentation

variable PRIORITY_ASCENT

const int16 Ase::EventLoop::PRIORITY_ASCENT;

variable PRIORITY_CEILING

const int16 Ase::EventLoop::PRIORITY_CEILING;

variable PRIORITY_HIGH

const int16 Ase::EventLoop::PRIORITY_HIGH;

variable PRIORITY_IDLE

const int16 Ase::EventLoop::PRIORITY_IDLE;

variable PRIORITY_LOW

const int16 Ase::EventLoop::PRIORITY_LOW;

variable PRIORITY_NEXT

const int16 Ase::EventLoop::PRIORITY_NEXT;

variable PRIORITY_NORMAL

const int16 Ase::EventLoop::PRIORITY_NORMAL;

variable PRIORITY_NOW

const int16 Ase::EventLoop::PRIORITY_NOW;

variable PRIORITY_UPDATE

const int16 Ase::EventLoop::PRIORITY_UPDATE;

Public Functions Documentation

function add

uint Ase::EventLoop::add (
    EventSourceP loop_source,
    int priority=PRIORITY_NORMAL
) 

function clear_source

bool Ase::EventLoop::clear_source (
    uint * id_pointer
) 

function destroy_loop

void Ase::EventLoop::destroy_loop (
    void
) 

Remove all sources from a loop and prevent any further execution. The destroy_loop() method removes all sources from a loop and in case of a sub EventLoop (see create_sub_loop()) removes it from its associated main loop. Calling destroy_loop() on a main loop also calls destroy_loop() for all its sub loops. Note that MainLoop objects are artificially kept alive until MainLoop::destroy_loop() is called, so calling destroy_loop() is mandatory for MainLoop objects to prevent object leaks. This method must be called only once on a loop.


function exec_callback

template<class BoolVoidFunctor>
uint Ase::EventLoop::exec_callback (
    BoolVoidFunctor && bvf,
    int priority=PRIORITY_NORMAL
) 

function exec_dispatcher

inline uint Ase::EventLoop::exec_dispatcher (
    const DispatcherSlot & sl,
    int priority=PRIORITY_NORMAL
) 

function exec_idle

template<class BoolVoidFunctor>
uint Ase::EventLoop::exec_idle (
    BoolVoidFunctor && bvf
) 

function exec_io_handler

template<class BoolVoidPollFunctor>
uint Ase::EventLoop::exec_io_handler (
    BoolVoidPollFunctor && bvf,
    int fd,
    const String & mode,
    int priority=PRIORITY_NORMAL
) 

function exec_now

template<class BoolVoidFunctor>
uint Ase::EventLoop::exec_now (
    BoolVoidFunctor && bvf
) 

function exec_once

Execute a signal callback for prepare, check, dispatch.

bool Ase::EventLoop::exec_once (
    uint delay_ms,
    uint * once_id,
    const VoidSlot & vfunc,
    int priority=PRIORITY_NORMAL
) 

Execute a callback once, re-schedules the callback if 0 != *once_id.


function exec_timer

template<class BoolVoidFunctor>
uint Ase::EventLoop::exec_timer (
    BoolVoidFunctor && bvf,
    uint delay_ms,
    int64 repeat_ms=-1,
    int priority=PRIORITY_NORMAL
) 

function exec_usignal

inline uint Ase::EventLoop::exec_usignal (
    int8 signum,
    const USignalSlot & sl,
    int priority=PRIORITY_NOW -1
) 

function flag_primary

bool Ase::EventLoop::flag_primary (
    bool on
) 

function has_primary

bool Ase::EventLoop::has_primary (
    void
) 

function main_loop

MainLoop * Ase::EventLoop::main_loop () const

function remove

void Ase::EventLoop::remove (
    uint id
) 

function try_remove

bool Ase::EventLoop::try_remove (
    uint id
) 

function wakeup

void Ase::EventLoop::wakeup () 

Protected Types Documentation

typedef SourceList

typedef std::vector<EventSourceP> Ase::EventLoop::SourceList;

Protected Attributes Documentation

variable dispatch_priority_

int16 Ase::EventLoop::dispatch_priority_;

variable main_loop_

MainLoop* Ase::EventLoop::main_loop_;

variable poll_sources_

std::vector<EventSourceP> Ase::EventLoop::poll_sources_;

variable primary_

bool Ase::EventLoop::primary_;

variable sources_

SourceList Ase::EventLoop::sources_;

Protected Functions Documentation

function EventLoop

explicit Ase::EventLoop::EventLoop (
    MainLoop & main
) 

function check_sources_Lm

bool Ase::EventLoop::check_sources_Lm (
    LoopState & state,
    const QuickPfdArray & pfda
) 

function collect_sources_Lm

void Ase::EventLoop::collect_sources_Lm (
    LoopState & state
) 

function dispatch_source_Lm

void Ase::EventLoop::dispatch_source_Lm (
    LoopState & state
) 

function find_first_L

inline EventSourceP & Ase::EventLoop::find_first_L () 

function find_source_L

inline EventSourceP & Ase::EventLoop::find_source_L (
    uint id
) 

function has_primary_L

bool Ase::EventLoop::has_primary_L (
    void
) 

function kill_sources_Lm

void Ase::EventLoop::kill_sources_Lm (
    void
) 

function prepare_sources_Lm

bool Ase::EventLoop::prepare_sources_Lm (
    LoopState & state,
    QuickPfdArray & pfda
) 

function remove_source_Lm

void Ase::EventLoop::remove_source_Lm (
    EventSourceP source
) 

function unpoll_sources_U

void Ase::EventLoop::unpoll_sources_U () 

function ~EventLoop

virtual Ase::EventLoop::~EventLoop () 


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