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*218295dcSEd Tanous #include "registries/task_event_message_registry.hpp" 17e5d5006bSJames Feist 18*218295dcSEd Tanous #include <nlohmann/json.hpp> 19*218295dcSEd Tanous 20*218295dcSEd Tanous #include <array> 21*218295dcSEd Tanous namespace redfish::messages 22e5d5006bSJames Feist { 23e5d5006bSJames Feist 24*218295dcSEd Tanous inline nlohmann::json 25*218295dcSEd Tanous getLogTaskEvent(redfish::registries::task_event::Index name, 26*218295dcSEd Tanous std::span<const std::string_view> args) 27e5d5006bSJames Feist { 28*218295dcSEd Tanous size_t index = static_cast<size_t>(name); 29*218295dcSEd Tanous if (index >= redfish::registries::task_event::registry.size()) 30e5d5006bSJames Feist { 31*218295dcSEd Tanous return {}; 32*218295dcSEd Tanous } 33*218295dcSEd Tanous return getLogFromRegistry(redfish::registries::task_event::header, 34*218295dcSEd Tanous redfish::registries::task_event::registry, index, 35*218295dcSEd Tanous args); 36e5d5006bSJames Feist } 37e5d5006bSJames Feist 38*218295dcSEd Tanous inline nlohmann::json taskAborted(std::string_view arg1) 39e5d5006bSJames Feist { 40*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskAborted, 41*218295dcSEd Tanous std::to_array({arg1})); 42e5d5006bSJames Feist } 43e5d5006bSJames Feist 44*218295dcSEd Tanous inline nlohmann::json taskCancelled(std::string_view arg1) 45e5d5006bSJames Feist { 46*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskCancelled, 47*218295dcSEd Tanous std::to_array({arg1})); 48e5d5006bSJames Feist } 49e5d5006bSJames Feist 50*218295dcSEd Tanous inline nlohmann::json taskCompletedOK(std::string_view arg1) 51e5d5006bSJames Feist { 52*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskCompletedOK, 53*218295dcSEd Tanous std::to_array({arg1})); 54e5d5006bSJames Feist } 55e5d5006bSJames Feist 56*218295dcSEd Tanous inline nlohmann::json taskCompletedWarning(std::string_view arg1) 57e5d5006bSJames Feist { 58*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskCompletedWarning, 59*218295dcSEd Tanous std::to_array({arg1})); 60e5d5006bSJames Feist } 61e5d5006bSJames Feist 62*218295dcSEd Tanous inline nlohmann::json taskPaused(std::string_view arg1) 63e5d5006bSJames Feist { 64*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskPaused, 65*218295dcSEd Tanous std::to_array({arg1})); 66e5d5006bSJames Feist } 67e5d5006bSJames Feist 68*218295dcSEd Tanous inline nlohmann::json taskProgressChanged(std::string_view arg1, size_t arg2) 69e5d5006bSJames Feist { 70*218295dcSEd Tanous std::string arg2Str = std::to_string(arg2); 71*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskProgressChanged, 72*218295dcSEd Tanous std::to_array<std::string_view>({arg1, arg2Str})); 73e5d5006bSJames Feist } 74e5d5006bSJames Feist 75*218295dcSEd Tanous inline nlohmann::json taskRemoved(std::string_view arg1) 76e5d5006bSJames Feist { 77*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskRemoved, 78*218295dcSEd Tanous std::to_array({arg1})); 79e5d5006bSJames Feist } 80e5d5006bSJames Feist 81*218295dcSEd Tanous inline nlohmann::json taskResumed(std::string_view arg1) 82e5d5006bSJames Feist { 83*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskResumed, 84*218295dcSEd Tanous std::to_array({arg1})); 85e5d5006bSJames Feist } 86e5d5006bSJames Feist 87*218295dcSEd Tanous inline nlohmann::json taskStarted(std::string_view arg1) 88*218295dcSEd Tanous { 89*218295dcSEd Tanous return getLogTaskEvent(registries::task_event::Index::taskStarted, 90*218295dcSEd Tanous std::to_array({arg1})); 91*218295dcSEd Tanous } 92e5d5006bSJames Feist 93*218295dcSEd Tanous } // namespace redfish::messages 94