#include <PacketQueue.h>
Inherits CLockMechanism.
Public Member Functions | |
CPacketQueue () | |
virtual | ~CPacketQueue () |
bool | setQueueMaxsize (INT32 maxsize, UINT32 &lasterr) |
Adjust the Queue depth. | |
UINT32 | getLastError () |
Returns last error code happened. | |
bool | pop_front (CMessage **obj, UINT32 &lasterr) |
Gets the first message (FIFO) out of the queue. | |
bool | push_back (const CMessage *obj, UINT32 &lasterr) |
Appends a CMessage object to the end of the (FIFO) queue. | |
bool | remove_elem (UINT16 requestid, UINT32 &lasterr) |
bool | find_elem (UINT16 requestid, CMessage **obj, UINT32 &lasterr) |
bool | find_and_remove_elem (UINT16 requestid, CMessage **obj, UINT32 &lasterr) |
int | size (UINT32 &lasterr) |
bool | find_elem_ack_and_signal (const CMessage &aAckPacket, UINT32 &lasterr) |
bool | find_and_remove_passed_elem (CMessage *obj, UINT32 &lasterr) |
bool | setQueueMaxsize (INT32 maxsize) |
bool | pop_front (CMessage **obj) |
bool | push_back (const CMessage *obj) |
bool | remove_elem (UINT16 requestid) |
bool | find_elem (UINT16 requestid, CMessage **obj) |
bool | find_and_remove_elem (UINT16 requestid, CMessage **obj) |
int | size () |
Returns the current amount of elements stored in the queue. | |
bool | find_elem_ack_and_signal (const CMessage &aAckPacket) |
bool | find_and_remove_passed_elem (CMessage *obj) |
Private Attributes | |
INT32 | m_iQueueFirstElement |
INT32 | m_iQueueLastElement |
INT32 | m_iQueueNumElements |
VOIDP * | m_pQueueValue |
INT32 * | m_iQueueNextElement |
INT32 | m_iQueueMaxSize |
UINT32 | m_iLastError |
Friends | |
class | CMessage |
Using C++ STL this could be done much more easily, but implementation on Nios2 platform did not work (reason not fully known, stack issues suspected). This CPacketQueue was created as a slightly inferior, but working solution.
Implementation details:
Definition at line 25 of file PacketQueue.h.
CPacketQueue::CPacketQueue | ( | ) |
Definition at line 12 of file PacketQueue.cpp.
CPacketQueue::~CPacketQueue | ( | ) | [virtual] |
Definition at line 37 of file PacketQueue.cpp.
bool CPacketQueue::setQueueMaxsize | ( | INT32 | maxsize, | |
UINT32 & | lasterr | |||
) |
Adjust the Queue depth.
This method adjusts the queue depth by reinitializing the queue pool. Any data accumulated in the queue might be lost after readjustment.
maxsize | new 'queue depth' | |
lasterr | unique error code |
true | successfully readjusted to 'maxsize' depth | |
false | failure, something happened (see lasterr) if lasterr ERR_PQ_LOCK, mutex locking failed |
Definition at line 122 of file PacketQueue.cpp.
Referenced by CNetworkQueue::CNetworkQueue(), and setQueueMaxsize().
UINT32 CPacketQueue::getLastError | ( | ) |
Returns last error code happened.
for detailed list of possible error codes, see Declarations.h
Definition at line 766 of file PacketQueue.cpp.
bool CPacketQueue::pop_front | ( | CMessage ** | obj, | |
UINT32 & | lasterr | |||
) |
Gets the first message (FIFO) out of the queue.
obj | place to store extracted element (empty variable of type CMessage) | |
lasterr | unique error code |
true | successful, first element extracted and put to **obj | |
false | failure, something happened (see lasterr) |
Definition at line 175 of file PacketQueue.cpp.
Referenced by CNetworkQueue::close(), pop_front(), CNetworkQueue::recvMsg(), and CNetworkQueue::SendProcessTask().
bool CPacketQueue::push_back | ( | const CMessage * | obj, | |
UINT32 & | lasterr | |||
) |
Appends a CMessage object to the end of the (FIFO) queue.
obj | object reference to store | |
lasterr | unique error code |
true | successful, element reference to obj appended | |
false | failure, something happened (see lasterr) |
Definition at line 237 of file PacketQueue.cpp.
Referenced by push_back(), CNetworkQueue::ReceiveProcessTask(), CNetworkQueue::sendMsgTo(), and CNetworkQueue::sendMsgToInternal().
bool CPacketQueue::remove_elem | ( | UINT16 | requestid, | |
UINT32 & | lasterr | |||
) |
This method traverses the queue, looks for a CMessage element that contains the 'requestid' and removes it.
requestid | CMessage object's request id (this object will be removed from the queue if found) | |
lasterr | unique error code |
true | successful, element reference was removed | |
false | failure, something happened (see lasterr) |
Definition at line 325 of file PacketQueue.cpp.
Referenced by remove_elem().
bool CPacketQueue::find_elem | ( | UINT16 | requestid, | |
CMessage ** | obj, | |||
UINT32 & | lasterr | |||
) |
This method traverses the queue, looks for a CMessage element that contains the 'requestid' and returns it without removeing it.
requestid | CMessage object's request id (this object will be returned if found) | |
obj | place to store element, if found (empty variable of type CMessage *) | |
lasterr | unique error code |
true | successful, element is returned | |
false | failure, something happened, element is NOT returned (see lasterr) |
Definition at line 426 of file PacketQueue.cpp.
Referenced by find_elem().
bool CPacketQueue::find_and_remove_elem | ( | UINT16 | requestid, | |
CMessage ** | obj, | |||
UINT32 & | lasterr | |||
) |
This method traverses the queue, looks for a CMessage element that contains the 'requestid' and returns it. The object reference is removed from the queue.
requestid | CMessage object's request id (this object will be returned if found) | |
obj | place to store element, if found (empty variable of type CMessage *) | |
lasterr | unique error code |
true | successful, element is returned and removed from queue | |
false | failure, something happened, element is NOT returned (see lasterr) |
note\ This function contains assert() which gives more failure reasons during development/debugging.
Definition at line 664 of file PacketQueue.cpp.
Referenced by find_and_remove_elem(), and CNetworkQueue::sendRecvMsg().
int CPacketQueue::size | ( | UINT32 & | lasterr | ) |
bool CPacketQueue::find_elem_ack_and_signal | ( | const CMessage & | ack_packet, | |
UINT32 & | lasterr | |||
) |
This method traverses the queue, looks for a CMessage element that matches the passed 'ack packet' and signals the attached semaphore in case a match is found.
This method is used in order to signal 'waiting to be ACKed' packets inside ReceiveProcessTask on successful reception of an ACK packet.
ack_packet | CMessage object's ack_packet | |
lasterr | unique error code |
true | successful, element is returned | |
false | failure, something happened, element is NOT returned (see lasterr) |
Definition at line 493 of file PacketQueue.cpp.
Referenced by find_elem_ack_and_signal(), and CNetworkQueue::ReceiveProcessTask().
bool CPacketQueue::find_and_remove_passed_elem | ( | CMessage * | obj, | |
UINT32 & | lasterr | |||
) |
This method traverses the queue, looks for a CMessage element that matches the passed CMessage and, if found, removes the object reference from the queue.
obj | a valid CMessage to look for inside the queue | |
lasterr | unique error code |
true | successful, element is returned and removed from queue | |
false | failure, something happened, element is NOT returned (see lasterr) |
Definition at line 562 of file PacketQueue.cpp.
Referenced by find_and_remove_passed_elem(), and CNetworkQueue::sendMsgTo().
bool CPacketQueue::setQueueMaxsize | ( | INT32 | maxsize | ) |
bool CPacketQueue::pop_front | ( | CMessage ** | obj | ) |
bool CPacketQueue::push_back | ( | const CMessage * | obj | ) |
bool CPacketQueue::remove_elem | ( | UINT16 | requestid | ) |
bool CPacketQueue::find_elem | ( | UINT16 | requestid, | |
CMessage ** | obj | |||
) |
bool CPacketQueue::find_and_remove_elem | ( | UINT16 | requestid, | |
CMessage ** | obj | |||
) |
int CPacketQueue::size | ( | ) |
Returns the current amount of elements stored in the queue.
>0 | number of elements in queue | |
0 | failure or queue is empty (see lasterr) |
Definition at line 754 of file PacketQueue.cpp.
bool CPacketQueue::find_elem_ack_and_signal | ( | const CMessage & | aAckPacket | ) |
bool CPacketQueue::find_and_remove_passed_elem | ( | CMessage * | obj | ) |
friend class CMessage [friend] |
Definition at line 27 of file PacketQueue.h.
INT32 CPacketQueue::m_iQueueFirstElement [private] |
Definition at line 58 of file PacketQueue.h.
Referenced by CPacketQueue(), find_and_remove_elem(), find_and_remove_passed_elem(), find_elem(), find_elem_ack_and_signal(), pop_front(), push_back(), remove_elem(), and setQueueMaxsize().
INT32 CPacketQueue::m_iQueueLastElement [private] |
Definition at line 59 of file PacketQueue.h.
Referenced by CPacketQueue(), find_and_remove_elem(), find_and_remove_passed_elem(), pop_front(), push_back(), remove_elem(), and setQueueMaxsize().
INT32 CPacketQueue::m_iQueueNumElements [private] |
Definition at line 60 of file PacketQueue.h.
Referenced by CPacketQueue(), find_and_remove_elem(), find_and_remove_passed_elem(), find_elem(), find_elem_ack_and_signal(), pop_front(), push_back(), remove_elem(), setQueueMaxsize(), and size().
VOIDP* CPacketQueue::m_pQueueValue [private] |
Definition at line 62 of file PacketQueue.h.
Referenced by CPacketQueue(), find_and_remove_elem(), find_and_remove_passed_elem(), find_elem(), find_elem_ack_and_signal(), pop_front(), push_back(), remove_elem(), setQueueMaxsize(), and ~CPacketQueue().
INT32* CPacketQueue::m_iQueueNextElement [private] |
Definition at line 63 of file PacketQueue.h.
Referenced by CPacketQueue(), find_and_remove_elem(), find_and_remove_passed_elem(), find_elem(), find_elem_ack_and_signal(), pop_front(), push_back(), remove_elem(), setQueueMaxsize(), and ~CPacketQueue().
INT32 CPacketQueue::m_iQueueMaxSize [private] |
Definition at line 65 of file PacketQueue.h.
Referenced by CPacketQueue(), push_back(), and setQueueMaxsize().
UINT32 CPacketQueue::m_iLastError [private] |
Definition at line 67 of file PacketQueue.h.
Referenced by CPacketQueue(), find_and_remove_elem(), find_and_remove_passed_elem(), find_elem(), find_elem_ack_and_signal(), getLastError(), pop_front(), push_back(), remove_elem(), and setQueueMaxsize().