From fad55256b2835028e3c08146764ffee7e025dd6f Mon Sep 17 00:00:00 2001
From: Olivier Stasse <ostasse@laas.fr>
Date: Fri, 5 May 2017 18:23:05 +0200
Subject: [PATCH] Add a clean up procedure and change the dependency from
 bullet to tf2_bullet.

---
 CMakeLists.txt                                   |  6 +++---
 include/dynamic_graph_bridge/sot_loader_basic.hh |  7 ++++++-
 package.xml                                      |  4 ++--
 src/sot_loader_basic.cpp                         | 15 +++++++++++----
 4 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 58b4c76..7bce72d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,7 +67,7 @@ dynamic_graph_bridge_msgs)
 add_required_dependency(roscpp)
 add_required_dependency(tf)
 add_required_dependency("realtime_tools >= 1.8")
-add_required_dependency(bullet)
+add_required_dependency(tf2_bullet)
 ADD_REQUIRED_DEPENDENCY("pinocchio")
 ADD_REQUIRED_DEPENDENCY("dynamic-graph >= 3.0.0")
 ADD_REQUIRED_DEPENDENCY("dynamic-graph-python >= 3.0.0")
@@ -89,7 +89,7 @@ add_library(ros_bridge
   include/dynamic_graph_bridge/ros_init.hh src/ros_init.cpp
   src/sot_to_ros.hh src/sot_to_ros.cpp
   )
-pkg_config_use_dependency(ros_bridge bullet)
+pkg_config_use_dependency(ros_bridge tf2_bullet)
 pkg_config_use_dependency(ros_bridge dynamic_graph_bridge_msgs)
 install(TARGETS ros_bridge DESTINATION lib)
 
@@ -184,7 +184,7 @@ generate_messages( DEPENDENCIES std_msgs )
 
 # This is necessary so that the pc file generated by catking is similar to the on
 # done directly by jrl-cmake-modules
-catkin_package(CATKIN_DEPENDS message_runtime roscpp realtime_tools bullet ${SOT_PKGNAMES} tf
+catkin_package(CATKIN_DEPENDS message_runtime roscpp realtime_tools tf2_bullet ${SOT_PKGNAMES} tf
 LIBRARIES ros_bridge ros_interpreter sot_loader
 )
 
diff --git a/include/dynamic_graph_bridge/sot_loader_basic.hh b/include/dynamic_graph_bridge/sot_loader_basic.hh
index 6f7fbdf..b561d48 100644
--- a/include/dynamic_graph_bridge/sot_loader_basic.hh
+++ b/include/dynamic_graph_bridge/sot_loader_basic.hh
@@ -60,6 +60,8 @@ protected:
   po::variables_map vm_;
   std::string dynamicLibraryName_;
 
+  /// \brief Handle on the SoT library.
+  void * sotRobotControllerLibrary_;
 
   /// \brief Map between SoT state vector and some joint_state_links
   XmlRpc::XmlRpcValue stateVectorMap_;
@@ -89,9 +91,12 @@ public:
   // \brief Read user input to extract the path of the SoT dynamic library.
   int parseOptions(int argc, char *argv[]);
 
-  // \brief Load the SoT
+  /// \brief Load the SoT device corresponding to the robot.
   void Initialization();
 
+  /// \brief Unload the library which handles the robot device.
+  void CleanUp();
+
   // \brief Create a thread for ROS.
   virtual void initializeRosNode(int argc, char *argv[]);
   
diff --git a/package.xml b/package.xml
index c4370a7..7bdb5a6 100644
--- a/package.xml
+++ b/package.xml
@@ -1,6 +1,6 @@
 <package format="2">
   <name>dynamic_graph_bridge</name>
-  <version>3.0.4</version>
+  <version>3.0.6</version>
   <description>
 
      ROS bindings for dynamic graph.
@@ -27,7 +27,7 @@
   <depend>realtime_tools</depend>
   <depend>message_generation</depend>
   <depend>message_runtime</depend>
-  <depend>bullet</depend>
+  <depend>tf2_bullet</depend>
   <depend>dynamic-graph</depend>
   <depend>dynamic-graph-python</depend>
   <depend>sot-core</depend>
diff --git a/src/sot_loader_basic.cpp b/src/sot_loader_basic.cpp
index e9c3f19..4193a9b 100644
--- a/src/sot_loader_basic.cpp
+++ b/src/sot_loader_basic.cpp
@@ -54,7 +54,8 @@ void createRosSpin(SotLoaderBasic *aSotLoaderBasic)
 
 
 SotLoaderBasic::SotLoaderBasic():
-  dynamic_graph_stopped_(true)
+  dynamic_graph_stopped_(true),
+  sotRobotControllerLibrary_(0)
 {
   readSotVectorStateParam();
   initPublication();
@@ -192,9 +193,9 @@ void SotLoaderBasic::Initialization()
 {
   
   // Load the SotRobotBipedController library.
-  void * SotRobotControllerLibrary = dlopen( dynamicLibraryName_.c_str(),
+  sotRobotControllerLibrary_ = dlopen( dynamicLibraryName_.c_str(),
                                              RTLD_LAZY | RTLD_GLOBAL );
-  if (!SotRobotControllerLibrary) {
+  if (!sotRobotControllerLibrary_) {
     std::cerr << "Cannot load library: " << dlerror() << '\n';
     return ;
   }
@@ -206,7 +207,7 @@ void SotLoaderBasic::Initialization()
   createSotExternalInterface_t * createSot =
     reinterpret_cast<createSotExternalInterface_t *> 
     (reinterpret_cast<long> 
-     (dlsym(SotRobotControllerLibrary, 
+     (dlsym(sotRobotControllerLibrary_, 
 	    "createSotExternalInterface")));
   const char* dlsym_error = dlerror();
   if (dlsym_error) {
@@ -219,6 +220,12 @@ void SotLoaderBasic::Initialization()
   cout <<"Went out from Initialization." << endl;
 }
 
+void SotLoaderBasic::CleanUp()
+{
+  /// Uncount the number of access to this library.
+  dlclose(sotRobotControllerLibrary_);
+}
+
 
 
 bool SotLoaderBasic::start_dg(std_srvs::Empty::Request& , 
-- 
GitLab