Panda3D
|
00001 // Filename: queuedReturn.h 00002 // Created by: drose (25Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef QUEUEDRETURN_H 00016 #define QUEUEDRETURN_H 00017 00018 #include "pandabase.h" 00019 00020 #include "connectionListener.h" 00021 #include "connection.h" 00022 #include "netAddress.h" 00023 #include "lightMutex.h" 00024 #include "pdeque.h" 00025 #include "config_net.h" 00026 #include "lightMutexHolder.h" 00027 00028 #include <algorithm> 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Class : QueuedReturn 00032 // Description : This is the implementation of a family of things that 00033 // queue up their return values for later retrieval by 00034 // client code, like QueuedConnectionReader, 00035 // QueuedConnectionListener, QueuedConnectionManager. 00036 //////////////////////////////////////////////////////////////////// 00037 template<class Thing> 00038 class QueuedReturn { 00039 PUBLISHED: 00040 void set_max_queue_size(int max_size); 00041 int get_max_queue_size() const; 00042 int get_current_queue_size() const; 00043 00044 bool get_overflow_flag() const; 00045 void reset_overflow_flag(); 00046 00047 protected: 00048 QueuedReturn(); 00049 ~QueuedReturn(); 00050 00051 INLINE bool thing_available() const; 00052 bool get_thing(Thing &thing); 00053 00054 bool enqueue_thing(const Thing &thing); 00055 bool enqueue_unique_thing(const Thing &thing); 00056 00057 private: 00058 LightMutex _mutex; 00059 pdeque<Thing> _things; 00060 bool _available; 00061 int _max_queue_size; 00062 bool _overflow_flag; 00063 }; 00064 00065 #include "queuedReturn.I" 00066 00067 #endif 00068