libcamera
v0.4.0
Supporting cameras in Linux since 2019
|
Single-shot timer interface. More...
Public Member Functions | |
Timer (Object *parent=nullptr) | |
Construct a timer. More... | |
void | start (std::chrono::milliseconds duration) |
Start or restart the timer with a timeout of duration. More... | |
void | start (std::chrono::steady_clock::time_point deadline) |
Start or restart the timer with a deadline. More... | |
void | stop () |
Stop the timer. More... | |
bool | isRunning () const |
Check if the timer is running. More... | |
std::chrono::steady_clock::time_point | deadline () const |
Retrieve the timer deadline. More... | |
Public Member Functions inherited from libcamera::Object | |
Object (Object *parent=nullptr) | |
Construct an Object instance. More... | |
virtual | ~Object () |
Destroy an Object instance. More... | |
void | deleteLater () |
Schedule deletion of the instance in the thread it belongs to. More... | |
void | postMessage (std::unique_ptr< Message > msg) |
Post a message to the object's thread. More... | |
template<typename T , typename R , typename... FuncArgs, typename... Args, std::enable_if_t< std::is_base_of< Object, T >::value > * = nullptr> | |
R | invokeMethod (R(T::*func)(FuncArgs...), ConnectionType type, Args &&... args) |
Invoke a method asynchronously on an Object instance. More... | |
Thread * | thread () const |
Retrieve the thread the object is bound to. More... | |
void | moveToThread (Thread *thread) |
Move the object and all its children to a different thread. More... | |
Object * | parent () const |
Retrieve the object's parent. More... | |
Public Attributes | |
Signal | timeout |
Signal emitted when the timer times out. More... | |
Protected Member Functions | |
void | message (Message *msg) override |
Message handler for the object. More... | |
Protected Member Functions inherited from libcamera::Object | |
bool | assertThreadBound (const char *message) |
Check if the caller complies with thread-bound constraints. More... | |
Single-shot timer interface.
The Timer class models a single-shot timer that is started with start() and emits the timeout signal when it times out.
Once started the timer will run until it times out. It can be stopped with stop(), and once it times out or is stopped, can be started again with start().
The timer deadline is specified as either a duration in milliseconds or an absolute time point. If the deadline is set to the current time or to the past, the timer will time out immediately when execution returns to the event loop of the timer's thread.
Timers run in the thread they belong to, and thus emit the ref timeout signal from that thread. To avoid race conditions they must not be started or stopped from a different thread, attempts to do so will be rejected and logged, and may cause undefined behaviour.
libcamera::Timer::Timer | ( | Object * | parent = nullptr | ) |
Construct a timer.
[in] | parent | The parent Object |
|
inline |
Retrieve the timer deadline.
bool libcamera::Timer::isRunning | ( | ) | const |
Check if the timer is running.
|
overrideprotectedvirtual |
Message handler for the object.
[in] | msg | The message |
This virtual function receives messages for the object. It is called in the context of the object's thread, and can be overridden to process custom messages. The parent Object::message() function shall be called for any message not handled by the override function.
The message msg is valid only for the duration of the call, no reference to it shall be kept after this function returns.
Reimplemented from libcamera::Object.
void libcamera::Timer::start | ( | std::chrono::milliseconds | duration | ) |
Start or restart the timer with a timeout of duration.
[in] | duration | The timer duration in milliseconds |
If the timer is already running it will be stopped and restarted.
void libcamera::Timer::start | ( | std::chrono::steady_clock::time_point | deadline | ) |
Start or restart the timer with a deadline.
[in] | deadline | The timer deadline |
If the timer is already running it will be stopped and restarted.
void libcamera::Timer::stop | ( | ) |
Stop the timer.
After this function returns the timer is guaranteed not to emit the timeout signal.
If the timer is not running this function performs no operation.
libcamera::Timer::timeout |
Signal emitted when the timer times out.
The timer pointer is passed as a parameter.