Skip to content

Commit

Permalink
Code formatting
Browse files Browse the repository at this point in the history
Code formatting
1. While loop
while (condition);
->
do
{

}while(condition)

2. Lambda
[](){
   body
}
->
[]{}->return type{
   body
}
  • Loading branch information
dujeonglee committed Oct 8, 2017
1 parent 6ff7d50 commit c33ca12
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 99 deletions.
106 changes: 57 additions & 49 deletions rx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -378,14 +366,18 @@ bool ReceptionBlock::Decoding()
uint8_t *pkt = DecodeOut[i].release();
if (!(reinterpret_cast<Header::Data *>(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<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);
}
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<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);
}
delete[] pkt;
});
} while (result == false);
}
else
{
Expand Down Expand Up @@ -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<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);
}
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<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);
}
delete[] pkt;
});
} while (result == false);
reinterpret_cast<Header::Data *>(m_DecodedPacketBuffer.back().get())->m_Flags |= Header::Data::DataHeaderFlag::FLAGS_CONSUMED;
if (reinterpret_cast<Header::Data *>(m_DecodedPacketBuffer.back().get())->m_Flags & Header::Data::DataHeaderFlag::FLAGS_END_OF_BLK)
{
Expand Down Expand Up @@ -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<Header::Data *>((*pp_block)->m_DecodedPacketBuffer[i].get())->m_TotalSize)];
memcpy(pkt, (*pp_block)->m_DecodedPacketBuffer[i].get(), ntohs(reinterpret_cast<Header::Data *>((*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<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);
}
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<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);
}
delete[] pkt;
});
} while (result == false);
reinterpret_cast<Header::Data *>((*pp_block)->m_DecodedPacketBuffer[i].get())->m_Flags |= Header::Data::DataHeaderFlag::FLAGS_CONSUMED;
break;
}
Expand Down Expand Up @@ -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<Header::Data *>(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<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(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<Header::Data *>(pkt)->m_MaximumRank - 1, ntohs(reinterpret_cast<Header::Data *>(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);
});
}
}
Expand Down
95 changes: 45 additions & 50 deletions tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool, uint32_t, uint32_t> {
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<bool, uint32_t, uint32_t> {
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;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit c33ca12

Please sign in to comment.