TimerSerenity.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright (c) 2022, Andreas Kling <andreas@ladybird.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include "TimerSerenity.h"
  7. #include <LibCore/Timer.h>
  8. #include <LibJS/Heap/Heap.h>
  9. #include <LibJS/Heap/HeapFunction.h>
  10. namespace Web::Platform {
  11. JS::NonnullGCPtr<TimerSerenity> TimerSerenity::create(JS::Heap& heap)
  12. {
  13. return heap.allocate<TimerSerenity>();
  14. }
  15. TimerSerenity::TimerSerenity()
  16. : m_timer(Core::Timer::try_create().release_value_but_fixme_should_propagate_errors())
  17. {
  18. m_timer->on_timeout = [this] {
  19. if (on_timeout)
  20. on_timeout->function()();
  21. };
  22. }
  23. TimerSerenity::~TimerSerenity() = default;
  24. void TimerSerenity::start()
  25. {
  26. m_timer->start();
  27. }
  28. void TimerSerenity::start(int interval_ms)
  29. {
  30. m_timer->start(interval_ms);
  31. }
  32. void TimerSerenity::restart()
  33. {
  34. m_timer->restart();
  35. }
  36. void TimerSerenity::restart(int interval_ms)
  37. {
  38. m_timer->restart(interval_ms);
  39. }
  40. void TimerSerenity::stop()
  41. {
  42. m_timer->stop();
  43. }
  44. void TimerSerenity::set_active(bool active)
  45. {
  46. m_timer->set_active(active);
  47. }
  48. bool TimerSerenity::is_active() const
  49. {
  50. return m_timer->is_active();
  51. }
  52. int TimerSerenity::interval() const
  53. {
  54. return m_timer->interval();
  55. }
  56. void TimerSerenity::set_interval(int interval_ms)
  57. {
  58. m_timer->set_interval(interval_ms);
  59. }
  60. bool TimerSerenity::is_single_shot() const
  61. {
  62. return m_timer->is_single_shot();
  63. }
  64. void TimerSerenity::set_single_shot(bool single_shot)
  65. {
  66. m_timer->set_single_shot(single_shot);
  67. }
  68. }