mirror of
https://github.com/micro-ROS/micro-ROS-Agent.git
synced 2026-09-06 09:55:15 +02:00
Refactor micro-ROS-Agent to use new singleton class (#34)
This commit is contained in:
@@ -12,76 +12,18 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <uxr/agent/utils/CLI.hpp>
|
||||
#include <csignal>
|
||||
#include <uxr/agent/AgentInstance.hpp>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
sigset_t signals;
|
||||
sigemptyset(&signals);
|
||||
if(sigaddset(&signals, SIGINT) && sigaddset(&signals, SIGTERM))
|
||||
{
|
||||
std::cerr << "Wrong signalset" << std::endl;
|
||||
std::exit(EXIT_FAILURE);
|
||||
}
|
||||
sigprocmask( SIG_BLOCK, &signals, nullptr );
|
||||
#endif
|
||||
eprosima::uxr::AgentInstance& xrce_dds_agent_instance =
|
||||
xrce_dds_agent_instance.getInstance();
|
||||
|
||||
|
||||
/* CLI application. */
|
||||
CLI::App app("micro-ROS Agent");
|
||||
app.require_subcommand(1, 1);
|
||||
app.get_formatter()->column_width(42);
|
||||
|
||||
/* CLI subcommands. */
|
||||
eprosima::uxr::cli::UDPv4Subcommand udpv4_subcommand(app);
|
||||
eprosima::uxr::cli::UDPv6Subcommand udpv6_subcommand(app);
|
||||
eprosima::uxr::cli::TCPv4Subcommand tcpv4_subcommand(app);
|
||||
eprosima::uxr::cli::TCPv6Subcommand tcpv6_subcommand(app);
|
||||
#ifndef _WIN32
|
||||
eprosima::uxr::cli::TermiosSubcommand serial_subcommand(app);
|
||||
eprosima::uxr::cli::PseudoTerminalSubcommand pseudo_serial_subcommand(app);
|
||||
#endif
|
||||
eprosima::uxr::cli::ExitSubcommand exit_subcommand(app);
|
||||
|
||||
/* CLI parse. */
|
||||
std::string cli_input{};
|
||||
for (int i = 1; i < argc; ++i)
|
||||
if (!xrce_dds_agent_instance.create(argc, argv))
|
||||
{
|
||||
cli_input.append(argv[i]);
|
||||
cli_input.append(" ");
|
||||
return 1;
|
||||
}
|
||||
xrce_dds_agent_instance.run();
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
app.parse(cli_input);
|
||||
break;
|
||||
}
|
||||
catch (const CLI::ParseError& e)
|
||||
{
|
||||
app.exit(e);
|
||||
std::cin.clear();
|
||||
std::cout << std::endl;
|
||||
std::cout << "Enter command: ";
|
||||
std::getline(std::cin, cli_input);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
/* Waiting until exit. */
|
||||
std::cin.clear();
|
||||
char exit_flag = 0;
|
||||
while ('q' != exit_flag)
|
||||
{
|
||||
std::cin >> exit_flag;
|
||||
}
|
||||
#else
|
||||
/* Wait for SIGTERM/SIGINT instead, as reading from stdin may be redirected to /dev/null. */
|
||||
int n_signal = 0;
|
||||
sigwait(&signals, &n_signal);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user