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