YARP
Yet Another Robot Platform
BufferedPort.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 Istituto Italiano di Tecnologia (IIT)
3  * Copyright (C) 2006-2010 RobotCub Consortium
4  * All rights reserved.
5  *
6  * This software may be modified and distributed under the terms of the
7  * BSD-3-Clause license. See the accompanying LICENSE file for details.
8  */
9 
10 #ifndef YARP_OS_BUFFEREDPORT_H
11 #define YARP_OS_BUFFEREDPORT_H
12 
13 #include <yarp/os/Contactable.h>
14 #include <yarp/os/Port.h>
17 
18 
19 // Defined in this file:
20 namespace yarp { namespace os { template <typename T> class BufferedPort; }}
21 
22 
23 namespace yarp {
24 namespace os {
25 
66 template <typename T>
67 class BufferedPort : public Contactable,
68  public TypedReader<T>,
69  public TypedReaderCallback<T>
70 {
71 public:
73 
77  typedef T ContentType;
78 
82  BufferedPort();
83 
87  BufferedPort(Port& port);
88 
92  virtual ~BufferedPort();
93 
94  // Documented in Contactable
95  virtual bool open(const std::string& name) override;
96 
97  // Documented in Contactable
98  virtual bool open(const Contact& contact, bool registerName = true) override;
99 
100  // Documented in Contactable
101  virtual bool addOutput(const std::string& name) override;
102 
103  // Documented in Contactable
104  virtual bool addOutput(const std::string& name, const std::string& carrier) override;
105 
106  // Documented in Contactable
107  virtual bool addOutput(const Contact& contact) override;
108 
109  // Documented in Contactable
110  virtual void close() override;
111 
112  // Documented in Contactable
113  virtual void interrupt() override;
114 
115  virtual void resume() override;
116 
120  virtual int getPendingReads() override;
121 
122  // Documented in Contactable
123  virtual Contact where() const override;
124 
125  // Documented in Contactable
126  virtual std::string getName() const override;
127 
128 
148  T& prepare();
149 
155  bool unprepare();
156 
171  void write(bool forceStrict = false);
172 
183  void writeStrict();
184 
188  void waitForWrite();
189 
190  // Documented in TypedReader
191  virtual void setStrict(bool strict = true) override;
192 
193  // Documented in TypedReader
194  virtual T* read(bool shouldWait = true) override;
195 
196  // Documented in TypedReader
197  virtual T* lastRead() override;
198 
199  // Documented in TypedReader
200  virtual bool isClosed() override;
201 
202  // Documented in TypedReader
203  void setReplier(PortReader& reader) override;
204 
205  // Documented in Contactable
206  void setReader(PortReader& reader) override;
207 
208  // Documented in Contactable
209  void setAdminReader(PortReader& reader) override;
210 
219  virtual void onRead(T& datum) override;
220 
221  // Documented in TypedReader
222  virtual void useCallback(TypedReaderCallback<T>& callback) override;
223 
229  void useCallback();
230 
231  // Documented in TypedReader
232  virtual void disableCallback() override;
233 
234  // documented in Contactable
235  virtual bool setEnvelope(PortWriter& envelope) override;
236 
237  // documented in Contactable
238  virtual bool getEnvelope(PortReader& envelope) override;
239 
240  // documented in Contactable
241  virtual int getInputCount() override;
242 
243  // documented in Contactable
244  virtual int getOutputCount() override;
245 
246  // documented in Contactable
247  bool isWriting() override;
248 
249  // documented in Contactable
250  virtual void getReport(PortReport& reporter) override;
251 
252  // documented in Contactable
253  virtual void setReporter(PortReport& reporter) override;
254 
255  // documented in Contactable
256  virtual void resetReporter() override ;
257 
258  // documented in TypedReader
259  virtual void* acquire() override ;
260 
261  // documented in TypedReader
262  virtual void release(void* handle) override;
263 
264  // documented in TypedReader
265  virtual void setTargetPeriod(double period) override;
266 
267  // documented in Contactable
268  virtual Type getType() override;
269 
270  // documented in Contactable
271  virtual void promiseType(const Type& typ) override;
272 
273  // documented in Contactable
274  virtual void setInputMode(bool expectInput) override;
275 
276  // documented in Contactable
277  virtual void setOutputMode(bool expectOutput) override;
278 
279  // documented in Contactable
280  virtual void setRpcMode(bool expectRpc) override;
281 
282  // documented in Contactable
283  virtual Property* acquireProperties(bool readOnly) override;
284 
285  // documented in Contactable
286  virtual void releaseProperties(Property* prop) override;
287 
288  // documented in Contactable
289  virtual void includeNodeInName(bool flag) override;
290 
291  // documented in Contactable
292  virtual bool setCallbackLock(yarp::os::Mutex* mutex) override;
293 
294  // documented in Contactable
295  virtual bool removeCallbackLock() override;
296 
297  // documented in Contactable
298  virtual bool lockCallback() override;
299 
300  // documented in Contactable
301  virtual bool tryLockCallback() override;
302 
303  // documented in Contactable
304  virtual void unlockCallback() override;
305 
306 private:
311  bool attached;
312 
313  // forbid this
314  BufferedPort(const BufferedPort& alt) = delete;
315  const BufferedPort& operator=(const BufferedPort& alt) = delete;
316 
317  void attachIfNeeded();
318  bool sharedOpen(Port& port);
319 };
320 
321 } // namespace os
322 } // namespace yarp
323 
325 
326 #endif // YARP_OS_BUFFEREDPORT_H
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:430
An abstract port.
Definition: Contactable.h:34
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
Definition: ImageFile.cpp:393
A base class for objects that want information about port status changes.
Definition: PortReport.h:29
A class for storing options and configuration information.
Definition: Property.h:35
A callback for typed data from a port.
Buffer incoming data to a port.
Buffer outgoing data to a port.
A mini-server for network communication.
Definition: Port.h:50
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:26
The main, catch-all namespace for YARP.
Definition: numeric.h:47
PortWriterBuffer< T > writer
Definition: BufferedPort.h:307
Interface implemented by all objects that can read themselves from the network, such as Bottle object...
Definition: PortReader.h:27
T ContentType
The type of content stored by this BufferedPort.
Definition: BufferedPort.h:77
PortReaderBuffer< T > reader
Definition: BufferedPort.h:309
Represents how to reach a part of a YARP network.
Definition: Contact.h:34
A mini-server for performing network communication in the background.
Definition: BufferedPort.h:20
A base class for sources of typed data.
Definition: TypedReader.h:14
Basic wrapper for mutual exclusion.
Definition: Mutex.h:28