libcamera: include/libcamera/base/timer.h Source File

libcamera v0.3.2 Supporting cameras in Linux since 2019

Loading...
Searching...
No Matches
timer.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: LGPL-2.1-or-later */
2/*
3 * Copyright (C) 2019, Google Inc.
4 *
5 * Generic timer
6 */
7
8#pragma once
9
10#include <chrono>
11
12#include <libcamera/base/private.h>
13
14#include <libcamera/base/object.h>
15#include <libcamera/base/signal.h>
16
17namespace libcamera {
18
19class Message;
20
21 class Timer : public Object
22{
23public:
24 Timer(Object *parent = nullptr);
25 ~Timer();
26
27 void start(std::chrono::milliseconds duration);
28 void start(std::chrono::steady_clock::time_point deadline);
29 void stop();
30 bool isRunning() const;
31
32 std::chrono::steady_clock::time_point deadline() const { return deadline_; }
33
34 Signal<> timeout;
35
36protected:
37 void message(Message *msg) override;
38
39private:
40 void registerTimer();
41 void unregisterTimer();
42
43 bool running_;
44 std::chrono::steady_clock::time_point deadline_;
45};
46
47} /* namespace libcamera */
libcamera::Message
A message that can be posted to a Thread.
Definition message.h:24
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:47
libcamera::Signal
Generic signal and slot communication mechanism.
Definition signal.h:39
libcamera::Timer
Single-shot timer interface.
Definition timer.h:22
libcamera::Timer::isRunning
bool isRunning() const
Check if the timer is running.
Definition timer.cpp:140
libcamera::Timer::message
void message(Message *msg) override
Message handler for the object.
Definition timer.cpp:158
libcamera::Timer::start
void start(std::chrono::milliseconds duration)
Start or restart the timer with a timeout of duration.
Definition timer.cpp:73
libcamera::Timer::timeout
Signal timeout
Signal emitted when the timer times out.
Definition timer.h:34
libcamera::Timer::stop
void stop()
Stop the timer.
Definition timer.cpp:113
libcamera::Timer::Timer
Timer(Object *parent=nullptr)
Construct a timer.
Definition timer.cpp:55
libcamera::Timer::deadline
std::chrono::steady_clock::time_point deadline() const
Retrieve the timer deadline.
Definition timer.h:32
libcamera
Top-level libcamera namespace.
Definition backtrace.h:17
object.h
Base object to support automatic signal disconnection.
signal.h
Signal & slot implementation.