xref: /openbmc/bmcweb/redfish-core/src/task_messages.cpp (revision 6e1a52fae1e39bdae6427bf060598242e1e4e4e6)
1 /****************************************************************
2  *                 READ THIS WARNING FIRST
3  * This is an auto-generated header which contains definitions
4  * for Redfish DMTF defined messages.
5  * DO NOT modify this registry outside of running the
6  * parse_registries.py script.  The definitions contained within
7  * this file are owned by DMTF.  Any modifications to these files
8  * should be first pushed to the relevant registry in the DMTF
9  * github organization.
10  ***************************************************************/
11 #include "task_messages.hpp"
12 
13 #include "registries.hpp"
14 #include "registries/task_event_message_registry.hpp"
15 
16 #include <nlohmann/json.hpp>
17 
18 #include <array>
19 #include <cstddef>
20 #include <cstdint>
21 #include <span>
22 #include <string>
23 #include <string_view>
24 
25 // Clang can't seem to decide whether this header needs to be included or not,
26 // and is inconsistent.  Include it for now
27 // NOLINTNEXTLINE(misc-include-cleaner)
28 #include <utility>
29 
30 namespace redfish
31 {
32 
33 namespace messages
34 {
35 
36 static nlohmann::json getLog(redfish::registries::task_event::Index name,
37                              std::span<const std::string_view> args)
38 {
39     size_t index = static_cast<size_t>(name);
40     if (index >= redfish::registries::task_event::registry.size())
41     {
42         return {};
43     }
44     return getLogFromRegistry(redfish::registries::task_event::header,
45                               redfish::registries::task_event::registry, index,
46                               args);
47 }
48 
49 /**
50  * @internal
51  * @brief Formats TaskStarted message into JSON
52  *
53  * See header file for more information
54  * @endinternal
55  */
56 nlohmann::json taskStarted(std::string_view arg1)
57 {
58     return getLog(redfish::registries::task_event::Index::taskStarted,
59                   std::to_array({arg1}));
60 }
61 
62 /**
63  * @internal
64  * @brief Formats TaskCompletedOK message into JSON
65  *
66  * See header file for more information
67  * @endinternal
68  */
69 nlohmann::json taskCompletedOK(std::string_view arg1)
70 {
71     return getLog(redfish::registries::task_event::Index::taskCompletedOK,
72                   std::to_array({arg1}));
73 }
74 
75 /**
76  * @internal
77  * @brief Formats TaskCompletedWarning message into JSON
78  *
79  * See header file for more information
80  * @endinternal
81  */
82 nlohmann::json taskCompletedWarning(std::string_view arg1)
83 {
84     return getLog(redfish::registries::task_event::Index::taskCompletedWarning,
85                   std::to_array({arg1}));
86 }
87 
88 /**
89  * @internal
90  * @brief Formats TaskAborted message into JSON
91  *
92  * See header file for more information
93  * @endinternal
94  */
95 nlohmann::json taskAborted(std::string_view arg1)
96 {
97     return getLog(redfish::registries::task_event::Index::taskAborted,
98                   std::to_array({arg1}));
99 }
100 
101 /**
102  * @internal
103  * @brief Formats TaskCancelled message into JSON
104  *
105  * See header file for more information
106  * @endinternal
107  */
108 nlohmann::json taskCancelled(std::string_view arg1)
109 {
110     return getLog(redfish::registries::task_event::Index::taskCancelled,
111                   std::to_array({arg1}));
112 }
113 
114 /**
115  * @internal
116  * @brief Formats TaskRemoved message into JSON
117  *
118  * See header file for more information
119  * @endinternal
120  */
121 nlohmann::json taskRemoved(std::string_view arg1)
122 {
123     return getLog(redfish::registries::task_event::Index::taskRemoved,
124                   std::to_array({arg1}));
125 }
126 
127 /**
128  * @internal
129  * @brief Formats TaskPaused message into JSON
130  *
131  * See header file for more information
132  * @endinternal
133  */
134 nlohmann::json taskPaused(std::string_view arg1)
135 {
136     return getLog(redfish::registries::task_event::Index::taskPaused,
137                   std::to_array({arg1}));
138 }
139 
140 /**
141  * @internal
142  * @brief Formats TaskResumed message into JSON
143  *
144  * See header file for more information
145  * @endinternal
146  */
147 nlohmann::json taskResumed(std::string_view arg1)
148 {
149     return getLog(redfish::registries::task_event::Index::taskResumed,
150                   std::to_array({arg1}));
151 }
152 
153 /**
154  * @internal
155  * @brief Formats TaskProgressChanged message into JSON
156  *
157  * See header file for more information
158  * @endinternal
159  */
160 nlohmann::json taskProgressChanged(std::string_view arg1, uint64_t arg2)
161 {
162     std::string arg2Str = std::to_string(arg2);
163     return getLog(redfish::registries::task_event::Index::taskProgressChanged,
164                   std::to_array<std::string_view>({arg1, arg2Str}));
165 }
166 
167 } // namespace messages
168 } // namespace redfish
169