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