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