xref: /openbmc/openpower-proc-control/proc_control.cpp (revision 597e05c9cdd6c5dc767ec0b811e842bb48bda948)
1 /**
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>
20 #include "p9_procedures.hpp"
21 
22 constexpr auto procedures =
23 {
24     std::make_tuple("startHost", openpower::p9::startHost),
25     std::make_tuple("vcsWorkaround", openpower::p9::vcsWorkaround)
26 };
27 
28 void usage(char** argv)
29 {
30     std::cerr << "Usage: " << argv[0] << " [action]\n";
31     std::cerr << "   actions:\n";
32 
33     for (const auto& p : procedures)
34     {
35         std::cerr << "     " << std::get<0>(p) << "\n";
36     }
37 }
38 
39 int main(int argc, char** argv)
40 {
41     if (argc != 2)
42     {
43         usage(argv);
44         return -1;
45     }
46 
47     std::string action{argv[1]};
48 
49     auto finder = [&action](const auto& p)
50     {
51         return std::get<0>(p) == action;
52     };
53     auto procedure = std::find_if(procedures.begin(), procedures.end(), finder);
54 
55     if (procedure == procedures.end())
56     {
57         usage(argv);
58         return -1;
59     }
60 
61     auto function = std::get<1>(*procedure);
62     try
63     {
64         function();
65     }
66     catch (std::exception& e)
67     {
68         //TODO: commit an actual error that does a callout
69         phosphor::logging::log<phosphor::logging::level::ERR>(e.what());
70         return -1;
71     }
72 
73     return 0;
74 }
75