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 
13 namespace yarp {
14 namespace os {
15 namespace impl {
16 
22 {
23 public:
28  int ct;
29  bool owned;
31  bool completed;
32 
37  prev_(nullptr),
38  next_(nullptr),
39  content(nullptr),
40  callback(nullptr),
41  ct(0),
42  owned(false),
43  ownedCallback(false),
44  completed(false)
45  {
46  reset();
47  }
48 
52  virtual ~PortCorePacket()
53  {
54  complete();
55  reset();
56  }
57 
61  int getCount()
62  {
63  return ct;
64  }
65 
69  void inc()
70  {
71  ct++;
72  }
73 
77  void dec()
78  {
79  ct--;
80  }
81 
86  {
87  return content;
88  }
89 
94  {
95  return (callback != nullptr) ? callback : content;
96  }
97 
106  void setContent(const yarp::os::PortWriter* writable,
107  bool owned = false,
108  const yarp::os::PortWriter* callback = nullptr,
109  bool ownedCallback = false)
110  {
111  content = writable;
112  this->callback = callback;
113  ct = 1;
114  this->owned = owned;
115  this->ownedCallback = ownedCallback;
116  completed = false;
117  }
118 
122  void reset()
123  {
124  if (owned) {
125  delete content;
126  }
127  if (ownedCallback) {
128  delete callback;
129  }
130  content = nullptr;
131  callback = nullptr;
132  ct = 0;
133  owned = false;
134  ownedCallback = false;
135  completed = false;
136  }
137 
142  void complete()
143  {
144  if (!completed) {
145  if (getContent() != nullptr) {
147  completed = true;
148  }
149  }
150  }
151 };
152 
153 } // namespace impl
154 } // namespace os
155 } // namespace yarp
156 
157 #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:24
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 * getContent()
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.
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
const yarp::os::PortWriter * getCallback()
PortCorePacket * next_
this packet will be in a list of active packets
void dec()
Decrement the usage count for this messagae.
bool owned
should we memory-manage the content object
The main, catch-all namespace for YARP.
Definition: dirs.h:16