~aleteoryx/muditaos

ref: 2a53becd2524fc0dba7260632d3ec409eb3a61fd muditaos/module-apps/application-clock/ApplicationClock.cpp -rw-r--r-- 3.4 KiB
2a53becd — Maciej Janicki [BH-1136] Fix bootloop after low power 4 years 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

// module-gui
#include "AppWindow.hpp"
#include "gui/widgets/Window.hpp"

// module-utils
#include <log/log.hpp>
#include <service-evtmgr/EVMessages.hpp>
#include <service-evtmgr/EventManagerCommon.hpp>
#include <Timers/TimerFactory.hpp>
// MessageType
#include "MessageType.hpp"
// this module
#include "windows/ClockMainWindow.hpp"
#include "ApplicationClock.hpp"

namespace app
{
    ApplicationClock::ApplicationClock(std::string name,
                                       std::string parent,
                                       sys::phone_modes::PhoneMode phoneMode,
                                       sys::bluetooth::BluetoothMode bluetoothMode,
                                       StartInBackground startInBackground,
                                       uint32_t stackDepth,
                                       sys::ServicePriority priority)
        : Application(name, parent, phoneMode, bluetoothMode, startInBackground, stackDepth, priority)
    {
        timerClock = sys::TimerFactory::createPeriodicTimer(
            this, "Clock", std::chrono::milliseconds{1000}, [&](sys::Timer &) { timerClockCallback(); });
        timerClock.start();
    }

    void ApplicationClock::timerClockCallback()
    {
        auto win = reinterpret_cast<gui::ClockMainWindow *>(windowsStack.get(gui::name::window::main_window));
        win->incrementSecond();
        win->updateLabels();
        render(gui::RefreshModes::GUI_REFRESH_FAST);
    }

    // Invoked upon receiving data message
    sys::MessagePointer ApplicationClock::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
    {

        auto retMsg = Application::DataReceivedHandler(msgl);
        // if message was handled by application's template there is no need to process further.
        if (reinterpret_cast<sys::ResponseMessage *>(retMsg.get())->retCode == sys::ReturnCodes::Success) {
            return retMsg;
        }

        // this variable defines whether message was processed.
        bool handled = false;
        // if keyboard message received

        if (handled)
            return std::make_shared<sys::ResponseMessage>();
        else
            return std::make_shared<sys::ResponseMessage>(sys::ReturnCodes::Unresolved);
    }

    // Invoked during initialization
    sys::ReturnCodes ApplicationClock::InitHandler()
    {

        auto ret = Application::InitHandler();
        if (ret != sys::ReturnCodes::Success)
            return ret;

        createUserInterface();

        setActiveWindow("MainWindow");

        return ret;
    }

    sys::ReturnCodes ApplicationClock::DeinitHandler()
    {
        timerClock.stop();
        return Application::DeinitHandler();
    }

    void ApplicationClock::createUserInterface()
    {
        windowsFactory.attach(gui::name::window::main_window, [](ApplicationCommon *app, const std::string &name) {
            return std::make_unique<gui::ClockMainWindow>(app, name);
        });

        attachPopups({gui::popup::ID::Volume,
                      gui::popup::ID::Tethering,
                      gui::popup::ID::PhoneModes,
                      gui::popup::ID::PhoneLock,
                      gui::popup::ID::Alarm});
    }

    void ApplicationClock::destroyUserInterface()
    {}

} /* namespace app */