blob: 3bdce8b68bc5d89825bb4becd5c2a7a9d8280856 [file] [log] [blame]
Matt Spinlerf716f322017-02-28 09:37:38 -06001/**
Patrick Venturee84b4dd2018-11-01 16:06:31 -07002 * Copyright (C) 2017 IBM Corporation
Matt Spinlerf716f322017-02-28 09:37:38 -06003 *
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 Venturef78d9042018-11-01 15:39:53 -070016#include "registration.hpp"
17
Matt Spinlerf716f322017-02-28 09:37:38 -060018#include <algorithm>
19#include <functional>
20#include <iostream>
Matt Spinleree401e92017-09-18 14:15:31 -050021#include <org/open_power/Proc/FSI/error.hpp>
Patrick Venturef78d9042018-11-01 15:39:53 -070022#include <phosphor-logging/elog-errors.hpp>
23#include <phosphor-logging/elog.hpp>
24#include <phosphor-logging/log.hpp>
Matt Spinlera231ceb2017-10-04 11:26:09 -050025#include <xyz/openbmc_project/Common/Device/error.hpp>
26#include <xyz/openbmc_project/Common/File/error.hpp>
Patrick Venturef78d9042018-11-01 15:39:53 -070027#include <xyz/openbmc_project/Common/error.hpp>
Matt Spinlerf716f322017-02-28 09:37:38 -060028
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060029using namespace openpower::util;
Lakshminarayana R. Kammath16ab00c2019-06-03 04:33:33 -050030
Patrick Venturef78d9042018-11-01 15:39:53 -070031namespace common_error = sdbusplus::xyz::openbmc_project::Common::Error;
32namespace device_error = sdbusplus::xyz::openbmc_project::Common::Device::Error;
33namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error;
Matt Spinleree401e92017-09-18 14:15:31 -050034namespace fsi_error = sdbusplus::org::open_power::Proc::FSI::Error;
Matt Spinlerf716f322017-02-28 09:37:38 -060035
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060036void usage(char** argv, const ProcedureMap& procedures)
Matt Spinlerf716f322017-02-28 09:37:38 -060037{
38 std::cerr << "Usage: " << argv[0] << " [action]\n";
39 std::cerr << " actions:\n";
40
41 for (const auto& p : procedures)
42 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060043 std::cerr << " " << p.first << "\n";
Matt Spinlerf716f322017-02-28 09:37:38 -060044 }
45}
46
47int main(int argc, char** argv)
48{
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050049 using namespace phosphor::logging;
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060050 const ProcedureMap& procedures = Registration::getProcedures();
51
Matt Spinlerf716f322017-02-28 09:37:38 -060052 if (argc != 2)
53 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060054 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060055 return -1;
56 }
57
58 std::string action{argv[1]};
59
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060060 auto procedure = procedures.find(action);
Matt Spinlerf716f322017-02-28 09:37:38 -060061
62 if (procedure == procedures.end())
63 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060064 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060065 return -1;
66 }
67
Matt Spinlerf716f322017-02-28 09:37:38 -060068 try
69 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060070 procedure->second();
Matt Spinlerf716f322017-02-28 09:37:38 -060071 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050072 catch (file_error::Seek& e)
Matt Spinlerf716f322017-02-28 09:37:38 -060073 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050074 commit<file_error::Seek>();
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050075 return -1;
76 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050077 catch (file_error::Open& e)
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050078 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050079 commit<file_error::Open>();
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050080 return -1;
81 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050082 catch (device_error::WriteFailure& e)
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050083 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050084 commit<device_error::WriteFailure>();
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050085 return -1;
86 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050087 catch (device_error::ReadFailure& e)
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050088 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050089 commit<device_error::ReadFailure>();
Matt Spinlerf716f322017-02-28 09:37:38 -060090 return -1;
91 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050092 catch (common_error::InvalidArgument& e)
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050093 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050094 commit<common_error::InvalidArgument>();
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050095 return -1;
96 }
Matt Spinleree401e92017-09-18 14:15:31 -050097 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 Rao78479602020-01-06 03:45:11 -0600107 catch (std::exception& e)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500108 {
Marri Devender Rao78479602020-01-06 03:45:11 -0600109 log<level::ERR>("exception raised", entry("EXCEPTION=%s", e.what()));
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500110 return -1;
111 }
Matt Spinleree401e92017-09-18 14:15:31 -0500112
Matt Spinlerf716f322017-02-28 09:37:38 -0600113 return 0;
114}