libcamera  v0.3.0
Supporting cameras in Linux since 2019
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 #include <stdint.h>
12 
13 #include <libcamera/base/private.h>
14 
15 #include <libcamera/base/object.h>
16 #include <libcamera/base/signal.h>
17 
18 namespace libcamera {
19 
20 class Message;
21 
22 class Timer : public Object
23 {
24 public:
25  Timer(Object *parent = nullptr);
26  ~Timer();
27 
28  void start(std::chrono::milliseconds duration);
29  void start(std::chrono::steady_clock::time_point deadline);
30  void stop();
31  bool isRunning() const;
32 
33  std::chrono::steady_clock::time_point deadline() const { return deadline_; }
34 
36 
37 protected:
38  void message(Message *msg) override;
39 
40 private:
41  void registerTimer();
42  void unregisterTimer();
43 
44  bool running_;
45  std::chrono::steady_clock::time_point deadline_;
46 };
47 
48 } /* namespace libcamera */
void message(Message *msg) override
Message handler for the object.
Definition: timer.cpp:158
Top-level libcamera namespace.
Definition: backtrace.h:17
void stop()
Stop the timer.
Definition: timer.cpp:113
void start(std::chrono::milliseconds duration)
Start or restart the timer with a timeout of duration.
Definition: timer.cpp:73
Signal & slot implementation.
Single-shot timer interface.
Definition: timer.h:22
A message that can be posted to a Thread.
Definition: message.h:23
Timer(Object *parent=nullptr)
Construct a timer.
Definition: timer.cpp:55
Base object to support automatic signal disconnection.
Object * parent() const
Retrieve the object&#39;s parent.
Definition: object.h:47
Generic signal and slot communication mechanism.
Definition: object.h:20
Signal timeout
Signal emitted when the timer times out.
Definition: timer.h:35
Base object to support automatic signal disconnection.
Definition: object.h:24
std::chrono::steady_clock::time_point deadline() const
Retrieve the timer deadline.
Definition: timer.h:33
bool isRunning() const
Check if the timer is running.
Definition: timer.cpp:140