24 #ifndef GOBY_MIDDLEWARE_APPLICATION_TOOL_H
25 #define GOBY_MIDDLEWARE_APPLICATION_TOOL_H
27 #include <google/protobuf/descriptor.h>
42 const google::protobuf::EnumDescriptor* action_enum_desc)
43 : name_(name), tool_cfg_(tool_cfg), action_enum_desc_(action_enum_desc)
51 bool help(
int* action_for_help);
53 template <
typename App,
57 template <
typename App,
59 void help(
int action_for_help);
62 void exec_external(std::string app, std::vector<std::string> args,
64 template <
typename App,
typename Configurator>
65 void exec_internal(std::string app, std::vector<std::string> args);
71 const google::protobuf::EnumDescriptor* action_enum_desc_;
79 for (
const auto& lib : load_libs) load_lib(lib);
84 for (
const auto& lib : load_libs) load_lib(lib);
91 void load_lib(
const std::string& lib);
94 std::vector<void*> dl_handles_;
102 const google::protobuf::EnumValueDescriptor* value_desc =
103 action_enum_desc_->FindValueByNumber(action);
106 action_ = value_desc->name();
111 std::vector<std::string> args;
112 for (
const auto& cli_extra : tool_cfg_.
extra_cli_param()) args.push_back(cli_extra);
113 exec_external(external_command, args, ev_options);
118 template <
typename App,
typename Configurator>
119 void goby::middleware::ToolHelper::exec_internal(std::string app, std::vector<std::string> args)
121 std::vector<std::string> bin_args;
122 bin_args.push_back(
"--binary=" + name_ +
" " + action_);
124 std::vector<char*> c_args;
125 c_args.push_back(
const_cast<char*
>(app.c_str()));
126 for (
const auto& arg : bin_args) { c_args.push_back(
const_cast<char*
>(arg.c_str())); }
127 for (
const auto& arg : args) { c_args.push_back(
const_cast<char*
>(arg.c_str())); }
128 goby::run<App>(Configurator(c_args.size(), c_args.data()));
134 std::vector<std::string> args;
135 for (
const auto& cli_extra : tool_cfg_.extra_cli_param()) args.push_back(cli_extra);
136 exec_internal<App, Configurator>(name_, args);
139 template <
typename App,
typename Configurator>
143 const google::protobuf::EnumValueDescriptor* help_action_value_desc =
144 action_enum_desc_->FindValueByNumber(action_for_help);
147 help_action_value_desc->options().GetExtension(
goby::ev);
149 action_ = help_action_value_desc->name();
151 std::vector<std::string> args;
152 if (tool_cfg_.extra_cli_param_size() > 1)
154 for (
int i = 0, n = tool_cfg_.extra_cli_param_size() - 1; i < n; ++i)
155 args.push_back(tool_cfg_.extra_cli_param(i));
162 exec_internal<App, Configurator>(name_, args);