Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2017 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 <algorithm> |
| 17 | #include <functional> |
| 18 | #include <iostream> |
| 19 | #include <phosphor-logging/log.hpp> |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 20 | #include <phosphor-logging/elog.hpp> |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 21 | #include "registration.hpp" |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 22 | #include "elog-errors.hpp" |
Dhruvaraj Subhashchandran | 7ce535c | 2017-05-15 05:06:36 -0500 | [diff] [blame] | 23 | #include <xyz/openbmc_project/Common/error.hpp> |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 24 | |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 25 | using namespace openpower::util; |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 26 | |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 27 | void usage(char** argv, const ProcedureMap& procedures) |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 28 | { |
| 29 | std::cerr << "Usage: " << argv[0] << " [action]\n"; |
| 30 | std::cerr << " actions:\n"; |
| 31 | |
| 32 | for (const auto& p : procedures) |
| 33 | { |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 34 | std::cerr << " " << p.first << "\n"; |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 35 | } |
| 36 | } |
| 37 | |
| 38 | int main(int argc, char** argv) |
| 39 | { |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 40 | using namespace phosphor::logging; |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 41 | const ProcedureMap& procedures = Registration::getProcedures(); |
| 42 | |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 43 | if (argc != 2) |
| 44 | { |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 45 | usage(argv, procedures); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 46 | return -1; |
| 47 | } |
| 48 | |
| 49 | std::string action{argv[1]}; |
| 50 | |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 51 | auto procedure = procedures.find(action); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 52 | |
| 53 | if (procedure == procedures.end()) |
| 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 | |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 59 | try |
| 60 | { |
Matt Spinler | d9bdcf7 | 2017-03-09 15:06:23 -0600 | [diff] [blame] | 61 | procedure->second(); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 62 | } |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 63 | catch (org::open_power::Proc::CFAM::SeekFailure& e) |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 64 | { |
Dhruvaraj Subhashchandran | 18b0786 | 2017-04-26 07:13:35 -0500 | [diff] [blame] | 65 | commit<org::open_power::Proc::CFAM::SeekFailure>(); |
| 66 | return -1; |
| 67 | } |
| 68 | catch (org::open_power::Proc::CFAM::OpenFailure& e) |
| 69 | { |
| 70 | commit<org::open_power::Proc::CFAM::OpenFailure>(); |
| 71 | return -1; |
| 72 | } |
| 73 | catch (org::open_power::Proc::CFAM::WriteFailure& e) |
| 74 | { |
| 75 | commit<org::open_power::Proc::CFAM::WriteFailure>(); |
| 76 | return -1; |
| 77 | } |
| 78 | catch (org::open_power::Proc::CFAM::ReadFailure& e) |
| 79 | { |
| 80 | commit<org::open_power::Proc::CFAM::ReadFailure>(); |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 81 | return -1; |
| 82 | } |
Dhruvaraj Subhashchandran | 7ce535c | 2017-05-15 05:06:36 -0500 | [diff] [blame] | 83 | catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e) |
| 84 | { |
| 85 | commit<sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument>(); |
| 86 | return -1; |
| 87 | } |
Matt Spinler | f716f32 | 2017-02-28 09:37:38 -0600 | [diff] [blame] | 88 | |
| 89 | return 0; |
| 90 | } |