openrave.org

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
plugincpp.cpp
Go to the documentation of this file.
1 
40 #include <openrave/openrave.h>
41 #include <openrave/plugin.h>
42 #include <boost/bind.hpp>
43 
44 using namespace std;
45 using namespace OpenRAVE;
46 
47 namespace cppexamples {
48 
49 class MyModule : public ModuleBase
50 {
51 public:
53  {
54  __description = "A very simple plugin.";
55  RegisterCommand("numbodies",boost::bind(&MyModule::NumBodies,this,_1,_2),"returns bodies");
56  RegisterCommand("load",boost::bind(&MyModule::Load, this,_1,_2),"loads a given file");
57  }
58  virtual ~MyModule() {
59  }
60 
61  void Destroy() {
62  RAVELOG_INFO("module unloaded from environment\n");
63  }
64 
65  int main(const string& cmd)
66  {
67  RAVELOG_INFO("module initialized cmd; %s\n", cmd.c_str());
68  return 0;
69  }
70 
71  bool NumBodies(ostream& sout, istream& sinput)
72  {
73  vector<KinBodyPtr> vbodies;
74  GetEnv()->GetBodies(vbodies);
75  sout << vbodies.size(); // publish the results
76  return true;
77  }
78 
79  bool Load(ostream& sout, istream& sinput)
80  {
81  string filename;
82  sinput >> filename;
83  bool bSuccess = GetEnv()->Load(filename.c_str()); // load the file
84  return bSuccess;
85  }
86 };
87 
88 } // end namespace cppexamples
89 
90 InterfaceBasePtr CreateInterfaceValidated(InterfaceType type, const std::string& interfacename, std::istream& sinput, EnvironmentBasePtr penv)
91 {
92  if( type == PT_Module && interfacename == "mymodule" ) {
93  return InterfaceBasePtr(new cppexamples::MyModule(penv));
94  }
95  return InterfaceBasePtr();
96 }
97 
99 {
100  info.interfacenames[PT_Module].push_back("MyModule");
101 }
102 
104 {
105  RAVELOG_INFO("destroying plugin\n");
106 }