YARP
Yet Another Robot Platform
PortCorePacket.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_IMPL_PORTCOREPACKET_H
11 #define YARP_OS_IMPL_PORTCOREPACKET_H
12 
13 #include <yarp/os/NetType.h>
14 #include <yarp/os/PortWriter.h>
15 
16 namespace yarp {
17 namespace os {
18 namespace impl {
19 
25 {
26 public:
31  int ct;
32  bool owned;
34  bool completed;
35 
40  prev_(nullptr),
41  next_(nullptr),
42  content(nullptr),
43  callback(nullptr),
44  ct(0),
45  owned(false),
46  ownedCallback(false),
47  completed(false)
48  {
49  reset();
50  }
51 
55  virtual ~PortCorePacket()
56  {
57  complete();
58  reset();
59  }
60 
64  int getCount()
65  {
66  return ct;
67  }
68 
72  void inc()
73  {
74  ct++;
75  }
76 
80  void dec()
81  {
82  ct--;
83  }
84 
89  {
90  return content;
91  }
92 
97  {
98  return (callback != nullptr) ? callback : content;
99  }
100 
109  void setContent(const yarp::os::PortWriter* writable,
110  bool owned = false,
111  const yarp::os::PortWriter* callback = nullptr,
112  bool ownedCallback = false)
113  {
114  content = writable;
115  this->callback = callback;
116  ct = 1;
117  this->owned = owned;
118  this->ownedCallback = ownedCallback;
119  completed = false;
120  }
121 
125  void reset()
126  {
127  if (owned) {
128  delete content;
129  }
130  if (ownedCallback) {
131  delete callback;
132  }
133  content = nullptr;
134  callback = nullptr;
135  ct = 0;
136  owned = false;
137  ownedCallback = false;
138  completed = false;
139  }
140 
145  void complete()
146  {
147  if (!completed) {
148  if (getContent() != nullptr) {
150  completed = true;
151  }
152  }
153  }
154 };
155 
156 } // namespace impl
157 } // namespace os
158 } // namespace yarp
159 
160 #endif // YARP_OS_IMPL_PORTCOREPACKET_H
yarp::os::impl::PortCorePacket::owned
bool owned
should we memory-manage the content object
Definition: PortCorePacket.h:32
yarp::os::impl::PortCorePacket::getContent
const yarp::os::PortWriter * getContent()
Definition: PortCorePacket.h:88
yarp::os::impl::PortCorePacket::getCallback
const yarp::os::PortWriter * getCallback()
Definition: PortCorePacket.h:96
yarp::os::impl::PortCorePacket::callback
const yarp::os::PortWriter * callback
where to send event notifications
Definition: PortCorePacket.h:30
yarp::os::impl::PortCorePacket::ownedCallback
bool ownedCallback
should we memory-manage the callback object
Definition: PortCorePacket.h:33
yarp::os::impl::PortCorePacket::dec
void dec()
Decrement the usage count for this messagae.
Definition: PortCorePacket.h:80
yarp::os::PortWriter::onCompletion
virtual void onCompletion() const
This is called when the port has finished all writing operations.
Definition: PortWriter.cpp:16
yarp::os::PortWriter
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:27
yarp::os::impl::PortCorePacket::inc
void inc()
Increment the usage count for this messagae.
Definition: PortCorePacket.h:72
yarp::os::impl::PortCorePacket::PortCorePacket
PortCorePacket()
Constructor.
Definition: PortCorePacket.h:39
NetType.h
PortWriter.h
yarp::os::impl::PortCorePacket::prev_
PortCorePacket * prev_
this packet will be in a list of active packets
Definition: PortCorePacket.h:27
yarp::os::impl::PortCorePacket::content
const yarp::os::PortWriter * content
the object being sent
Definition: PortCorePacket.h:29
yarp::os::impl::PortCorePacket
A single message, potentially being transmitted on multiple connections.
Definition: PortCorePacket.h:25
yarp::os::impl::PortCorePacket::ct
int ct
number of uses of the messagae
Definition: PortCorePacket.h:31
yarp::os::impl::PortCorePacket::reset
void reset()
Delete anything we own and enter a clean state, as if freshly created.
Definition: PortCorePacket.h:125
yarp::os::impl::PortCorePacket::completed
bool completed
has a notification of completion been sent
Definition: PortCorePacket.h:34
yarp::os::impl::PortCorePacket::getCount
int getCount()
Definition: PortCorePacket.h:64
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::os::impl::PortCorePacket::next_
PortCorePacket * next_
this packet will be in a list of active packets
Definition: PortCorePacket.h:28
yarp::os::impl::PortCorePacket::setContent
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.
Definition: PortCorePacket.h:109
yarp::os::impl::PortCorePacket::~PortCorePacket
virtual ~PortCorePacket()
Destructor.
Definition: PortCorePacket.h:55
yarp::os::impl::PortCorePacket::complete
void complete()
Send a completion notification if we haven't already, and there's somewhere to send it to.
Definition: PortCorePacket.h:145