Skip to content

Commit c33ca12

Browse files
committed
Code formatting
Code formatting 1. While loop while (condition); -> do { }while(condition) 2. Lambda [](){ body } -> []{}->return type{ body }
1 parent 6ff7d50 commit c33ca12

File tree

2 files changed

+102
-99
lines changed

2 files changed

+102
-99
lines changed

rx.cpp

Lines changed: 57 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,7 @@ bool ReceptionBlock::Decoding()
311311
uint32_t decodingposition = Header::Data::CodingOffset;
312312
while (decodingposition < length)
313313
{
314-
/*if(length - decodingposition > 1024)
315-
{
316-
Decoding1024(DecodeOut.back().get(), m_DecodedPacketBuffer, m_DecodingMatrix, decodingposition, i, row);
317-
}
318-
else if(length - decodingposition > 512)
319-
{
320-
Decoding512(DecodeOut.back().get(), m_DecodedPacketBuffer, m_DecodingMatrix, decodingposition, i, row);
321-
}
322-
else if(length - decodingposition > 256)
323-
{
324-
Decoding256(DecodeOut.back().get(), m_DecodedPacketBuffer, m_DecodingMatrix, decodingposition, i, row);
325-
}
326-
else */ if (length - decodingposition > 128)
314+
if (length - decodingposition > 128)
327315
{
328316
Decoding128(DecodeOut.back().get(), m_DecodedPacketBuffer, m_DecodingMatrix, decodingposition, i, row);
329317
}
@@ -378,14 +366,18 @@ bool ReceptionBlock::Decoding()
378366
uint8_t *pkt = DecodeOut[i].release();
379367
if (!(reinterpret_cast<Header::Data *>(pkt)->m_Flags & Header::Data::DataHeaderFlag::FLAGS_CONSUMED))
380368
{
381-
while (false == c_Session->m_RxTaskQueue.Enqueue([this, pkt]() {
382-
if (c_Reception->m_RxCallback)
383-
{
384-
c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength);
385-
}
386-
delete[] pkt;
387-
}))
388-
;
369+
bool result = false;
370+
do
371+
{
372+
result = c_Session->m_RxTaskQueue.Enqueue(
373+
[this, pkt]() -> void {
374+
if (c_Reception->m_RxCallback)
375+
{
376+
c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength);
377+
}
378+
delete[] pkt;
379+
});
380+
} while (result == false);
389381
}
390382
else
391383
{
@@ -451,16 +443,20 @@ void ReceptionBlock::Receive(uint8_t *buffer, uint16_t length, const sockaddr *c
451443
try
452444
{
453445
TEST_EXCEPTION(std::bad_alloc());
446+
bool result = false;
454447
pkt = new uint8_t[length];
455448
memcpy(pkt, buffer, length);
456-
while (false == c_Session->m_RxTaskQueue.Enqueue([this, pkt]() {
457-
if (c_Reception->m_RxCallback)
458-
{
459-
c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength);
460-
}
461-
delete[] pkt;
462-
}))
463-
;
449+
do
450+
{
451+
result = c_Session->m_RxTaskQueue.Enqueue(
452+
[this, pkt]() -> void {
453+
if (c_Reception->m_RxCallback)
454+
{
455+
c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength);
456+
}
457+
delete[] pkt;
458+
});
459+
} while (result == false);
464460
reinterpret_cast<Header::Data *>(m_DecodedPacketBuffer.back().get())->m_Flags |= Header::Data::DataHeaderFlag::FLAGS_CONSUMED;
465461
if (reinterpret_cast<Header::Data *>(m_DecodedPacketBuffer.back().get())->m_Flags & Header::Data::DataHeaderFlag::FLAGS_END_OF_BLK)
466462
{
@@ -526,16 +522,20 @@ void ReceptionBlock::Receive(uint8_t *buffer, uint16_t length, const sockaddr *c
526522
try
527523
{
528524
TEST_EXCEPTION(std::bad_alloc());
525+
bool result = false;
529526
pkt = new uint8_t[ntohs(reinterpret_cast<Header::Data *>((*pp_block)->m_DecodedPacketBuffer[i].get())->m_TotalSize)];
530527
memcpy(pkt, (*pp_block)->m_DecodedPacketBuffer[i].get(), ntohs(reinterpret_cast<Header::Data *>((*pp_block)->m_DecodedPacketBuffer[i].get())->m_TotalSize));
531-
while (false == c_Session->m_RxTaskQueue.Enqueue([this, pkt]() {
532-
if (c_Reception->m_RxCallback)
533-
{
534-
c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength);
535-
}
536-
delete[] pkt;
537-
}))
538-
;
528+
do
529+
{
530+
result = c_Session->m_RxTaskQueue.Enqueue(
531+
[this, pkt]() -> void {
532+
if (c_Reception->m_RxCallback)
533+
{
534+
c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength);
535+
}
536+
delete[] pkt;
537+
});
538+
} while (result == false);
539539
reinterpret_cast<Header::Data *>((*pp_block)->m_DecodedPacketBuffer[i].get())->m_Flags |= Header::Data::DataHeaderFlag::FLAGS_CONSUMED;
540540
break;
541541
}
@@ -593,29 +593,37 @@ void ReceptionSession::Receive(uint8_t *buffer, uint16_t length, const sockaddr
593593
for (uint8_t i = 0; i < p_block->m_DecodedPacketBuffer.size(); i++)
594594
{
595595
uint8_t *pkt = p_block->m_DecodedPacketBuffer[i].release();
596+
bool result = false;
596597
if (reinterpret_cast<Header::Data *>(pkt)->m_Flags & Header::Data::DataHeaderFlag::FLAGS_CONSUMED)
597598
{
598599
delete[] pkt;
599600
continue;
600601
}
601-
while (false == m_RxTaskQueue.Enqueue([this, pkt]() {
602-
if (c_Reception->m_RxCallback)
603-
{
604-
c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(pkt)->m_PayloadSize), (sockaddr *)&m_SenderAddress.Addr, m_SenderAddress.AddrLength);
605-
}
606-
delete[] pkt;
607-
}))
608-
;
602+
do
603+
{
604+
result = m_RxTaskQueue.Enqueue(
605+
[this, pkt]() -> void {
606+
if (c_Reception->m_RxCallback)
607+
{
608+
c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(pkt)->m_PayloadSize), (sockaddr *)&m_SenderAddress.Addr, m_SenderAddress.AddrLength);
609+
}
610+
delete[] pkt;
611+
});
612+
} while (result == false);
609613
}
610614
}
611615
}
612616
m_SequenceNumberForService++;
613617
}
614618
m_Blocks.Remove(m_MinSequenceNumberAwaitingAck, [this](ReceptionBlock *&data) {
615-
while (false == m_RxTaskQueue.Enqueue([data]() {
616-
delete data;
617-
}))
618-
;
619+
bool result = false;
620+
do
621+
{
622+
result = m_RxTaskQueue.Enqueue(
623+
[data]() -> void {
624+
delete data;
625+
});
626+
} while (result == false);
619627
});
620628
}
621629
}

