YARP
Yet Another Robot Platform
PortWriterBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 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_PORTWRITERBUFFER_H
11 #define YARP_OS_PORTWRITERBUFFER_H
12 
13 #include <yarp/os/Portable.h>
15 
16 namespace yarp {
17 namespace os {
18 
19 class Port;
20 
21 #ifndef DOXYGEN_SHOULD_SKIP_THIS
22 
23 template <class T>
24 class PortWriterBufferAdaptor : public PortWriterWrapper
25 {
26 public:
27  PortWriterBufferManager& creator;
28  T writer;
29  void* tracker;
30 
31  PortWriterBufferAdaptor(PortWriterBufferManager& creator,
32  void* tracker) :
33  creator(creator),
34  tracker(tracker)
35  {
36  }
37 
38  bool write(ConnectionWriter& connection) const override
39  {
40  return writer.write(connection);
41  }
42 
43  void onCompletion() const override
44  {
45  writer.onCompletion();
46  creator.onCompletion(tracker);
47  }
48 
49  void onCommencement() const override
50  {
51  writer.onCommencement();
52  }
53 
54  PortWriter* getInternal() override
55  {
56  return &writer;
57  }
58 };
59 
60 #endif // DOXYGEN_SHOULD_SKIP_THIS
61 
62 
68 template <class T>
70 {
71 public:
81  T& prepare()
82  {
83  return get();
84  }
85 
93  bool unprepare()
94  {
95  return releaseContent();
96  }
97 
102  T& get()
103  {
104  PortWriterBufferAdaptor<T>* content = (PortWriterBufferAdaptor<T>*)getContent(); // guaranteed to be non-NULL
105  return content->writer;
106  }
107 
116  int getCount()
117  {
119  }
120 
125  void attach(Port& port)
126  {
128  }
129 
133  void write(bool forceStrict = false)
134  {
135  PortWriterBufferBase::write(forceStrict);
136  }
137 
142  {
144  }
145 
146  virtual PortWriterWrapper* create(PortWriterBufferManager& man,
147  void* tracker) override
148  {
149  return new PortWriterBufferAdaptor<T>(man, tracker);
150  }
151 };
152 
153 } // namespace os
154 } // namespace yarp
155 
156 #endif // YARP_OS_PORTWRITERBUFFER_H
yarp::os::PortWriterBufferBase::getContent
const void * getContent() const
Definition: PortWriterBufferBase.cpp:194
PortWriterBufferBase.h
yarp::os::PortWriterBuffer::waitForWrite
void waitForWrite()
Wait until any pending writes are done.
Definition: PortWriterBuffer.h:141
yarp::os::PortWriterBufferBase::write
void write(bool strict)
Definition: PortWriterBufferBase.cpp:220
yarp::os::PortWriterBuffer::prepare
T & prepare()
Access the object which will be transmitted by the next call to PortWriterBuffer::write.
Definition: PortWriterBuffer.h:81
Portable.h
yarp::os::PortWriterBuffer::unprepare
bool unprepare()
Give the last prepared object back to YARP without writing it.
Definition: PortWriterBuffer.h:93
yarp::os::PortWriterBuffer
Buffer outgoing data to a port.
Definition: PortWriterBuffer.h:70
yarp::os::PortWriterBufferBase::getCount
int getCount()
Definition: PortWriterBufferBase.cpp:205
yarp::os::PortWriterBufferBase::attach
void attach(Port &port)
Definition: PortWriterBufferBase.cpp:210
yarp::os::Port
A mini-server for network communication.
Definition: Port.h:50
yarp::os::PortWriterBuffer::create
virtual PortWriterWrapper * create(PortWriterBufferManager &man, void *tracker) override
Definition: PortWriterBuffer.h:146
yarp::os::PortWriterBuffer::getCount
int getCount()
Check the number of buffers currently in use for communication.
Definition: PortWriterBuffer.h:116
yarp::os::PortWriterBuffer::attach
void attach(Port &port)
Set the Port to which objects will be written.
Definition: PortWriterBuffer.h:125
yarp::os::PortWriterBufferBase::waitForWrite
void waitForWrite()
Definition: PortWriterBufferBase.cpp:225
yarp::os::PortWriterBufferBase::releaseContent
bool releaseContent()
Definition: PortWriterBufferBase.cpp:199
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::PortWriterBuffer::get
T & get()
A synonym of PortWriterBuffer::prepare.
Definition: PortWriterBuffer.h:102
yarp::os::PortWriterBuffer::write
void write(bool forceStrict=false)
Try to write the last buffer returned by PortWriterBuffer::get.
Definition: PortWriterBuffer.h:133
yarp::os::PortWriterBufferBase
Definition: PortWriterBufferBase.h:40
yarp::sig::file::write
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:971