1 /** 2 * Copyright (C) 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 "registration.hpp" 17 18 #include <algorithm> 19 #include <functional> 20 #include <iostream> 21 #include <org/open_power/Proc/FSI/error.hpp> 22 #include <phosphor-logging/elog-errors.hpp> 23 #include <phosphor-logging/elog.hpp> 24 #include <phosphor-logging/log.hpp> 25 #include <xyz/openbmc_project/Common/Device/error.hpp> 26 #include <xyz/openbmc_project/Common/File/error.hpp> 27 #include <xyz/openbmc_project/Common/error.hpp> 28 29 using namespace openpower::util; 30 namespace common_error = sdbusplus::xyz::openbmc_project::Common::Error; 31 namespace device_error = sdbusplus::xyz::openbmc_project::Common::Device::Error; 32 namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error; 33 namespace fsi_error = sdbusplus::org::open_power::Proc::FSI::Error; 34 35 void usage(char** argv, const ProcedureMap& procedures) 36 { 37 std::cerr << "Usage: " << argv[0] << " [action]\n"; 38 std::cerr << " actions:\n"; 39 40 for (const auto& p : procedures) 41 { 42 std::cerr << " " << p.first << "\n"; 43 } 44 } 45 46 int main(int argc, char** argv) 47 { 48 using namespace phosphor::logging; 49 const ProcedureMap& procedures = Registration::getProcedures(); 50 51 if (argc != 2) 52 { 53 usage(argv, procedures); 54 return -1; 55 } 56 57 std::string action{argv[1]}; 58 59 auto procedure = procedures.find(action); 60 61 if (procedure == procedures.end()) 62 { 63 usage(argv, procedures); 64 return -1; 65 } 66 67 try 68 { 69 procedure->second(); 70 } 71 catch (file_error::Seek& e) 72 { 73 commit<file_error::Seek>(); 74 return -1; 75 } 76 catch (file_error::Open& e) 77 { 78 commit<file_error::Open>(); 79 return -1; 80 } 81 catch (device_error::WriteFailure& e) 82 { 83 commit<device_error::WriteFailure>(); 84 return -1; 85 } 86 catch (device_error::ReadFailure& e) 87 { 88 commit<device_error::ReadFailure>(); 89 return -1; 90 } 91 catch (common_error::InvalidArgument& e) 92 { 93 commit<common_error::InvalidArgument>(); 94 return -1; 95 } 96 catch (fsi_error::MasterDetectionFailure& e) 97 { 98 commit<fsi_error::MasterDetectionFailure>(); 99 return -1; 100 } 101 catch (fsi_error::SlaveDetectionFailure& e) 102 { 103 commit<fsi_error::SlaveDetectionFailure>(); 104 return -1; 105 } 106 107 return 0; 108 } 109