James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 1 | /* |
| 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 Tanous | 5b90429 | 2024-04-16 11:10:17 -0700 | [diff] [blame] | 16 | #pragma once |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 17 | #include "registries/task_event_message_registry.hpp" |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 18 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 19 | #include <nlohmann/json.hpp> |
| 20 | |
| 21 | #include <array> |
| 22 | namespace redfish::messages |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 23 | { |
| 24 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 25 | inline nlohmann::json |
| 26 | getLogTaskEvent(redfish::registries::task_event::Index name, |
| 27 | std::span<const std::string_view> args) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 28 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 29 | 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 Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 37 | } |
| 38 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 39 | inline nlohmann::json taskAborted(std::string_view arg1) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 40 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 41 | return getLogTaskEvent(registries::task_event::Index::taskAborted, |
| 42 | std::to_array({arg1})); |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 45 | inline nlohmann::json taskCancelled(std::string_view arg1) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 46 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 47 | return getLogTaskEvent(registries::task_event::Index::taskCancelled, |
| 48 | std::to_array({arg1})); |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 51 | inline nlohmann::json taskCompletedOK(std::string_view arg1) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 52 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 53 | return getLogTaskEvent(registries::task_event::Index::taskCompletedOK, |
| 54 | std::to_array({arg1})); |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 57 | inline nlohmann::json taskCompletedWarning(std::string_view arg1) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 58 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 59 | return getLogTaskEvent(registries::task_event::Index::taskCompletedWarning, |
| 60 | std::to_array({arg1})); |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 61 | } |
| 62 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 63 | inline nlohmann::json taskPaused(std::string_view arg1) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 64 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 65 | return getLogTaskEvent(registries::task_event::Index::taskPaused, |
| 66 | std::to_array({arg1})); |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 69 | inline nlohmann::json taskProgressChanged(std::string_view arg1, size_t arg2) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 70 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 71 | 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 Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 76 | inline nlohmann::json taskRemoved(std::string_view arg1) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 77 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 78 | return getLogTaskEvent(registries::task_event::Index::taskRemoved, |
| 79 | std::to_array({arg1})); |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 82 | inline nlohmann::json taskResumed(std::string_view arg1) |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 83 | { |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 84 | return getLogTaskEvent(registries::task_event::Index::taskResumed, |
| 85 | std::to_array({arg1})); |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 88 | inline nlohmann::json taskStarted(std::string_view arg1) |
| 89 | { |
| 90 | return getLogTaskEvent(registries::task_event::Index::taskStarted, |
| 91 | std::to_array({arg1})); |
| 92 | } |
James Feist | e5d5006 | 2020-05-11 17:29:00 -0700 | [diff] [blame] | 93 | |
Ed Tanous | 218295d | 2022-08-05 16:00:56 -0700 | [diff] [blame] | 94 | } // namespace redfish::messages |