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