TimerSerenity.cpp 1.4 KB

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