blob: aceb6d6afa1f214db17230bb0b17d7d8d549cdfc [file] [log] [blame]
Matt Spinlerf716f322017-02-28 09:37:38 -06001/**
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 Subhashchandran18b07862017-04-26 07:13:35 -050020#include <phosphor-logging/elog.hpp>
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060021#include "registration.hpp"
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050022#include "elog-errors.hpp"
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050023#include <xyz/openbmc_project/Common/error.hpp>
Matt Spinlerf716f322017-02-28 09:37:38 -060024
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060025using namespace openpower::util;
Matt Spinlerf716f322017-02-28 09:37:38 -060026
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060027void usage(char** argv, const ProcedureMap& procedures)
Matt Spinlerf716f322017-02-28 09:37:38 -060028{
29 std::cerr << "Usage: " << argv[0] << " [action]\n";
30 std::cerr << " actions:\n";
31
32 for (const auto& p : procedures)
33 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060034 std::cerr << " " << p.first << "\n";
Matt Spinlerf716f322017-02-28 09:37:38 -060035 }
36}
37
38int main(int argc, char** argv)
39{
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050040 using namespace phosphor::logging;
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060041 const ProcedureMap& procedures = Registration::getProcedures();
42
Matt Spinlerf716f322017-02-28 09:37:38 -060043 if (argc != 2)
44 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060045 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060046 return -1;
47 }
48
49 std::string action{argv[1]};
50
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060051 auto procedure = procedures.find(action);
Matt Spinlerf716f322017-02-28 09:37:38 -060052
53 if (procedure == procedures.end())
54 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060055 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060056 return -1;
57 }
58
Matt Spinlerf716f322017-02-28 09:37:38 -060059 try
60 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060061 procedure->second();
Matt Spinlerf716f322017-02-28 09:37:38 -060062 }
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050063 catch (org::open_power::Proc::CFAM::SeekFailure& e)
Matt Spinlerf716f322017-02-28 09:37:38 -060064 {
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050065 commit<org::open_power::Proc::CFAM::SeekFailure>();
66 return -1;
67 }
68 catch (org::open_power::Proc::CFAM::OpenFailure& e)
69 {
70 commit<org::open_power::Proc::CFAM::OpenFailure>();
71 return -1;
72 }
73 catch (org::open_power::Proc::CFAM::WriteFailure& e)
74 {
75 commit<org::open_power::Proc::CFAM::WriteFailure>();
76 return -1;
77 }
78 catch (org::open_power::Proc::CFAM::ReadFailure& e)
79 {
80 commit<org::open_power::Proc::CFAM::ReadFailure>();
Matt Spinlerf716f322017-02-28 09:37:38 -060081 return -1;
82 }
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050083 catch (sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument& e)
84 {
85 commit<sdbusplus::xyz::openbmc_project::Common::Error::InvalidArgument>();
86 return -1;
87 }
Matt Spinlerf716f322017-02-28 09:37:38 -060088
89 return 0;
90}