blob: 56ebc00681c0505ed52414fdb2a9660659aa8332 [file] [log] [blame]
James Feiste5d50062020-05-11 17:29:00 -07001/*
2// Copyright (c) 2020 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
Ed Tanous218295d2022-08-05 16:00:56 -070016#include "registries/task_event_message_registry.hpp"
James Feiste5d50062020-05-11 17:29:00 -070017
Ed Tanous218295d2022-08-05 16:00:56 -070018#include <nlohmann/json.hpp>
19
20#include <array>
21namespace redfish::messages
James Feiste5d50062020-05-11 17:29:00 -070022{
23
Ed Tanous218295d2022-08-05 16:00:56 -070024inline nlohmann::json
25 getLogTaskEvent(redfish::registries::task_event::Index name,
26 std::span<const std::string_view> args)
James Feiste5d50062020-05-11 17:29:00 -070027{
Ed Tanous218295d2022-08-05 16:00:56 -070028 size_t index = static_cast<size_t>(name);
29 if (index >= redfish::registries::task_event::registry.size())
30 {
31 return {};
32 }
33 return getLogFromRegistry(redfish::registries::task_event::header,
34 redfish::registries::task_event::registry, index,
35 args);
James Feiste5d50062020-05-11 17:29:00 -070036}
37
Ed Tanous218295d2022-08-05 16:00:56 -070038inline nlohmann::json taskAborted(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070039{
Ed Tanous218295d2022-08-05 16:00:56 -070040 return getLogTaskEvent(registries::task_event::Index::taskAborted,
41 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070042}
43
Ed Tanous218295d2022-08-05 16:00:56 -070044inline nlohmann::json taskCancelled(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070045{
Ed Tanous218295d2022-08-05 16:00:56 -070046 return getLogTaskEvent(registries::task_event::Index::taskCancelled,
47 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070048}
49
Ed Tanous218295d2022-08-05 16:00:56 -070050inline nlohmann::json taskCompletedOK(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070051{
Ed Tanous218295d2022-08-05 16:00:56 -070052 return getLogTaskEvent(registries::task_event::Index::taskCompletedOK,
53 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070054}
55
Ed Tanous218295d2022-08-05 16:00:56 -070056inline nlohmann::json taskCompletedWarning(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070057{
Ed Tanous218295d2022-08-05 16:00:56 -070058 return getLogTaskEvent(registries::task_event::Index::taskCompletedWarning,
59 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070060}
61
Ed Tanous218295d2022-08-05 16:00:56 -070062inline nlohmann::json taskPaused(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070063{
Ed Tanous218295d2022-08-05 16:00:56 -070064 return getLogTaskEvent(registries::task_event::Index::taskPaused,
65 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070066}
67
Ed Tanous218295d2022-08-05 16:00:56 -070068inline nlohmann::json taskProgressChanged(std::string_view arg1, size_t arg2)
James Feiste5d50062020-05-11 17:29:00 -070069{
Ed Tanous218295d2022-08-05 16:00:56 -070070 std::string arg2Str = std::to_string(arg2);
71 return getLogTaskEvent(registries::task_event::Index::taskProgressChanged,
72 std::to_array<std::string_view>({arg1, arg2Str}));
James Feiste5d50062020-05-11 17:29:00 -070073}
74
Ed Tanous218295d2022-08-05 16:00:56 -070075inline nlohmann::json taskRemoved(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070076{
Ed Tanous218295d2022-08-05 16:00:56 -070077 return getLogTaskEvent(registries::task_event::Index::taskRemoved,
78 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070079}
80
Ed Tanous218295d2022-08-05 16:00:56 -070081inline nlohmann::json taskResumed(std::string_view arg1)
James Feiste5d50062020-05-11 17:29:00 -070082{
Ed Tanous218295d2022-08-05 16:00:56 -070083 return getLogTaskEvent(registries::task_event::Index::taskResumed,
84 std::to_array({arg1}));
James Feiste5d50062020-05-11 17:29:00 -070085}
86
Ed Tanous218295d2022-08-05 16:00:56 -070087inline nlohmann::json taskStarted(std::string_view arg1)
88{
89 return getLogTaskEvent(registries::task_event::Index::taskStarted,
90 std::to_array({arg1}));
91}
James Feiste5d50062020-05-11 17:29:00 -070092
Ed Tanous218295d2022-08-05 16:00:56 -070093} // namespace redfish::messages