RunLoop Class Reference

#include <runloop.h>

Detailed Description

Run loop interface. Use this interface to implement an application UI event run loop. Usually there already is a default implementation, but there might be cases where different UI toolkits are available for a system. Depending on the project's requirements the adequate one can be selected (via command line or project option). Only one run loop will be active for the run time of an application.

Public Types

using TimerCallback = void(*)(void *self)
 

Public Member Functions

 MAXON_OBSERVABLE_STATIC (Result< void >, ObservableExitLoop,(), ObservableCombinerRunAllAggregateErrorsComponent)
 
 MAXON_OBSERVABLE_STATIC (Result< void >, ObservableActivationChange,(Bool becomesActive), ObservableCombinerRunAllAggregateErrorsComponent)
 
 MAXON_OBSERVABLE_STATIC (Bool, ObservableRunLoopMessage,(const void *message), ObservableCombinerRunAllBoolUntilTrue)
 

Static Public Member Functions

static MAXON_METHOD Result< void > EnterLoop (Bool isInternalLoop=true)
 
static MAXON_METHOD Result< void > EnterLoop (Bool isInternalLoop, void *osSpecific)
 
static MAXON_METHOD void ExitLoop ()
 
static MAXON_METHOD void TriggerMainThreadQueue ()
 
static MAXON_METHOD Result< Timer * > AddTimer (TimeValue interval, TimeValue delay, TimeValue tolerance, TimerCallback callback, void *self)
 
static MAXON_METHOD void RemoveTimer (Timer *timer)
 
static MAXON_METHOD void GetLinuxDefaultDisplayAndScreen (void *&display, int &screen)
 
static MAXON_METHOD void ** PrivateGetMainThreadQueueTrigger ()
 
static MAXON_METHOD void PrivateSetWaitInterval (TimeValue waitInterval)
 
static MAXON_METHOD void PrivateSetDefaultDisplayAndScreen (void *display, int screen)
 

Private Member Functions

 MAXON_INTERFACE_NONVIRTUAL (RunLoop, MAXON_REFERENCE_NONE, "net.maxon.interface.runloop")
 

Member Typedef Documentation

◆ TimerCallback

using TimerCallback = void (*)(void* self)

Member Function Documentation

◆ MAXON_INTERFACE_NONVIRTUAL()

MAXON_INTERFACE_NONVIRTUAL ( RunLoop  ,
MAXON_REFERENCE_NONE  ,
"net.maxon.interface.runloop"   
)
private

◆ EnterLoop() [1/2]

static MAXON_METHOD Result<void> EnterLoop ( Bool  isInternalLoop = true)
static

Enters the main thread run loop. Returns IllegalArgumentError if there's no run loop. Errors returned by subscribers to ObservableExitLoop() will be returned as AggregatedError.

Parameters
[in]isInternalLoopTrue by default, false if the method is to return immediately after initialization because the main thread is driven by a different host.
Returns
OK on success.

◆ EnterLoop() [2/2]

static MAXON_METHOD Result<void> EnterLoop ( Bool  isInternalLoop,
void *  osSpecific 
)
static

Enters the main thread run loop. Returns IllegalArgumentError if there's no run loop. Errors returned by subscribers to ObservableExitLoop() will be returned as AggregatedError.

Parameters
[in]isInternalLoopTrue by default, false if the method is to return immediately after initialization because the main thread is driven by a different host.
[in]osSpecificAn OS-specific parameter, nullptr by default.
Returns
OK on success.

◆ ExitLoop()

static MAXON_METHOD void ExitLoop ( )
static

Asks the main thread run loop to exit. THREADSAFE.

◆ TriggerMainThreadQueue()

static MAXON_METHOD void TriggerMainThreadQueue ( )
static

Notifies the main thread event loop that it should execute jobs. THREADSAFE.

◆ AddTimer()

static MAXON_METHOD Result<Timer*> AddTimer ( TimeValue  interval,
TimeValue  delay,
TimeValue  tolerance,
TimerCallback  callback,
void *  self 
)
static

Schedules a job to be called periodically at the specified interval on the main thread. If the interval is 0.0 the timer is fired once after the specified delay. For each AddTimer() call you must call RemoveTimer() to remove it. Otherwise the timer runs forever or (for a one-shot timer) at least its memory will leak. If the run loop does not support timers a nullptr is returned (this is not an error). In this case the timer implementation has to enqueue jobs on the main thread (which is less efficient but works).

Parameters
[in]intervalTimer interval.
[in]delayDelay until the timer fires the first time.
[in]toleranceMaximum tolerance of execution (used for timer coalescing).
[in]callbackTo be called by the timer (periodically).
[in]selfPointer to callback data.
Returns
OK on success.

◆ RemoveTimer()

static MAXON_METHOD void RemoveTimer ( Timer *  timer)
static

Removes a timer created with AddTimer.

Parameters
[in]timerTimer interval.

◆ GetLinuxDefaultDisplayAndScreen()

static MAXON_METHOD void GetLinuxDefaultDisplayAndScreen ( void *&  display,
int screen 
)
static

Returns the default display for the Linux runloop.

Parameters
[out]displayA reference which will hold the display pointer. The pointer can be cast to Display.
[out]screenThe screen.

◆ MAXON_OBSERVABLE_STATIC() [1/3]

MAXON_OBSERVABLE_STATIC ( Result< void >  ,
ObservableExitLoop  ,
()  ,
ObservableCombinerRunAllAggregateErrorsComponent   
)

Notifies the observers that the run loop will exit.

◆ MAXON_OBSERVABLE_STATIC() [2/3]

MAXON_OBSERVABLE_STATIC ( Result< void >  ,
ObservableActivationChange  ,
(Bool becomesActive)  ,
ObservableCombinerRunAllAggregateErrorsComponent   
)

Notifies the observers that the application changes from active to inactive.

◆ MAXON_OBSERVABLE_STATIC() [3/3]

MAXON_OBSERVABLE_STATIC ( Bool  ,
ObservableRunLoopMessage  ,
(const void *message ,
ObservableCombinerRunAllBoolUntilTrue   
)

Invokes the observer(s) with a pointer to the current event. The observer might return true if it already handled the event and it should be discarded.

Note
This observable is OS-specific and may only be used to work around bugs or shortcomings in UI toolkits/window managers. I must not be used for regular event handling or forwarding. Linux & Windows only.

◆ PrivateGetMainThreadQueueTrigger()

static MAXON_METHOD void** PrivateGetMainThreadQueueTrigger ( )
static

◆ PrivateSetWaitInterval()

static MAXON_METHOD void PrivateSetWaitInterval ( TimeValue  waitInterval)
static

◆ PrivateSetDefaultDisplayAndScreen()

static MAXON_METHOD void PrivateSetDefaultDisplayAndScreen ( void *  display,
int  screen 
)
static