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