4 #ifndef __SOT_EVENT_H__
5 #define __SOT_EVENT_H__
7 #include <dynamic-graph/command-bind.h>
8 #include <dynamic-graph/command-getter.h>
9 #include <dynamic-graph/command-setter.h>
10 #include <dynamic-graph/entity.h>
11 #include <dynamic-graph/pool.h>
12 #include <dynamic-graph/signal-ptr.h>
13 #include <dynamic-graph/signal-time-dependent.h>
14 #include <dynamic-graph/signal.h>
16 #include <sot/core/config.hh>
21 class SOT_CORE_DLLAPI
Event :
public dynamicgraph::Entity {
22 DYNAMIC_GRAPH_ENTITY_DECL();
24 Event(
const std::string &name)
25 : Entity(name), checkSOUT(
"Event(" + name +
")::output(bool)::check"),
26 conditionSIN(NULL,
"Event(" + name +
")::input(bool)::condition"),
29 checkSOUT.setFunction(boost::bind(&Event::check,
this, _1, _2));
30 signalRegistration(conditionSIN);
31 signalRegistration(checkSOUT);
33 using command::makeCommandVoid1;
34 std::string docstring =
"\n"
36 addCommand(
"addSignal",
37 makeCommandVoid1(*
this, &Event::addSignal, docstring));
40 " Get list of signals\n";
41 addCommand(
"list",
new command::Getter<Event, std::string>(
42 *
this, &Event::getSignalsByName, docstring));
46 " Triggers an event only when condition goes from False to True\n";
47 addCommand(
"setOnlyUp",
new command::Setter<Event, bool>(
48 *
this, &Event::setOnlyUp, docstring));
54 virtual std::string getDocString()
const {
55 return "Send an event when the input changes\n\n"
56 " The signal triggered is called whenever the condition is "
60 void addSignal(
const std::string &signal) {
61 std::istringstream iss(signal);
66 std::string getSignalsByName()
const {
67 std::ostringstream oss;
69 for (Triggers_t::const_iterator _sig = triggers.begin();
70 _sig != triggers.end(); ++_sig)
71 oss <<
'\'' << (*_sig)->getName() <<
"\', ";
76 void setOnlyUp(
const bool &up) { onlyUp_ = up; }
79 typedef SignalBase<int> *Trigger_t;
80 typedef std::vector<Trigger_t> Triggers_t;
82 bool &check(
bool &ret,
const int &time);
84 Signal<bool, int> checkSOUT;
87 SignalPtr<bool, int> conditionSIN;
89 bool lastVal_, onlyUp_;
93 #endif // __SOT_EVENT_H__