Serenity Operating System
1/*
2 * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include "TimerSerenity.h"
8#include <AK/NonnullRefPtr.h>
9#include <LibCore/Timer.h>
10
11namespace Web::Platform {
12
13NonnullRefPtr<TimerSerenity> TimerSerenity::create()
14{
15 return adopt_ref(*new TimerSerenity);
16}
17
18TimerSerenity::TimerSerenity()
19 : m_timer(Core::Timer::try_create().release_value_but_fixme_should_propagate_errors())
20{
21 m_timer->on_timeout = [this] {
22 if (on_timeout)
23 on_timeout();
24 };
25}
26
27TimerSerenity::~TimerSerenity() = default;
28
29void TimerSerenity::start()
30{
31 m_timer->start();
32}
33
34void TimerSerenity::start(int interval_ms)
35{
36 m_timer->start(interval_ms);
37}
38
39void TimerSerenity::restart()
40{
41 m_timer->restart();
42}
43
44void TimerSerenity::restart(int interval_ms)
45{
46 m_timer->restart(interval_ms);
47}
48
49void TimerSerenity::stop()
50{
51 m_timer->stop();
52}
53
54void TimerSerenity::set_active(bool active)
55{
56 m_timer->set_active(active);
57}
58
59bool TimerSerenity::is_active() const
60{
61 return m_timer->is_active();
62}
63
64int TimerSerenity::interval() const
65{
66 return m_timer->interval();
67}
68
69void TimerSerenity::set_interval(int interval_ms)
70{
71 m_timer->set_interval(interval_ms);
72}
73
74bool TimerSerenity::is_single_shot() const
75{
76 return m_timer->is_single_shot();
77}
78
79void TimerSerenity::set_single_shot(bool single_shot)
80{
81 m_timer->set_single_shot(single_shot);
82}
83
84}