summaryrefslogtreecommitdiff
path: root/include/libcamera/base/timer.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libcamera/base/timer.h')
-rw-r--r--include/libcamera/base/timer.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/include/libcamera/base/timer.h b/include/libcamera/base/timer.h
new file mode 100644
index 00000000..e79e85f1
--- /dev/null
+++ b/include/libcamera/base/timer.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2019, Google Inc.
+ *
+ * timer.h - Generic timer
+ */
+#ifndef __LIBCAMERA_BASE_TIMER_H__
+#define __LIBCAMERA_BASE_TIMER_H__
+
+#include <chrono>
+#include <stdint.h>
+
+#include <libcamera/base/object.h>
+#include <libcamera/base/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_BASE_TIMER_H__ */