Panda3D
pStatMonitor.h
1 // Filename: pStatMonitor.h
2 // Created by: drose (08Jul00)
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 PSTATMONITOR_H
16 #define PSTATMONITOR_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "pStatClientData.h"
21 #include "pStatView.h"
22 
23 #include "referenceCount.h"
24 #include "pointerTo.h"
25 #include "luse.h"
26 
27 #include "pmap.h"
28 
29 class PStatCollectorDef;
30 class PStatServer;
31 
32 ////////////////////////////////////////////////////////////////////
33 // Class : PStatMonitor
34 // Description : This is an abstract class that presents the interface
35 // to any number of different front-ends for the stats
36 // monitor. One of these will be created by the
37 // PStatMonitor as each client is connected; this class
38 // is responsible for opening up a new strip-chart graph
39 // or whatever is appropriate. It defines a number of
40 // empty virtual functions that will be called as new
41 // data becomes available.
42 ////////////////////////////////////////////////////////////////////
43 class PStatMonitor : public ReferenceCount {
44 public:
45  // The following functions are primarily for use by internal classes
46  // to set up the monitor.
47  PStatMonitor(PStatServer *server);
48  virtual ~PStatMonitor();
49 
50  void hello_from(const string &hostname, const string &progname);
51  void bad_version(const string &hostname, const string &progname,
52  int client_major, int client_minor,
53  int server_major, int server_minor);
54  void set_client_data(PStatClientData *client_data);
55 
56 
57  // The following functions are for use by user code to determine
58  // information about the client data available.
59  bool is_alive() const;
60  void close();
61 
62  INLINE PStatServer *get_server();
63  INLINE const PStatClientData *get_client_data() const;
64  INLINE string get_collector_name(int collector_index);
65  const LRGBColor &get_collector_color(int collector_index);
66 
67  INLINE bool is_client_known() const;
68  INLINE string get_client_hostname() const;
69  INLINE string get_client_progname() const;
70 
71  PStatView &get_view(int thread_index);
72  PStatView &get_level_view(int collector_index, int thread_index);
73 
74 
75  // The following virtual methods may be overridden by a derived
76  // monitor class to customize behavior.
77 
78  virtual string get_monitor_name()=0;
79 
80  virtual void initialized();
81  virtual void got_hello();
82  virtual void got_bad_version(int client_major, int client_minor,
83  int server_major, int server_minor);
84  virtual void new_collector(int collector_index);
85  virtual void new_thread(int thread_index);
86  virtual void new_data(int thread_index, int frame_number);
87 
88  virtual void lost_connection();
89  virtual void idle();
90  virtual bool has_idle();
91 
92  virtual bool is_thread_safe();
93 
94  virtual void user_guide_bars_changed();
95 
96 protected:
97  PStatServer *_server;
98 
99 private:
100  PT(PStatClientData) _client_data;
101 
102  bool _client_known;
103  string _client_hostname;
104  string _client_progname;
105 
106  typedef pmap<int, PStatView> Views;
107  Views _views;
109  LevelViews _level_views;
110 
112  Colors _colors;
113 };
114 
115 #include "pStatMonitor.I"
116 
117 #endif
This is the base class for all three-component vectors and points.
Definition: lvecBase3.h:105
void set_client_data(PStatClientData *client_data)
Called by the PStatServer at setup time to set the new data pointer for the first time...
virtual void initialized()
Called after the monitor has been fully set up.
virtual bool has_idle()
Should be redefined to return true if you want to redefine idle() and expect it to be called...
virtual void new_data(int thread_index, int frame_number)
Called as each frame&#39;s data is made available.
const LRGBColor & get_collector_color(int collector_index)
Returns the color associated with the indicated collector.
PStatView & get_level_view(int collector_index, int thread_index)
Returns a view on the level value (as opposed to elapsed time) for the given collector over the given...
string get_collector_name(int collector_index)
Returns the name of the indicated collector, if it is known.
Definition: pStatMonitor.I:43
virtual void got_bad_version(int client_major, int client_minor, int server_major, int server_minor)
Like got_hello(), this is called when the "hello" message has been received from the client...
The data associated with a particular client, but not with any one particular frame or thread: the li...
void close()
Closes the client connection if it is active.
void bad_version(const string &hostname, const string &progname, int client_major, int client_minor, int server_major, int server_minor)
Called shortly after startup time with the greeting from the client.
virtual bool is_thread_safe()
Should be redefined to return true if this monitor class can handle running in a sub-thread.
bool is_alive() const
Returns true if the client is alive and connected, false otherwise.
virtual void got_hello()
Called when the "hello" message has been received from the client.
void hello_from(const string &hostname, const string &progname)
Called shortly after startup time with the greeting from the client.
This is an abstract class that presents the interface to any number of different front-ends for the s...
Definition: pStatMonitor.h:43
PStatServer * get_server()
Returns the server that owns this monitor.
Definition: pStatMonitor.I:22
A View boils down the frame data to a linear list of times spent in a number of different Collectors...
Definition: pStatView.h:34
PStatView & get_view(int thread_index)
Returns a view on the given thread index.
virtual void lost_connection()
Called whenever the connection to the client has been lost.
virtual void new_thread(int thread_index)
Called whenever a new Thread definition is received from the client.
virtual void idle()
If has_idle() returns true, this will be called periodically to allow the monitor to update its displ...
A base class for all things that want to be reference-counted.
bool is_client_known() const
Returns true if we&#39;ve yet received the "hello" message from the client indicating its name...
Definition: pStatMonitor.I:58
virtual void user_guide_bars_changed()
Called when the user guide bars have been changed.
The overall manager of the network connections.
Definition: pStatServer.h:41
string get_client_progname() const
Returns the program name of the client we&#39;re connected to, if known.
Definition: pStatMonitor.I:86
const PStatClientData * get_client_data() const
Returns the client data associated with this monitor.
Definition: pStatMonitor.I:32
Defines the details about the Collectors: the name, the suggested color, etc.
virtual void new_collector(int collector_index)
Called whenever a new Collector definition is received from the client.
string get_client_hostname() const
Returns the hostname of the client we&#39;re connected to, if known.
Definition: pStatMonitor.I:72