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 int 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);
90 void load_lib(
const std::string& lib);
98 const google::protobuf::EnumValueDescriptor* value_desc =
99 action_enum_desc_->FindValueByNumber(action);
102 action_ = value_desc->name();
107 std::vector<std::string> args;
108 for (
const auto& cli_extra : tool_cfg_.
extra_cli_param()) args.push_back(cli_extra);
109 exec_external(external_command, args, ev_options);
114template <
typename App,
typename Configurator>
115int goby::middleware::ToolHelper::exec_internal(std::string app, std::vector<std::string> args)
117 std::vector<std::string> bin_args;
118 bin_args.push_back(
"--binary=" + name_ +
" " + action_);
120 std::vector<char*> c_args;
121 c_args.push_back(
const_cast<char*
>(app.c_str()));
122 for (
const auto& arg : bin_args) { c_args.push_back(
const_cast<char*
>(arg.c_str())); }
123 for (
const auto& arg : args) { c_args.push_back(
const_cast<char*
>(arg.c_str())); }
124 return goby::run<App>(Configurator(c_args.size(), c_args.data()));
129 std::vector<std::string> args;
130 for (
const auto& cli_extra : tool_cfg_.extra_cli_param()) args.push_back(cli_extra);
131 return exec_internal<App, Configurator>(name_, args);
134template <
typename App,
typename Configurator>
138 const google::protobuf::EnumValueDescriptor* help_action_value_desc =
139 action_enum_desc_->FindValueByNumber(action_for_help);
142 help_action_value_desc->options().GetExtension(
goby::ev);
144 action_ = help_action_value_desc->name();
146 std::vector<std::string> args;
147 if (tool_cfg_.extra_cli_param_size() > 1)
149 for (
int i = 0, n = tool_cfg_.extra_cli_param_size() - 1; i < n; ++i)
150 args.push_back(tool_cfg_.extra_cli_param(i));
157 exec_internal<App, Configurator>(name_, args);
const std::string & external_command() const
const std::string & external_help_param() const
bool has_external_command() const
const ::goby::GobyEnumValueOptions_ConfigurationOptions & cfg() const
Implementation of ConfiguratorInterface for Google Protocol buffers.
The global namespace for the Goby project.
extern ::PROTOBUF_NAMESPACE_ID::internal::ExtensionIdentifier< ::PROTOBUF_NAMESPACE_ID::EnumValueOptions, ::PROTOBUF_NAMESPACE_ID::internal::MessageTypeTraits< ::goby::GobyEnumValueOptions >, 11, false > ev