ObstacleProviderContainer.cpp
Go to the documentation of this file.
00001 /*
00002  * ObstacleProviderContainer.cpp
00003  *
00004  *  Created on: Dec 14, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <obs_detection/ObstacleProviderContainer.hpp>
00009 
00010 #include <boost/foreach.hpp>
00011 
00012 namespace TELEKYB_NAMESPACE {
00013 
00014 ObstacleProviderContainer::ObstacleProviderContainer()
00015         : obstacleProviderLoader("tk_obstacle", std::string( TELEKYB_NAMESPACE_STRING ) + "::ObstacleProvider")
00016 {
00017 
00018 }
00019 
00020 ObstacleProviderContainer::~ObstacleProviderContainer()
00021 {
00022         // delete all Behaviors that are still loaded
00023         BOOST_FOREACH(ObstacleProvider *op, obstacleProviderInstances) {
00024                 op->destroy();
00025                 delete op;
00026         }
00027 }
00028 
00029 // should be const, but getDeclaredClasses is declared wrongly.
00030 void ObstacleProviderContainer::getAvailableObstacleProviders(std::vector<std::string>& obstacleProviderClassNames)
00031 {
00032         obstacleProviderClassNames = obstacleProviderLoader.getDeclaredClasses();
00033 }
00034 
00035 // returns 0 if fails
00036 ObstacleProvider* ObstacleProviderContainer::loadObstacleProvider(const std::string& obstacleProviderClassName)
00037 {
00038         ObstacleProvider *op = NULL;
00039         try {
00040                 op = obstacleProviderLoader.createClassInstance(obstacleProviderClassName);
00041 
00042                 // initialize
00043                 op->initialize();
00044 
00045                 // add local
00046                 obstacleProviderInstances.insert(op);
00047 
00048                 // success
00049                 //ROS_INFO_STREAM("Successfully loaded Behavior: " << behaviorClassName << ", Instance: " << (long)b);
00050         } catch (pluginlib::PluginlibException &e) {
00051                 ROS_ERROR_STREAM("ObstacleProvider Plugin " << obstacleProviderClassName << " failed to load. Message: " << e.what());
00052         }
00053 
00054         return op;
00055 }
00056 
00057 void ObstacleProviderContainer::unLoadObstacleProvider(ObstacleProvider* op)
00058 {
00059         ROS_INFO_STREAM("Unloading Trajectory Module: " << op->getName());
00060         if(obstacleProviderInstances.erase(op)) {
00061                 // Inform behavior
00062                 op->destroy();
00063                 // delete
00064                 delete op;
00065         }
00066 }
00067 
00068 const std::set<ObstacleProvider*>& ObstacleProviderContainer::getLoadedObstacleProviders() const
00069 {
00070         return obstacleProviderInstances;
00071 }
00072 
00073 } /* namespace telekyb */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends


tk_obstacle
Author(s): Martin Riedel
autogenerated on Mon Nov 11 2013 11:13:22