82 int main(
int argc,
char * argv[])
85 cout <<
"plugin_tool - A command line tool for pluginlib testing" << endl;
86 cout <<
"-------------------------------------------------------" << endl;
90 cout <<
"Error: Invalid arguments passed to plugin_tool." << endl;
94 cout <<
"Base class = " <<
baseClass() << endl;
95 cout <<
"Package name = " <<
packageName() << endl << endl;
106 FILE * pipe = popen(cmd,
"r");
111 std::string result =
"";
112 while (!feof(pipe)) {
113 if (fgets(buffer, 128, pipe) != NULL) {
131 cout <<
"Generating typed plugin interface cpp..." << endl;
133 cout <<
"***************************************************" << endl;
134 cout << code << endl;
135 cout <<
"***************************************************" << endl;
140 cout <<
"Building interface shared object..." << endl;
145 cout <<
"Command 1 = " << cmd1 << endl;
146 cout <<
"Command 2 = " << cmd2 << endl;
148 if (-1 == system(cmd1.c_str())) {
149 cout <<
"Error: Failed to compile interface." << endl;
152 cout <<
"Interface compiled to an object file, attempting to build..." << endl;
153 if (-1 == system(cmd2.c_str())) {
154 cout <<
"Error: Failed to build shared object." << endl;
157 cout <<
"Build of shared object succeeded." << endl;
161 cout <<
"Loading shared object into memory." << endl;
164 cout <<
"Shared object successfully loaded into memory." << endl;
166 cout <<
"Error: Failed to load shared object into memory." << endl;
189 file.open(filename.c_str());
199 assert(allVals.size() > 0);
200 return allVals.at(0);
208 file.open(path.c_str());
210 cout <<
"Error: Cannot find file " + path +
" to generate class loader";
215 while (!file.eof()) {
218 contents.push_back(c);
229 string class_with_type_set;
230 for (
unsigned int c = 0; c < class_template.size(); c++) {
231 if (
'$' == class_template.at(c)) {
233 }
else if (
'@' == class_template.at(c)) {
236 class_with_type_set.push_back(class_template.at(c));
239 return class_with_type_set;
246 typedef std::string (* WhereIsFunc)(
const string &,
const string &);
247 WhereIsFunc
f = getPluginFunction<WhereIsFunc>(
"whereIsPluginLocated");
249 cout <<
"Attempting to find plugin " <<
pluginName() <<
" exported from package " <<
\ 253 cout <<
"Plugin " <<
pluginName() <<
" is located in library " << \
256 cout <<
"Error: Could not find function 'whereIsPluginLocated' in shared object." << endl;
265 typedef std::vector<std::string>(*ListFunc)(
const string &);
266 ListFunc
f = getPluginFunction<ListFunc>(
"availablePlugins");
268 cout <<
"The following plugins are available in package " <<
packageName() <<
":" << endl;
270 std::vector<std::string> plugins = f(
packageName());
271 for (
unsigned int c = 0; c < plugins.size(); c++) {
272 cout << plugins.at(c) << endl;
275 cout <<
"Error: Could not find function 'availablePlugins' in shared object." << endl;
284 typedef bool (* LoadPluginFunc)(
const string &,
const string &);
285 LoadPluginFunc
f = getPluginFunction<LoadPluginFunc>(
"loadPlugin");
287 cout <<
"Attempting to find plugin " << plugin_name <<
"..." << endl;
290 cout <<
"Opened plugin successfully :)" << endl;
292 cout <<
"Error: Plugin did not open :(" << endl;
296 cout <<
"Error: Could not find function 'loadPlugin' in shared object." << endl;
305 vector<string> parse_result;
306 for (
unsigned int c = 0; c < newline_delimited_str.size(); c++) {
307 char ch = newline_delimited_str.at(c);
309 parse_result.push_back(next);
323 if (
"find" == verb) {
325 }
else if (
"list" == verb) {
327 }
else if (
"load" == verb) {
330 cout <<
"Error: Unknown verb for plugin_tool, available verbs are" <<
331 "'load', 'list', and 'find'." << endl;
339 for (
int c = 0; c < argc; c++) {
348 for (
unsigned int c = 0; c < s.size(); c++) {
349 if (s.at(c) !=
'\n') {
350 stripped.push_back(s.at(c));
361 if (args.size() < 5) {
362 cout <<
"Not enough arguments. Usage: plugin_tool <BASE CLASS> <BASE_CLASS_HEADER> " << \
363 "<PACKAGE_NAME> <find [class_name] | list | load [class_name]>";
367 for (
size_t c = 0; c < args.size(); c++) {
368 cout <<
"Arg " << c <<
": " << args.at(c) << endl;