YARP
Yet Another Robot Platform
PortCorePacket.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_IMPL_PORTCOREPACKET_H
8#define YARP_OS_IMPL_PORTCOREPACKET_H
9
10#include <yarp/os/NetType.h>
11#include <yarp/os/PortWriter.h>
12
13namespace yarp::os::impl {
14
20{
21public:
26 int ct;
27 bool owned;
29 bool completed;
30
35 prev_(nullptr),
36 next_(nullptr),
37 content(nullptr),
38 callback(nullptr),
39 ct(0),
40 owned(false),
41 ownedCallback(false),
42 completed(false)
43 {
44 reset();
45 }
46
51 {
52 complete();
53 reset();
54 }
55
60 {
61 return ct;
62 }
63
67 void inc()
68 {
69 ct++;
70 }
71
75 void dec()
76 {
77 ct--;
78 }
79
84 {
85 return content;
86 }
87
92 {
93 return (callback != nullptr) ? callback : content;
94 }
95
104 void setContent(const yarp::os::PortWriter* writable,
105 bool owned = false,
106 const yarp::os::PortWriter* callback = nullptr,
107 bool ownedCallback = false)
108 {
109 content = writable;
110 this->callback = callback;
111 ct = 1;
112 this->owned = owned;
113 this->ownedCallback = ownedCallback;
114 completed = false;
115 }
116
120 void reset()
121 {
122 if (owned) {
123 delete content;
124 }
125 if (ownedCallback) {
126 delete callback;
127 }
128 content = nullptr;
129 callback = nullptr;
130 ct = 0;
131 owned = false;
132 ownedCallback = false;
133 completed = false;
134 }
135
140 void complete()
141 {
142 if (!completed) {
143 if (getContent() != nullptr) {
145 completed = true;
146 }
147 }
148 }
149};
150
151} // namespace yarp::os::impl
152
153#endif // YARP_OS_IMPL_PORTCOREPACKET_H
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:23
virtual void onCompletion() const
This is called when the port has finished all writing operations.
Definition: PortWriter.cpp:13
A single message, potentially being transmitted on multiple connections.
bool completed
has a notification of completion been sent
void setContent(const yarp::os::PortWriter *writable, bool owned=false, const yarp::os::PortWriter *callback=nullptr, bool ownedCallback=false)
Configure the object being sent and where to send notifications.
PortCorePacket * prev_
this packet will be in a list of active packets
int ct
number of uses of the messagae
void inc()
Increment the usage count for this messagae.
const yarp::os::PortWriter * callback
where to send event notifications
virtual ~PortCorePacket()
Destructor.
void complete()
Send a completion notification if we haven't already, and there's somewhere to send it to.
const yarp::os::PortWriter * getContent()
void reset()
Delete anything we own and enter a clean state, as if freshly created.
const yarp::os::PortWriter * content
the object being sent
bool ownedCallback
should we memory-manage the callback object
PortCorePacket * next_
this packet will be in a list of active packets
const yarp::os::PortWriter * getCallback()
void dec()
Decrement the usage count for this messagae.
bool owned
should we memory-manage the content object
The components from which ports and connections are built.