~aleteoryx/muditaos

ref: 0eb652a5152de6bdf77c897a787d037d6e6b43d4 muditaos/module-services/service-db/agents/settings/SettingsAgent.hpp -rw-r--r-- 1.9 KiB
0eb652a5 — Kuba Kleczkowski [MOS-792] Added VoLTE setting in db 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
52
53
54
55
56
57
58
59
60
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "FactorySettings.hpp"

#include <service-db/DatabaseAgent.hpp>
#include <service-db/SettingsMessages.hpp>
#include <Service/Message.hpp>

#include <map>
#include <optional>
#include <string>

namespace settings
{
    struct EntryPath;
    class SettingsCache;
} // namespace settings
namespace sys
{
    class Service;
} // namespace sys

class SettingsAgent : public DatabaseAgent
{
  public:
    SettingsAgent(sys::Service *parentService, std::string dbName, settings::SettingsCache *cache = nullptr);
    ~SettingsAgent() = default;

    void registerMessages() override;
    void unRegisterMessages() override;
    auto getAgentName() -> const std::string override;
    auto getDbFilePath() -> const std::string override;

  private:
    settings::SettingsCache *cache;
    settings::FactorySettings factorySettings;

    using MapOfRecipentsToBeNotified = std::map<std::string, std::set<settings::EntryPath>>;
    MapOfRecipentsToBeNotified variableChangeRecipients;
    using SetOfRecipents = std::set<std::string>;
    SetOfRecipents profileChangedRecipients;
    SetOfRecipents modeChangeRecipients;
    const std::string dbName;

    // db operations
    auto dbGetValue(const settings::EntryPath &path) -> std::optional<std::string>;
    auto dbSetValue(const settings::EntryPath &path, const std::string &value) -> bool;
    auto dbRegisterValueChange(const settings::EntryPath &path) -> bool;
    auto dbUnregisterValueChange(const settings::EntryPath &path) -> bool;

    // msg handlers
    // variable
    auto handleGetVariable(sys::Message *req) -> sys::MessagePointer;
    auto handleSetVariable(sys::Message *req) -> sys::MessagePointer;
    auto handleRegisterOnVariableChange(sys::Message *req) -> sys::MessagePointer;
    auto handleUnregisterOnVariableChange(sys::Message *req) -> sys::MessagePointer;
};