tx.cpp

Lines changed: 45 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,19 @@ bool TransmissionBlock::Send(uint8_t *buffer, uint16_t buffersize)
9595
if ((m_TransmissionCount == m_BlockSize))
9696
{
9797
p_Session->p_TransmissionBlock = nullptr;
98-
p_Session->m_Timer.PeriodicTaskAdv([this]() -> std::tuple<bool, uint32_t, uint32_t> {
99-
const bool schedulenextretransmission = Retransmission();
100-
if (schedulenextretransmission)
101-
{
102-
const uint32_t priority = (p_Session->m_MinBlockSequenceNumber == m_BlockSequenceNumber ? TransmissionSession::MIDDLE_PRIORITY : TransmissionSession::LOW_PRIORITY);
103-
return std::make_tuple(schedulenextretransmission, p_Session->m_RetransmissionInterval, priority);
104-
}
105-
else
106-
{
107-
return std::make_tuple(false, 0, 0);
108-
}
109-
});
98+
p_Session->m_Timer.PeriodicTaskAdv(
99+
[this]() -> std::tuple<bool, uint32_t, uint32_t> {
100+
const bool schedulenextretransmission = Retransmission();
101+
if (schedulenextretransmission)
102+
{
103+
const uint32_t priority = (p_Session->m_MinBlockSequenceNumber == m_BlockSequenceNumber ? TransmissionSession::MIDDLE_PRIORITY : TransmissionSession::LOW_PRIORITY);
104+
return std::make_tuple(schedulenextretransmission, p_Session->m_RetransmissionInterval, priority);
105+
}
106+
else
107+
{
108+
return std::make_tuple(false, 0, 0);
109+
}
110+
});
110111
}
111112
return true;
112113
}
@@ -207,19 +208,7 @@ const bool TransmissionBlock::Retransmission()
207208
uint16_t CodingOffset = Header::Data::OffSets::CodingOffset;
208209
while (CodingOffset < length)
209210
{
210-
/*if(length - CodingOffset > 1024)
211-
{
212-
Encoding1024(m_RemedyPacketBuffer, OriginalBuffer, RandomCoefficients, CodingOffset, PacketIndex);
213-
}
214-
else if(length - CodingOffset > 512)
215-
{
216-
Encoding512(m_RemedyPacketBuffer, OriginalBuffer, RandomCoefficients, CodingOffset, PacketIndex);
217-
}
218-
else if(length - CodingOffset > 256)
219-
{
220-
Encoding256(m_RemedyPacketBuffer, OriginalBuffer, RandomCoefficients, CodingOffset, PacketIndex);
221-
}
222-
else */ if (length - CodingOffset > 128)
211+
if (length - CodingOffset > 128)
223212
{
224213
Encoding128(m_RemedyPacketBuffer, OriginalBuffer, RandomCoefficients, CodingOffset, PacketIndex);
225214
}
@@ -291,35 +280,39 @@ TransmissionSession::~TransmissionSession()
291280
/*OK*/
292281
void TransmissionSession::ChangeTransmissionMode(const Parameter::TRANSMISSION_MODE TransmissionMode)
293282
{
294-
m_Timer.ImmediateTask([this, TransmissionMode]() {
295-
m_TransmissionMode = TransmissionMode;
296-
});
283+
m_Timer.ImmediateTask(
284+
[this, TransmissionMode]() -> void {
285+
m_TransmissionMode = TransmissionMode;
286+
});
297287
}
298288

299289
/*OK*/
300290
void TransmissionSession::ChangeBlockSize(const Parameter::BLOCK_SIZE BlockSize)
301291
{
302-
m_Timer.ImmediateTask([this, BlockSize]() {
303-
m_BlockSize = BlockSize;
304-
});
292+
m_Timer.ImmediateTask(
293+
[this, BlockSize]() -> void {
294+
m_BlockSize = BlockSize;
295+
});
305296
}
306297

307298
/*OK*/
308299
void TransmissionSession::ChangeRetransmissionRedundancy(const uint16_t RetransmissionRedundancy)
309300
{
310-
m_Timer.ImmediateTask([this, RetransmissionRedundancy]() {
311-
m_RetransmissionRedundancy = RetransmissionRedundancy;
312-
});
301+
m_Timer.ImmediateTask(
302+
[this, RetransmissionRedundancy]() -> void {
303+
m_RetransmissionRedundancy = RetransmissionRedundancy;
304+
});
313305
}
314306

315307
/*OK*/
316308
void TransmissionSession::ChangeSessionParameter(const Parameter::TRANSMISSION_MODE TransmissionMode, const Parameter::BLOCK_SIZE BlockSize, const uint16_t RetransmissionRedundancy)
317309
{
318-
m_Timer.ImmediateTask([this, TransmissionMode, BlockSize, RetransmissionRedundancy]() {
319-
m_TransmissionMode = TransmissionMode;
320-
m_BlockSize = BlockSize;
321-
m_RetransmissionRedundancy = RetransmissionRedundancy;
322-
});
310+
m_Timer.ImmediateTask(
311+
[this, TransmissionMode, BlockSize, RetransmissionRedundancy]() -> void {
312+
m_TransmissionMode = TransmissionMode;
313+
m_BlockSize = BlockSize;
314+
m_RetransmissionRedundancy = RetransmissionRedundancy;
315+
});
323316
}
324317

325318
const bool TransmissionSession::SendPing()
@@ -345,15 +338,16 @@ const bool TransmissionSession::SendPing()
345338

346339
void TransmissionSession::ProcessPong(const uint16_t rtt)
347340
{
348-
m_Timer.ImmediateTask([this, rtt]() {
349-
m_RetransmissionInterval = (m_RetransmissionInterval + rtt) / 2;
350-
});
341+
m_Timer.ImmediateTask(
342+
[this, rtt]() -> void {
343+
m_RetransmissionInterval = (m_RetransmissionInterval + rtt) / 2;
344+
});
351345
}
352346

353347
void TransmissionSession::ProcessDataAck(const uint16_t sequence, const uint8_t loss)
354348
{
355349
m_Timer.ImmediateTask(
356-
[this, sequence, loss]() {
350+
[this, sequence, loss]() -> void {
357351
if (m_AckList[sequence % (Parameter::MAXIMUM_NUMBER_OF_CONCURRENT_RETRANSMISSION * 2)] == true)
358352
{
359353
return;
@@ -368,7 +362,7 @@ void TransmissionSession::ProcessDataAck(const uint16_t sequence, const uint8_t
368362
void TransmissionSession::ProcessSyncAck(const uint16_t sequence)
369363
{
370364
m_Timer.ImmediateTask(
371-
[this, sequence]() {
365+
[this, sequence]() -> void {
372366
if (sequence == m_MaxBlockSequenceNumber)
373367
{
374368
m_IsConnected = true;
@@ -385,7 +379,7 @@ Transmission::Transmission(int32_t Socket) : c_Socket(Socket) {}
385379
/* OK */
386380
Transmission::~Transmission()
387381
{
388-
m_Sessions.DoSomethingOnAllData([](TransmissionSession *&session) { delete session; });
382+
m_Sessions.DoSomethingOnAllData([](TransmissionSession *&session) -> void { delete session; });
389383
m_Sessions.Clear();
390384
}
391385

@@ -488,7 +482,7 @@ bool Transmission::Send(const DataStructures::AddressType Addr, uint8_t *buffer,
488482
std::this_thread::sleep_for(std::chrono::milliseconds(1));
489483
}
490484
const uint32_t TransmissionIsScheduled = p_session->m_Timer.ImmediateTask(
491-
[buffer, buffersize, p_session, &TransmissionIsCompleted, &TransmissionResult]() {
485+
[buffer, buffersize, p_session, &TransmissionIsCompleted, &TransmissionResult]() -> void {
492486
// 1. Get Transmission Block
493487
if (p_session->p_TransmissionBlock == nullptr)
494488
{
@@ -553,7 +547,7 @@ bool Transmission::Flush(const DataStructures::AddressType Addr)
553547
return false;
554548
}
555549
const uint32_t TaskID = p_session->m_Timer.ImmediateTask(
556-
[p_session]() {
550+
[p_session]() -> void {
557551
// 1. Get Transmission Block
558552
if (p_session->p_TransmissionBlock)
559553
{
@@ -622,9 +616,10 @@ void Transmission::Disconnect(const DataStructures::AddressType Addr)
622616
{
623617
std::this_thread::sleep_for(std::chrono::milliseconds(1));
624618
}
625-
m_Sessions.Remove(key, [](TransmissionSession *&session) {
626-
delete session;
627-
});
619+
m_Sessions.Remove(key,
620+
[](TransmissionSession *&session) -> void {
621+
delete session;
622+
});
628623
}
629624

630625
/* OK */

0 commit comments

Comments
 (0)