test_abstract_interface.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2011,
3  * Olivier Stasse,
4  *
5  * CNRS
6  *
7  */
8 /* -------------------------------------------------------------------------- */
9 /* --- INCLUDES ------------------------------------------------------------- */
10 /* -------------------------------------------------------------------------- */
11 
12 #include <iostream>
13 
14 // POSIX.1-2001
15 #include <dlfcn.h>
16 
17 #include <boost/program_options.hpp>
18 #include <sot/core/debug.hh>
19 
20 #include "plugin.hh"
21 
22 using namespace std;
23 using namespace dynamicgraph::sot;
24 namespace po = boost::program_options;
25 
26 class PluginLoader {
27  protected:
29  po::variables_map vm_;
30  std::string dynamicLibraryName_;
31 
32  public:
35 
36  int parseOptions(int argc, char *argv[]) {
37  po::options_description desc("Allowed options");
38  desc.add_options()("help", "produce help message")(
39  "input-file", po::value<string>(), "library to load");
40 
41  po::store(po::parse_command_line(argc, argv, desc), vm_);
42  po::notify(vm_);
43 
44  if (vm_.count("help")) {
45  cout << desc << "\n";
46  return -1;
47  }
48  if (!vm_.count("input-file")) {
49  cout << "No filename specified\n";
50  return -1;
51  } else
52  dynamicLibraryName_ = vm_["input-file"].as<string>();
53 
54  Initialization();
55  return 0;
56  }
57 
58  void Initialization() {
59  // Load the SotRobotBipedController library.
60  void *SotRobotControllerLibrary =
61  dlopen("libpluginabstract.so", RTLD_LAZY | RTLD_LOCAL);
62  if (!SotRobotControllerLibrary) {
63  std::cerr << "Cannot load library: " << dlerror() << '\n';
64  return;
65  }
66 
67  // reset errors
68  dlerror();
69 
70  // Load the symbols.
72  (createPlugin_t *)dlsym(SotRobotControllerLibrary, "createPlugin");
73  const char *dlsym_error = dlerror();
74  if (dlsym_error) {
75  std::cerr << "Cannot load symbol create: " << dlsym_error << '\n';
76  return;
77  }
78 
79  // Create robot-controller
80  sotController_ = createPlugin();
81  // std::string s="libsot-hrp2-14-controller.so";
82  sotController_->Initialization(dynamicLibraryName_);
83  cout << "Went out from Initialization." << endl;
84  }
85 };
86 
87 int main(int argc, char *argv[]) {
88  PluginLoader aPluginLoader;
89  aPluginLoader.parseOptions(argc, argv);
90 }
PluginLoader::Initialization
void Initialization()
Definition: test_abstract_interface.cpp:58
PluginLoader::PluginLoader
PluginLoader()
Definition: test_abstract_interface.cpp:33
createPlugin_t
PluginAbstract * createPlugin_t()
Definition: plugin.hh:11
debug.hh
plugin.hh
main
int main(int argc, char *argv[])
Definition: test_abstract_interface.cpp:87
PluginLoader::sotController_
PluginAbstract * sotController_
Definition: test_abstract_interface.cpp:28
PluginLoader::parseOptions
int parseOptions(int argc, char *argv[])
Definition: test_abstract_interface.cpp:36
PluginLoader::dynamicLibraryName_
std::string dynamicLibraryName_
Definition: test_abstract_interface.cpp:30
PluginLoader
Definition: test_abstract_interface.cpp:26
PluginLoader::vm_
po::variables_map vm_
Definition: test_abstract_interface.cpp:29
dynamicgraph::sot
PluginAbstract::Initialization
virtual void Initialization(std::string &astr)=0
PluginAbstract
Definition: plugin.hh:4
createPlugin
PluginAbstract * createPlugin()
Definition: plugin.cc:73
PluginLoader::~PluginLoader
~PluginLoader()
Definition: test_abstract_interface.cpp:34


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:32