ITS
UnicastForwardingPacketBuffer.cpp
Go to the documentation of this file.
2 
4 
6 {
7  m_mutex = new QMutex;
8 }
9 
11 {
12  this->m_mutex = other.m_mutex;
14 }
15 
16 void UnicastForwardingPacketBuffer::addPacket(BasicHeader bh, CommonHeader ch, GUCPacket guc, QByteArray payload, QByteArray sender)
17 {
18  m_mutex->lock();
19  UnicastForwardingPacketEntry bfpe(bh, ch, guc, payload, sender);
20 
21  /* If the number of packet exceed the max buffer size, the first packet will be dropped and the packet will be added to the end of the queue */
23  {
24  m_ucForwardPacketBuffer.pop_front();
26  }
27 
28  /* If packet is already in the buffer, replace the old one with the new one */
29 
30  bfpe.m_elapsed.start();
31  m_ucForwardPacketBuffer.push_back(bfpe);
33  m_mutex->unlock();
34 }
35 
37 {
38  bool b = false;
39  int j = 0;
40  for(QVector<UnicastForwardingPacketEntry>::Iterator i = m_ucForwardPacketBuffer.begin();j < m_ucForwardPacketBuffer.size(); ++i, j++)
41  if(isDuplicatePacketDetectionTimestampSN(i->gucPacket().soPv().timestamp(), packet.soPv().timestamp(), i->gucPacket().sequenceNumber(), packet.sequenceNumber()))
42  {
43  m_ucForwardPacketBuffer.erase(i);
45  b = true;
46  }
47  return b;
48 }
49 
51 {
52  bool b = false;
53  m_mutex->lock();
54  for(QVector<UnicastForwardingPacketEntry>::Iterator i = m_ucForwardPacketBuffer.begin();i != m_ucForwardPacketBuffer.end(); ++i)
55  if(isDuplicatePacketDetectionTimestampSN(i->gucPacket().soPv().timestamp(), packet.soPv().timestamp(), i->gucPacket().sequenceNumber(), packet.sequenceNumber()))
56  b = true;
57  m_mutex->unlock();
58  return b;
59 }
60 
62 {
63  m_mutex->lock();
66  m_mutex->unlock();
67 }
void addPacket(BasicHeader bh, CommonHeader ch, GUCPacket packet, QByteArray payload, QByteArray sender)
addPacket Add packet to the buffer.
QVector< UnicastForwardingPacketEntry > m_ucForwardPacketBuffer
quint32 timestamp() const
timestamp Timestamp field getter
QElapsedTimer m_elapsed
Buffer used for unicast forwarding.
UnicastForwardingPacketBuffer()
UnicastForwardingPacketBuffer Default constructor.
bool isDuplicatePacketDetectionTimestampSN(quint32 lastReceivedTimestamp, quint32 nowReceivedTimestamp, quint16 lastReceivedSN, quint16 nowReceivedSN)
isDuplicatePacketDetectionTimestamp Calculate if the packet is a duplicate using the timestamp and th...
Definition: apiNetwork.cpp:104
bool isDuplicateTimestamp(GUCPacket packet)
isDuplicateTimestamp Check is the packet is duplicate.
bool erase(GUCPacket packet)
erase Remove packet from the buffer.
#define itsGnUcForwardingPacketBufferSize
Definition: constantes.h:125
quint16 sequenceNumber() const
sequenceNumber GUC sequence number getter.
Definition: GUCPacket.h:72
LongPositionVector soPv() const
soPv GUC SO PV getter.
Definition: GUCPacket.h:77
void clear()
clear Clear the buffer.