~aleteoryx/muditaos

ref: 0823d82e5141f44812c54debf07245d0ca746124 muditaos/module-services/service-db/messages/SettingsMessages.hpp -rw-r--r-- 9.2 KiB
0823d82e — Radoslaw Wicik [EGD-3743] Update copyrights in fies - add empty line after license 5 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#pragma once

#include <Service/Message.hpp>
#include <MessageType.hpp>

#include <memory>
#include <utility>
#include <variant>
#include <set>
#include <list>

namespace Settings
{
    struct EntryPath
    {
        std::string mode;
        std::string service;
        std::string profile;
        std::string variable;

        [[nodiscard]] auto to_string(std::string sep = "\\") const -> std::string
        {
            return mode + sep + service + sep + profile + sep + variable;
        }
    };

    namespace Messages
    {
        class SettingsMessage : public sys::DataMessage
        {
          public:
            explicit SettingsMessage(MessageType type = MessageType::Settings) : sys::DataMessage(type){};
            ~SettingsMessage() override = default;
        };

        /// Variable manipulation
        class Variable : public SettingsMessage
        {
          public:
            Variable() = default;
            explicit Variable(EntryPath path, std::optional<std::string> value = {})
                : SettingsMessage(), path(std::move(path)), value(std::move(value))
            {}

            [[nodiscard]] auto getValue() const -> std::optional<std::string>
            {
                return value;
            }

            [[nodiscard]] auto getPath() const -> EntryPath
            {
                return path;
            }

          protected:
            EntryPath path;
            std::optional<std::string> value;
        };

        class GetVariable : public Variable
        {
          public:
            GetVariable() = default;
            explicit GetVariable(EntryPath path) : Variable(path)
            {}
        };

        class SetVariable : public Variable
        {
          public:
            SetVariable() = default;
            SetVariable(EntryPath path, std::string value) : Variable(path, value)
            {}
        };

        class RegisterOnVariableChange : public Variable
        {
          public:
            RegisterOnVariableChange() = default;
            explicit RegisterOnVariableChange(EntryPath path) : Variable(path)
            {}
        };

        class UnregisterOnVariableChange : public Variable
        {
          public:
            UnregisterOnVariableChange() = default;
            explicit UnregisterOnVariableChange(EntryPath path) : Variable(path)
            {}
        };

        class VariableChanged : public Variable
        {
          public:
            VariableChanged() = default;
            explicit VariableChanged(EntryPath path, std::string value, std::string old_value)
                : Variable(path, value), old_value(std::move(old_value))
            {}

            [[nodiscard]] auto getOldValue() const -> std::string
            {
                return old_value;
            }

          protected:
            std::string old_value;
        };

        /// Profiles manipulation
        class ListProfiles : public SettingsMessage
        {
          public:
            [[nodiscard]] auto getProfiles() const -> std::set<std::string>
            {
                return profiles;
            }

          private:
            std::set<std::string> profiles;
        };

        class ProfileSettingsMessage : public SettingsMessage
        {
          public:
            [[nodiscard]] auto getProfileName() const -> std::string
            {
                return profile;
            }

          protected:
            ProfileSettingsMessage() = default;
            explicit ProfileSettingsMessage(std::string name) : SettingsMessage(), profile(std::move(name))
            {}

          protected:
            std::string profile;
        };

        class SetCurrentProfile : public ProfileSettingsMessage
        {
          public:
            SetCurrentProfile() = default;
            explicit SetCurrentProfile(std::string profile) : ProfileSettingsMessage(profile)
            {}
        };

        class AddProfile : public ProfileSettingsMessage
        {
          public:
            AddProfile() = default;
            explicit AddProfile(std::string profile) : ProfileSettingsMessage(profile)
            {}
        };

        class GetCurrentProfile : public ProfileSettingsMessage
        {
          public:
            GetCurrentProfile() = default;
            explicit GetCurrentProfile(std::string profile) : ProfileSettingsMessage(profile)
            {}
        };

        class RegisterOnProfileChange : public SettingsMessage
        {};

