Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FX::FXReactor Class Reference

FXReactor implements the reactor pattern. More...

#include <FXReactor.h>

Inheritance diagram for FX::FXReactor:
FX::FXDispatcher FX::FXEventDispatcher

Public Types

enum  { InputNone = 0, InputRead = 1, InputWrite = 2, InputExcept = 4 }
 Modes. More...
 
enum  {
  DispatchAll = 0xffffffff, DispatchSignals = 0x00000001, DispatchTimers = 0x00000002, DispatchIdle = 0x00000004,
  DispatchEvents = 0x00000008, DispatchOther = 0x00000010
}
 Dispatch flags. More...
 

Public Member Functions

 FXReactor ()
 Construct reactor.
 
virtual FXbool init ()
 Initialize reactor.
 
FXbool isInitialized () const
 Is reactor initialized.
 
virtual FXbool dispatch (FXTime blocking=forever, FXuint flags=DispatchAll)
 Dispatch if something happens within given blocking time. More...
 
virtual FXbool addHandle (FXInputHandle hnd, FXuint mode=InputRead)
 Add new handle hnd to watch-list.
 
virtual FXbool remHandle (FXInputHandle hnd)
 Remove handle hnd from watch-list.
 
virtual FXbool dispatchHandle (FXInputHandle hnd, FXuint mode, FXuint flags)
 Dispatch handler for handle hnd. More...
 
virtual FXbool addSignal (FXint sig, FXbool=false)
 Add (optionally asynchronous) signal sig to signal-set.
 
virtual FXbool remSignal (FXint sig)
 Remove signal sig from signal-set.
 
virtual FXbool hasSignal (FXint sig) const
 Return true if signal sig is handled by this dispatcher.
 
virtual FXbool dispatchSignal (FXint sig)
 Dispatch when a signal was fired; return true when handled.
 
virtual FXTime nextTimeout ()
 Return time when first timer callback is due; the special value forever is returned when no timer is in effect. More...
 
virtual FXbool dispatchTimeout (FXTime due)
 Dispatch when timeout expires; return true when handled.
 
virtual FXbool dispatchIdle ()
 Dispatch when idle; return true when handled.
 
virtual FXbool exit ()
 Exit reactor.
 
virtual ~FXReactor ()
 Destroy reactor object.
 

Static Public Attributes

static const FXTime maxwait
 Sleep no longer than this.
 

Friends

class FXEventDispatcher
 

Detailed Description

FXReactor implements the reactor pattern.

Given a list of file descriptors (handles), calling thread is blocked until any of the following happens:

  • One or more of the file descriptors becomes active;
  • A timeout occurs;
  • The maximum blocking time is exceeded;
  • An interrupt (signal) occurs.
  • One or more of the handles develops an error and an FXFatalException is thrown.

Depending on what occurred, FXReactor dispatches to one of the handling API's: dispatchHandle(), dispatchTimeout(), or dispatchSignal(). Prior to blocking, if nothing demands immediate attention, the special handler dispatchIdle() is called.

If dispatchHandle(), dispatchTimeout(), dispatchSignal() or dispatchIdle() returned true, FXReactor will return with true; otherwise, it will continue to loop, decreasing the initial blocking time until eventually returning false when nothing happened during the entire blocking interval.

Each FXReactor can manage a set of signals, but note that only one single FXReactor is allowed to manage a particular signal; other signals may be left unassigned, or managed by other FXReactors.

If waiting for a very long but finite amount of time, FXReactor will wake up after at most FXReactor::maxwait, which is about 1 day. It will continue to loop and wait for additional intervals, decreasing the initial blocking time until eventually returning false when nothing happened.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Modes.

Enumerator
InputRead 

Inactive handle.

InputWrite 

Read input handle.

InputExcept 

Write input handle.

◆ anonymous enum

anonymous enum

Dispatch flags.

Enumerator
DispatchSignals 

Dispatch all events.

DispatchTimers 

Dispatch signals.

DispatchIdle 

Dispatch timers.

DispatchEvents 

Dispatch idle processing.

DispatchOther 

Dispatch events.

Member Function Documentation

◆ dispatch()

virtual FXbool FX::FXReactor::dispatch ( FXTime  blocking = forever,
FXuint  flags = DispatchAll 
)
virtual

Dispatch if something happens within given blocking time.

Flags control subsets of events to be dispatched (signals, timers, idle, and more). Default is to dispatch all events.

Reimplemented in FX::FXEventDispatcher.

◆ dispatchHandle()

virtual FXbool FX::FXReactor::dispatchHandle ( FXInputHandle  hnd,
FXuint  mode,
FXuint  flags 
)
virtual

Dispatch handler for handle hnd.

Return true if the callback returned true.

Reimplemented in FX::FXDispatcher.

◆ nextTimeout()

virtual FXTime FX::FXReactor::nextTimeout ( )
virtual

Return time when first timer callback is due; the special value forever is returned when no timer is in effect.

Reimplemented in FX::FXDispatcher.


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

Copyright © 1997-2022 Jeroen van der Zijp