iCub-main
IPortEventListener.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_IPORTEVENTLISTENER__
20 #define LM_IPORTEVENTLISTENER__
21 
22 #include <string>
23 
24 #include <yarp/os/Port.h>
25 
27 
28 
29 namespace iCub {
30 namespace learningmachine {
31 
44 protected:
48  yarp::os::Port port;
49 
53  bool verbose;
54 
58  std::string portPrefix;
59 
67  void resetPort(std::string portName);
68 
69 public:
75  IPortEventListener(std::string pp) : portPrefix(pp), verbose(false) { }
76 
81  : IEventListener(other), portPrefix(other.portPrefix), verbose(other.verbose) { }
82 
86  virtual ~IPortEventListener() {
87  this->port.interrupt();
88  this->port.close();
89  }
90 
94  virtual IPortEventListener& operator=(const IPortEventListener& other);
95 
99  virtual void start() {
100  this->resetPort("");
101  }
102 
103  /*
104  * Configure.
105  */
106  virtual bool configure(yarp::os::Searchable& config);
107 
114  virtual std::string getInfo() {
115  std::string verbosity = this->verbose ? "verbose" : "silent";
116  return this->IEventListener::getInfo() + " [port: " + this->port.where().toString().c_str() + " " + verbosity + "]";
117  }
118 
119 };
120 
121 } // learningmachine
122 } // iCub
123 
124 #endif
virtual std::string getInfo()
Asks the event listener to return a string containing information on its configuration so far.
The abstract base class for EventListeners that output to a port.
yarp::os::Port port
The outgoing port for the events.
IPortEventListener(const IPortEventListener &other)
Copy Constructor.
virtual std::string getInfo()
Asks the event listener to return a string containing information on its configuration so far.
IPortEventListener(std::string pp)
Constructor.
bool verbose
Verbosity controls whether events are printed to standard output.
std::string portPrefix
A prefix path for the ports that will be registered.
virtual IPortEventListener & operator=(const IPortEventListener &other)
Assignment operator.
virtual bool configure(yarp::os::Searchable &config)
virtual void start()
Starts the IEventListener.
void resetPort(std::string portName)
Resets the port and opens it at the specified name.
int verbosity
Definition: main.cpp:17
This file contains the definition of unique IDs for the body parts and the skin parts of the robot.