Skip to content

Commit 8bbe143

Browse files
authored
Refactor micro-ROS-Agent to use new singleton class (#34)
1 parent 8131610 commit 8bbe143

File tree

1 file changed

+6
-64
lines changed

1 file changed

+6
-64
lines changed

micro_ros_agent/src/main.cpp

Lines changed: 6 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -12,76 +12,18 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
#include <uxr/agent/utils/CLI.hpp>
16-
#include <csignal>
15+
#include <uxr/agent/AgentInstance.hpp>
1716

1817
int main(int argc, char** argv)
1918
{
20-
#ifndef _WIN32
21-
sigset_t signals;
22-
sigemptyset(&signals);
23-
if(sigaddset(&signals, SIGINT) && sigaddset(&signals, SIGTERM))
24-
{
25-
std::cerr << "Wrong signalset" << std::endl;
26-
std::exit(EXIT_FAILURE);
27-
}
28-
sigprocmask( SIG_BLOCK, &signals, nullptr );
29-
#endif
30-
31-
32-
/* CLI application. */
33-
CLI::App app("micro-ROS Agent");
34-
app.require_subcommand(1, 1);
35-
app.get_formatter()->column_width(42);
36-
37-
/* CLI subcommands. */
38-
eprosima::uxr::cli::UDPv4Subcommand udpv4_subcommand(app);
39-
eprosima::uxr::cli::UDPv6Subcommand udpv6_subcommand(app);
40-
eprosima::uxr::cli::TCPv4Subcommand tcpv4_subcommand(app);
41-
eprosima::uxr::cli::TCPv6Subcommand tcpv6_subcommand(app);
42-
#ifndef _WIN32
43-
eprosima::uxr::cli::TermiosSubcommand serial_subcommand(app);
44-
eprosima::uxr::cli::PseudoTerminalSubcommand pseudo_serial_subcommand(app);
45-
#endif
46-
eprosima::uxr::cli::ExitSubcommand exit_subcommand(app);
19+
eprosima::uxr::AgentInstance& xrce_dds_agent_instance =
20+
xrce_dds_agent_instance.getInstance();
4721

48-
/* CLI parse. */
49-
std::string cli_input{};
50-
for (int i = 1; i < argc; ++i)
22+
if (!xrce_dds_agent_instance.create(argc, argv))
5123
{
52-
cli_input.append(argv[i]);
53-
cli_input.append(" ");
24+
return 1;
5425
}
26+
xrce_dds_agent_instance.run();
5527

56-
while (true)
57-
{
58-
try
59-
{
60-
app.parse(cli_input);
61-
break;
62-
}
63-
catch (const CLI::ParseError& e)
64-
{
65-
app.exit(e);
66-
std::cin.clear();
67-
std::cout << std::endl;
68-
std::cout << "Enter command: ";
69-
std::getline(std::cin, cli_input);
70-
}
71-
}
72-
73-
#ifdef _WIN32
74-
/* Waiting until exit. */
75-
std::cin.clear();
76-
char exit_flag = 0;
77-
while ('q' != exit_flag)
78-
{
79-
std::cin >> exit_flag;
80-
}
81-
#else
82-
/* Wait for SIGTERM/SIGINT instead, as reading from stdin may be redirected to /dev/null. */
83-
int n_signal = 0;
84-
sigwait(&signals, &n_signal);
85-
#endif
8628
return 0;
8729
}

0 commit comments

Comments
 (0)