libcamera v0.6.0 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
libcamera::Timer Class Reference

Single-shot timer interface. More...

Inheritance diagram for libcamera::Timer:
[legend]
Collaboration diagram for libcamera::Timer:
[legend]

## Public Member Functions
| Timer (Object *parent=nullptr)
| Construct a timer.
void | start (std::chrono::milliseconds duration)
| Start or restart the timer with a timeout of duration.
void | start (std::chrono::steady_clock::time_point deadline)
| Start or restart the timer with a deadline.
void | stop ()
| Stop the timer.
bool | isRunning () const
| Check if the timer is running.
std::chrono::steady_clock::time_point | deadline () const
| Retrieve the timer deadline.
Public Member Functions inherited from libcamera::Object
| Object (Object *parent=nullptr)
| Construct an Object instance.
virtual | ~Object ()
| Destroy an Object instance.
void | deleteLater ()
| Schedule deletion of the instance in the thread it belongs to.
void | postMessage (std::unique_ptr< Message > msg)
| Post a message to the object's thread.
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.
Thread * | thread () const
| Retrieve the thread the object is bound to.
void | moveToThread (Thread *thread)
| Move the object and all its children to a different thread.
Object * | parent () const
| Retrieve the object's parent.

## Public Attributes
Signal | timeout
| Signal emitted when the timer times out.

## Protected Member Functions
void | message (Message *msg) override
| Message handler for the object.
Protected Member Functions inherited from libcamera::Object
bool | assertThreadBound (const char *message)
| Check if the caller complies with thread-bound constraints.

## Detailed Description

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.

## Constructor & Destructor Documentation

## ◆ Timer()

libcamera::Timer::Timer | ( | Object * | parent = nullptr | ) |

Construct a timer.

Parameters

  [in] | parent | The parent Object

## Member Function Documentation

## ◆ deadline()

std::chrono::steady_clock::time_point libcamera::Timer::deadline | ( |  | ) | const
| inline

Retrieve the timer deadline.

Returns
  The timer deadline

## ◆ isRunning()

bool libcamera::Timer::isRunning | ( |  | ) | const

Check if the timer is running.

Returns
  True if the timer is running, false otherwise

## ◆ message()

void libcamera::Timer::message | ( | Message * | msg | ) |
| override protected virtual

Message handler for the object.

Parameters

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

## ◆ start() [1/2]

void libcamera::Timer::start | ( | std::chrono::milliseconds | duration | ) |

Start or restart the timer with a timeout of duration.

Parameters

  [in] | duration | The timer duration in milliseconds

If the timer is already running it will be stopped and restarted.

Thread Safety
  This function is thread-bound.

## ◆ start() [2/2]

void libcamera::Timer::start | ( | std::chrono::steady_clock::time_point | deadline | ) |

Start or restart the timer with a deadline.

Parameters

  [in] | deadline | The timer deadline

If the timer is already running it will be stopped and restarted.

Thread Safety
  This function is thread-bound.

## ◆ stop()

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.

Thread Safety
  This function is thread-bound.

## Member Data Documentation

## ◆ timeout

Signal libcamera::Timer::timeout

Signal emitted when the timer times out.

The timer pointer is passed as a parameter.

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

- include/libcamera/base/timer.h
- src/libcamera/base/timer.cpp