Panda3D
 All Classes Functions Variables Enumerations
pStatClientImpl.h
1 // Filename: pStatClientImpl.h
2 // Created by: drose (23Dec04)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PSTATCLIENTIMPL_H
16 #define PSTATCLIENTIMPL_H
17 
18 #include "pandabase.h"
19 
20 // This class doesn't exist at all unless DO_PSTATS is defined.
21 #ifdef DO_PSTATS
22 
23 #include "pStatFrameData.h"
24 #include "connectionManager.h"
25 #include "queuedConnectionReader.h"
26 #include "connectionWriter.h"
27 #include "netAddress.h"
28 
29 #include "trueClock.h"
30 #include "pmap.h"
31 
32 class PStatClient;
34 class PStatCollector;
35 class PStatCollectorDef;
36 class PStatThread;
37 
38 ////////////////////////////////////////////////////////////////////
39 // Class : PStatClientImpl
40 // Description : This class is the implementation of the actual
41 // PStatClient class (which is just for interface). All
42 // of the stuff to manage sending stats up to the server
43 // is handled by this class.
44 //
45 // This separation between PStatClient and
46 // PStatClientImpl allows the global PStatClient to be
47 // constructed at static init time, without having to
48 // consult any config variables at that time. We don't
49 // actually do any real work until someone explicitly
50 // calls PStatClient::connect().
51 //
52 // This class doesn't exist at all unless DO_PSTATS is
53 // defined.
54 ////////////////////////////////////////////////////////////////////
55 class EXPCL_PANDA_PSTATCLIENT PStatClientImpl : public ConnectionManager {
56 public:
57  PStatClientImpl(PStatClient *client);
58  ~PStatClientImpl();
59 
60  INLINE void set_client_name(const string &name);
61  INLINE string get_client_name() const;
62  INLINE void set_max_rate(double rate);
63  INLINE double get_max_rate() const;
64 
65  INLINE double get_real_time() const;
66 
67  INLINE void client_main_tick();
68  bool client_connect(string hostname, int port);
69  void client_disconnect();
70  INLINE bool client_is_connected() const;
71 
72  INLINE void client_resume_after_pause();
73 
74  void new_frame(int thread_index);
75  void add_frame(int thread_index, const PStatFrameData &frame_data);
76 
77 private:
78  void transmit_frame_data(int thread_index, int frame_number,
79  const PStatFrameData &frame_data);
80 
81  void transmit_control_data();
82 
83  TrueClock *_clock;
84  double _delta;
85  double _last_frame;
86 
87  // Networking stuff
88  string get_hostname();
89  void send_hello();
90  void report_new_collectors();
91  void report_new_threads();
92  void handle_server_control_message(const PStatServerControlMessage &message);
93 
94  virtual void connection_reset(const PT(Connection) &connection,
95  bool okflag);
96 
97  PStatClient *_client;
98 
99  bool _is_connected;
100  bool _got_udp_port;
101 
102  NetAddress _server;
103  QueuedConnectionReader _reader;
104  ConnectionWriter _writer;
105 
106  PT(Connection) _tcp_connection;
107  PT(Connection) _udp_connection;
108 
109  int _collectors_reported;
110  int _threads_reported;
111 
112  string _hostname;
113  string _client_name;
114  double _max_rate;
115 
116  double _tcp_count_factor;
117  double _udp_count_factor;
118  unsigned int _tcp_count;
119  unsigned int _udp_count;
120 };
121 
122 #include "pStatClientImpl.I"
123 
124 #endif // DO_PSTATS
125 
126 #endif
127 
This kind of message is sent from the server to the client on the TCP socket to establish critical co...
The primary interface to the low-level networking layer in this package.
A lightweight class that represents a single element that may be timed and/or counted via stats...
Contains the raw timing and level data for a single frame.
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
A lightweight class that represents a single thread of execution to PStats.
Definition: pStatThread.h:31
An interface to whatever real-time clock we might have available in the current environment.
Definition: trueClock.h:38
This flavor of ConnectionReader will read from its sockets and queue up all of the datagrams read for...
Defines the details about the Collectors: the name, the suggested color, etc.
Manages the communications to report statistics via a network connection to a remote PStatServer...
Definition: pStatClient.h:261
Represents a single TCP or UDP socket for input or output.
Definition: connection.h:32
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound...
Definition: netAddress.h:27