~aleteoryx/muditaos

ref: 0e8b4c848e3f87f3bbb1f64ef7460cf56017b87f muditaos/module-services/service-test/ServiceTest.cpp -rw-r--r-- 2.9 KiB
0e8b4c84 — Lefucjusz [BH-2108] Fix misaligned charging symbol 3 months 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
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "service-test/ServiceTest.hpp"
#include "Timers/TimerFactory.hpp"
#include "application-test/include/application-test/ApplicationTest.hpp"
#include "service-appmgr/Controller.hpp"

namespace service::test
{

    static std::uint32_t stackSize       = 2048;
    constexpr auto setting_private_value = "private value";

    ServiceTest::ServiceTest() : sys::Service(service::name::service_test, "", stackSize)
    {
    }

    sys::ReturnCodes ServiceTest::InitHandler()
    {
        settings.init(service::ServiceProxy(shared_from_this()));
        // set some value to settings
        settings.setValue(setting_private_value, "it works");
        // log this value in logs
        // it will output: "Now we can use settings! it works"
        LOG_INFO("Now we can use settings! %s", settings.getValue(setting_private_value).c_str());

        // this code will create a periodic timer which will in 2 seconds:
        // - log "timers are awesome, periodic timer is active: 1" around each second
        // - trigger popup to the test application on the timer
        th = sys::TimerFactory::createPeriodicTimer(
            this, "my  periodic timer", std::chrono::milliseconds(2 * 1000), [this](sys::Timer &t) {
                LOG_INFO("timers are avesome, single shot timer is active: %d", t.isActive());
                if (appStarted == false) {
                    LOG_INFO("Launching TestApplication");
                    app::manager::Controller::sendAction(
                        this,
                        app::manager::actions::Launch,
                        std::make_unique<app::ApplicationLaunchData>(app::application_test));
                    // not really started but.. will be good enough
                    appStarted = true;
                    return;
                }
                LOG_INFO("send action to the test appliaction!");
                app::manager::Controller::sendAction(
                    this,
                    app::manager::actions::ShowPopup,
                    std::make_unique<gui::PopupRequestParams>(gui::popup::ID::AppTestPopup));
                t.stop();
            });
        th.start();

        LOG_INFO("Initialized");
        return sys::ReturnCodes::Success;
    }

    sys::ReturnCodes ServiceTest::DeinitHandler()
    {
        LOG_INFO("Deinitialized");
        return sys::ReturnCodes::Success;
    }

    sys::ReturnCodes ServiceTest::SwitchPowerModeHandler(const sys::ServicePowerMode /*mode*/)
    {
        return sys::ReturnCodes::Success;
    }

    sys::MessagePointer ServiceTest::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)
    {
        return std::make_shared<sys::ResponseMessage>(sys::ReturnCodes::Unresolved);
    }
} // namespace service::test