blob: 3a990f8a5937430ddb74d290cca15ccb26cea882 [file] [log] [blame]
Matt Spinler711d51d2019-11-06 09:36:51 -06001/**
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 */
Matt Spinlerc8705e22019-09-11 12:36:07 -050016#include "data_interface.hpp"
Matt Spinler99c2b402019-05-23 14:29:16 -050017#include "elog_entry.hpp"
Matt Spinlerf682b402019-12-18 13:48:08 -060018#include "event_logger.hpp"
Matt Spinler99c2b402019-05-23 14:29:16 -050019#include "extensions.hpp"
Matt Spinler4e8078c2019-07-09 13:22:32 -050020#include "manager.hpp"
Matt Spinler17ed2ed2019-12-12 14:12:23 -060021#include "pldm_interface.hpp"
Matt Spinler99c2b402019-05-23 14:29:16 -050022
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050023#include <phosphor-logging/log.hpp>
24
25#ifdef SBE_FFDC_SUPPORTED
Jayanth Othayothc74c2202021-06-04 06:42:43 -050026#include <libekb.H>
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050027#include <libpdbg.h>
28#endif
29
Matt Spinler99c2b402019-05-23 14:29:16 -050030namespace openpower
31{
32namespace pels
33{
34
35using namespace phosphor::logging;
36
Matt Spinler4e8078c2019-07-09 13:22:32 -050037std::unique_ptr<Manager> manager;
38
Patrick Williamsd26fa3e2021-04-21 15:22:23 -050039DISABLE_LOG_ENTRY_CAPS()
Matt Spinlerb9883ea2020-07-07 15:08:35 -050040
Matt Spinler99c2b402019-05-23 14:29:16 -050041void pelStartup(internal::Manager& logManager)
42{
Matt Spinlerf682b402019-12-18 13:48:08 -060043 EventLogger::LogFunction logger = std::bind(
44 std::mem_fn(&internal::Manager::create), &logManager,
45 std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
46
Matt Spinlerc8705e22019-09-11 12:36:07 -050047 std::unique_ptr<DataInterfaceBase> dataIface =
48 std::make_unique<DataInterface>(logManager.getBus());
49
Matt Spinler17ed2ed2019-12-12 14:12:23 -060050#ifndef DONT_SEND_PELS_TO_HOST
51 std::unique_ptr<HostInterface> hostIface = std::make_unique<PLDMInterface>(
52 logManager.getBus().get_event(), *(dataIface.get()));
53
Matt Spinlerf682b402019-12-18 13:48:08 -060054 manager =
55 std::make_unique<Manager>(logManager, std::move(dataIface),
56 std::move(logger), std::move(hostIface));
Matt Spinler17ed2ed2019-12-12 14:12:23 -060057#else
Matt Spinlerf682b402019-12-18 13:48:08 -060058 manager = std::make_unique<Manager>(logManager, std::move(dataIface),
59 std::move(logger));
Matt Spinler17ed2ed2019-12-12 14:12:23 -060060#endif
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050061
62#ifdef SBE_FFDC_SUPPORTED
63 if (!pdbg_targets_init(NULL))
64 {
65 log<level::ERR>("pdbg_targets_init failed");
66 throw std::runtime_error("pdbg target initialization failed");
67 }
Jayanth Othayothc74c2202021-06-04 06:42:43 -050068
69 if (libekb_init())
70 {
71 log<level::ERR>("libekb_init failed");
72 throw std::runtime_error("libekb initialization failed");
73 }
Jayanth Othayoth4d779b22021-06-03 05:45:13 -050074#endif
Matt Spinler99c2b402019-05-23 14:29:16 -050075}
76
Patrick Williamsd26fa3e2021-04-21 15:22:23 -050077REGISTER_EXTENSION_FUNCTION(pelStartup)
Matt Spinler99c2b402019-05-23 14:29:16 -050078
79void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp,
80 Entry::Level severity, const AdditionalDataArg& additionalData,
Matt Spinlerc64b7122020-03-26 10:55:01 -050081 const AssociationEndpointsArg& assocs, const FFDCArg& ffdc)
Matt Spinler99c2b402019-05-23 14:29:16 -050082{
Matt Spinler56ad2a02020-03-26 14:00:52 -050083 manager->create(message, id, timestamp, severity, additionalData, assocs,
84 ffdc);
Matt Spinler99c2b402019-05-23 14:29:16 -050085}
86
Patrick Williamsd26fa3e2021-04-21 15:22:23 -050087REGISTER_EXTENSION_FUNCTION(pelCreate)
Matt Spinler99c2b402019-05-23 14:29:16 -050088
89void pelDelete(uint32_t id)
90{
Matt Spinler4e8078c2019-07-09 13:22:32 -050091 return manager->erase(id);
Matt Spinler99c2b402019-05-23 14:29:16 -050092}
93
Patrick Williamsd26fa3e2021-04-21 15:22:23 -050094REGISTER_EXTENSION_FUNCTION(pelDelete)
Matt Spinler99c2b402019-05-23 14:29:16 -050095
96void pelDeleteProhibited(uint32_t id, bool& prohibited)
97{
Matt Spinler4e8078c2019-07-09 13:22:32 -050098 prohibited = manager->isDeleteProhibited(id);
Matt Spinler99c2b402019-05-23 14:29:16 -050099}
100
Patrick Williamsd26fa3e2021-04-21 15:22:23 -0500101REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited)
Matt Spinler99c2b402019-05-23 14:29:16 -0500102
103} // namespace pels
104} // namespace openpower