2020-03-04 15:51:16 -05:00
|
|
|
/*
|
|
|
|
|
Copyright (c) 2020 - present Advanced Micro Devices, Inc. All rights reserved.
|
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include "rdc_lib/rdc_common.h"
|
|
|
|
|
#include "rdc/rdc.h"
|
2020-03-10 14:02:05 -04:00
|
|
|
#include "rdc_lib/RdcException.h"
|
2020-03-04 15:51:16 -05:00
|
|
|
#include "RdciDiscoverySubSystem.h"
|
2020-03-27 11:16:58 -04:00
|
|
|
#include "RdciDmonSubSystem.h"
|
2021-06-21 15:35:06 -04:00
|
|
|
#include "RdciDiagSubSystem.h"
|
2020-03-27 11:16:58 -04:00
|
|
|
#include "RdciFieldGroupSubSystem.h"
|
|
|
|
|
#include "RdciGroupSubSystem.h"
|
2020-04-21 09:48:14 -04:00
|
|
|
#include "RdciStatsSubSystem.h"
|
2020-03-04 15:51:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char ** argv) {
|
|
|
|
|
const std::string usage_help =
|
|
|
|
|
"Usage:\trdci <subsystem>\nsubsystem: discovery, dmon, group, "
|
2021-06-21 15:35:06 -04:00
|
|
|
"fieldgroup, stats, diag\n";
|
2020-03-04 15:51:16 -05:00
|
|
|
|
|
|
|
|
if (argc <= 1) {
|
|
|
|
|
std::cout << usage_help;
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-14 15:20:08 -04:00
|
|
|
amd::rdc::RdciSubSystemPtr subsystem;
|
2020-03-04 15:51:16 -05:00
|
|
|
try {
|
|
|
|
|
std::string subsystem_name = argv[1];
|
|
|
|
|
if (subsystem_name == "discovery") {
|
|
|
|
|
subsystem.reset(new amd::rdc::RdciDiscoverySubSystem());
|
2020-03-27 11:16:58 -04:00
|
|
|
} else if (subsystem_name == "dmon") {
|
|
|
|
|
subsystem.reset(new amd::rdc::RdciDmonSubSystem());
|
2021-06-21 15:35:06 -04:00
|
|
|
} else if (subsystem_name == "diag") {
|
|
|
|
|
subsystem.reset(new amd::rdc::RdciDiagSubSystem());
|
2020-03-27 11:16:58 -04:00
|
|
|
} else if (subsystem_name == "group") {
|
|
|
|
|
subsystem.reset(new amd::rdc::RdciGroupSubSystem());
|
|
|
|
|
} else if (subsystem_name == "fieldgroup") {
|
|
|
|
|
subsystem.reset(new amd::rdc::RdciFieldGroupSubSystem());
|
2020-04-21 09:48:14 -04:00
|
|
|
} else if (subsystem_name == "stats") {
|
|
|
|
|
subsystem.reset(new amd::rdc::RdciStatsSubSystem());
|
2020-03-04 15:51:16 -05:00
|
|
|
} else {
|
|
|
|
|
std::cout << usage_help;
|
|
|
|
|
exit(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
subsystem->parse_cmd_opts(argc, argv);
|
|
|
|
|
|
|
|
|
|
subsystem->connect();
|
|
|
|
|
|
|
|
|
|
subsystem->process();
|
|
|
|
|
} catch (const amd::rdc::RdcException& e) {
|
2020-07-14 15:20:08 -04:00
|
|
|
if (subsystem && subsystem->is_json_output()) {
|
|
|
|
|
std::cout << "\"status\": \"error\", \"description\": \""
|
|
|
|
|
<< e.what() << '"';
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "rdci Error: " << e.what() << std::endl;
|
|
|
|
|
}
|
2020-03-04 15:51:16 -05:00
|
|
|
return e.error_code();
|
|
|
|
|
} catch (...) {
|
2020-07-14 15:20:08 -04:00
|
|
|
if (subsystem && subsystem->is_json_output()) {
|
|
|
|
|
std::cout << "\"status\": \"error\", \"description\": "
|
|
|
|
|
<< "\"Unhandled exception.\"";
|
|
|
|
|
} else {
|
|
|
|
|
std::cout << "Unhandled exception." << std::endl;
|
|
|
|
|
} return 1;
|
2020-03-04 15:51:16 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|