tool: Refactor base type Commands
Each command will be implemented as a CLI subcommand
command handers registration process:
CLI::App app;
auto base = app.add_subcommand("base");
auto GetPLDMVersion = base->add_subcommand("GetPLDMVersion");
/* register callback for GetPLDMVersion Command */
GetPLDMVersion->callback(exec());
CLI11_PARSER();
Each command will be implemented as a class. To avoid duplicate,
An interface class is abstracted as the base class for commands.
CommandInterface
{
CommandInterface(CLI::App* app){
app->callback([&](){exec();}) //register exec() to CLI11
}
virtual createRequestMsg();
virtual parseResponseMsg();
exec(){
createRequestMsg();
send_recv();
parseResponseMsg();
}
};
GetPLDMVersion : public CommandInterface
{
GetPLDMVersion(CLI::App *app){
app->add_option(); // add options for this command
}
...
}
Then, the main is like below:
int main()
{
CLI::App app{"PLDM requester tool for OpenBMC"};
auto base = app.add_subcommand("base");
auto version = base->add_subcommand("GetPLDMVersion");
GetPLDMVersion getPLDMVersion(version);
CLI11_PARSE(app, argc, argv);
}
Tested:
root@fp5280g2:~# pldmtool base GetPLDMTypes
Encode request successfully
Request Message:
08 01 80 00 04
Success in creating the socket : RC = 3
Success in connecting to socket : RC = 0
Success in sending message type as pldm to mctp : RC = 0
Write to socket successful : RC = 5
Total length:5
Loopback response message:
08 01 80 00 04
On first recv(),response == request : RC = 0
Total length: 14
Shutdown Socket successful : RC = 0
Response Message:
08 01 00 00 04 00 0d 00 00 00 00 00 00 00
Supported types: 0(base) 2(platform) 3(bios)
root@fp5280g2:~# pldmtool base GetPLDMVersion -t platform
Encode request successfully
Request Message:
08 01 80 00 03 00 00 00 00 01 02
Success in creating the socket : RC = 3
Success in connecting to socket : RC = 0
Success in sending message type as pldm to mctp : RC = 0
Write to socket successful : RC = 11
Total length:11
Loopback response message:
08 01 80 00 03 00 00 00 00 01 02
On first recv(),response == request : RC = 0
Total length: 15
Shutdown Socket successful : RC = 0
Response Message:
08 01 00 00 03 00 00 00 00 00 05 f1 f1 f1 00
Type 2(platform): 1.1.1
root@fp5280g2:~# pldmtool raw -d 0x80 0x00 0x04
Encode request successfully
Request Message:
08 01 80 00 04
Success in creating the socket : RC = 3
Success in connecting to socket : RC = 0
Success in sending message type as pldm to mctp : RC = 0
Write to socket successful : RC = 5
Total length:5
Loopback response message:
08 01 80 00 04
On first recv(),response == request : RC = 0
Total length: 14
Shutdown Socket successful : RC = 0
Response Message:
08 01 00 00 04 00 0d 00 00 00 00 00 00 00
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: I658b2c8094e9e5d972d786b26f9f8d52bc011981
diff --git a/tool/pldm_base_cmd.hpp b/tool/pldm_base_cmd.hpp
index d709ede..b465963 100644
--- a/tool/pldm_base_cmd.hpp
+++ b/tool/pldm_base_cmd.hpp
@@ -1,37 +1,14 @@
#pragma once
-#ifndef PLDM_BASE_CMD_H
-#define PLDM_BASE_CMD_H
+#include <CLI/CLI.hpp>
-#include "pldm_cmd_helper.hpp"
+namespace pldmtool
+{
-/** @brief Handler for GetPLDMTypes command
- *
- * @param[in] args - Argument to be passed to the handler.
- * Optional argument.
- *
- * @return - None
- */
-void getPLDMTypes(std::vector<std::string>&& args);
+namespace base
+{
-/** @brief Handler for GetPLDMVersion command
- *
- *
- * @param[in] args - Argument to be passed to the handler
- * e.g : PLDM Command Type : base, bios etc.
- *
- * @return - None
- */
-void getPLDMVersion(std::vector<std::string>&& args);
+void registerCommand(CLI::App& app);
+}
-/** @brief Handler for Raw PLDM commands
- *
- *
- * @param[in] args - Argument to be passed to the handler
- * e.g : PLDM raw commands.
- *
- * @return - None
- */
-void handleRawOp(std::vector<std::string>&& args);
-
-#endif /* PLDM_BASE_CMD_H */
+} // namespace pldmtool
\ No newline at end of file