libcamera  v0.3.0+92-226ce294
Supporting cameras in Linux since 2019
Public Member Functions | Public Attributes | Protected Member Functions | List of all members
libcamera::Timer Class Reference

Single-shot timer interface. More...

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

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>
invokeMethod (R(T::*func)(FuncArgs...), ConnectionType type, Args &&... args)
 Invoke a method asynchronously on an Object instance. More...
 
Threadthread () 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...
 
Objectparent () 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...
 

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]parentThe parent Object

Member Function Documentation

◆ deadline()

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)
overrideprotectedvirtual

Message handler for the object.

Parameters
[in]msgThe 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]durationThe 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]deadlineThe 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

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: