Panda3D

pStatReader.h

00001 // Filename: pStatReader.h
00002 // Created by:  drose (09Jul00)
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 PSTATREADER_H
00016 #define PSTATREADER_H
00017 
00018 #include "pandatoolbase.h"
00019 
00020 #include "pStatClientData.h"
00021 #include "pStatMonitor.h"
00022 
00023 #include "connectionReader.h"
00024 #include "connectionWriter.h"
00025 #include "referenceCount.h"
00026 #include "circBuffer.h"
00027 
00028 class PStatServer;
00029 class PStatMonitor;
00030 class PStatClientControlMessage;
00031 class PStatFrameData;
00032 
00033 // This is the maximum number of frame records that will be queued up
00034 // from this particular client between processing loops.
00035 static const int queued_frame_records = 500;
00036 
00037 ////////////////////////////////////////////////////////////////////
00038 //       Class : PStatReader
00039 // Description : This is the class that does all the work for handling
00040 //               communications from a single Panda client.  It reads
00041 //               sockets received from the client and boils them down
00042 //               into PStatData.
00043 ////////////////////////////////////////////////////////////////////
00044 class PStatReader : public ConnectionReader {
00045 public:
00046   PStatReader(PStatServer *manager, PStatMonitor *monitor);
00047   ~PStatReader();
00048 
00049   void close();
00050 
00051   void set_tcp_connection(Connection *tcp_connection);
00052   void lost_connection();
00053   void idle();
00054 
00055   PStatMonitor *get_monitor();
00056 
00057 private:
00058   string get_hostname();
00059   void send_hello();
00060 
00061   virtual void receive_datagram(const NetDatagram &datagram);
00062 
00063   void handle_client_control_message(const PStatClientControlMessage &message);
00064   void handle_client_udp_data(const Datagram &datagram);
00065   void dequeue_frame_data();
00066 
00067 private:
00068   PStatServer *_manager;
00069   PT(PStatMonitor) _monitor;
00070   ConnectionWriter _writer;
00071 
00072   PT(Connection) _tcp_connection;
00073   PT(Connection) _udp_connection;
00074   int _udp_port;
00075 
00076   PT(PStatClientData) _client_data;
00077 
00078   string _hostname;
00079 
00080   class FrameData {
00081   public:
00082     int _thread_index;
00083     int _frame_number;
00084     PStatFrameData *_frame_data;
00085   };
00086   typedef CircBuffer<FrameData, queued_frame_records> QueuedFrameData;
00087   QueuedFrameData _queued_frame_data;
00088 };
00089 
00090 #endif
 All Classes Functions Variables Enumerations