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>
43 DYNAMIC_GRAPH_ENTITY_DECL();
45 Event(
const std::string &name)
47 checkSOUT(
"Event(" + name +
")::output(bool)::check"),
48 conditionSIN(NULL,
"Event(" + name +
")::input(bool)::condition"),
51 repeatAfterNIterations_(0) {
52 checkSOUT.setFunction(boost::bind(&Event::check,
this, _1, _2));
53 signalRegistration(conditionSIN);
54 signalRegistration(checkSOUT);
56 using command::makeCommandVoid1;
57 std::string docstring =
60 addCommand(
"addSignal",
61 makeCommandVoid1(*
this, &Event::addSignal, docstring));
65 " Get list of signals\n";
66 addCommand(
"list",
new command::Getter<Event, std::string>(
67 *
this, &Event::getSignalsByName, docstring));
71 " Repease event if input signal remains True for a while\n"
72 " Input: number of iterations before repeating output\n."
73 " 0 for no repetition";
74 addCommand(
"repeat",
new command::Setter<Event, int>(*
this, &Event::repeat,
81 virtual std::string getDocString()
const {
82 return "Send an event when the input changes\n\n"
83 " The signal triggered is called whenever the condition is "
87 void addSignal(
const std::string &signal) {
88 std::istringstream iss(signal);
93 std::string getSignalsByName()
const {
94 std::ostringstream oss;
96 for (Triggers_t::const_iterator _sig = triggers.begin();
97 _sig != triggers.end(); ++_sig)
98 oss <<
'\'' << (*_sig)->getName() <<
"\', ";
103 void repeat(
const int &nbIterations) {
104 repeatAfterNIterations_ = nbIterations;
108 typedef SignalBase<int> *Trigger_t;
109 typedef std::vector<Trigger_t> Triggers_t;
111 bool &check(
bool &ret,
const int &time);
113 Signal<bool, int> checkSOUT;
116 SignalPtr<bool, int> conditionSIN;
119 int timeSinceUp_, repeatAfterNIterations_;
static PoolStorage * getInstance()
Get unique instance of the class.
#define SOT_CORE_DLLAPI
Definition: config.hh:64
Definition: abstract-sot-external-interface.hh:17