Mixe for Privacy and Anonymity in the Internet
CAQueue.hpp
Go to the documentation of this file.
1 /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 #ifndef __CAQUEUE__
29 #define __CAQUEUE__
30 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
31 #include "CAConditionVariable.hpp"
32 #include "CAMsg.hpp"
33 
34 struct _t_queue
35  {
37  struct _t_queue* next;
40  };
41 
42 typedef struct _t_queue QUEUE;
43 
49 class CAQueue
50  {
51  public:
57  CAQueue(UINT32 expectedElementSize=0)
58  {
59  m_Queue=NULL;
60  m_lastElem=NULL;
61  m_nExpectedElementSize=expectedElementSize;
62  m_nQueueSize=0;
63  m_pcsQueue=new CAMutex();
65  m_bClosed=false;
66 #ifdef QUEUE_SIZE_LOG
67  m_nLogSize=0;
68 #endif
69  //m_pHeap=NULL;
70  //incHeap();
71  }
72  ~CAQueue();
73  SINT32 add(const void* buff,UINT32 size);
74 
78  {
79  m_pcsQueue->lock();
80  m_bClosed=true;
81  m_pcsQueue->unlock();
82  if (m_Queue == NULL) //signal possible reader that the queue ist closed...
83  {
87  }
88  return E_SUCCESS;
89  }
90 
91  SINT32 get(UINT8* pbuff,UINT32* psize);
92  SINT32 getOrWait(UINT8* pbuff,UINT32* psize);
93  SINT32 getOrWait(UINT8* pbuff,UINT32* psize,UINT32 msTimeOut);
94  SINT32 peek(UINT8* pbuff,UINT32* psize);
95  SINT32 remove(UINT32* psize);
96  SINT32 clean();
97 
102  {
103  if (m_pcsQueue)
104  {
105  m_pcsQueue->lock();
107  m_pcsQueue->unlock();
108  return s;
109  }
110  return 0;
111  }
112 
117  {
118  return m_nQueueSize;
119  }
120 
125  bool isEmpty()
126  {
127  return (m_Queue==NULL);
128  }
129 
134  bool isClosed()
135  {
136  return m_bClosed;
137  }
138 
142  static SINT32 test();
143 
144 #ifdef QUEUE_SIZE_LOG
145  void logIfSizeGreaterThen(UINT32 size)
146  {
147  m_nLogSize=size;
148  }
149 #endif
150 
151  private:
152  volatile QUEUE* m_Queue;
153  volatile QUEUE* m_lastElem;
155  volatile bool m_bClosed;
157  //QUEUE* m_pHeap;
160 
161 #ifdef QUEUE_SIZE_LOG
162  UINT32 m_nLogSize;
163 #endif
164  /* SINT32 incHeap()
165  {
166  QUEUE* pEntry;
167  for(int i=0;i<100;i++)
168  {
169  pEntry=new QUEUE;
170  pEntry->next=m_pHeap;
171  if(m_nExpectedElementSize>0)
172  pEntry->pBuff=new UINT8[m_nExpectedElementSize];
173  else
174  pEntry->pBuff=NULL;
175  m_pHeap=pEntry;
176  }
177  return E_SUCCESS;
178  }*/
179  };
180 #endif
181 #endif //ONLY_LOCAL_PROXY
signed int SINT32
Definition: basetypedefs.h:132
unsigned char UINT8
Definition: basetypedefs.h:135
unsigned int UINT32
Definition: basetypedefs.h:131
SINT32 signal()
Signals this object.
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
This is a simple FIFO-Queue.
Definition: CAQueue.hpp:50
CAConditionVariable * m_pconvarSize
Definition: CAQueue.hpp:159
SINT32 add(const void *buff, UINT32 size)
Adds data to the Queue.
Definition: CAQueue.cpp:76
static SINT32 test()
Method to test the Queue.
Definition: CAQueue.cpp:437
CAMutex * m_pcsQueue
Definition: CAQueue.hpp:158
SINT32 clean()
Removes any stored data from the Queue.
Definition: CAQueue.cpp:47
volatile UINT32 m_nQueueSize
Definition: CAQueue.hpp:154
volatile bool m_bClosed
Definition: CAQueue.hpp:155
SINT32 getOrWait(UINT8 *pbuff, UINT32 *psize)
Gets data from the Queue or waits until some data is available, if the Queue is empty.
Definition: CAQueue.cpp:209
SINT32 get(UINT8 *pbuff, UINT32 *psize)
Gets up to psize number of bytes from the Queue.
Definition: CAQueue.cpp:148
SINT32 peek(UINT8 *pbuff, UINT32 *psize)
Peeks data from the Queue.
Definition: CAQueue.cpp:258
CAQueue(UINT32 expectedElementSize=0)
Give the size of the amount of data what you will add in one step.
Definition: CAQueue.hpp:57
SINT32 close()
Closes the Queue (for writing).
Definition: CAQueue.hpp:77
SINT32 remove(UINT32 *psize)
Removes data from the Queue.
Definition: CAQueue.cpp:302
UINT32 getSize()
Returns the size of stored data in byte.
Definition: CAQueue.hpp:101
~CAQueue()
Deletes this Queue and all stored data.
Definition: CAQueue.cpp:36
bool isClosed()
Returns true, if the Queue is closed.
Definition: CAQueue.hpp:134
volatile QUEUE * m_lastElem
Definition: CAQueue.hpp:153
volatile QUEUE * m_Queue
Definition: CAQueue.hpp:152
bool isEmpty()
Returns true, if the Queue is empty.
Definition: CAQueue.hpp:125
UINT32 m_nExpectedElementSize
Definition: CAQueue.hpp:156
UINT32 getSizeLookFree()
Returns the size of stored data in byte.
Definition: CAQueue.hpp:116
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
UINT8 * pBuff
Definition: CAQueue.hpp:36
UINT32 size
Definition: CAQueue.hpp:38
UINT32 index
Definition: CAQueue.hpp:39
struct _t_queue * next
Definition: CAQueue.hpp:37