Revision: 8770
http://playerstage.svn.sourceforge.net/playerstage/?rev=8770&view=rev
Author: natepak
Date: 2010-06-22 21:42:18 +0000 (Tue, 22 Jun 2010)
Log Message:
-----------
Modified the new plugin routines
Modified Paths:
--------------
code/gazebo/branches/simpar/libgazebo/SimIface.cc
code/gazebo/branches/simpar/libgazebo/gz.h
code/gazebo/branches/simpar/plugins/ball_drop.cc
code/gazebo/branches/simpar/plugins/box_push.cc
code/gazebo/branches/simpar/plugins/box_stack.cc
code/gazebo/branches/simpar/plugins/pioneer_circle.cc
code/gazebo/branches/simpar/plugins/pioneer_gripper.cc
code/gazebo/branches/simpar/plugins/pioneer_line.cc
code/gazebo/branches/simpar/server/CMakeLists.txt
code/gazebo/branches/simpar/server/Logger.cc
code/gazebo/branches/simpar/server/Simulator.cc
code/gazebo/branches/simpar/server/Simulator.hh
code/gazebo/branches/simpar/server/World.cc
code/gazebo/branches/simpar/server/main.cc
code/gazebo/branches/simpar/tools/CMakeLists.txt
code/gazebo/branches/simpar/tools/gazebomodel.cc
code/gazebo/branches/simpar/worlds/single_box.world
Added Paths:
-----------
code/gazebo/branches/simpar/server/Plugin.cc
code/gazebo/branches/simpar/server/Plugin.hh
code/gazebo/branches/simpar/tools/gazeboplugin.cc
Removed Paths:
-------------
code/gazebo/branches/simpar/server/Handler.cc
code/gazebo/branches/simpar/server/Handler.hh
Modified: code/gazebo/branches/simpar/libgazebo/SimIface.cc
===================================================================
--- code/gazebo/branches/simpar/libgazebo/SimIface.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/libgazebo/SimIface.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -1008,26 +1008,72 @@
}
////////////////////////////////////////////////////////////////////////////////
-/// Add a handler
-void SimulationIface::AddHandler(const std::string &name)
+// The number of plugins in the simulation
+bool SimulationIface::GetPluginCount(unsigned int &count)
{
this->Lock(1);
+ this->data->responseCount = 0;
+ SimulationRequestData *request;
+ request = &(this->data->requests[this->data->requestCount++]);
+ request->type = SimulationRequestData::GET_PLUGIN_COUNT;
+ this->Unlock();
+ if (!this->WaitForResponse())
+ return false;
+
+ assert(this->data->responseCount == 1);
+ count = data->responses[0].uintValue;
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the name of a plugin
+bool SimulationIface::GetPluginName(unsigned int i, std::string &name)
+{
+ this->Lock(1);
+
this->data->responseCount = 0;
SimulationRequestData *request;
request = &(this->data->requests[this->data->requestCount++]);
- request->type = SimulationRequestData::ADD_HANDLER;
+ request->type = SimulationRequestData::GET_PLUGIN_NAME;
+ request->uintValue = i;
+
+ this->Unlock();
+ if (!this->WaitForResponse())
+ return false;
+
+ assert(this->data->responseCount == 1);
+ name = data->responses[0].strValue;
+ return true;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Add a plugin
+void SimulationIface::AddPlugin(const std::string &filename, const std::string
&handle)
+{
+ this->Lock(1);
+
+ this->data->responseCount = 0;
+ SimulationRequestData *request;
+
+ request = &(this->data->requests[this->data->requestCount++]);
+ request->type = SimulationRequestData::ADD_PLUGIN;
+
memset(request->strValue, 0, 512);
- strncpy(request->strValue, name.c_str(), 512);
+ strncpy(request->strValue, filename.c_str(), 512);
request->strValue[511] = '\0';
+ memset(request->name, 0, 512);
+ strncpy(request->name, handle.c_str(), 512);
+ request->name[511] = '\0';
+
this->Unlock();
}
////////////////////////////////////////////////////////////////////////////////
-/// Remove a handler
-void SimulationIface::RemoveHandler(const std::string &name)
+/// Remove a plugin
+void SimulationIface::RemovePlugin(const std::string &name)
{
this->Lock(1);
@@ -1035,7 +1081,7 @@
SimulationRequestData *request;
request = &(this->data->requests[this->data->requestCount++]);
- request->type = SimulationRequestData::REMOVE_HANDLER;
+ request->type = SimulationRequestData::REMOVE_PLUGIN;
memset(request->strValue, 0, 512);
strncpy(request->strValue, name.c_str(), 512);
request->strValue[511] = '\0';
Modified: code/gazebo/branches/simpar/libgazebo/gz.h
===================================================================
--- code/gazebo/branches/simpar/libgazebo/gz.h 2010-06-22 02:19:53 UTC (rev
8769)
+++ code/gazebo/branches/simpar/libgazebo/gz.h 2010-06-22 21:42:18 UTC (rev
8770)
@@ -455,8 +455,10 @@
GET_STEP_TYPE,
APPLY_FORCE,
APPLY_TORQUE,
- ADD_HANDLER,
- REMOVE_HANDLER
+ GET_PLUGIN_COUNT,
+ GET_PLUGIN_NAME,
+ ADD_PLUGIN,
+ REMOVE_PLUGIN
};
public: Type type;
@@ -688,12 +690,18 @@
/// \brief Get the step type
public: std::string GetStepType();
- /// \brief Add a handler
- public: void AddHandler(const std::string &name);
+ /// \brief Get the number of plugins
+ public: bool GetPluginCount(unsigned int &count);
+
+ /// \brief Get the name of a plugin
+ public: bool GetPluginName(unsigned int i, std::string &name);
- /// \brief Remove a handler
- public: void RemoveHandler(const std::string &name);
+ /// \brief Add a plugin
+ public: void AddPlugin(const std::string &filename,const std::string
&handle);
+ /// \brief Remove a plugin
+ public: void RemovePlugin(const std::string &name);
+
private: void BlockThread();
/// \brief Wait for a return message
Modified: code/gazebo/branches/simpar/plugins/ball_drop.cc
===================================================================
--- code/gazebo/branches/simpar/plugins/ball_drop.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/plugins/ball_drop.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -6,14 +6,13 @@
namespace gazebo
{
-
- class BallDrop : public Handler
+ class BallDrop : public Plugin
{
- public: BallDrop() : Handler()
+ public: BallDrop() : Plugin()
{
this->sphere = NULL;
this->model_name = "sphere";
- this->SpawnBall(0,0,5);
+ //this->SpawnBall(0,0,5);
//for (double i=0.001; i > 1e-5; i*=0.5)
this->stepTimes.push_back(0.1);
@@ -22,7 +21,7 @@
this->stepIters.push_back(10);
//this->stepTypes.push_back("robust");
- //this->stepTypes.push_back("world");
+ this->stepTypes.push_back("world");
//this->stepTypes.push_back("quick");
this->stepTypesIter = this->stepTypes.begin();
@@ -104,11 +103,11 @@
this->physics->SetStepType( *this->stepTypesIter );
this->physics->SetStepTime( *this->stepTimesIter );
+ this->physics->SetStepTime( *this->stepTimesIter );
this->physics->SetSORPGSIters( *this->stepItersIter );
World::Instance()->ConnectWorldUpdateStartSignal(
boost::bind(&BallDrop::UpdateCB, this));
-
}
public: void UpdateCB()
@@ -178,7 +177,7 @@
this->stepTypesIter++;
if (this->stepTypesIter == this->stepTypes.end())
{
- Simulator::Instance()->RemoveHandler(this->name);
+ Simulator::Instance()->RemovePlugin(this->handle);
return;
}
}
@@ -224,5 +223,5 @@
private: std::string model_name;
};
- GZ_REGISTER_HANDLER("BallDrop", BallDrop)
+ GZ_REGISTER_PLUGIN("BallDrop", BallDrop)
}
Modified: code/gazebo/branches/simpar/plugins/box_push.cc
===================================================================
--- code/gazebo/branches/simpar/plugins/box_push.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/plugins/box_push.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -7,9 +7,9 @@
namespace gazebo
{
- class BoxPush : public Handler
+ class BoxPush : public Plugin
{
- public: BoxPush() : Handler()
+ public: BoxPush() : Plugin()
{
this->box = NULL;
@@ -135,7 +135,7 @@
this->stepTypesIter++;
if (this->stepTypesIter == this->stepTypes.end())
{
- Simulator::Instance()->RemoveHandler(this->name);
+ Simulator::Instance()->RemovePlugin(this->handle);
return;
}
}
@@ -180,5 +180,5 @@
private: int skipCount;
};
- GZ_REGISTER_HANDLER("BoxPush", BoxPush)
+ GZ_REGISTER_PLUGIN("BoxPush", BoxPush)
}
Modified: code/gazebo/branches/simpar/plugins/box_stack.cc
===================================================================
--- code/gazebo/branches/simpar/plugins/box_stack.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/plugins/box_stack.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -7,9 +7,9 @@
namespace gazebo
{
- class BoxStack : public Handler
+ class BoxStack : public Plugin
{
- public: BoxStack() : Handler()
+ public: BoxStack() : Plugin()
{
this->box = NULL;
@@ -112,7 +112,7 @@
if (this->stepTypesIter == this->stepTypes.end())
{
Simulator::Instance()->SetUserQuit();
- Simulator::Instance()->RemoveHandler(this->name);
+ Simulator::Instance()->RemovePlugin(this->handle);
return;
}
}
@@ -154,5 +154,5 @@
private: unsigned int count;
};
- GZ_REGISTER_HANDLER("BoxStack", BoxStack)
+ GZ_REGISTER_PLUGIN("BoxStack", BoxStack)
}
Modified: code/gazebo/branches/simpar/plugins/pioneer_circle.cc
===================================================================
--- code/gazebo/branches/simpar/plugins/pioneer_circle.cc 2010-06-22
02:19:53 UTC (rev 8769)
+++ code/gazebo/branches/simpar/plugins/pioneer_circle.cc 2010-06-22
21:42:18 UTC (rev 8770)
@@ -7,9 +7,9 @@
namespace gazebo
{
- class PioneerCircle : public Handler
+ class PioneerCircle : public Plugin
{
- public: PioneerCircle() : Handler()
+ public: PioneerCircle() : Plugin()
{
//for (double i=0.001; i > 1e-5; i*=0.5)
this->stepTimes.push_back(0.001);
@@ -159,7 +159,7 @@
this->stepTypesIter++;
if (this->stepTypesIter == this->stepTypes.end())
{
- Simulator::Instance()->RemoveHandler(this->name);
+ Simulator::Instance()->RemovePlugin(this->handle);
return;
}
}
@@ -206,5 +206,5 @@
private: Pose3d startPose;
};
- GZ_REGISTER_HANDLER("PioneerCircle", PioneerCircle)
+ GZ_REGISTER_PLUGIN("PioneerCircle", PioneerCircle)
}
Modified: code/gazebo/branches/simpar/plugins/pioneer_gripper.cc
===================================================================
--- code/gazebo/branches/simpar/plugins/pioneer_gripper.cc 2010-06-22
02:19:53 UTC (rev 8769)
+++ code/gazebo/branches/simpar/plugins/pioneer_gripper.cc 2010-06-22
21:42:18 UTC (rev 8770)
@@ -7,9 +7,9 @@
namespace gazebo
{
- class PioneerGripper : public Handler
+ class PioneerGripper : public Plugin
{
- public: PioneerGripper() : Handler()
+ public: PioneerGripper() : Plugin()
{
//for (double i=0.001; i > 1e-5; i*=0.5)
//this->stepTimes.push_back(i);
@@ -222,7 +222,7 @@
this->stepTypesIter++;
if (this->stepTypesIter == this->stepTypes.end())
{
- Simulator::Instance()->RemoveHandler(this->name);
+ Simulator::Instance()->RemovePlugin(this->handle);
return;
}
}
@@ -274,5 +274,5 @@
private: double leftForce, rightForce;
};
- GZ_REGISTER_HANDLER("PioneerGripper", PioneerGripper)
+ GZ_REGISTER_PLUGIN("PioneerGripper", PioneerGripper)
}
Modified: code/gazebo/branches/simpar/plugins/pioneer_line.cc
===================================================================
--- code/gazebo/branches/simpar/plugins/pioneer_line.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/plugins/pioneer_line.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -7,9 +7,9 @@
namespace gazebo
{
- class PioneerLine : public Handler
+ class PioneerLine : public Plugin
{
- public: PioneerLine() : Handler()
+ public: PioneerLine() : Plugin()
{
//for (double i=0.001; i > 1e-5; i*=0.5)
this->stepTimes.push_back(0.001);
@@ -135,7 +135,7 @@
this->stepTypesIter++;
if (this->stepTypesIter == this->stepTypes.end())
{
- Simulator::Instance()->RemoveHandler(this->name);
+ Simulator::Instance()->RemovePlugin(this->handle);
return;
}
}
@@ -177,5 +177,5 @@
};
- GZ_REGISTER_HANDLER("PioneerLine", PioneerLine)
+ GZ_REGISTER_PLUGIN("PioneerLine", PioneerLine)
}
Modified: code/gazebo/branches/simpar/server/CMakeLists.txt
===================================================================
--- code/gazebo/branches/simpar/server/CMakeLists.txt 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/server/CMakeLists.txt 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -94,7 +94,7 @@
AssimpLoader.cc
STLLoader.cc
Logger.cc
- Handler.cc
+ Plugin.cc
)
SET (headers Common.hh
@@ -129,7 +129,7 @@
STLLoader.hh
Logger.hh
Event.hh
- Handler.hh
+ Plugin.hh
)
APPEND_TO_SERVER_HEADERS(${headers})
Deleted: code/gazebo/branches/simpar/server/Handler.cc
===================================================================
--- code/gazebo/branches/simpar/server/Handler.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/server/Handler.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -1,111 +0,0 @@
-#include "gazebo_config.h"
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <list>
-
-#include "Simulator.hh"
-#include "GazeboConfig.hh"
-#include "GazeboError.hh"
-#include "Handler.hh"
-
-#ifdef HAVE_DL
-#include <dlfcn.h>
-#elif HAVE_LTDL
-#include <ltdl.h>
-#endif
-
-
-using namespace gazebo;
-
-Handler::Handler() {}
-Handler::~Handler() {}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the name of the handler
-std::string Handler::GetName() const
-{
- return this->name;
-}
-
-
-Handler *Handler::Create(const std::string &plugin)
-{
- Handler *result = NULL;
- struct stat st;
- bool found = false;
- std::string fullname;
- std::list<std::string>::iterator iter;
- std::list<std::string> pluginPaths=
Simulator::Instance()->GetGazeboConfig()->GetPluginPaths();
- for (iter=pluginPaths.begin(); iter!=pluginPaths.end(); ++iter)
- {
- fullname = (*iter)+std::string("/")+plugin;
- if (stat(fullname.c_str(), &st) == 0) {found=true; break;}
- }
- if (!found) fullname = plugin;
- std::string registerName = "RegisterHandler";
-
-#ifdef HAVE_DL
- void* handle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
- if (!handle)
- {
- std::cerr << "Failed to load plugin " << fullname << ": " << dlerror();
- return NULL;
- }
-
- Handler *(*registerFunc)() = (Handler *(*)())dlsym(handle,
registerName.c_str());
- if(!registerFunc)
- {
- std::cerr << "Failed to resolve " << registerName << ": " << dlerror();
- return NULL;
- }
-
- // Register the new controller.
- result = registerFunc();
-
-#elif HAVE_LTDL
-
- static bool init_done = false;
-
- if (!init_done)
- {
- int errors = lt_dlinit();
- if (errors)
- {
- std::cerr << "Error(s) initializing dynamic loader ("
- << errors << ", " << lt_dlerror() << ")";
- return NULL;
- }
- else
- init_done = true;
- }
-
- lt_dlhandle handle = lt_dlopenext(fullname.c_str());
-
- if (!handle)
- {
- std::cerr << "Failed to load " << fullname << ": " << lt_dlerror();
- return NULL;
- }
-
- Handler *(*registerFunc)() = (Handler *(*)())lt_dlsym(handle,
registerName.c_str());
- if(!registerFunc)
- {
- std::cerr << "Failed to resolve " << registerName << ": " << lt_dlerror();
- return NULL;
- }
-
- // Register the new controller.
- result = registerFunc();
-
-#else // HAVE_LTDL
-
- gzthrow("Cannot load plugins as libtool is not installed.");
-
-#endif // HAVE_LTDL
-
- result->name = plugin;
-
- return result;
-}
Deleted: code/gazebo/branches/simpar/server/Handler.hh
===================================================================
--- code/gazebo/branches/simpar/server/Handler.hh 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/server/Handler.hh 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -1,32 +0,0 @@
-#ifndef HANDLER_HH
-#define HANDLER_HH
-
-#include <string>
-#include <boost/signals.hpp>
-
-namespace gazebo
-{
- class Event;
-
- class Handler : public boost::signals::trackable
- {
- public: Handler();
- public: virtual ~Handler();
- public: virtual void Load() = 0;
-
- /// \brief Get the name of the handler
- public: std::string GetName() const;
-
- public: static Handler *Create(const std::string &name);
-
- protected: std::string name;
- };
-}
-
-#define GZ_REGISTER_HANDLER(name, classname) \
-extern "C" Handler *RegisterHandler(); \
-Handler *RegisterHandler() \
-{\
- return new classname();\
-}
-#endif
Modified: code/gazebo/branches/simpar/server/Logger.cc
===================================================================
--- code/gazebo/branches/simpar/server/Logger.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/server/Logger.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -128,21 +128,8 @@
<< " " << pose3d.pos.x << " " << pose3d.pos.y << " " << pose3d.pos.z
<< " " << roll << " " << pitch << " " << yaw
<< " " << linearVel.x << " " << linearVel.y << " " << linearVel.z
- << " " << angularVel.x << " " << angularVel.y << " " << angularVel.z;
-
- if (this->entity->GetType() == Entity::GEOM)
- {
- Geom *geom = (Geom*)(this->entity);
- this->logFile << geom->GetContactCount() << " ";
- std::cout << "Is A Geom[" << geom->GetContactCount() << "] ";
- for (unsigned int i=0; i < geom->GetContactCount(); i++)
- {
- for (unsigned int j=0; j < geom->GetContact(i).depths.size(); j++)
- std::cout << " D[" << geom->GetContact(i).depths[j] << "] ";
- //this->logFile << geom->GetContact(i).depths[0] << " ";
- }
- std::cout << "\n";
- }
+ << " " << angularVel.x << " " << angularVel.y << " " << angularVel.z
+ << "\n";
}
else
this->logFile << "0 ";
Copied: code/gazebo/branches/simpar/server/Plugin.cc (from rev 8769,
code/gazebo/branches/simpar/server/Handler.cc)
===================================================================
--- code/gazebo/branches/simpar/server/Plugin.cc
(rev 0)
+++ code/gazebo/branches/simpar/server/Plugin.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -0,0 +1,119 @@
+#include "gazebo_config.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <list>
+
+#include "Simulator.hh"
+#include "GazeboConfig.hh"
+#include "GazeboError.hh"
+#include "Plugin.hh"
+
+#ifdef HAVE_DL
+#include <dlfcn.h>
+#elif HAVE_LTDL
+#include <ltdl.h>
+#endif
+
+
+using namespace gazebo;
+
+Plugin::Plugin() {}
+Plugin::~Plugin() {}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the name of the handler
+std::string Plugin::GetFilename() const
+{
+ return this->filename;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Get the short name of the handler
+std::string Plugin::GetHandle() const
+{
+ return this->handle;
+}
+
+Plugin *Plugin::Create(const std::string &filename, const std::string
&shortname)
+{
+ Plugin *result = NULL;
+ struct stat st;
+ bool found = false;
+ std::string fullname;
+ std::list<std::string>::iterator iter;
+ std::list<std::string> pluginPaths=
Simulator::Instance()->GetGazeboConfig()->GetPluginPaths();
+
+ for (iter=pluginPaths.begin(); iter!=pluginPaths.end(); ++iter)
+ {
+ fullname = (*iter)+std::string("/")+filename;
+ if (stat(fullname.c_str(), &st) == 0) {found=true; break;}
+ }
+ if (!found) fullname = filename;
+ std::string registerName = "RegisterPlugin";
+
+#ifdef HAVE_DL
+ void* handle = dlopen(fullname.c_str(), RTLD_LAZY|RTLD_GLOBAL);
+ if (!handle)
+ {
+ std::cerr << "Failed to load plugin " << fullname << ": " << dlerror();
+ return NULL;
+ }
+
+ Plugin *(*registerFunc)() = (Plugin *(*)())dlsym(handle,
registerName.c_str());
+ if(!registerFunc)
+ {
+ std::cerr << "Failed to resolve " << registerName << ": " << dlerror();
+ return NULL;
+ }
+
+ // Register the new controller.
+ result = registerFunc();
+
+#elif HAVE_LTDL
+
+ static bool init_done = false;
+
+ if (!init_done)
+ {
+ int errors = lt_dlinit();
+ if (errors)
+ {
+ std::cerr << "Error(s) initializing dynamic loader ("
+ << errors << ", " << lt_dlerror() << ")";
+ return NULL;
+ }
+ else
+ init_done = true;
+ }
+
+ lt_dlhandle handle = lt_dlopenext(fullname.c_str());
+
+ if (!handle)
+ {
+ std::cerr << "Failed to load " << fullname << ": " << lt_dlerror();
+ return NULL;
+ }
+
+ Plugin *(*registerFunc)() = (Plugin *(*)())lt_dlsym(handle,
registerName.c_str());
+ if(!registerFunc)
+ {
+ std::cerr << "Failed to resolve " << registerName << ": " << lt_dlerror();
+ return NULL;
+ }
+
+ // Register the new controller.
+ result = registerFunc();
+
+#else // HAVE_LTDL
+
+ gzthrow("Cannot load plugins as libtool is not installed.");
+
+#endif // HAVE_LTDL
+
+ result->handle = shortname;
+ result->filename = filename;
+
+ return result;
+}
Copied: code/gazebo/branches/simpar/server/Plugin.hh (from rev 8769,
code/gazebo/branches/simpar/server/Handler.hh)
===================================================================
--- code/gazebo/branches/simpar/server/Plugin.hh
(rev 0)
+++ code/gazebo/branches/simpar/server/Plugin.hh 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -0,0 +1,36 @@
+#ifndef HANDLER_HH
+#define HANDLER_HH
+
+#include <string>
+#include <boost/signals.hpp>
+
+namespace gazebo
+{
+ class Event;
+
+ class Plugin : public boost::signals::trackable
+ {
+ public: Plugin();
+ public: virtual ~Plugin();
+ public: virtual void Load() = 0;
+
+ /// \brief Get the name of the handler
+ public: std::string GetFilename() const;
+
+ /// \brief Get the short name of the handler
+ public: std::string GetHandle() const;
+
+ public: static Plugin *Create(const std::string &filename, const
std::string &handle);
+
+ protected: std::string filename;
+ protected: std::string handle;
+ };
+}
+
+#define GZ_REGISTER_PLUGIN(name, classname) \
+extern "C" Plugin *RegisterPlugin(); \
+Plugin *RegisterPlugin() \
+{\
+ return new classname();\
+}
+#endif
Modified: code/gazebo/branches/simpar/server/Simulator.cc
===================================================================
--- code/gazebo/branches/simpar/server/Simulator.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/server/Simulator.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -31,7 +31,7 @@
#include <boost/thread/recursive_mutex.hpp>
#include "gazebo_config.h"
-#include "Handler.hh"
+#include "Plugin.hh"
#include "Timer.hh"
#include "Body.hh"
#include "Geom.hh"
@@ -296,11 +296,12 @@
gzthrow("Failed to load the World\n" << e);
}
- XMLConfigNode *handlerNode = rootNode->GetChild("handler");
- while (handlerNode != NULL)
+ XMLConfigNode *pluginNode = rootNode->GetChild("plugin");
+ while (pluginNode != NULL)
{
- this->AddHandler(handlerNode->GetString("plugin","",1));
- handlerNode = handlerNode->GetNext("handler");
+ this->AddPlugin( pluginNode->GetString("filename","",1),
+ pluginNode->GetString("handle","",1) );
+ pluginNode = pluginNode->GetNext("plugin");
}
this->loaded=true;
@@ -763,28 +764,46 @@
}
////////////////////////////////////////////////////////////////////////////////
-// Add a handler
-void Simulator::AddHandler(const std::string &name)
+/// Get the number of plugins
+unsigned int Simulator::GetPluginCount() const
{
- Handler *handler = Handler::Create(name);
- if (handler)
+ return this->plugins.size();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Get the name of a plugin
+std::string Simulator::GetPluginName(unsigned int i) const
+{
+ std::string result;
+ if (i < this->plugins.size())
+ result = this->plugins[i]->GetHandle();
+
+ return result;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Add a plugin
+void Simulator::AddPlugin(const std::string &filename, const std::string
&handle)
+{
+ Plugin *plugin = Plugin::Create(filename, handle);
+ if (plugin)
{
- handler->Load();
- this->handlers.push_back(handler);
+ plugin->Load();
+ this->plugins.push_back(plugin);
}
}
////////////////////////////////////////////////////////////////////////////////
-// Add a handler
-void Simulator::RemoveHandler(const std::string &name)
+// Add a plugin
+void Simulator::RemovePlugin(const std::string &name)
{
- std::vector<Handler*>::iterator iter;
- for (iter = this->handlers.begin(); iter != this->handlers.end(); iter++)
+ std::vector<Plugin*>::iterator iter;
+ for (iter = this->plugins.begin(); iter != this->plugins.end(); iter++)
{
- if ((*iter)->GetName() == name)
+ if ((*iter)->GetHandle() == name)
{
delete (*iter);
- this->handlers.erase(iter);
+ this->plugins.erase(iter);
break;
}
}
Modified: code/gazebo/branches/simpar/server/Simulator.hh
===================================================================
--- code/gazebo/branches/simpar/server/Simulator.hh 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/server/Simulator.hh 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -55,7 +55,7 @@
class Common;
class Body;
class Model;
- class Handler;
+ class Plugin;
/// \brief The World
/*
@@ -171,16 +171,18 @@
/// \brief Get the state of the simulation
public: State GetState() const;
- /// \brief Add a handler
- public: void AddHandler(const std::string &plugin);
+ /// \brief Get the number of plugins
+ public: unsigned int GetPluginCount() const;
- /// \brief Remove a handler
- public: void RemoveHandler(const std::string &plugin);
+ /// \brief Get the name of a plugin
+ public: std::string GetPluginName(unsigned int i) const;
- /// \brief This function should be called from a Handler object
- /// to remove itself
- public: void DeferredRemoveHandler(const std::string &plugin);
+ /// \brief Add a plugin
+ public: void AddPlugin(const std::string &plugin, const std::string
&handle);
+ /// \brief Remove a plugin
+ public: void RemovePlugin(const std::string &plugin);
+
/// \brief Connect a boost::slot the the pause signal
public: template<typename T>
void ConnectPauseSignal( T subscriber )
@@ -266,8 +268,7 @@
private: static std::string defaultWorld;
- private: std::vector<Handler*> handlers;
- private: std::vector<std::string> handlersToRemove;
+ private: std::vector<Plugin*> plugins;
};
Modified: code/gazebo/branches/simpar/server/World.cc
===================================================================
--- code/gazebo/branches/simpar/server/World.cc 2010-06-22 02:19:53 UTC (rev
8769)
+++ code/gazebo/branches/simpar/server/World.cc 2010-06-22 21:42:18 UTC (rev
8770)
@@ -231,8 +231,6 @@
this->worldStatesEndIter = this->worldStates.begin();
this->worldStatesCurrentIter = this->worldStatesInsertIter;
- this->PrintEntityTree();
-
#ifdef USE_THREADPOOL
// start a thread pool with X threads
this->threadPool = new boost::threadpool::pool(this->threadsP->GetValue());
@@ -1594,18 +1592,38 @@
break;
}
- case libgazebo::SimulationRequestData::ADD_HANDLER:
+ case libgazebo::SimulationRequestData::GET_PLUGIN_COUNT:
{
- Simulator::Instance()->AddHandler(req->strValue);
+ response->type= req->type;
+ response->uintValue = Simulator::Instance()->GetPluginCount();
+ response++;
+ this->simIface->data->responseCount += 1;
break;
}
- case libgazebo::SimulationRequestData::REMOVE_HANDLER:
+ case libgazebo::SimulationRequestData::GET_PLUGIN_NAME:
{
- Simulator::Instance()->RemoveHandler(req->strValue);
+ memset(response->strValue, 0, 512);
+ strncpy(response->strValue,
Simulator::Instance()->GetPluginName(req->uintValue).c_str(), 512);
+ response->strValue[511] = '\0';
+ response++;
+ this->simIface->data->responseCount += 1;
break;
}
+
+ case libgazebo::SimulationRequestData::ADD_PLUGIN:
+ {
+ Simulator::Instance()->AddPlugin(req->strValue, req->name);
+ break;
+ }
+
+ case libgazebo::SimulationRequestData::REMOVE_PLUGIN:
+ {
+ Simulator::Instance()->RemovePlugin(req->strValue);
+ break;
+ }
+
case libgazebo::SimulationRequestData::GO:
{
int sec = req->runTime/1000;
Modified: code/gazebo/branches/simpar/server/main.cc
===================================================================
--- code/gazebo/branches/simpar/server/main.cc 2010-06-22 02:19:53 UTC (rev
8769)
+++ code/gazebo/branches/simpar/server/main.cc 2010-06-22 21:42:18 UTC (rev
8770)
@@ -140,6 +140,8 @@
fprintf(stderr, " -n : Do not do any time control\n");
fprintf(stderr, " -p : Run without physics engine\n");
fprintf(stderr, " -u : Start the simulation paused\n");
+ fprintf(stderr, " --add_plugin : Add a plugin to the running gazebo\n");
+ fprintf(stderr, " --remove_plugin : Remove a plugin from the running
gazebo\n");
fprintf(stderr, " <worldfile> : load the the indicated world file\n");
return;
}
Modified: code/gazebo/branches/simpar/tools/CMakeLists.txt
===================================================================
--- code/gazebo/branches/simpar/tools/CMakeLists.txt 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/tools/CMakeLists.txt 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -14,19 +14,24 @@
)
-set (sources gazebomodel.cc gazebobody.cc Toolbase.cc)
+set (sources gazebomodel.cc gazebobody.cc gazeboplugin.cc Toolbase.cc)
set_source_files_properties(${sources} PROPERTIES COMPILE_FLAGS "-ggdb -g2
-Wall")
add_executable(gazebomodel gazebomodel.cc Toolbase.cc)
add_executable(gazebobody gazebobody.cc Toolbase.cc)
+add_executable(gazeboplugin gazeboplugin.cc Toolbase.cc)
target_link_libraries(gazebomodel gazebo yaml ${boost_libraries})
target_link_libraries(gazebobody gazebo yaml ${boost_libraries})
+target_link_libraries(gazeboplugin gazebo yaml ${boost_libraries})
set_target_properties(gazebomodel PROPERTIES SKIP_BUILD_RPATH TRUE)
set_target_properties(gazebomodel PROPERTIES LINK_FLAGS "${LINK_FLAGS}
${gazebo_lflags}")
set_target_properties(gazebobody PROPERTIES SKIP_BUILD_RPATH TRUE)
set_target_properties(gazebobody PROPERTIES LINK_FLAGS "${LINK_FLAGS}
${gazebo_lflags}")
+set_target_properties(gazeboplugin PROPERTIES SKIP_BUILD_RPATH TRUE)
+set_target_properties(gazeboplugin PROPERTIES LINK_FLAGS "${LINK_FLAGS}
${gazebo_lflags}")
-install (TARGETS gazebomodel gazebobody DESTINATION
${CMAKE_INSTALL_PREFIX}/bin)
+
+install (TARGETS gazebomodel gazebobody gazeboplugin DESTINATION
${CMAKE_INSTALL_PREFIX}/bin)
Modified: code/gazebo/branches/simpar/tools/gazebomodel.cc
===================================================================
--- code/gazebo/branches/simpar/tools/gazebomodel.cc 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/tools/gazebomodel.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -132,48 +132,8 @@
}
}
-
//////////////////////////////////////////////////////////////////////////////
- // Add a handler
- public: void AddHandler()
- {
- if (this->params.size() < 2)
- std::cerr << "Missing pluing filename\n";
- else
- {
- std::string plugin;
- struct stat buf;
- if (stat(params[1].c_str(),&buf) == 0)
- plugin = std::string(getenv("PWD")) + "/" + params[1];
- else
- plugin = params[1];
- this->simIface->AddHandler(plugin);
- }
-
- }
-
//////////////////////////////////////////////////////////////////////////////
- // Remove a handler
- public: void RemoveHandler()
- {
- if (this->params.size() < 2)
- std::cerr << "Missing pluing filename\n";
- else
- {
- std::string plugin;
- struct stat buf;
- if (stat(params[1].c_str(),&buf) == 0)
- plugin = std::string(getenv("PWD")) + "/" + params[1];
- else
- plugin = params[1];
-
- this->simIface->RemoveHandler(plugin);
- }
-
- }
-
-
-
//////////////////////////////////////////////////////////////////////////////
// Spawn a new model into the world
public: void Spawn()
{
@@ -271,10 +231,6 @@
this->Spawn();
else if (params[0] == "set")
this->Set();
- else if (params[0] == "add_handler")
- this->AddHandler();
- else if (params[0] == "remove_handler")
- this->RemoveHandler();
else
std::cerr << "Unknown command[" << this->params[0] << "]\n";
}
Added: code/gazebo/branches/simpar/tools/gazeboplugin.cc
===================================================================
--- code/gazebo/branches/simpar/tools/gazeboplugin.cc
(rev 0)
+++ code/gazebo/branches/simpar/tools/gazeboplugin.cc 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -0,0 +1,123 @@
+#include <iostream>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <boost/regex.hpp>
+#include <boost/algorithm/string.hpp>
+#include <boost/lexical_cast.hpp>
+
+#include "Toolbase.hh"
+
+class PluginTool : public Toolbase
+{
+
+
//////////////////////////////////////////////////////////////////////////////
+ // Print out a list of all the plugins
+ public: void List()
+ {
+ unsigned int numPlugins = 0;
+
+ std::string prefix = "";
+ if (!this->simIface->GetPluginCount(numPlugins))
+ std::cerr << "Unable to get the plugin count\n";
+
+ for (unsigned int i=0; i < numPlugins; i++)
+ {
+ std::string name;
+ if (!this->simIface->GetPluginName(i, name))
+ std::cerr << "Unable to get plugin[" << i << "]\n";
+ else
+ std::cout << name << "\n";
+ }
+ }
+
+
//////////////////////////////////////////////////////////////////////////////
+ // Remove a plugin from the simulation
+ public: void RemovePlugin()
+ {
+ if (this->params.size() < 2)
+ std::cerr << "Missing pluing filename\n";
+ else
+ {
+ std::string plugin;
+ struct stat buf;
+ if (stat(params[1].c_str(),&buf) == 0)
+ plugin = std::string(getenv("PWD")) + "/" + params[1];
+ else
+ plugin = params[1];
+
+ this->simIface->RemovePlugin(plugin);
+ }
+ }
+
+
//////////////////////////////////////////////////////////////////////////////
+ // Add a handler
+ public: void AddPlugin()
+ {
+ if (this->params.size() < 3)
+ std::cerr << "Must specify a filename and a handle name\n";
+ else
+ {
+ std::string filename, handle;
+ struct stat buf;
+ if (stat(params[1].c_str(),&buf) == 0)
+ filename = std::string(getenv("PWD")) + "/" + params[1];
+ else
+ filename = params[1];
+
+ handle = params[2];
+
+ this->simIface->AddPlugin(filename, handle);
+ }
+
+ }
+
+ public: bool Run()
+ {
+ if (!Toolbase::Run())
+ {
+ if (this->params[0] == "list")
+ this->List();
+ else if (params[0] == "add")
+ this->AddPlugin();
+ else if (params[0] == "remove")
+ this->RemovePlugin();
+ else
+ std::cerr << "Unknown command[" << this->params[0] << "]\n";
+ }
+
+ return true;
+ }
+
+
+
//////////////////////////////////////////////////////////////////////////////
+ // Print out help information
+ public: void Help()
+ {
+ std::cout << "gazeboplugin is a command-line tool for manipulating plugins
in a gazebo world.\n";
+ std::cout << "\n";
+ std::cout << "Usage: gazeboplugin <command> <option_1> ... <option_n>\n";
+ std::cout << "\n";
+
+ std::cout << "Commands:\n";
+
+ this->PrintCommands("gazeboplugin");
+
+ std::cout << "\tgazeboplugin list \t List all the models\n";
+ std::cout << "\tgazeboplugin add \t Add a plugin to the world\n";
+ std::cout << "\tgazeboplugin remove \t Remove a plugin from the world\n";
+ }
+};
+
+////////////////////////////////////////////////////////////////////////////////
+// Main
+int main(int argc, char **argv)
+{
+ PluginTool tool;
+ tool.Init(argc, argv);
+ tool.Run();
+
+ return 1;
+}
Modified: code/gazebo/branches/simpar/worlds/single_box.world
===================================================================
--- code/gazebo/branches/simpar/worlds/single_box.world 2010-06-22 02:19:53 UTC
(rev 8769)
+++ code/gazebo/branches/simpar/worlds/single_box.world 2010-06-22 21:42:18 UTC
(rev 8770)
@@ -60,7 +60,7 @@
<visual>
<size>1 1 1</size>
<mesh>unit_box</mesh>
- <shader>pixel</shader>
+ <shader>vertex</shader>
<material>Gazebo/Rocky</material>
</visual>
</geom:box>
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Playerstage-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/playerstage-commit