openrave.org

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
interface.h
Go to the documentation of this file.
1 // -*- coding: utf-8 -*-
2 // Copyright (C) 2006-2011 Rosen Diankov <rosen.diankov@gmail.com>
3 //
4 // This file is part of OpenRAVE.
5 // OpenRAVE is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #ifndef OPENRAVE_INTERFACE_BASE
23 #define OPENRAVE_INTERFACE_BASE
24 
25 namespace OpenRAVE {
26 
29 {
30  SO_Kinematics = 0x01,
31  SO_Dynamics = 0x02,
32  SO_BodyState = 0x04,
35  SO_RobotSensors = 0x20,
36  SO_Geometry = 0x40,
37 };
38 
42 class OPENRAVE_API InterfaceBase : public boost::enable_shared_from_this<InterfaceBase>
43 {
44 public:
45  typedef std::map<std::string, XMLReadablePtr, CaseInsensitiveCompare> READERSMAP;
46 
47  InterfaceBase(InterfaceType type, EnvironmentBasePtr penv);
48  virtual ~InterfaceBase();
49 
50  inline InterfaceType GetInterfaceType() const {
51  return __type;
52  }
53 
57  inline const std::string& GetXMLId() const {
58  return __strxmlid;
59  }
60 
63  inline const std::string& GetPluginName() const {
64  return __strpluginname;
65  }
66 
68  inline EnvironmentBasePtr GetEnv() const {
69  return __penv;
70  }
71 
73  inline const READERSMAP& GetReadableInterfaces() const {
74  return __mapReadableInterfaces;
75  }
76 
78  virtual XMLReadablePtr GetReadableInterface(const std::string& xmltag) const;
79 
81  virtual XMLReadablePtr SetReadableInterface(const std::string& xmltag, XMLReadablePtr readable);
82 
84  virtual const std::string& GetDescription() const {
85  return __description;
86  }
87 
89  virtual void SetDescription(const std::string& description) {
90  __description = description;
91  }
92 
96  virtual void SetUserData(const std::string& key, UserDataPtr data) const;
97 
99  virtual UserDataPtr GetUserData(const std::string& key=std::string()) const;
100 
102  virtual bool RemoveUserData(const std::string& key) const;
103 
106  SetUserData(std::string(),data);
107  }
108 
110  virtual const std::string& GetURI() const {
111  return __struri;
112  }
113  virtual const std::string& GetXMLFilename() const {
114  return __struri;
115  }
116 
122  virtual void Clone(InterfaceBaseConstPtr preference, int cloningoptions);
123 
137  virtual bool SendCommand(std::ostream& os, std::istream& is);
138 
153  virtual void Serialize(BaseXMLWriterPtr writer, int options=0) const;
154 
155 protected:
161  typedef boost::function<bool (std::ostream&, std::istream&)> InterfaceCommandFn;
163  {
164 public:
166  }
167  InterfaceCommand(InterfaceCommandFn newfn, const std::string& newhelp) : fn(newfn), help(newhelp) {
168  }
170  std::string help;
171  };
172 
179  virtual void RegisterCommand(const std::string& cmdname, InterfaceCommandFn fncmd, const std::string& strhelp);
180 
182  virtual void UnregisterCommand(const std::string& cmdname);
183 
184  virtual const char* GetHash() const = 0;
185  std::string __description;
186 
187  virtual boost::shared_mutex& GetInterfaceMutex() const {
188  return _mutexInterface;
189  }
190 
191 private:
193  virtual bool _GetCommandHelp(std::ostream& sout, std::istream& sinput) const;
194 
195  inline InterfaceBase& operator=(const InterfaceBase&r) {
196  throw openrave_exception("InterfaceBase copying not allowed");
197  }
198 
199  mutable boost::shared_mutex _mutexInterface;
200  InterfaceType __type;
201  UserDataPtr __plugin;
202  std::string __struri;
203  std::string __strpluginname;
204  std::string __strxmlid;
205  EnvironmentBasePtr __penv;
206  mutable std::map<std::string, UserDataPtr> __mapUserData;
207 
208  READERSMAP __mapReadableInterfaces;
209  typedef std::map<std::string, boost::shared_ptr<InterfaceCommand>, CaseInsensitiveCompare> CMDMAP;
210  CMDMAP __mapCommands;
211 
212 #ifdef RAVE_PRIVATE
213 #ifdef _MSC_VER
214  friend class Environment;
215  friend class OpenRAVEXMLParser::InterfaceXMLReader;
216  friend class XFileReader;
217 #else
218  friend class ::Environment;
219  friend class ::OpenRAVEXMLParser::InterfaceXMLReader;
220  friend class ::XFileReader;
221 #endif
222 #endif
223  friend class ColladaReader;
224  friend class RaveDatabase;
225 };
226 
227 } // end namespace OpenRAVE
228 
229 #endif