iCub-main
IEventListener.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2010 RobotCub Consortium, European Commission FP6 Project IST-004370
3  * author: Arjan Gijsberts
4  * email: arjan.gijsberts@iit.it
5  * website: www.robotcub.org
6  * Permission is granted to copy, distribute, and/or modify this program
7  * under the terms of the GNU General Public License, version 2 or any
8  * later version published by the Free Software Foundation.
9  *
10  * A copy of the license can be found at
11  * http://www.robotcub.org/icub/license/gpl.txt
12  *
13  * This program is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
16  * Public License for more details
17  */
18 
19 #ifndef LM_IEVENTLISTENER__
20 #define LM_IEVENTLISTENER__
21 
25 
26 
27 namespace iCub {
28 namespace learningmachine {
29 
38 // forward prototype declarations
39 class IEvent;
40 class TrainEvent;
41 class PredictEvent;
42 
44 protected:
48  std::string name;
49 
53  bool enabled;
54 
55 public:
60 
64  virtual ~IEventListener() { }
65 
70  virtual void handle(IEvent& e) { }
71 
76  virtual void handle(TrainEvent& e) { }
77 
82  virtual void handle(PredictEvent& e) { }
83 
89  virtual IEventListener* clone() = 0;
90 
96  std::string getName() const {
97  return this->name;
98  }
99 
105  void setName(std::string name) {
106  this->name = name;
107  }
108 
113  virtual void start() { }
114 
120  virtual bool isEnabled() {
121  return this->enabled;
122  }
123 
129  virtual void setEnabled(bool val) {
130  this->enabled = val;
131  }
132 
133  /*
134  * Configure.
135  */
136  virtual bool configure(yarp::os::Searchable& config);
137 
144  virtual std::string getInfo() {
145  return this->getName() + (this->isEnabled() ? " (enabled)" : " (disabled)");
146  }
147 
148 };
149 
150 } // learningmachine
151 } // iCub
152 
153 #endif
virtual std::string getInfo()
Asks the event listener to return a string containing information on its configuration so far.
virtual void start()
Starts the IEventListener, such that it can do perform initialization (e.g.
virtual bool isEnabled()
Tells whether dispatching of events is enabled.
virtual void handle(TrainEvent &e)
Handling of a TrainEvent.
bool enabled
Boolean switch to disable or enable event the listener.
virtual IEventListener * clone()=0
Asks the event listener to return a new object of its type.
std::string name
The name of this type of EventListener.
virtual void handle(PredictEvent &e)
Handling of a PredictEvent.
virtual ~IEventListener()
Destructor (empty).
virtual bool configure(yarp::os::Searchable &config)
void setName(std::string name)
Set the name of this IEventListener.
virtual void setEnabled(bool val)
Enables or disables dispatching of events.
virtual void handle(IEvent &e)
Default handler for any Event, which means the Event is ignored.
std::string getName() const
Retrieve the name of this IEventListener.
A TrainEvent is raised when the machine handles a training sample.
Definition: TrainEvent.h:44
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.