Panda3D
queuedReturn.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file queuedReturn.h
10  * @author drose
11  * @date 2000-02-25
12  */
13 
14 #ifndef QUEUEDRETURN_H
15 #define QUEUEDRETURN_H
16 
17 #include "pandabase.h"
18 
19 #include "connectionListener.h"
20 #include "connection.h"
21 #include "netAddress.h"
22 #include "lightMutex.h"
23 #include "pdeque.h"
24 #include "config_net.h"
25 #include "lightMutexHolder.h"
26 
27 #include <algorithm>
28 
29 /**
30  * This is the implementation of a family of things that queue up their return
31  * values for later retrieval by client code, like QueuedConnectionReader,
32  * QueuedConnectionListener, QueuedConnectionManager.
33  */
34 template<class Thing>
35 class QueuedReturn {
36 PUBLISHED:
37  void set_max_queue_size(int max_size);
38  int get_max_queue_size() const;
39  int get_current_queue_size() const;
40 
41  bool get_overflow_flag() const;
42  void reset_overflow_flag();
43 
44 protected:
45  QueuedReturn();
46  ~QueuedReturn();
47 
48  INLINE bool thing_available() const;
49  bool get_thing(Thing &thing);
50 
51  bool enqueue_thing(const Thing &thing);
52  bool enqueue_unique_thing(const Thing &thing);
53 
54 private:
55  LightMutex _mutex;
56  pdeque<Thing> _things;
57  bool _available;
58  int _max_queue_size;
59  bool _overflow_flag;
60 };
61 
62 #include "queuedReturn.I"
63 
64 #endif
bool get_overflow_flag() const
Returns true if the queue has overflowed since the last call to reset_overflow_flag() (implying that ...
Definition: queuedReturn.I:57
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void reset_overflow_flag()
Resets the overflow flag so that get_overflow_flag() will return false until a new overflow occurs.
Definition: queuedReturn.I:67
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void set_max_queue_size(int max_size)
Sets the maximum size the queue is allowed to grow to.
Definition: queuedReturn.I:24
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_current_queue_size() const
Returns the current number of things in the queue.
Definition: queuedReturn.I:44
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the implementation of a family of things that queue up their return values for later retrieva...
Definition: queuedReturn.h:35
This is a standard, non-reentrant mutex, similar to the Mutex class.
Definition: lightMutex.h:39
int get_max_queue_size() const
Returns the maximum size the queue is allowed to grow to.
Definition: queuedReturn.I:35