~aleteoryx/muditaos

muditaos/module-apps/apps-common/GuiTimer.hpp -rw-r--r-- 2.2 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#pragma once

#include "Timers/Timer.hpp"       // for Timer
#include "Timers/TimerHandle.hpp" // for TimerHandle

#include <memory>
#include <string> // for string

namespace gui
{
    class Item;
} // namespace gui

namespace app
{
    class ApplicationCommon;

    /// Proxies system timer capabilities to the gui layer
    class GuiTimer : public sys::Timer
    {
      public:
        enum class Type
        {
            SingleShot,
            Periodic
        };

        GuiTimer(ApplicationCommon *parent,
                 gui::Item *item,
                 const std::string &name,
                 std::chrono::milliseconds timeout,
                 Type type);
        ~GuiTimer() noexcept override;

        void start() override;
        void restart(std::chrono::milliseconds newInterval) override;
        void stop() override;
        bool isActive() const noexcept override;

        class Impl;
        std::unique_ptr<Impl> pimpl;
        gui::Item *item = nullptr;
    };

    class GuiTimerFactory
    {
      public:
        static sys::TimerHandle createSingleShotTimer(ApplicationCommon *parent,
                                                      gui::Item *item,
                                                      const std::string &name,
                                                      std::chrono::milliseconds interval);
        static sys::TimerHandle createPeriodicTimer(ApplicationCommon *parent,
                                                    gui::Item *item,
                                                    const std::string &name,
                                                    std::chrono::milliseconds interval);

      private:
        static sys::TimerHandle createGuiTimer(ApplicationCommon *parent,
                                               gui::Item *item,
                                               const std::string &name,
                                               std::chrono::milliseconds interval,
                                               GuiTimer::Type type);
    };
}; // namespace app