FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
serial::vita49::PacedSender Class Reference

#include "paced_sender.h"

Public Member Functions

 PacedSender (std::unique_ptr< DatagramSender > sender, std::size_t queue_depth)
 
 ~PacedSender ()
 
 PacedSender (const PacedSender &)=delete
 
PacedSenderoperator= (const PacedSender &)=delete
 
void open (const std::string &host, std::uint16_t port)
 
void start (RealType simulation_epoch_time=0.0)
 
EnqueueResult enqueue (SerializedPacket packet)
 
bool enqueueBatch (std::vector< SerializedPacket > packets)
 
void flush ()
 
void stop ()
 
std::uint64_t lateDataPacketCount (std::uint32_t stream_id) const
 
std::uint64_t lateContextPacketCount (std::uint32_t stream_id) const
 
std::uint64_t sentPacketCount (std::uint32_t stream_id) const
 
std::uint64_t sendFailureCount (std::uint32_t stream_id) const
 
std::uint64_t droppedDataPacketCount (std::uint32_t stream_id) const
 
std::uint64_t droppedContextPacketCount (std::uint32_t stream_id) const
 
std::uint64_t droppedSampleCount (std::uint32_t stream_id) const
 
std::vector< DroppedDatagramconsumeDroppedDatagrams ()
 

Detailed Description

Definition at line 38 of file paced_sender.h.

Constructor & Destructor Documentation

◆ PacedSender() [1/2]

serial::vita49::PacedSender::PacedSender ( std::unique_ptr< DatagramSender sender,
std::size_t  queue_depth 
)

Definition at line 37 of file paced_sender.cpp.

37 :
38 _sender(std::move(sender)), _queue_depth(queue_depth)
39 {
40 if (!_sender)
41 {
42 throw std::invalid_argument("PacedSender requires a datagram sender");
43 }
44 if (queue_depth == 0)
45 {
46 throw std::invalid_argument("PacedSender queue depth must be positive");
47 }
48 }
math::Vec3 max

◆ ~PacedSender()

serial::vita49::PacedSender::~PacedSender ( )

Definition at line 50 of file paced_sender.cpp.

References stop().

+ Here is the call graph for this function:

◆ PacedSender() [2/2]

serial::vita49::PacedSender::PacedSender ( const PacedSender )
delete

Member Function Documentation

◆ consumeDroppedDatagrams()

std::vector< DroppedDatagram > serial::vita49::PacedSender::consumeDroppedDatagrams ( )

Definition at line 221 of file paced_sender.cpp.

222 {
223 std::scoped_lock const lock(_mutex);
224 auto result = std::move(_pending_dropped_datagrams);
225 _pending_dropped_datagrams.clear();
226 return result;
227 }

References max.

◆ droppedContextPacketCount()

std::uint64_t serial::vita49::PacedSender::droppedContextPacketCount ( std::uint32_t  stream_id) const

Definition at line 207 of file paced_sender.cpp.

208 {
209 std::scoped_lock const lock(_mutex);
210 const auto found = _dropped_context_packets.find(stream_id);
211 return found == _dropped_context_packets.end() ? 0 : found->second;
212 }

References max.

◆ droppedDataPacketCount()

std::uint64_t serial::vita49::PacedSender::droppedDataPacketCount ( std::uint32_t  stream_id) const

Definition at line 200 of file paced_sender.cpp.

201 {
202 std::scoped_lock const lock(_mutex);
203 const auto found = _dropped_data_packets.find(stream_id);
204 return found == _dropped_data_packets.end() ? 0 : found->second;
205 }

References max.

◆ droppedSampleCount()

std::uint64_t serial::vita49::PacedSender::droppedSampleCount ( std::uint32_t  stream_id) const

Definition at line 214 of file paced_sender.cpp.

215 {
216 std::scoped_lock const lock(_mutex);
217 const auto found = _dropped_samples.find(stream_id);
218 return found == _dropped_samples.end() ? 0 : found->second;
219 }

References max.

◆ enqueue()

EnqueueResult serial::vita49::PacedSender::enqueue ( SerializedPacket  packet)

Definition at line 68 of file paced_sender.cpp.

69 {
70 std::unique_lock lock(_mutex);
71 if (!_started)
72 {
73 throw std::logic_error("PacedSender must be started before enqueue");
74 }
75 if (_stopping)
76 {
77 return EnqueueResult{
78 .enqueued = false,
79 .dropped = std::nullopt,
80 };
81 }
82
83 while (queuedOrSendingCount() >= _queue_depth)
84 {
85 const bool precedes_latest = !_queue.empty() && packet.first_sample_time < _queue.back().first_sample_time;
86 if (!_priority_overflow_in_progress && precedes_latest)
87 {
88 _priority_overflow_in_progress = true;
89 insertByDeadlineUnlocked(std::move(packet));
90 _cv.notify_all();
91 _cv.wait(lock, [this] { return _stopping || queuedOrSendingCount() <= _queue_depth; });
92 _priority_overflow_in_progress = false;
93 _cv.notify_all();
94 return EnqueueResult{.enqueued = true, .dropped = std::nullopt};
95 }
96
97 _cv.wait(lock);
98 if (_stopping)
99 {
100 return EnqueueResult{
101 .enqueued = false,
102 .dropped = std::nullopt,
103 };
104 }
105 }
106
107 insertByDeadlineUnlocked(std::move(packet));
108 _cv.notify_all();
109 return EnqueueResult{.enqueued = true, .dropped = std::nullopt};
110 }