        class UnregisterOnProfileChange : public SettingsMessage
        {};

        class CurrentProfileChanged : public ProfileSettingsMessage
        {
          public:
            CurrentProfileChanged() = default;
            explicit CurrentProfileChanged(std::string profile) : ProfileSettingsMessage(profile)
            {}
        };

        /// Modes manipulation
        class ListModes : public SettingsMessage
        {
          public:
            [[nodiscard]] auto getModes() const -> std::set<std::string>
            {
                return modes;
            }

          private:
            std::set<std::string> modes;
        };

        class Mode : public SettingsMessage
        {
          public:
            [[nodiscard]] auto getModeName() const -> std::string
            {
                return mode;
            }

          protected:
            Mode() = default;
            explicit Mode(std::string mode) : SettingsMessage(), mode(std::move(mode))
            {}

          protected:
            std::string mode;
        };

        class SetCurrentMode : public ProfileSettingsMessage
        {
          public:
            SetCurrentMode() = default;
            explicit SetCurrentMode(std::string mode) : ProfileSettingsMessage(mode)
            {}
        };

        class AddMode : public ProfileSettingsMessage
        {
          public:
            AddMode() = default;
            explicit AddMode(std::string mode) : ProfileSettingsMessage(mode)
            {}
        };

        class GetCurrentMode : public ProfileSettingsMessage
        {
          public:
            GetCurrentMode() = default;
            explicit GetCurrentMode(std::string profile) : ProfileSettingsMessage(profile)
            {}
        };

        class RegisterOnModeChange : public SettingsMessage
        {};

        class UnregisterOnModeChange : public SettingsMessage
        {};

        class CurrentModeChanged : public ProfileSettingsMessage
        {
          public:
            CurrentModeChanged() = default;
            explicit CurrentModeChanged(std::string profile) : ProfileSettingsMessage(profile)
            {}
        };

        class ValueResponse : sys::ResponseMessage
        {
          public:
            ValueResponse() = default;
            ValueResponse(std::string value) : sys::ResponseMessage(), value(std::move(value))
            {}

            [[nodiscard]] auto getValue() const -> std::string
            {
                return value;
            }

          private:
            std::string value;
        };

        class VariableResponse : public sys::ResponseMessage
        {
          public:
            explicit VariableResponse(EntryPath path,
                                      std::optional<std::string> value,
                                      sys::ReturnCodes code = sys::ReturnCodes::Success)
                : sys::ResponseMessage(code), path(std::move(path)), value(std::move(value))
            {}

            [[nodiscard]] auto getValue() const -> std::optional<std::string>
            {
                return value;
            }

            [[nodiscard]] auto getPath() const -> std::string
            {
                return path.to_string();
            }

          protected:
            EntryPath path;
            std::optional<std::string> value;
        };

        class ProfileResponse : public ValueResponse
        {
          public:
            ProfileResponse() = default;
            explicit ProfileResponse(std::string profile) : ValueResponse(profile)
            {}
        };

        class ModeResponse : public ValueResponse
        {
          public:
            ModeResponse() = default;
            explicit ModeResponse(std::string mode) : ValueResponse(mode)
            {}
        };

        class ListResponse : public sys::ResponseMessage
        {
          public:
            ListResponse() = default;
            explicit ListResponse(std::list<std::string> value, sys::ReturnCodes code = sys::ReturnCodes::Success)
                : sys::ResponseMessage(code), value(std::move(value))
            {}

            [[nodiscard]] auto getValue() const -> std::list<std::string>
            {
                return value;
            }

          protected:
            std::list<std::string> value;
        };

        class ProfileListResponse : public ListResponse
        {
          public:
            ProfileListResponse() = default;
            explicit ProfileListResponse(std::list<std::string> profiles) : ListResponse(profiles)
            {}
        };

        class ModeListResponse : public ListResponse
        {
          public:
            ModeListResponse() = default;
            explicit ModeListResponse(std::list<std::string> modes) : ListResponse(modes)
            {}
        };

    } // namespace Messages
} // namespace Settings