00001 // Filename: recentConnectionReader.h 00002 // Created by: drose (23Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef RECENTCONNECTIONREADER_H 00020 #define RECENTCONNECTIONREADER_H 00021 00022 #include <pandabase.h> 00023 00024 #include "connectionReader.h" 00025 #include "netDatagram.h" 00026 00027 #include <prlock.h> 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Class : RecentConnectionReader 00031 // Description : This flavor of ConnectionReader will read from its 00032 // sockets and retain only the single most recent 00033 // datagram for inspection by client code. It's useful 00034 // particularly for reading telemetry-type data from UDP 00035 // sockets where you don't care about getting every last 00036 // socket, and in fact if the sockets are coming too 00037 // fast you'd prefer to skip some of them. 00038 // 00039 // This class will always create one thread for itself. 00040 //////////////////////////////////////////////////////////////////// 00041 class EXPCL_PANDA RecentConnectionReader : public ConnectionReader { 00042 PUBLISHED: 00043 RecentConnectionReader(ConnectionManager *manager); 00044 virtual ~RecentConnectionReader(); 00045 00046 bool data_available(); 00047 bool get_data(NetDatagram &result); 00048 bool get_data(Datagram &result); 00049 00050 protected: 00051 virtual void receive_datagram(const NetDatagram &datagram); 00052 00053 private: 00054 bool _available; 00055 Datagram _datagram; 00056 PRLock *_mutex; 00057 }; 00058 00059 #endif 00060