sot-core  4.11.2
Hierarchical task solver plug-in for dynamic-graph.
mailbox.hh
Go to the documentation of this file.
1 /*
2  * Copyright 2010,
3  * François Bleibel,
4  * Olivier Stasse,
5  *
6  * CNRS/AIST
7  *
8  */
9 
10 #ifndef __SOT_MAILBOX_HH
11 #define __SOT_MAILBOX_HH
12 
13 /* --- SOT PLUGIN --- */
14 #include <dynamic-graph/all-signals.h>
15 #include <dynamic-graph/entity.h>
16 
17 /* --- BOOST --- */
18 #include <boost/thread/mutex.hpp>
19 #include <boost/thread/thread.hpp>
20 #include <boost/thread/xtime.hpp>
21 
22 /* --- STD --- */
23 #include <time.h>
24 #ifndef WIN32
25 #include <sys/time.h>
26 #else
28 #endif /*WIN32*/
29 #include <string>
30 
31 namespace dynamicgraph {
32 namespace sot {
33 
34 namespace dg = dynamicgraph;
35 
36 template <class Object> struct MailboxTimestampedObject {
37  Object obj;
38  struct timeval timestamp;
39 };
40 
41 template <class Object> class Mailbox : public dg::Entity {
42 public:
43  static const std::string CLASS_NAME;
44  virtual const std::string &getClassName(void) const { return CLASS_NAME; }
45 
46 public:
48 
49 public:
50  Mailbox(const std::string &name);
51  ~Mailbox(void);
52 
53  void post(const Object &obj);
54  sotTimestampedObject &get(sotTimestampedObject &res, const int &dummy);
55 
56  Object &getObject(Object &res, const int &time);
57  struct timeval &getTimestamp(struct timeval &res, const int &time);
58 
59  bool hasBeenUpdated(void);
60 
61 protected:
62  boost::timed_mutex mainObjectMutex;
63  Object mainObject;
64  struct timeval mainTimeStamp;
65  bool update;
66 
67 public: /* --- SIGNALS --- */
68  dynamicgraph::SignalTimeDependent<sotTimestampedObject, int> SOUT;
69  dynamicgraph::SignalTimeDependent<Object, int> objSOUT;
70  dynamicgraph::SignalTimeDependent<struct timeval, int> timeSOUT;
71 };
72 
73 } /* namespace sot */
74 
75 template <class Object>
76 struct signal_io<sot::MailboxTimestampedObject<Object> >
77  : signal_io_unimplemented<sot::MailboxTimestampedObject<Object> > {};
78 
79 template <> struct signal_io<timeval> : signal_io_unimplemented<timeval> {};
80 } /* namespace dynamicgraph */
81 
82 #endif // #ifndef __SOT_MAILBOX_HH
dynamicgraph::SignalTimeDependent< struct timeval, int > timeSOUT
Definition: mailbox.hh:70
virtual const std::string & getClassName(void) const
Definition: mailbox.hh:44
boost::timed_mutex mainObjectMutex
Definition: mailbox.hh:62
MailboxTimestampedObject< Object > sotTimestampedObject
Definition: mailbox.hh:47
bool update
Definition: mailbox.hh:65
dynamicgraph::SignalTimeDependent< Object, int > objSOUT
Definition: mailbox.hh:69
static const std::string CLASS_NAME
Definition: mailbox.hh:43
Definition: mailbox.hh:41
Definition: trajectory.hh:85
Object obj
Definition: mailbox.hh:37
Object mainObject
Definition: mailbox.hh:63
dynamicgraph::SignalTimeDependent< sotTimestampedObject, int > SOUT
Definition: mailbox.hh:68
Definition: abstract-sot-external-interface.hh:17