GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: tests/tools/test_abstract_interface.cpp Lines: 0 34 0.0 %
Date: 2023-03-13 12:09:37 Branches: 0 54 0.0 %

Line Branch Exec Source
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:
28
  PluginAbstract *sotController_;
29
  po::variables_map vm_;
30
  std::string dynamicLibraryName_;
31
32
 public:
33
  PluginLoader(){};
34
  ~PluginLoader(){};
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.
71
    createPlugin_t *createPlugin =
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
}