blob: eca78127d864531a9be216af139b260370cd032a [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 Spinleree401e92017-09-18 14:15:31 -050018#include <org/open_power/Proc/FSI/error.hpp>
Patrick Venturef78d9042018-11-01 15:39:53 -070019#include <phosphor-logging/elog-errors.hpp>
20#include <phosphor-logging/elog.hpp>
21#include <phosphor-logging/log.hpp>
Matt Spinlera231ceb2017-10-04 11:26:09 -050022#include <xyz/openbmc_project/Common/Device/error.hpp>
23#include <xyz/openbmc_project/Common/File/error.hpp>
Patrick Venturef78d9042018-11-01 15:39:53 -070024#include <xyz/openbmc_project/Common/error.hpp>
Matt Spinlerf716f322017-02-28 09:37:38 -060025
Brad Bishop5e5d4452020-10-27 19:46:13 -040026#include <algorithm>
27#include <functional>
28#include <iostream>
29
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060030using namespace openpower::util;
Lakshminarayana R. Kammath16ab00c2019-06-03 04:33:33 -050031
Patrick Venturef78d9042018-11-01 15:39:53 -070032namespace common_error = sdbusplus::xyz::openbmc_project::Common::Error;
33namespace device_error = sdbusplus::xyz::openbmc_project::Common::Device::Error;
34namespace file_error = sdbusplus::xyz::openbmc_project::Common::File::Error;
Matt Spinleree401e92017-09-18 14:15:31 -050035namespace fsi_error = sdbusplus::org::open_power::Proc::FSI::Error;
Matt Spinlerf716f322017-02-28 09:37:38 -060036
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060037void usage(char** argv, const ProcedureMap& procedures)
Matt Spinlerf716f322017-02-28 09:37:38 -060038{
39 std::cerr << "Usage: " << argv[0] << " [action]\n";
40 std::cerr << " actions:\n";
41
42 for (const auto& p : procedures)
43 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060044 std::cerr << " " << p.first << "\n";
Matt Spinlerf716f322017-02-28 09:37:38 -060045 }
46}
47
48int main(int argc, char** argv)
49{
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050050 using namespace phosphor::logging;
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060051 const ProcedureMap& procedures = Registration::getProcedures();
52
Matt Spinlerf716f322017-02-28 09:37:38 -060053 if (argc != 2)
54 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060055 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060056 return -1;
57 }
58
59 std::string action{argv[1]};
60
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060061 auto procedure = procedures.find(action);
Matt Spinlerf716f322017-02-28 09:37:38 -060062
63 if (procedure == procedures.end())
64 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060065 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060066 return -1;
67 }
68
Matt Spinlerf716f322017-02-28 09:37:38 -060069 try
70 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060071 procedure->second();
Matt Spinlerf716f322017-02-28 09:37:38 -060072 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050073 catch (file_error::Seek& e)
Matt Spinlerf716f322017-02-28 09:37:38 -060074 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050075 commit<file_error::Seek>();
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050076 return -1;
77 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050078 catch (file_error::Open& e)
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050079 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050080 commit<file_error::Open>();
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050081 return -1;
82 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050083 catch (device_error::WriteFailure& e)
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050084 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050085 commit<device_error::WriteFailure>();
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050086 return -1;
87 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050088 catch (device_error::ReadFailure& e)
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050089 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050090 commit<device_error::ReadFailure>();
Matt Spinlerf716f322017-02-28 09:37:38 -060091 return -1;
92 }
Matt Spinlera231ceb2017-10-04 11:26:09 -050093 catch (common_error::InvalidArgument& e)
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050094 {
Matt Spinlera231ceb2017-10-04 11:26:09 -050095 commit<common_error::InvalidArgument>();
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050096 return -1;
97 }
Matt Spinleree401e92017-09-18 14:15:31 -050098 catch (fsi_error::MasterDetectionFailure& e)
99 {
100 commit<fsi_error::MasterDetectionFailure>();
101 return -1;
102 }
103 catch (fsi_error::SlaveDetectionFailure& e)
104 {
105 commit<fsi_error::SlaveDetectionFailure>();
106 return -1;
107 }
Marri Devender Rao78479602020-01-06 03:45:11 -0600108 catch (std::exception& e)
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500109 {
Marri Devender Rao78479602020-01-06 03:45:11 -0600110 log<level::ERR>("exception raised", entry("EXCEPTION=%s", e.what()));
Ramesh Iyyarb181d3b2019-10-17 13:39:10 -0500111 return -1;
112 }
Matt Spinleree401e92017-09-18 14:15:31 -0500113
Matt Spinlerf716f322017-02-28 09:37:38 -0600114 return 0;
115}