Line data Source code
1 : /*
2 : ___________________________________________
3 : | _ ___ _ |
4 : | | | |__ \ | | |
5 : | | |__ ) |__ _ __ _ ___ _ __ | |_ |
6 : | | '_ \ / // _` |/ _` |/ _ \ '_ \| __| | HTTP/2 AGENT FOR MOCK TESTING
7 : | | | | |/ /| (_| | (_| | __/ | | | |_ | Version 0.0.z
8 : | |_| |_|____\__,_|\__, |\___|_| |_|\__| | https://github.com/testillano/h2agent
9 : | __/ | |
10 : | |___/ |
11 : |___________________________________________|
12 :
13 : Licensed under the MIT License <http://opensource.org/licenses/MIT>.
14 : SPDX-License-Identifier: MIT
15 : Copyright (c) 2021 Eduardo Ramos
16 :
17 : Permission is hereby granted, free of charge, to any person obtaining a copy
18 : of this software and associated documentation files (the "Software"), to deal
19 : in the Software without restriction, including without limitation the rights
20 : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21 : copies of the Software, and to permit persons to whom the Software is
22 : furnished to do so, subject to the following conditions:
23 :
24 : The above copyright notice and this permission notice shall be included in all
25 : copies or substantial portions of the Software.
26 :
27 : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30 : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31 : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32 : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 : SOFTWARE.
34 : */
35 :
36 : #pragma once
37 :
38 : #include <nlohmann/json.hpp>
39 :
40 : #include <Map.hpp>
41 : #include <JsonSchema.hpp>
42 :
43 :
44 : namespace h2agent
45 : {
46 : namespace model
47 : {
48 :
49 : /**
50 : * This class stores the global variables list.
51 : */
52 : class GlobalVariable : public Map<std::string, std::string>
53 : {
54 : h2agent::jsonschema::JsonSchema global_variable_schema_{};
55 :
56 : public:
57 : GlobalVariable();
58 170 : ~GlobalVariable() = default;
59 :
60 : /**
61 : * Loads variable and value.
62 : * Append is done if variable already exists. This allows to use global variables
63 : * as memory buckets. To reset them, use 'eraser' source or just delete from
64 : * REST API.
65 : *
66 : * @param variable variable name
67 : * @param value value to append into variable
68 : */
69 : void load(const std::string &variable, const std::string &value);
70 :
71 : /**
72 : * Loads server data global operation data
73 : *
74 : * @param j Json document from operation body request
75 : *
76 : * @return Load operation result
77 : */
78 : bool loadJson(const nlohmann::json &j);
79 :
80 : /**
81 : * Json string representation for class information (json object)
82 : *
83 : * @return Json string representation ('{}' for empty object).
84 : */
85 : std::string asJsonString() const;
86 :
87 : /**
88 : * Builds json document for class information
89 : *
90 : * @return Json object
91 : */
92 : nlohmann::json getJson() const;
93 :
94 : /**
95 : * Gets global variables schema
96 : */
97 1 : const h2agent::jsonschema::JsonSchema& getSchema() const {
98 1 : return global_variable_schema_;
99 : }
100 : };
101 :
102 : }
103 : }
104 :
|