mvsim-cli
mvsim-cli-node.cpp
Go to the documentation of this file.
1
/*+-------------------------------------------------------------------------+
2
| MultiVehicle simulator (libmvsim) |
3
| |
4
| Copyright (C) 2014-2023 Jose Luis Blanco Claraco |
5
| Copyright (C) 2017 Borys Tymchenko (Odessa Polytechnic University) |
6
| Distributed under 3-clause BSD License |
7
| See COPYING |
8
+-------------------------------------------------------------------------+ */
9
10
#include <
mvsim/Comms/Client.h
>
11
12
#include "
mvsim-cli.h
"
13
14
static
int
printCommandsNode
(
bool
showErrorMsg);
15
static
int
nodeList
();
16
17
const
std::map<std::string, cmd_t>
cliNodeCommands
= {
18
{
"list"
,
cmd_t
(&
nodeList
)},
19
};
20
21
int
commandNode
()
22
{
23
const
auto
& lstCmds =
cli
->argCmd.getValue();
24
if
(
cli
->argHelp.isSet())
return
printCommandsNode
(
false
);
25
if
(lstCmds.size() != 2)
return
printCommandsNode
(
true
);
26
27
// Take second unlabeled argument:
28
const
std::string subcommand = lstCmds.at(1);
29
auto
itSubcmd =
cliNodeCommands
.find(subcommand);
30
31
if
(itSubcmd ==
cliNodeCommands
.end())
return
printCommandsNode
(
true
);
32
33
// Execute command:
34
return
(itSubcmd->second)();
35
}
36
37
int
nodeList
()
38
{
39
mvsim::Client
client
;
40
41
client.setMinLoggingLevel(
42
mrpt::typemeta::TEnumType<mrpt::system::VerbosityLevel>::name2value(
43
cli
->argVerbosity.getValue()));
44
45
std::cout <<
"# Connecting to server...\n"
;
46
client.
connect
();
47
std::cout <<
"# Connected.\n"
;
48
std::cout <<
"# Querying list of nodes to server...\n"
;
49
const
auto
lstNodes = client.
requestListOfNodes
();
50
51
std::cout <<
"# Done. Found "
<< lstNodes.size() <<
" nodes:\n"
;
52
53
for
(
const
auto
& n : lstNodes)
54
{
55
std::cout <<
"- name: \""
<< n.name <<
"\"\n"
;
56
}
57
58
return
0;
59
}
60
61
int
printCommandsNode
(
bool
showErrorMsg)
62
{
63
if
(showErrorMsg)
64
{
65
setConsoleErrorColor
();
66
std::cerr <<
"Error: missing or unknown subcommand.\n"
;
67
setConsoleNormalColor
();
68
}
69
70
fprintf(
71
stderr,
72
R
"XXX(Usage:
73
74
mvsim node --help Show this help
75
mvsim node list List all nodes connected to the server.
76
77
)XXX");
78
79
return
showErrorMsg ? 1 : 0;
80
}
commandNode
int commandNode()
Definition:
mvsim-cli-node.cpp:21
Client.h
mvsim::Client
Definition:
Client.h:48
cmd_t
std::function< int(void)> cmd_t
Definition:
mvsim-cli.h:74
call-shutdown.client
client
Definition:
call-shutdown.py:26
printCommandsNode
static int printCommandsNode(bool showErrorMsg)
Definition:
mvsim-cli-node.cpp:61
mvsim::Client::requestListOfNodes
std::vector< InfoPerNode > requestListOfNodes()
Definition:
src/Comms/Client.cpp:302
setConsoleErrorColor
void setConsoleErrorColor()
Definition:
mvsim-cli-main.cpp:34
cliNodeCommands
const std::map< std::string, cmd_t > cliNodeCommands
Definition:
mvsim-cli-node.cpp:17
nodeList
static int nodeList()
Definition:
mvsim-cli-node.cpp:37
cli
std::unique_ptr< cli_flags > cli
Definition:
mvsim-cli-main.cpp:24
setConsoleNormalColor
void setConsoleNormalColor()
Definition:
mvsim-cli-main.cpp:44
mvsim-cli.h
mvsim::Client::connect
void connect()
Definition:
src/Comms/Client.cpp:139
mvsim
Author(s):
autogenerated on Tue Jul 4 2023 03:08:21