libdisplaydevice latest
C++ library to modify display devices.
display_device::RetryScheduler< T > Class Template Referencefinal

A wrapper class around an interface that provides a thread-safe access to the interface and allows to schedule arbitrary logic for it to retry until it succeeds. More...

#include <src/common/include/display_device/retry_scheduler.h>

Public Member Functions

template<class FunctionT >
auto execute (FunctionT &&exec_fn)
 A non-const variant of the executeImpl method. See it for details.
 
template<class FunctionT >
auto execute (FunctionT &&exec_fn) const
 A const variant of the executeImpl method. See it for details.
 
bool isScheduled () const
 Check whether anything is scheduled for execution.
 
 RetryScheduler (std::unique_ptr< T > iface)
 Default constructor.
 
void schedule (std::function< void(T &, SchedulerStopToken &stop_token)> exec_fn, const SchedulerOptions &options)
 Schedule an interface executor function to be executed at specified intervals.
 
void stop ()
 Stop the scheduled function - will no longer be execute once THIS method returns.
 
 ~RetryScheduler ()
 A destructor that gracefully shuts down the thread.
 

Detailed Description

template<class T>
class display_device::RetryScheduler< T >

A wrapper class around an interface that provides a thread-safe access to the interface and allows to schedule arbitrary logic for it to retry until it succeeds.

Note
The scheduler is designed to only schedule 1 callback at a time, until it is either replaced or stopped.

Constructor & Destructor Documentation

◆ RetryScheduler()

template<class T >
display_device::RetryScheduler< T >::RetryScheduler ( std::unique_ptr< T > iface)
inlineexplicit

Default constructor.

Parameters
ifaceInterface to be passed around to the executor functions.

Member Function Documentation

◆ isScheduled()

template<class T >
bool display_device::RetryScheduler< T >::isScheduled ( ) const
inlinenodiscard

Check whether anything is scheduled for execution.

Returns
True if something is scheduled, false otherwise.

◆ schedule()

template<class T >
void display_device::RetryScheduler< T >::schedule ( std::function< void(T &, SchedulerStopToken &stop_token)> exec_fn,
const SchedulerOptions & options )
inline

Schedule an interface executor function to be executed at specified intervals.

Parameters
exec_fnProvides thread-safe access to the interface for executing arbitrary logic. It accepts a stop_token as a second parameter which can be used to stop the scheduler.
optionsOptions for the scheduler.
Note
Previously scheduled executor is replaced by a new one!

*Examples**

std::unique_ptr<SettingsManagerInterface> iface = getIface(...);
RetryScheduler<SettingsManagerInterface> scheduler{std::move(iface)};
scheduler.schedule([](SettingsManagerInterface& iface, SchedulerStopToken& stop_token){
if (iface.revertSettings()) {
stop_token.requestStop();
}
}, { .m_sleep_durations = { 50ms, 10ms });
A wrapper class around an interface that provides a thread-safe access to the interface and allows to...
Definition retry_scheduler.h:143
void schedule(std::function< void(T &, SchedulerStopToken &stop_token)> exec_fn, const SchedulerOptions &options)
Schedule an interface executor function to be executed at specified intervals.
Definition retry_scheduler.h:219
A convenience class for stopping the RetryScheduler.
Definition retry_scheduler.h:25
void requestStop()
Request the scheduler to be stopped.
Definition retry_scheduler.cpp:19
A class for applying and reverting display device settings.
Definition settings_manager_interface.h:14
virtual RevertResult revertSettings()=0
Revert the applied configuration and restore the previous settings.

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