YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
PortWriterBuffer.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_OS_PORTWRITERBUFFER_H
8#define YARP_OS_PORTWRITERBUFFER_H
9
10#include <yarp/os/Portable.h>
12
13namespace yarp::os {
14
15class Port;
16
17#ifndef DOXYGEN_SHOULD_SKIP_THIS
18
19template <class T>
20class PortWriterBufferAdaptor : public PortWriterWrapper
21{
22public:
23 PortWriterBufferManager& creator;
24 T writer;
25 void* tracker;
26
27 PortWriterBufferAdaptor(PortWriterBufferManager& creator,
28 void* tracker) :
31 {
32 }
33
34 bool write(ConnectionWriter& connection) const override
35 {
36 return writer.write(connection);
37 }
38
39 void onCompletion() const override
40 {
41 writer.onCompletion();
42 creator.onCompletion(tracker);
43 }
44
45 void onCommencement() const override
46 {
47 writer.onCommencement();
48 }
49
50 PortWriter* getInternal() override
51 {
52 return &writer;
53 }
54};
55
56#endif // DOXYGEN_SHOULD_SKIP_THIS
57
58
64template <class T>
66{
67public:
78 {
79 return get();
80 }
81
89 bool unprepare()
90 {
91 return releaseContent();
92 }
93
98 T& get()
99 {
100 PortWriterBufferAdaptor<T>* content = (PortWriterBufferAdaptor<T>*)getContent(); // guaranteed to be non-NULL
101 return content->writer;
102 }
103
113 {
115 }
116
121 void attach(Port& port)
122 {
124 }
125
129 void write(bool forceStrict = false)
130 {
132 }
133
141
142 virtual PortWriterWrapper* create(PortWriterBufferManager& man,
143 void* tracker) override
144 {
146 }
147};
148
149} // namespace yarp::os
150
151#endif // YARP_OS_PORTWRITERBUFFER_H
A mini-server for performing network communication in the background.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
Buffer outgoing data to a port.
bool unprepare()
Give the last prepared object back to YARP without writing it.
T & get()
A synonym of PortWriterBuffer::prepare.
void write(bool forceStrict=false)
Try to write the last buffer returned by PortWriterBuffer::get.
void waitForWrite()
Wait until any pending writes are done.
int getCount()
Check the number of buffers currently in use for communication.
T & prepare()
Access the object which will be transmitted by the next call to PortWriterBuffer::write.
void attach(Port &port)
Set the Port to which objects will be written.
virtual PortWriterWrapper * create(PortWriterBufferManager &man, void *tracker) override
A mini-server for network communication.
Definition Port.h:46
An interface to the operating system, including Port based communication.