2022-09-07 20:30:31 +02:00
|
|
|
/*
|
2024-10-04 13:19:50 +02:00
|
|
|
* Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
|
2022-09-07 20:30:31 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "TimerSerenity.h"
|
|
|
|
#include <LibCore/Timer.h>
|
2024-10-30 21:37:08 +13:00
|
|
|
#include <LibJS/Heap/Heap.h>
|
2024-10-30 21:42:05 +13:00
|
|
|
#include <LibJS/Heap/HeapFunction.h>
|
2022-09-07 20:30:31 +02:00
|
|
|
|
2022-09-21 19:33:57 +01:00
|
|
|
namespace Web::Platform {
|
2022-09-07 20:30:31 +02:00
|
|
|
|
2024-10-30 21:37:08 +13:00
|
|
|
JS::NonnullGCPtr<TimerSerenity> TimerSerenity::create(JS::Heap& heap)
|
2022-09-07 20:30:31 +02:00
|
|
|
{
|
2024-11-14 06:13:46 +13:00
|
|
|
return heap.allocate<TimerSerenity>();
|
2022-09-07 20:30:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
TimerSerenity::TimerSerenity()
|
2023-01-11 17:27:28 +00:00
|
|
|
: m_timer(Core::Timer::try_create().release_value_but_fixme_should_propagate_errors())
|
2022-09-07 20:30:31 +02:00
|
|
|
{
|
|
|
|
m_timer->on_timeout = [this] {
|
|
|
|
if (on_timeout)
|
2024-10-30 21:42:05 +13:00
|
|
|
on_timeout->function()();
|
2022-09-07 20:30:31 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
TimerSerenity::~TimerSerenity() = default;
|
|
|
|
|
|
|
|
void TimerSerenity::start()
|
|
|
|
{
|
|
|
|
m_timer->start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerSerenity::start(int interval_ms)
|
|
|
|
{
|
|
|
|
m_timer->start(interval_ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerSerenity::restart()
|
|
|
|
{
|
|
|
|
m_timer->restart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerSerenity::restart(int interval_ms)
|
|
|
|
{
|
|
|
|
m_timer->restart(interval_ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerSerenity::stop()
|
|
|
|
{
|
|
|
|
m_timer->stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerSerenity::set_active(bool active)
|
|
|
|
{
|
|
|
|
m_timer->set_active(active);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TimerSerenity::is_active() const
|
|
|
|
{
|
|
|
|
return m_timer->is_active();
|
|
|
|
}
|
|
|
|
|
|
|
|
int TimerSerenity::interval() const
|
|
|
|
{
|
|
|
|
return m_timer->interval();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerSerenity::set_interval(int interval_ms)
|
|
|
|
{
|
|
|
|
m_timer->set_interval(interval_ms);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TimerSerenity::is_single_shot() const
|
|
|
|
{
|
|
|
|
return m_timer->is_single_shot();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimerSerenity::set_single_shot(bool single_shot)
|
|
|
|
{
|
|
|
|
m_timer->set_single_shot(single_shot);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|