YARP
Yet Another Robot Platform
PortCorePackets.cpp
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
8
10
13
14namespace {
15YARP_OS_LOG_COMPONENT(PORTCOREPACKETS, "yarp.os.impl.PortCorePackets")
16} // namespace
17
18PortCorePackets::~PortCorePackets()
19{
20 while (!inactive.empty()) {
21 delete inactive.back();
22 inactive.pop_back();
23 }
24 while (!active.empty()) {
25 delete active.back();
26 active.pop_back();
27 }
28}
29
31{
32 return active.size();
33}
34
36{
37 if (inactive.empty()) {
38 PortCorePacket* obj = nullptr;
39 obj = new PortCorePacket();
40 yCAssert(PORTCOREPACKETS, obj != nullptr);
41 inactive.push_back(obj);
42 }
43 PortCorePacket* next = inactive.front();
44 if (next == nullptr) {
45 yCError(PORTCOREPACKETS, "*** YARP consistency check failed.\n");
46 yCError(PORTCOREPACKETS, "*** There has been a low-level failure in \"PortCorePackets\".\n");
47 yCError(PORTCOREPACKETS, "*** This typically occurs when ports are accessed in a non-threadsafe way.\n");
48 yCError(PORTCOREPACKETS, "*** For help: https://github.com/robotology/yarp/issues/new\n");
49 }
50 yCAssert(PORTCOREPACKETS, next != nullptr);
51 inactive.remove(next);
52 active.push_back(next);
53 return next;
54}
55
57{
58 if (packet != nullptr) {
59 if (clear) {
60 packet->reset();
61 }
62 packet->completed = true;
63 active.remove(packet);
64 inactive.push_back(packet);
65 }
66}
67
69{
70 if (packet != nullptr) {
71 if (packet->getCount() <= 0) {
72 packet->complete();
73 return true;
74 }
75 }
76 return false;
77}
78
80{
81 if (packet != nullptr) {
82 if (packet->getCount() <= 0) {
83 packet->complete();
84 freePacket(packet);
85 return true;
86 }
87 }
88 return false;
89}
A single message, potentially being transmitted on multiple connections.
bool completed
has a notification of completion been sent
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.
A collection of messages being transmitted over connections.
bool completePacket(PortCorePacket *packet)
Send a completion notification if a packet has finished being sent on all connections.
PortCorePacket * getFreePacket()
Get a packet that we can prepare for sending.
bool checkPacket(PortCorePacket *packet)
Move a packet to the inactive state if it has finished being sent on all connections.
void freePacket(PortCorePacket *packet, bool clear=true)
Force the given packet into an inactive state.
#define yCError(component,...)
Definition: LogComponent.h:213
#define yCAssert(component, x)
Definition: LogComponent.h:240
#define YARP_OS_LOG_COMPONENT(name, name_string)
Definition: LogComponent.h:29