timer.h
Go to the documentation of this file.
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2019, Google Inc.
*
* timer.h - Generic timer
*/
#ifndef __LIBCAMERA_TIMER_H__
#define __LIBCAMERA_TIMER_H__
#include <chrono>
#include <stdint.h>
#include <libcamera/object.h>
#include <libcamera/signal.h>
namespace libcamera {
class Message;
class Timer : public Object
{
public:
Timer(Object *parent = nullptr);
~Timer();
void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); }
void start(std::chrono::milliseconds duration);
void start(std::chrono::steady_clock::time_point deadline);
void stop();
bool isRunning() const;
std::chrono::steady_clock::time_point deadline() const { return deadline_; }
Signal<Timer *> timeout;
protected:
void message(Message *msg) override;
private:
void registerTimer();
void unregisterTimer();
bool running_;
std::chrono::steady_clock::time_point deadline_;
};
} /* namespace libcamera */
#endif /* __LIBCAMERA_TIMER_H__ */
libcamera::Message
A message that can be posted to a Thread.
Definition: message.h:22
libcamera::Object
Base object to support automatic signal disconnection.
Definition: object.h:25
libcamera::Object::parent
Object * parent() const
Retrieve the object's parent.
Definition: object.h:45
libcamera::Signal
Generic signal and slot communication mechanism.
Definition: signal.h:39
libcamera::Timer
Single-shot timer interface.
Definition: timer.h:21
libcamera::Timer::isRunning
bool isRunning() const
Check if the timer is running.
Definition: timer.cpp:154
libcamera::Timer::message
void message(Message *msg) override
Message handler for the object.
Definition: timer.cpp:172
libcamera::Timer::deadline
std::chrono::steady_clock::time_point deadline() const
Retrieve the timer deadline.
Definition: timer.h:32
libcamera::Timer::start
void start(unsigned int msec)
Start or restart the timer with a timeout of msec.
Definition: timer.h:26
libcamera::Timer::stop
void stop()
Stop the timer.
Definition: timer.cpp:125
libcamera::Timer::timeout
Signal< Timer * > timeout
Signal emitted when the timer times out.
Definition: timer.h:34
libcamera::Timer::Timer
Timer(Object *parent=nullptr)
Construct a timer.
Definition: timer.cpp:55
object.h
Base object to support automatic signal disconnection.
signal.h
Signal & slot implementation.