1 /**
2  * Copyright © 2019 IBM 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 "data_interface.hpp"
17 #include "elog_entry.hpp"
18 #include "event_logger.hpp"
19 #include "extensions.hpp"
20 #include "journal.hpp"
21 #include "manager.hpp"
22 #include "pldm_interface.hpp"
23 
24 #include <phosphor-logging/lg2.hpp>
25 
26 #include <format>
27 
28 namespace openpower
29 {
30 namespace pels
31 {
32 
33 using namespace phosphor::logging;
34 
35 std::unique_ptr<Manager> manager;
36 
37 DISABLE_LOG_ENTRY_CAPS()
38 
39 void pelStartup(internal::Manager& logManager)
40 {
41     EventLogger::LogFunction logger =
42         std::bind(std::mem_fn(&internal::Manager::create), &logManager,
43                   std::placeholders::_1, std::placeholders::_2,
44                   std::placeholders::_3, phosphor::logging::FFDCEntries{});
45 
46     std::unique_ptr<DataInterfaceBase> dataIface =
47         std::make_unique<DataInterface>(logManager.getBus());
48 
49     std::unique_ptr<JournalBase> journal = std::make_unique<Journal>();
50 
51 #ifndef DONT_SEND_PELS_TO_HOST
52     std::unique_ptr<HostInterface> hostIface = std::make_unique<PLDMInterface>(
53         logManager.getBus().get_event(), *(dataIface.get()));
54 
55     manager = std::make_unique<Manager>(logManager, std::move(dataIface),
56                                         std::move(logger), std::move(journal),
57                                         std::move(hostIface));
58 #else
59     manager = std::make_unique<Manager>(logManager, std::move(dataIface),
60                                         std::move(logger), std::move(journal));
61 #endif
62 }
63 
64 REGISTER_EXTENSION_FUNCTION(pelStartup)
65 
66 void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp,
67                Entry::Level severity, const AdditionalDataArg& additionalData,
68                const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
69 {
70     manager->create(message, id, timestamp, severity, additionalData, assocs,
71                     ffdc);
72 }
73 
74 REGISTER_EXTENSION_FUNCTION(pelCreate)
75 
76 void pelDelete(uint32_t id)
77 {
78     return manager->erase(id);
79 }
80 
81 REGISTER_EXTENSION_FUNCTION(pelDelete)
82 
83 void pelDeleteProhibited(uint32_t id, bool& prohibited)
84 {
85     prohibited = manager->isDeleteProhibited(id);
86 }
87 
88 REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited)
89 
90 void getLogIDWithHwIsolation(std::vector<uint32_t>& logIDs)
91 {
92     manager->getLogIDWithHwIsolation(logIDs);
93 }
94 
95 REGISTER_EXTENSION_FUNCTION(getLogIDWithHwIsolation)
96 
97 } // namespace pels
98 } // namespace openpower
99