Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 1 | /** |
Patrick Venture | e84b4dd | 2018-11-01 16:06:31 -0700 | [diff] [blame] | 2 | * Copyright (C) 2017 IBM Corporation |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 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 | */ |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 16 | #include "registration.hpp" |
| 17 | |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 18 | #include <org/open_power/Proc/FSI/error.hpp> |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 19 | #include <phosphor-logging/elog-errors.hpp> |
| 20 | #include <phosphor-logging/elog.hpp> |
| 21 | #include <phosphor-logging/log.hpp> |
Matt Spinler | a231ceb | 2017-10-04 11:26:09 -0500 | [diff] [blame] | 22 | #include <xyz/openbmc_project/Common/Device/error.hpp> |
| 23 | #include <xyz/openbmc_project/Common/File/error.hpp> |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 24 | #include <xyz/openbmc_project/Common/error.hpp> |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 25 | |
Brad Bishop | 5e5d445 | 2020-10-27 19:46:13 -0400 | [diff] [blame] | 26 | #include <algorithm> |
| 27 | #include <functional> |
| 28 | #include <iostream> |
| 29 | |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 30 | using namespace openpower::util; |
Lakshminarayana R. Kammath | 16ab00c | 2019-06-03 04:33:33 -0500 | [diff] [blame] | 31 | |
Patrick Venture | f78d904 | 2018-11-01 15:39:53 -0700 | [diff] [blame] | 32 | namespace common_error = sdbusplus::xyz::openbmc_project::Common::Error; |
| 33 | namespace device_error = sdbusplus::xyz::openbmc_project::Common::Device::Error; |
| 34 | namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error; |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 35 | namespace fsi_error = sdbusplus::org::open_power::Proc::FSI::Error; |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 36 | |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 37 | void usage(char** argv, const ProcedureMap& procedures) |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 38 | { |
| 39 | std::cerr << "Usage: " << argv[0] << " [action]\n"; |
| 40 | std::cerr << " actions:\n"; |
| 41 | |
| 42 | for (const auto& p : procedures) |
| 43 | { |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 44 | std::cerr << " " << p.first << "\n"; |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 45 | } |
| 46 | } |
| 47 | |
| 48 | int main(int argc, char** argv) |
| 49 | { |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 50 | using namespace phosphor::logging; |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 51 | const ProcedureMap& procedures = Registration::getProcedures(); |
| 52 | |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 53 | if (argc != 2) |
| 54 | { |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 55 | usage(argv, procedures); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 56 | return -1; |
| 57 | } |
| 58 | |
| 59 | std::string action{argv[1]}; |
| 60 | |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 61 | auto procedure = procedures.find(action); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 62 | |
| 63 | if (procedure == procedures.end()) |
| 64 | { |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 65 | usage(argv, procedures); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 66 | return -1; |
| 67 | } |
| 68 | |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 69 | try |
| 70 | { |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 71 | procedure->second(); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 72 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 73 | catch (const file_error::Seek& e) |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 74 | { |
Matt Spinler | a231ceb | 2017-10-04 11:26:09 -0500 | [diff] [blame] | 75 | commit<file_error::Seek>(); |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 76 | return -1; |
| 77 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 78 | catch (const file_error::Open& e) |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 79 | { |
Matt Spinler | a231ceb | 2017-10-04 11:26:09 -0500 | [diff] [blame] | 80 | commit<file_error::Open>(); |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 81 | return -1; |
| 82 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 83 | catch (const device_error::WriteFailure& e) |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 84 | { |
Matt Spinler | a231ceb | 2017-10-04 11:26:09 -0500 | [diff] [blame] | 85 | commit<device_error::WriteFailure>(); |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 86 | return -1; |
| 87 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 88 | catch (const device_error::ReadFailure& e) |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 89 | { |
Matt Spinler | a231ceb | 2017-10-04 11:26:09 -0500 | [diff] [blame] | 90 | commit<device_error::ReadFailure>(); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 91 | return -1; |
| 92 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 93 | catch (const common_error::InvalidArgument& e) |
Dhruvaraj Subhashchandran | 7ce535c | 2017-05-15 05:06:36 -0500 | [diff] [blame] | 94 | { |
Matt Spinler | a231ceb | 2017-10-04 11:26:09 -0500 | [diff] [blame] | 95 | commit<common_error::InvalidArgument>(); |
Dhruvaraj Subhashchandran | 7ce535c | 2017-05-15 05:06:36 -0500 | [diff] [blame] | 96 | return -1; |
| 97 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 98 | catch (const fsi_error::MasterDetectionFailure& e) |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 99 | { |
| 100 | commit<fsi_error::MasterDetectionFailure>(); |
| 101 | return -1; |
| 102 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 103 | catch (const fsi_error::SlaveDetectionFailure& e) |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 104 | { |
| 105 | commit<fsi_error::SlaveDetectionFailure>(); |
| 106 | return -1; |
| 107 | } |
Patrick Williams | 1a9a5a6 | 2021-10-06 13:05:06 -0500 | [diff] [blame] | 108 | catch (const std::exception& e) |
Ramesh Iyyar | b181d3b | 2019-10-17 13:39:10 -0500 | [diff] [blame] | 109 | { |
Marri Devender Rao | 7847960 | 2020-01-06 03:45:11 -0600 | [diff] [blame] | 110 | log<level::ERR>("exception raised", entry("EXCEPTION=%s", e.what())); |
Ramesh Iyyar | b181d3b | 2019-10-17 13:39:10 -0500 | [diff] [blame] | 111 | return -1; |
| 112 | } |
Matt Spinler | ee401e9 | 2017-09-18 14:15:31 -0500 | [diff] [blame] | 113 | |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 114 | return 0; |
| 115 | } |