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