blob: ed16e09a811962d70d2e82707b12d41b8a56bde3 [file] [log] [blame]
James Feiste5d50062020-05-11 17:29:00 -07001/*
Ed Tanous6be832e2024-09-10 11:44:48 -07002Copyright (c) 2020 Intel Corporation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
James Feiste5d50062020-05-11 17:29:00 -070015*/
Ed Tanous5b904292024-04-16 11:10:17 -070016#pragma once
Ed Tanous218295d2022-08-05 16:00:56 -070017#include "registries/task_event_message_registry.hpp"
James Feiste5d50062020-05-11 17:29:00 -070018
Ed Tanous218295d2022-08-05 16:00:56 -070019#include <nlohmann/json.hpp>
20
21#include <array>
22namespace redfish::messages
James Feiste5d50062020-05-11 17:29:00 -070023{
24
Ed Tanous218295d2022-08-05 16:00:56 -070025inline nlohmann::json
26 getLogTaskEvent(redfish::registries::task_event::Index name,
27 std::span<const std::string_view> args)
James Feiste5d50062020-05-11 17:29:00 -070028{
Ed Tanous218295d2022-08-05 16:00:56 -070029 size_t index = static_cast<size_t>(name);
30 if (index >= redfish::registries::task_event::registry.size())
31 {
32 return {};
33 }
34 return getLogFromRegistry(redfish::registries::task_event::header,
35 redfish::registries::task_event::registry, index,
36 args);
James Feiste5d50062020-05-11 17:29:00 -070037}
38
Ed Tanous218295d2022-08-05 16:00:56 -070039inline nlohmann::json taskAborted(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070040{
Ed Tanous218295d2022-08-05 16:00:56 -070041 return getLogTaskEvent(registries::task_event::Index::taskAborted,
42 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070043}
44
Ed Tanous218295d2022-08-05 16:00:56 -070045inline nlohmann::json taskCancelled(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070046{
Ed Tanous218295d2022-08-05 16:00:56 -070047 return getLogTaskEvent(registries::task_event::Index::taskCancelled,
48 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070049}
50
Ed Tanous218295d2022-08-05 16:00:56 -070051inline nlohmann::json taskCompletedOK(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070052{
Ed Tanous218295d2022-08-05 16:00:56 -070053 return getLogTaskEvent(registries::task_event::Index::taskCompletedOK,
54 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070055}
56
Ed Tanous218295d2022-08-05 16:00:56 -070057inline nlohmann::json taskCompletedWarning(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070058{
Ed Tanous218295d2022-08-05 16:00:56 -070059 return getLogTaskEvent(registries::task_event::Index::taskCompletedWarning,
60 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070061}
62
Ed Tanous218295d2022-08-05 16:00:56 -070063inline nlohmann::json taskPaused(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070064{
Ed Tanous218295d2022-08-05 16:00:56 -070065 return getLogTaskEvent(registries::task_event::Index::taskPaused,
66 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070067}
68
Ed Tanous218295d2022-08-05 16:00:56 -070069inline nlohmann::json taskProgressChanged(std::string_view arg1, size_t arg2)
James Feiste5d50062020-05-11 17:29:00 -070070{
Ed Tanous218295d2022-08-05 16:00:56 -070071 std::string arg2Str = std::to_string(arg2);
72 return getLogTaskEvent(registries::task_event::Index::taskProgressChanged,
73 std::to_array<std::string_view>({arg1, arg2Str}));
James Feiste5d50062020-05-11 17:29:00 -070074}
75
Ed Tanous218295d2022-08-05 16:00:56 -070076inline nlohmann::json taskRemoved(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070077{
Ed Tanous218295d2022-08-05 16:00:56 -070078 return getLogTaskEvent(registries::task_event::Index::taskRemoved,
79 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070080}
81
Ed Tanous218295d2022-08-05 16:00:56 -070082inline nlohmann::json taskResumed(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070083{
Ed Tanous218295d2022-08-05 16:00:56 -070084 return getLogTaskEvent(registries::task_event::Index::taskResumed,
85 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070086}
87
Ed Tanous218295d2022-08-05 16:00:56 -070088inline nlohmann::json taskStarted(std::string_view arg1)
89{
90 return getLogTaskEvent(registries::task_event::Index::taskStarted,
91 std::to_array({arg1}));
92}
James Feiste5d50062020-05-11 17:29:00 -070093
Ed Tanous218295d2022-08-05 16:00:56 -070094} // namespace redfish::messages