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