References serial::vita49::EnqueueResult::enqueued, and max.

◆ enqueueBatch()

bool serial::vita49::PacedSender::enqueueBatch ( std::vector< SerializedPacket packets)

Definition at line 112 of file paced_sender.cpp.

113 {
114 if (packets.empty())
115 {
116 return true;
117 }
118
119 std::unique_lock lock(_mutex);
120 if (!_started)
121 {
122 throw std::logic_error("PacedSender must be started before enqueue");
123 }
124 if (_stopping)
125 {
126 return false;
127 }
128
129 for (auto& packet : packets)
130 {
131 insertByDeadlineUnlocked(std::move(packet));
132 }
133 _cv.notify_all();
134 _cv.wait(lock, [this] { return _stopping || queuedOrSendingCount() <= _queue_depth; });
135 return true;
136 }

References max.

◆ flush()

void serial::vita49::PacedSender::flush ( )

Definition at line 138 of file paced_sender.cpp.

139 {
140 std::unique_lock lock(_mutex);
141 _cv.wait(lock, [this] { return _queue.empty() && !_send_in_progress; });
142 }

References max.

◆ lateContextPacketCount()

std::uint64_t serial::vita49::PacedSender::lateContextPacketCount ( std::uint32_t  stream_id) const

Definition at line 179 of file paced_sender.cpp.

180 {
181 std::scoped_lock const lock(_mutex);
182 const auto found = _late_context_packets.find(stream_id);
183 return found == _late_context_packets.end() ? 0 : found->second;
184 }

References max.

◆ lateDataPacketCount()

std::uint64_t serial::vita49::PacedSender::lateDataPacketCount ( std::uint32_t  stream_id) const

Definition at line 172 of file paced_sender.cpp.

173 {
174 std::scoped_lock const lock(_mutex);
175 const auto found = _late_data_packets.find(stream_id);
176 return found == _late_data_packets.end() ? 0 : found->second;
177 }

References max.

◆ open()

void serial::vita49::PacedSender::open ( const std::string &  host,
std::uint16_t  port 
)

Definition at line 52 of file paced_sender.cpp.

52{ _sender->open(host, port); }

◆ operator=()

PacedSender & serial::vita49::PacedSender::operator= ( const PacedSender )
delete

◆ sendFailureCount()

std::uint64_t serial::vita49::PacedSender::sendFailureCount ( std::uint32_t  stream_id) const

Definition at line 193 of file paced_sender.cpp.

194 {
195 std::scoped_lock const lock(_mutex);
196 const auto found = _send_failures.find(stream_id);
197 return found == _send_failures.end() ? 0 : found->second;
198 }

References max.

◆ sentPacketCount()

std::uint64_t serial::vita49::PacedSender::sentPacketCount ( std::uint32_t  stream_id) const

Definition at line 186 of file paced_sender.cpp.

187 {
188 std::scoped_lock const lock(_mutex);
189 const auto found = _sent_packets.find(stream_id);
190 return found == _sent_packets.end() ? 0 : found->second;
191 }

References max.

◆ start()

void serial::vita49::PacedSender::start ( RealType  simulation_epoch_time = 0.0)

Definition at line 54 of file paced_sender.cpp.

55 {
56 std::scoped_lock const lock(_mutex);
57 if (_started)
58 {
59 return;
60 }
61 _simulation_epoch_time = simulation_epoch_time;
62 _steady_epoch = std::chrono::steady_clock::now();
63 _stopping = false;
64 _started = true;
65 _thread = std::thread([this] { run(); });
66 }

References max.

◆ stop()

void serial::vita49::PacedSender::stop ( )

Definition at line 144 of file paced_sender.cpp.

145 {
146 {
147 std::scoped_lock const lock(_mutex);
148 if (!_started && !_thread.joinable())
149 {
150 _sender->close();
151 return;
152 }
153 _stopping = true;
154 _cv.notify_all();
155 }
156
157 if (_thread.joinable())
158 {
159 _thread.join();
160 }
161
162 {
163 std::scoped_lock const lock(_mutex);
164 _started = false;
165 _stopping = false;
166 _send_in_progress = false;
167 _cv.notify_all();
168 }
169 _sender->close();
170 }

References max.

Referenced by ~PacedSender().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: