Panda3D
 All Classes Functions Variables Enumerations
pStatServer.h
1 // Filename: pStatServer.h
2 // Created by: drose (09Jul00)
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 PSTATSERVER_H
16 #define PSTATSERVER_H
17 
18 #include "pandatoolbase.h"
19 #include "pStatListener.h"
20 #include "connectionManager.h"
21 #include "vector_stdfloat.h"
22 #include "pmap.h"
23 #include "pdeque.h"
24 
25 class PStatReader;
26 
27 ////////////////////////////////////////////////////////////////////
28 // Class : PStatServer
29 // Description : The overall manager of the network connections. This
30 // class gets the ball rolling; to use this package, you
31 // need to derive from this and define make_monitor() to
32 // allocate and return a PStatMonitor of the suitable
33 // type.
34 //
35 // Then create just one PStatServer object and call
36 // listen() with the port(s) you would like to listen
37 // on. It will automatically create PStatMonitors as
38 // connections are established and mark the connections
39 // closed as they are lost.
40 ////////////////////////////////////////////////////////////////////
42 public:
43  PStatServer();
44  ~PStatServer();
45 
46  bool listen(int port = -1);
47 
48  void poll();
49  void main_loop(bool *interrupt_flag = NULL);
50 
51  virtual PStatMonitor *make_monitor()=0;
52  void add_reader(Connection *connection, PStatReader *reader);
53  void remove_reader(Connection *connection, PStatReader *reader);
54 
55  int get_udp_port();
56  void release_udp_port(int port);
57 
58  int get_num_user_guide_bars() const;
59  double get_user_guide_bar_height(int n) const;
60  void move_user_guide_bar(int n, double height);
61  int add_user_guide_bar(double height);
62  void remove_user_guide_bar(int n);
63  int find_user_guide_bar(double from_height, double to_height) const;
64 
65  virtual bool is_thread_safe();
66 
67 protected:
68  virtual void connection_reset(const PT(Connection) &connection,
69  bool okflag);
70 
71 private:
72  void user_guide_bars_changed();
73 
74  PStatListener *_listener;
75 
77  Readers _readers;
79  LostReaders _lost_readers;
80  LostReaders _removed_readers;
81 
82  typedef pdeque<int> Ports;
83  Ports _available_udp_ports;
84  int _next_udp_port;
85 
86  typedef vector_stdfloat GuideBars;
87  GuideBars _user_guide_bars;
88 };
89 
90 #endif
int add_user_guide_bar(double height)
Creates a new user guide bar and returns its index number.
void remove_user_guide_bar(int n)
Removes the user guide bar with the indicated index number.
double get_user_guide_bar_height(int n) const
Returns the height of the nth user-defined guide bar.
The primary interface to the low-level networking layer in this package.
int get_udp_port()
Returns a new port number that will probably be free to use as a UDP port.
int find_user_guide_bar(double from_height, double to_height) const
Returns the index number of the first user guide bar found whose height is within the indicated range...
This is an abstract class that presents the interface to any number of different front-ends for the s...
Definition: pStatMonitor.h:43
This is the class that does all the work for handling communications from a single Panda client...
Definition: pStatReader.h:44
This is the TCP rendezvous socket listener.
Definition: pStatListener.h:32
void add_reader(Connection *connection, PStatReader *reader)
Adds the newly-created PStatReader to the list of currently active readers.
void remove_reader(Connection *connection, PStatReader *reader)
Removes the indicated reader.
void poll()
Checks for any network activity and handles it, if appropriate, and then returns. ...
Definition: pStatServer.cxx:96
void move_user_guide_bar(int n, double height)
Adjusts the height of the nth user-defined guide bar.
int get_num_user_guide_bars() const
Returns the current number of user-defined guide bars.
virtual bool is_thread_safe()
This should be redefined to return true in derived classes that want to deal with multithreaded reade...
bool listen(int port=-1)
Establishes a port number that the manager will listen on for TCP connections.
Definition: pStatServer.cxx:59
void main_loop(bool *interrupt_flag=NULL)
An alternative to repeatedly calling poll(), this function yields control of the program to the PStat...
The overall manager of the network connections.
Definition: pStatServer.h:41
Represents a single TCP or UDP socket for input or output.
Definition: connection.h:32
void release_udp_port(int port)
Indicates that the given UDP port is once again free for use.