~aleteoryx/muditaos

ref: d9a66b8b47f730a198242706c578d48617a28d92 muditaos/module-utils/EventStore/EventStore.cpp -rw-r--r-- 2.5 KiB
d9a66b8b — Lefucjusz Revert "[MOS-170] Report domestic roaming as home network" 2 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
101
102
103
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "EventStore.hpp"
#include <log/log.hpp>
#include <memory>
#include <mutex.hpp>

namespace Store
{
    // if it grows bigger than these few variables - consider moving it to ram with i.e.
    // delayed construction singletone
    Battery battery;
    bool Battery::updated = true;

    const Battery &Battery::get()
    {
        return battery;
    }

    Battery &Battery::modify()
    {
        Battery::setUpdated();
        return battery;
    }

    void Battery::setUpdated()
    {
        battery.updated = true;
    }

    bool Battery::takeUpdated()
    {
        if (battery.updated) {
            battery.updated = false;
            return true;
        }
        return false;
    }

    cpp_freertos::MutexStandard GSM::mutex;

    GSM *GSM::get()
    {
        static auto ptr = new GSM();
        return ptr;
    }

    void GSM::setSignalStrength(const SignalStrength &signalStrength)
    {
        cpp_freertos::LockGuard lock(mutex);
        LOG_INFO("Setting signal strength to rssi = %d dBm (%d) : %d bars",
                 signalStrength.rssidBm,
                 signalStrength.rssi,
                 static_cast<int>(signalStrength.rssiBar));

        this->signalStrength = signalStrength;
    }

    SignalStrength GSM::getSignalStrength() const
    {
        cpp_freertos::LockGuard lock(mutex);
        return signalStrength;
    }

    void GSM::setNetwork(const Network &network)
    {
        cpp_freertos::LockGuard lock(mutex);
        this->network = network;
    }

    Network GSM::getNetwork() const
    {
        cpp_freertos::LockGuard lock(mutex);
        return network;
    }

    bool GSM::simCardInserted()
    {
        cpp_freertos::LockGuard lock(mutex);
        return (sim == SIM::SIM1 || sim == SIM::SIM2);
    }
    void GSM::setNetworkOperatorName(const std::string &newNetworkOperatorName)
    {
        cpp_freertos::LockGuard lock(mutex);
        networkOperatorName = newNetworkOperatorName;
    }
    std::string GSM::getNetworkOperatorName() const
    {
        cpp_freertos::LockGuard lock(mutex);
        return networkOperatorName;
    }
    void GSM::setTethering(const Tethering &tethering)
    {
        cpp_freertos::LockGuard lock(mutex);
        this->tethering = tethering;
    }
    Tethering GSM::getTethering() const
    {
        cpp_freertos::LockGuard lock(mutex);
        return tethering;
    }
}; // namespace Store