summaryrefslogtreecommitdiff
path: root/redfish-core/src/task_messages.cpp
blob: 79c312a95d6899085d79e16087f0f72373dd37fd (plain)
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
/****************************************************************
 *                 READ THIS WARNING FIRST
 * This is an auto-generated header which contains definitions
 * for Redfish DMTF defined messages.
 * DO NOT modify this registry outside of running the
 * parse_registries.py script.  The definitions contained within
 * this file are owned by DMTF.  Any modifications to these files
 * should be first pushed to the relevant registry in the DMTF
 * github organization.
 ***************************************************************/
#include "task_messages.hpp"

#include "registries.hpp"
#include "registries/task_event_message_registry.hpp"

#include <nlohmann/json.hpp>

#include <array>
#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <string_view>

// Clang can't seem to decide whether this header needs to be included or not,
// and is inconsistent.  Include it for now
// NOLINTNEXTLINE(misc-include-cleaner)
#include <utility>

namespace redfish
{

namespace messages
{

static nlohmann::json::object_t getLog(
    redfish::registries::TaskEvent::Index name,
    std::span<const std::string_view> args)
{
    size_t index = static_cast<size_t>(name);
    if (index >= redfish::registries::TaskEvent::registry.size())
    {
        return {};
    }
    return getLogFromRegistry(redfish::registries::TaskEvent::header,
                              redfish::registries::TaskEvent::registry, index,
                              args);
}

/**
 * @internal
 * @brief Formats TaskStarted message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskStarted(std::string_view arg1)
{
    return getLog(redfish::registries::TaskEvent::Index::taskStarted,
                  std::to_array({arg1}));
}

/**
 * @internal
 * @brief Formats TaskCompletedOK message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskCompletedOK(std::string_view arg1)
{
    return getLog(redfish::registries::TaskEvent::Index::taskCompletedOK,
                  std::to_array({arg1}));
}

/**
 * @internal
 * @brief Formats TaskCompletedWarning message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskCompletedWarning(std::string_view arg1)
{
    return getLog(redfish::registries::TaskEvent::Index::taskCompletedWarning,
                  std::to_array({arg1}));
}

/**
 * @internal
 * @brief Formats TaskAborted message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskAborted(std::string_view arg1)
{
    return getLog(redfish::registries::TaskEvent::Index::taskAborted,
                  std::to_array({arg1}));
}

/**
 * @internal
 * @brief Formats TaskCancelled message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskCancelled(std::string_view arg1)
{
    return getLog(redfish::registries::TaskEvent::Index::taskCancelled,
                  std::to_array({arg1}));
}

/**
 * @internal
 * @brief Formats TaskRemoved message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskRemoved(std::string_view arg1)
{
    return getLog(redfish::registries::TaskEvent::Index::taskRemoved,
                  std::to_array({arg1}));
}

/**
 * @internal
 * @brief Formats TaskPaused message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskPaused(std::string_view arg1)
{
    return getLog(redfish::registries::TaskEvent::Index::taskPaused,
                  std::to_array({arg1}));
}

/**
 * @internal
 * @brief Formats TaskResumed message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskResumed(std::string_view arg1)
{
    return getLog(redfish::registries::TaskEvent::Index::taskResumed,
                  std::to_array({arg1}));
}

/**
 * @internal
 * @brief Formats TaskProgressChanged message into JSON
 *
 * See header file for more information
 * @endinternal
 */
nlohmann::json::object_t taskProgressChanged(std::string_view arg1,
                                             uint64_t arg2)
{
    std::string arg2Str = std::to_string(arg2);
    return getLog(redfish::registries::TaskEvent::Index::taskProgressChanged,
                  std::to_array<std::string_view>({arg1, arg2Str}));
}

} // namespace messages
} // namespace redfish