FreeNOS
NetworkQueue.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef __LIB_LIBNET_NETWORKQUEUE_H
19 #define __LIB_LIBNET_NETWORKQUEUE_H
20 
21 #include <Types.h>
22 #include <Index.h>
23 #include <Memory.h>
24 #include <Log.h>
25 
38 {
39  public:
40 
42  static const Size PayloadBufferSize = 2048;
43 
45  static const Size MaxPackets = 64u;
46 
50  typedef struct Packet
51  {
53  u8 *data;
54  }
55  Packet;
56 
57  public:
58 
65  NetworkQueue(const Size packetSize,
66  const Size queueSize = MaxPackets);
67 
71  virtual ~NetworkQueue();
72 
76  Packet * get();
77 
81  void release(Packet *packet);
82 
86  void push(Packet *packet);
87 
91  Packet * pop();
92 
98  bool hasData() const;
99 
100  private:
101 
104 
107 
110 };
111 
112 Log & operator << (Log &log, const NetworkQueue::Packet & pkt);
113 
119 #endif /* __LIB_LIBNET_NETWORKQUEUE_H */
NetworkQueue::NetworkQueue
NetworkQueue(const Size packetSize, const Size queueSize=MaxPackets)
Constructor.
Definition: NetworkQueue.cpp:23
Memory::Range
Memory range.
Definition: Memory.h:55
operator<<
Log & operator<<(Log &log, const NetworkQueue::Packet &pkt)
Definition: NetworkQueue.cpp:117
Types.h
NetworkQueue::pop
Packet * pop()
Retrieve packet with data.
Definition: NetworkQueue.cpp:98
Index.h
NetworkQueue::Packet
struct NetworkQueue::Packet Packet
Represents a network packet.
NetworkQueue::MaxPackets
static const Size MaxPackets
Maximum number of packets available.
Definition: NetworkQueue.h:45
NetworkQueue::m_free
Index< Packet, MaxPackets > m_free
Contains unused packets.
Definition: NetworkQueue.h:103
Index
Index is a N-sized array of pointers to items of type T.
Definition: Index.h:36
NetworkQueue::m_data
Index< Packet, MaxPackets > m_data
Contains packets with data.
Definition: NetworkQueue.h:106
NetworkQueue::Packet::data
u8 * data
Definition: NetworkQueue.h:53
NetworkQueue::release
void release(Packet *packet)
Put unused packet back.
Definition: NetworkQueue.cpp:87
NetworkQueue::Packet::size
Size size
Definition: NetworkQueue.h:52
NetworkQueue::hasData
bool hasData() const
Check if data packets are available.
Definition: NetworkQueue.cpp:112
NetworkQueue
Networking packet queue implementation.
Definition: NetworkQueue.h:37
NetworkQueue::get
Packet * get()
Get unused packet.
Definition: NetworkQueue.cpp:72
Log.h
Log
Logging class.
Definition: Log.h:96
NetworkQueue::push
void push(Packet *packet)
Enqueue packet with data.
Definition: NetworkQueue.cpp:93
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
NetworkQueue::~NetworkQueue
virtual ~NetworkQueue()
Destructor.
Definition: NetworkQueue.cpp:58
Memory.h
u8
unsigned char u8
Unsigned 8-bit number.
Definition: Types.h:59
NetworkQueue::PayloadBufferSize
static const Size PayloadBufferSize
Size of payload memory buffer.
Definition: NetworkQueue.h:42
NetworkQueue::Packet
Represents a network packet.
Definition: NetworkQueue.h:50
NetworkQueue::m_payloadRange
Memory::Range m_payloadRange
Defines the memory range of mapped payload data.
Definition: NetworkQueue.h:109