From c33ca127260734fbf8a7fe02195fcd3284d06cb0 Mon Sep 17 00:00:00 2001 From: Dujeong Lee Date: Sun, 8 Oct 2017 19:48:44 +0900 Subject: [PATCH] Code formatting Code formatting 1. While loop while (condition); -> do { }while(condition) 2. Lambda [](){ body } -> []{}->return type{ body } --- rx.cpp | 106 +++++++++++++++++++++++++++++++-------------------------- tx.cpp | 95 ++++++++++++++++++++++++--------------------------- 2 files changed, 102 insertions(+), 99 deletions(-) diff --git a/rx.cpp b/rx.cpp index fd44ef1..80805aa 100755 --- a/rx.cpp +++ b/rx.cpp @@ -311,19 +311,7 @@ bool ReceptionBlock::Decoding() uint32_t decodingposition = Header::Data::CodingOffset; while (decodingposition < length) { - /*if(length - decodingposition > 1024) - { - Decoding1024(DecodeOut.back().get(), m_DecodedPacketBuffer, m_DecodingMatrix, decodingposition, i, row); - } - else if(length - decodingposition > 512) - { - Decoding512(DecodeOut.back().get(), m_DecodedPacketBuffer, m_DecodingMatrix, decodingposition, i, row); - } - else if(length - decodingposition > 256) - { - Decoding256(DecodeOut.back().get(), m_DecodedPacketBuffer, m_DecodingMatrix, decodingposition, i, row); - } - else */ if (length - decodingposition > 128) + if (length - decodingposition > 128) { Decoding128(DecodeOut.back().get(), m_DecodedPacketBuffer, m_DecodingMatrix, decodingposition, i, row); } @@ -378,14 +366,18 @@ bool ReceptionBlock::Decoding() uint8_t *pkt = DecodeOut[i].release(); if (!(reinterpret_cast(pkt)->m_Flags & Header::Data::DataHeaderFlag::FLAGS_CONSUMED)) { - while (false == c_Session->m_RxTaskQueue.Enqueue([this, pkt]() { - if (c_Reception->m_RxCallback) - { - c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength); - } - delete[] pkt; - })) - ; + bool result = false; + do + { + result = c_Session->m_RxTaskQueue.Enqueue( + [this, pkt]() -> void { + if (c_Reception->m_RxCallback) + { + c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength); + } + delete[] pkt; + }); + } while (result == false); } else { @@ -451,16 +443,20 @@ void ReceptionBlock::Receive(uint8_t *buffer, uint16_t length, const sockaddr *c try { TEST_EXCEPTION(std::bad_alloc()); + bool result = false; pkt = new uint8_t[length]; memcpy(pkt, buffer, length); - while (false == c_Session->m_RxTaskQueue.Enqueue([this, pkt]() { - if (c_Reception->m_RxCallback) - { - c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength); - } - delete[] pkt; - })) - ; + do + { + result = c_Session->m_RxTaskQueue.Enqueue( + [this, pkt]() -> void { + if (c_Reception->m_RxCallback) + { + c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength); + } + delete[] pkt; + }); + } while (result == false); reinterpret_cast(m_DecodedPacketBuffer.back().get())->m_Flags |= Header::Data::DataHeaderFlag::FLAGS_CONSUMED; if (reinterpret_cast(m_DecodedPacketBuffer.back().get())->m_Flags & Header::Data::DataHeaderFlag::FLAGS_END_OF_BLK) { @@ -526,16 +522,20 @@ void ReceptionBlock::Receive(uint8_t *buffer, uint16_t length, const sockaddr *c try { TEST_EXCEPTION(std::bad_alloc()); + bool result = false; pkt = new uint8_t[ntohs(reinterpret_cast((*pp_block)->m_DecodedPacketBuffer[i].get())->m_TotalSize)]; memcpy(pkt, (*pp_block)->m_DecodedPacketBuffer[i].get(), ntohs(reinterpret_cast((*pp_block)->m_DecodedPacketBuffer[i].get())->m_TotalSize)); - while (false == c_Session->m_RxTaskQueue.Enqueue([this, pkt]() { - if (c_Reception->m_RxCallback) - { - c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength); - } - delete[] pkt; - })) - ; + do + { + result = c_Session->m_RxTaskQueue.Enqueue( + [this, pkt]() -> void { + if (c_Reception->m_RxCallback) + { + c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast(pkt)->m_PayloadSize), (sockaddr *)&c_Session->m_SenderAddress.Addr, c_Session->m_SenderAddress.AddrLength); + } + delete[] pkt; + }); + } while (result == false); reinterpret_cast((*pp_block)->m_DecodedPacketBuffer[i].get())->m_Flags |= Header::Data::DataHeaderFlag::FLAGS_CONSUMED; break; } @@ -593,29 +593,37 @@ void ReceptionSession::Receive(uint8_t *buffer, uint16_t length, const sockaddr for (uint8_t i = 0; i < p_block->m_DecodedPacketBuffer.size(); i++) { uint8_t *pkt = p_block->m_DecodedPacketBuffer[i].release(); + bool result = false; if (reinterpret_cast(pkt)->m_Flags & Header::Data::DataHeaderFlag::FLAGS_CONSUMED) { delete[] pkt; continue; } - while (false == m_RxTaskQueue.Enqueue([this, pkt]() { - if (c_Reception->m_RxCallback) - { - c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast(pkt)->m_PayloadSize), (sockaddr *)&m_SenderAddress.Addr, m_SenderAddress.AddrLength); - } - delete[] pkt; - })) - ; + do + { + result = m_RxTaskQueue.Enqueue( + [this, pkt]() -> void { + if (c_Reception->m_RxCallback) + { + c_Reception->m_RxCallback(pkt + sizeof(Header::Data) + reinterpret_cast(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast(pkt)->m_PayloadSize), (sockaddr *)&m_SenderAddress.Addr, m_SenderAddress.AddrLength); + } + delete[] pkt; + }); + } while (result == false); } } } m_SequenceNumberForService++; } m_Blocks.Remove(m_MinSequenceNumberAwaitingAck, [this](ReceptionBlock *&data) { - while (false == m_RxTaskQueue.Enqueue([data]() { - delete data; - })) - ; + bool result = false; + do + { + result = m_RxTaskQueue.Enqueue( + [data]() -> void { + delete data; + }); + } while (result == false); }); } } diff --git a/tx.cpp b/tx.cpp index 746c2b3..d396acb 100755 --- a/tx.cpp +++ b/tx.cpp @@ -95,18 +95,19 @@ bool TransmissionBlock::Send(uint8_t *buffer, uint16_t buffersize) if ((m_TransmissionCount == m_BlockSize)) { p_Session->p_TransmissionBlock = nullptr; - p_Session->m_Timer.PeriodicTaskAdv([this]() -> std::tuple { - const bool schedulenextretransmission = Retransmission(); - if (schedulenextretransmission) - { - const uint32_t priority = (p_Session->m_MinBlockSequenceNumber == m_BlockSequenceNumber ? TransmissionSession::MIDDLE_PRIORITY : TransmissionSession::LOW_PRIORITY); - return std::make_tuple(schedulenextretransmission, p_Session->m_RetransmissionInterval, priority); - } - else - { - return std::make_tuple(false, 0, 0); - } - }); + p_Session->m_Timer.PeriodicTaskAdv( + [this]() -> std::tuple { + const bool schedulenextretransmission = Retransmission(); + if (schedulenextretransmission) + { + const uint32_t priority = (p_Session->m_MinBlockSequenceNumber == m_BlockSequenceNumber ? TransmissionSession::MIDDLE_PRIORITY : TransmissionSession::LOW_PRIORITY); + return std::make_tuple(schedulenextretransmission, p_Session->m_RetransmissionInterval, priority); + } + else + { + return std::make_tuple(false, 0, 0); + } + }); } return true; } @@ -207,19 +208,7 @@ const bool TransmissionBlock::Retransmission() uint16_t CodingOffset = Header::Data::OffSets::CodingOffset; while (CodingOffset < length) { - /*if(length - CodingOffset > 1024) - { - Encoding1024(m_RemedyPacketBuffer, OriginalBuffer, RandomCoefficients, CodingOffset, PacketIndex); - } - else if(length - CodingOffset > 512) - { - Encoding512(m_RemedyPacketBuffer, OriginalBuffer, RandomCoefficients, CodingOffset, PacketIndex); - } - else if(length - CodingOffset > 256) - { - Encoding256(m_RemedyPacketBuffer, OriginalBuffer, RandomCoefficients, CodingOffset, PacketIndex); - } - else */ if (length - CodingOffset > 128) + if (length - CodingOffset > 128) { Encoding128(m_RemedyPacketBuffer, OriginalBuffer, RandomCoefficients, CodingOffset, PacketIndex); } @@ -291,35 +280,39 @@ TransmissionSession::~TransmissionSession() /*OK*/ void TransmissionSession::ChangeTransmissionMode(const Parameter::TRANSMISSION_MODE TransmissionMode) { - m_Timer.ImmediateTask([this, TransmissionMode]() { - m_TransmissionMode = TransmissionMode; - }); + m_Timer.ImmediateTask( + [this, TransmissionMode]() -> void { + m_TransmissionMode = TransmissionMode; + }); } /*OK*/ void TransmissionSession::ChangeBlockSize(const Parameter::BLOCK_SIZE BlockSize) { - m_Timer.ImmediateTask([this, BlockSize]() { - m_BlockSize = BlockSize; - }); + m_Timer.ImmediateTask( + [this, BlockSize]() -> void { + m_BlockSize = BlockSize; + }); } /*OK*/ void TransmissionSession::ChangeRetransmissionRedundancy(const uint16_t RetransmissionRedundancy) { - m_Timer.ImmediateTask([this, RetransmissionRedundancy]() { - m_RetransmissionRedundancy = RetransmissionRedundancy; - }); + m_Timer.ImmediateTask( + [this, RetransmissionRedundancy]() -> void { + m_RetransmissionRedundancy = RetransmissionRedundancy; + }); } /*OK*/ void TransmissionSession::ChangeSessionParameter(const Parameter::TRANSMISSION_MODE TransmissionMode, const Parameter::BLOCK_SIZE BlockSize, const uint16_t RetransmissionRedundancy) { - m_Timer.ImmediateTask([this, TransmissionMode, BlockSize, RetransmissionRedundancy]() { - m_TransmissionMode = TransmissionMode; - m_BlockSize = BlockSize; - m_RetransmissionRedundancy = RetransmissionRedundancy; - }); + m_Timer.ImmediateTask( + [this, TransmissionMode, BlockSize, RetransmissionRedundancy]() -> void { + m_TransmissionMode = TransmissionMode; + m_BlockSize = BlockSize; + m_RetransmissionRedundancy = RetransmissionRedundancy; + }); } const bool TransmissionSession::SendPing() @@ -345,15 +338,16 @@ const bool TransmissionSession::SendPing() void TransmissionSession::ProcessPong(const uint16_t rtt) { - m_Timer.ImmediateTask([this, rtt]() { - m_RetransmissionInterval = (m_RetransmissionInterval + rtt) / 2; - }); + m_Timer.ImmediateTask( + [this, rtt]() -> void { + m_RetransmissionInterval = (m_RetransmissionInterval + rtt) / 2; + }); } void TransmissionSession::ProcessDataAck(const uint16_t sequence, const uint8_t loss) { m_Timer.ImmediateTask( - [this, sequence, loss]() { + [this, sequence, loss]() -> void { if (m_AckList[sequence % (Parameter::MAXIMUM_NUMBER_OF_CONCURRENT_RETRANSMISSION * 2)] == true) { return; @@ -368,7 +362,7 @@ void TransmissionSession::ProcessDataAck(const uint16_t sequence, const uint8_t void TransmissionSession::ProcessSyncAck(const uint16_t sequence) { m_Timer.ImmediateTask( - [this, sequence]() { + [this, sequence]() -> void { if (sequence == m_MaxBlockSequenceNumber) { m_IsConnected = true; @@ -385,7 +379,7 @@ Transmission::Transmission(int32_t Socket) : c_Socket(Socket) {} /* OK */ Transmission::~Transmission() { - m_Sessions.DoSomethingOnAllData([](TransmissionSession *&session) { delete session; }); + m_Sessions.DoSomethingOnAllData([](TransmissionSession *&session) -> void { delete session; }); m_Sessions.Clear(); } @@ -488,7 +482,7 @@ bool Transmission::Send(const DataStructures::AddressType Addr, uint8_t *buffer, std::this_thread::sleep_for(std::chrono::milliseconds(1)); } const uint32_t TransmissionIsScheduled = p_session->m_Timer.ImmediateTask( - [buffer, buffersize, p_session, &TransmissionIsCompleted, &TransmissionResult]() { + [buffer, buffersize, p_session, &TransmissionIsCompleted, &TransmissionResult]() -> void { // 1. Get Transmission Block if (p_session->p_TransmissionBlock == nullptr) { @@ -553,7 +547,7 @@ bool Transmission::Flush(const DataStructures::AddressType Addr) return false; } const uint32_t TaskID = p_session->m_Timer.ImmediateTask( - [p_session]() { + [p_session]() -> void { // 1. Get Transmission Block if (p_session->p_TransmissionBlock) { @@ -622,9 +616,10 @@ void Transmission::Disconnect(const DataStructures::AddressType Addr) { std::this_thread::sleep_for(std::chrono::milliseconds(1)); } - m_Sessions.Remove(key, [](TransmissionSession *&session) { - delete session; - }); + m_Sessions.Remove(key, + [](TransmissionSession *&session) -> void { + delete session; + }); } /* OK */