Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 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 | */ |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 16 | #include "data_interface.hpp" |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 17 | #include "elog_entry.hpp" |
Matt Spinler | f682b40 | 2019-12-18 13:48:08 -0600 | [diff] [blame] | 18 | #include "event_logger.hpp" |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 19 | #include "extensions.hpp" |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 20 | #include "manager.hpp" |
Matt Spinler | 17ed2ed | 2019-12-12 14:12:23 -0600 | [diff] [blame] | 21 | #include "pldm_interface.hpp" |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 22 | |
| 23 | namespace openpower |
| 24 | { |
| 25 | namespace pels |
| 26 | { |
| 27 | |
| 28 | using namespace phosphor::logging; |
| 29 | |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 30 | std::unique_ptr<Manager> manager; |
| 31 | |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 32 | void pelStartup(internal::Manager& logManager) |
| 33 | { |
Matt Spinler | f682b40 | 2019-12-18 13:48:08 -0600 | [diff] [blame] | 34 | EventLogger::LogFunction logger = std::bind( |
| 35 | std::mem_fn(&internal::Manager::create), &logManager, |
| 36 | std::placeholders::_1, std::placeholders::_2, std::placeholders::_3); |
| 37 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 38 | std::unique_ptr<DataInterfaceBase> dataIface = |
| 39 | std::make_unique<DataInterface>(logManager.getBus()); |
| 40 | |
Matt Spinler | 17ed2ed | 2019-12-12 14:12:23 -0600 | [diff] [blame] | 41 | #ifndef DONT_SEND_PELS_TO_HOST |
| 42 | std::unique_ptr<HostInterface> hostIface = std::make_unique<PLDMInterface>( |
| 43 | logManager.getBus().get_event(), *(dataIface.get())); |
| 44 | |
Matt Spinler | f682b40 | 2019-12-18 13:48:08 -0600 | [diff] [blame] | 45 | manager = |
| 46 | std::make_unique<Manager>(logManager, std::move(dataIface), |
| 47 | std::move(logger), std::move(hostIface)); |
Matt Spinler | 17ed2ed | 2019-12-12 14:12:23 -0600 | [diff] [blame] | 48 | #else |
Matt Spinler | f682b40 | 2019-12-18 13:48:08 -0600 | [diff] [blame] | 49 | manager = std::make_unique<Manager>(logManager, std::move(dataIface), |
| 50 | std::move(logger)); |
Matt Spinler | 17ed2ed | 2019-12-12 14:12:23 -0600 | [diff] [blame] | 51 | #endif |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | REGISTER_EXTENSION_FUNCTION(pelStartup); |
| 55 | |
| 56 | void pelCreate(const std::string& message, uint32_t id, uint64_t timestamp, |
| 57 | Entry::Level severity, const AdditionalDataArg& additionalData, |
Matt Spinler | c64b712 | 2020-03-26 10:55:01 -0500 | [diff] [blame] | 58 | const AssociationEndpointsArg& assocs, const FFDCArg& ffdc) |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 59 | { |
Matt Spinler | 56ad2a0 | 2020-03-26 14:00:52 -0500 | [diff] [blame] | 60 | manager->create(message, id, timestamp, severity, additionalData, assocs, |
| 61 | ffdc); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | REGISTER_EXTENSION_FUNCTION(pelCreate); |
| 65 | |
| 66 | void pelDelete(uint32_t id) |
| 67 | { |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 68 | return manager->erase(id); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | REGISTER_EXTENSION_FUNCTION(pelDelete); |
| 72 | |
| 73 | void pelDeleteProhibited(uint32_t id, bool& prohibited) |
| 74 | { |
Matt Spinler | 4e8078c | 2019-07-09 13:22:32 -0500 | [diff] [blame] | 75 | prohibited = manager->isDeleteProhibited(id); |
Matt Spinler | 99c2b40 | 2019-05-23 14:29:16 -0500 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | REGISTER_EXTENSION_FUNCTION(pelDeleteProhibited); |
| 79 | |
| 80 | } // namespace pels |
| 81 | } // namespace openpower |