ITS
LocationServicePacketBuffer.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;
13  this->m_lsPacketBuffer = other.m_lsPacketBuffer;
14 }
15 
16 void LocationServicePacketBuffer::addPacket(GnAddr destination, gnDataRequest_t packet, quint32 timestamp)
17 {
18  LocationServicePacketEntry lspe(destination, packet, timestamp);
19 
20  printf("LSPB add toLOCK\n");
21  m_mutex->lock();
22  printf("LSPB add locked\n");
23  /* 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 */
25  {
26  m_lsPacketBuffer.pop_front();
28  }
29 
30  m_lsPacketBuffer.push_back(lspe);
32  printf("LSPB add toUNLOCK\n");
33  m_mutex->unlock();
34  printf("LSPB add UNLOCKED\n");
35 }
36 
38 {
39  printf("LSPB find toLOCK\n");
40  m_mutex->lock();
41  printf("LSPB find locked\n");
42  for(QList<LocationServicePacketEntry>::Iterator i = m_lsPacketBuffer.begin();i != m_lsPacketBuffer.end(); ++i)
43  {
44  if(i->destination() == destination)
45  {
46  printf("LSPB find if toUNLOCK\n");
47  m_mutex->unlock();
48  printf("LSPB find if UNLOCKED\n");
49  return true;
50  }
51  }
52  printf("LSPB find toUNLOCK\n");
53  m_mutex->unlock();
54  printf("LSPB find UNLOCKED\n");
55  return false;
56 }
57 
59 {
60  printf("LSPB erase toLOCK\n");
61  m_mutex->lock();
62  printf("LSPB erase locked\n");
63  int cpt = 0;
64  for(int i = 0 ; i < nbLSForwardingPacketQueued ; i++)
65  {
66  if(m_lsPacketBuffer.at(i).destination() == destination)
67  {
68  m_lsPacketBuffer.removeAt(i--);
70  cpt++;
71  }
72  }
73 // nbLSForwardingPacketQueued -= cpt;
74  printf("LSPB erase toUNLOCK\n");
75  m_mutex->unlock();
76  printf("LSPB erase untoLOCKed\n");
77 }
78 
80 {
81  printf("LSPB remove toLOCK\n");
82  m_mutex->lock();
83  printf("LSPB remove locked\n");
84  m_lsPacketBuffer.removeOne(lspe);
85  printf("LSPB remove toUNLOCK\n");
86  m_mutex->unlock();
87  printf("LSPB remove untoLOCKed\n");
88 }
89 
91 {
92  printf("LSPB clear toLOCK\n");
93  m_mutex->lock();
94  printf("LSPB clear locked\n");
95  m_lsPacketBuffer.clear();
97  printf("LSPB clear toUNLOCK\n");
98  m_mutex->unlock();
99  printf("LSPB clear UNLOCKED\n");
100 }
gnDataRequest_t structure is the GN data request definition.
Definition: GNDataRequest.h:46
void clear()
clear Clear the buffer.
LocationServicePacketBuffer()
LocationServicePacketBuffer Default constructor.
QList< LocationServicePacketEntry > m_lsPacketBuffer
void remove(LocationServicePacketEntry lspe)
find Remove packet in the buffer.
void erase(GnAddr destination)
find Remove packet in the buffer.
Definition: GnAddr.h:28
#define itsGnLocationServicePacketBufferSize
Definition: constantes.h:107
bool find(GnAddr destination)
find Search packet in the buffer.
void addPacket(GnAddr destination, gnDataRequest_t packet, quint32 timestamp)
addPacket Add packet to the buffer.