xref: /openbmc/bmcweb/features/redfish/include/task_messages.hpp (revision 5b90429a75c58797ec29ac9a8ed18c2dcd7d4950)
1e5d5006bSJames Feist /*
2e5d5006bSJames Feist // Copyright (c) 2020 Intel Corporation
3e5d5006bSJames Feist //
4e5d5006bSJames Feist // Licensed under the Apache License, Version 2.0 (the "License");
5e5d5006bSJames Feist // you may not use this file except in compliance with the License.
6e5d5006bSJames Feist // You may obtain a copy of the License at
7e5d5006bSJames Feist //
8e5d5006bSJames Feist //      http://www.apache.org/licenses/LICENSE-2.0
9e5d5006bSJames Feist //
10e5d5006bSJames Feist // Unless required by applicable law or agreed to in writing, software
11e5d5006bSJames Feist // distributed under the License is distributed on an "AS IS" BASIS,
12e5d5006bSJames Feist // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e5d5006bSJames Feist // See the License for the specific language governing permissions and
14e5d5006bSJames Feist // limitations under the License.
15e5d5006bSJames Feist */
16*5b90429aSEd Tanous #pragma once
17218295dcSEd Tanous #include "registries/task_event_message_registry.hpp"
18e5d5006bSJames Feist 
19218295dcSEd Tanous #include <nlohmann/json.hpp>
20218295dcSEd Tanous 
21218295dcSEd Tanous #include <array>
22218295dcSEd Tanous namespace redfish::messages
23e5d5006bSJames Feist {
24e5d5006bSJames Feist 
25218295dcSEd Tanous inline nlohmann::json
26218295dcSEd Tanous     getLogTaskEvent(redfish::registries::task_event::Index name,
27218295dcSEd Tanous                     std::span<const std::string_view> args)
28e5d5006bSJames Feist {
29218295dcSEd Tanous     size_t index = static_cast<size_t>(name);
30218295dcSEd Tanous     if (index >= redfish::registries::task_event::registry.size())
31e5d5006bSJames Feist     {
32218295dcSEd Tanous         return {};
33218295dcSEd Tanous     }
34218295dcSEd Tanous     return getLogFromRegistry(redfish::registries::task_event::header,
35218295dcSEd Tanous                               redfish::registries::task_event::registry, index,
36218295dcSEd Tanous                               args);
37e5d5006bSJames Feist }
38e5d5006bSJames Feist 
39218295dcSEd Tanous inline nlohmann::json taskAborted(std::string_view arg1)
40e5d5006bSJames Feist {
41218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskAborted,
42218295dcSEd Tanous                            std::to_array({arg1}));
43e5d5006bSJames Feist }
44e5d5006bSJames Feist 
45218295dcSEd Tanous inline nlohmann::json taskCancelled(std::string_view arg1)
46e5d5006bSJames Feist {
47218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskCancelled,
48218295dcSEd Tanous                            std::to_array({arg1}));
49e5d5006bSJames Feist }
50e5d5006bSJames Feist 
51218295dcSEd Tanous inline nlohmann::json taskCompletedOK(std::string_view arg1)
52e5d5006bSJames Feist {
53218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskCompletedOK,
54218295dcSEd Tanous                            std::to_array({arg1}));
55e5d5006bSJames Feist }
56e5d5006bSJames Feist 
57218295dcSEd Tanous inline nlohmann::json taskCompletedWarning(std::string_view arg1)
58e5d5006bSJames Feist {
59218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskCompletedWarning,
60218295dcSEd Tanous                            std::to_array({arg1}));
61e5d5006bSJames Feist }
62e5d5006bSJames Feist 
63218295dcSEd Tanous inline nlohmann::json taskPaused(std::string_view arg1)
64e5d5006bSJames Feist {
65218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskPaused,
66218295dcSEd Tanous                            std::to_array({arg1}));
67e5d5006bSJames Feist }
68e5d5006bSJames Feist 
69218295dcSEd Tanous inline nlohmann::json taskProgressChanged(std::string_view arg1, size_t arg2)
70e5d5006bSJames Feist {
71218295dcSEd Tanous     std::string arg2Str = std::to_string(arg2);
72218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskProgressChanged,
73218295dcSEd Tanous                            std::to_array<std::string_view>({arg1, arg2Str}));
74e5d5006bSJames Feist }
75e5d5006bSJames Feist 
76218295dcSEd Tanous inline nlohmann::json taskRemoved(std::string_view arg1)
77e5d5006bSJames Feist {
78218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskRemoved,
79218295dcSEd Tanous                            std::to_array({arg1}));
80e5d5006bSJames Feist }
81e5d5006bSJames Feist 
82218295dcSEd Tanous inline nlohmann::json taskResumed(std::string_view arg1)
83e5d5006bSJames Feist {
84218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskResumed,
85218295dcSEd Tanous                            std::to_array({arg1}));
86e5d5006bSJames Feist }
87e5d5006bSJames Feist 
88218295dcSEd Tanous inline nlohmann::json taskStarted(std::string_view arg1)
89218295dcSEd Tanous {
90218295dcSEd Tanous     return getLogTaskEvent(registries::task_event::Index::taskStarted,
91218295dcSEd Tanous                            std::to_array({arg1}));
92218295dcSEd Tanous }
93e5d5006bSJames Feist 
94218295dcSEd Tanous } // namespace redfish::messages
95