~aleteoryx/muditaos

ref: 6f257d38dbd42ac6aa54258e640571b6cbe003ad muditaos/module-services/service-test/ServiceTest.cpp -rw-r--r-- 1.8 KiB
6f257d38 — Marcin Lyda [MOS-303] Add playback path gain params to json 3 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "service-test/ServiceTest.hpp"
#include "Timers/TimerFactory.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)
    {
        LOG_INFO("[ServiceTest] Initializing");
    }

    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 periodic system timer which will log:
        // "timers are avesome, periodic timer is active: 1" around each second
        th = sys::TimerFactory::createPeriodicTimer(
            this, "my  periodic timer", std::chrono::milliseconds(1000), [](sys::Timer &t) {
                LOG_INFO("timers are avesome, periodic timer is active: %d", t.isActive());
            });
        th.start();
        return sys::ReturnCodes::Success;
    }

    sys::ReturnCodes ServiceTest::DeinitHandler()
    {
        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