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
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#include <uxr/agent/utils/CLI.hpp>
|
#include <uxr/agent/AgentInstance.hpp>
|
||||||
#include <csignal>
|
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
#ifndef _WIN32
|
eprosima::uxr::AgentInstance& xrce_dds_agent_instance =
|
||||||
sigset_t signals;
|
xrce_dds_agent_instance.getInstance();
|
||||||
sigemptyset(&signals);
|
|
||||||
if(sigaddset(&signals, SIGINT) && sigaddset(&signals, SIGTERM))
|
if (!xrce_dds_agent_instance.create(argc, argv))
|
||||||
{
|
{
|
||||||
std::cerr << "Wrong signalset" << std::endl;
|
return 1;
|
||||||
std::exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
sigprocmask( SIG_BLOCK, &signals, nullptr );
|
xrce_dds_agent_instance.run();
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/* 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)
|
|
||||||
{
|
|
||||||
cli_input.append(argv[i]);
|
|
||||||
cli_input.append(" ");
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user