libcamera  v0.0.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  * timer.h - Generic timer
6  */
7 #ifndef __LIBCAMERA_TIMER_H__
8 #define __LIBCAMERA_TIMER_H__
9 
10 #include <chrono>
11 #include <stdint.h>
12 
13 #include <libcamera/object.h>
14 #include <libcamera/signal.h>
15 
16 namespace libcamera {
17 
18 class Message;
19 
20 class Timer : public Object
21 {
22 public:
23  Timer(Object *parent = nullptr);
24  ~Timer();
25 
26  void start(unsigned int msec) { start(std::chrono::milliseconds(msec)); }
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 
35 
36 protected:
37  void message(Message *msg) override;
38 
39 private:
40  void registerTimer();
41  void unregisterTimer();
42 
43  bool running_;
44  std::chrono::steady_clock::time_point deadline_;
45 };
46 
47 } /* namespace libcamera */
48 
49 #endif /* __LIBCAMERA_TIMER_H__ */
A message that can be posted to a Thread.
Definition: message.h:22
Base object to support automatic signal disconnection.
Definition: object.h:25
Object * parent() const
Retrieve the object's parent.
Definition: object.h:45
Generic signal and slot communication mechanism.
Definition: signal.h:39
Single-shot timer interface.
Definition: timer.h:21
bool isRunning() const
Check if the timer is running.
Definition: timer.cpp:154
void message(Message *msg) override
Message handler for the object.
Definition: timer.cpp:172
std::chrono::steady_clock::time_point deadline() const
Retrieve the timer deadline.
Definition: timer.h:32
void start(unsigned int msec)
Start or restart the timer with a timeout of msec.
Definition: timer.h:26
void stop()
Stop the timer.
Definition: timer.cpp:125
Signal< Timer * > timeout
Signal emitted when the timer times out.
Definition: timer.h:34
Timer(Object *parent=nullptr)
Construct a timer.
Definition: timer.cpp:55
Base object to support automatic signal disconnection.
Signal & slot implementation.