blob: a86b35490a12f2292c9d8d2291c084934fa153e4 [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"
Matt Spinlerf716f322017-02-28 09:37:38 -060023
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060024using namespace openpower::util;
Matt Spinlerf716f322017-02-28 09:37:38 -060025
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060026void usage(char** argv, const ProcedureMap& procedures)
Matt Spinlerf716f322017-02-28 09:37:38 -060027{
28 std::cerr << "Usage: " << argv[0] << " [action]\n";
29 std::cerr << " actions:\n";
30
31 for (const auto& p : procedures)
32 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060033 std::cerr << " " << p.first << "\n";
Matt Spinlerf716f322017-02-28 09:37:38 -060034 }
35}
36
37int main(int argc, char** argv)
38{
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050039 using namespace phosphor::logging;
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060040 const ProcedureMap& procedures = Registration::getProcedures();
41
Matt Spinlerf716f322017-02-28 09:37:38 -060042 if (argc != 2)
43 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060044 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060045 return -1;
46 }
47
48 std::string action{argv[1]};
49
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060050 auto procedure = procedures.find(action);
Matt Spinlerf716f322017-02-28 09:37:38 -060051
52 if (procedure == procedures.end())
53 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060054 usage(argv, procedures);
Matt Spinlerf716f322017-02-28 09:37:38 -060055 return -1;
56 }
57
Matt Spinlerf716f322017-02-28 09:37:38 -060058 try
59 {
Matt Spinlerd9bdcf72017-03-09 15:06:23 -060060 procedure->second();
Matt Spinlerf716f322017-02-28 09:37:38 -060061 }
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050062 catch (org::open_power::Proc::CFAM::SeekFailure& e)
Matt Spinlerf716f322017-02-28 09:37:38 -060063 {
Dhruvaraj Subhashchandran18b07862017-04-26 07:13:35 -050064 commit<org::open_power::Proc::CFAM::SeekFailure>();
65 return -1;
66 }
67 catch (org::open_power::Proc::CFAM::OpenFailure& e)
68 {
69 commit<org::open_power::Proc::CFAM::OpenFailure>();
70 return -1;
71 }
72 catch (org::open_power::Proc::CFAM::WriteFailure& e)
73 {
74 commit<org::open_power::Proc::CFAM::WriteFailure>();
75 return -1;
76 }
77 catch (org::open_power::Proc::CFAM::ReadFailure& e)
78 {
79 commit<org::open_power::Proc::CFAM::ReadFailure>();
Matt Spinlerf716f322017-02-28 09:37:38 -060080 return -1;
81 }
82
83 return 0;
84}