Panda3D
pStatServer.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pStatServer.h
10  * @author drose
11  * @date 2000-07-09
12  */
13 
14 #ifndef PSTATSERVER_H
15 #define PSTATSERVER_H
16 
17 #include "pandatoolbase.h"
18 #include "pStatListener.h"
19 #include "connectionManager.h"
20 #include "vector_stdfloat.h"
21 #include "pmap.h"
22 #include "pdeque.h"
23 
24 class PStatReader;
25 
26 /**
27  * The overall manager of the network connections. This class gets the ball
28  * rolling; to use this package, you need to derive from this and define
29  * make_monitor() to allocate and return a PStatMonitor of the suitable type.
30  *
31  * Then create just one PStatServer object and call listen() with the port(s)
32  * you would like to listen on. It will automatically create PStatMonitors as
33  * connections are established and mark the connections closed as they are
34  * lost.
35  */
37 public:
38  PStatServer();
39  ~PStatServer();
40 
41  bool listen(int port = -1);
42 
43  void poll();
44  void main_loop(bool *interrupt_flag = nullptr);
45 
46  virtual PStatMonitor *make_monitor()=0;
47  void add_reader(Connection *connection, PStatReader *reader);
48  void remove_reader(Connection *connection, PStatReader *reader);
49 
50  int get_udp_port();
51  void release_udp_port(int port);
52 
53  int get_num_user_guide_bars() const;
54  double get_user_guide_bar_height(int n) const;
55  void move_user_guide_bar(int n, double height);
56  int add_user_guide_bar(double height);
57  void remove_user_guide_bar(int n);
58  int find_user_guide_bar(double from_height, double to_height) const;
59 
60  virtual bool is_thread_safe();
61 
62 protected:
63  virtual void connection_reset(const PT(Connection) &connection,
64  bool okflag);
65 
66 private:
67  void user_guide_bars_changed();
68 
69  PStatListener *_listener;
70 
71  typedef pmap<PT(Connection), PStatReader *> Readers;
72  Readers _readers;
74  LostReaders _lost_readers;
75  LostReaders _removed_readers;
76 
77  typedef pdeque<int> Ports;
78  Ports _available_udp_ports;
79  int _next_udp_port;
80 
81  typedef vector_stdfloat GuideBars;
82  GuideBars _user_guide_bars;
83 };
84 
85 #endif
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...
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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 get_num_user_guide_bars() const
Returns the current number of user-defined guide bars.
This is an abstract class that presents the interface to any number of different front-ends for the s...
Definition: pStatMonitor.h:39
double get_user_guide_bar_height(int n) const
Returns the height of the nth user-defined guide bar.
This is the class that does all the work for handling communications from a single Panda client.
Definition: pStatReader.h:41
This is the TCP rendezvous socket listener.
Definition: pStatListener.h:29
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 main_loop(bool *interrupt_flag=nullptr)
An alternative to repeatedly calling poll(), this function yields control of the program to the PStat...
void poll()
Checks for any network activity and handles it, if appropriate, and then returns.
Definition: pStatServer.cxx:82
void move_user_guide_bar(int n, double height)
Adjusts the height of the nth user-defined guide bar.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool is_thread_safe()
This should be redefined to return true in derived classes that want to deal with multithreaded reade...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool listen(int port=-1)
Establishes a port number that the manager will listen on for TCP connections.
Definition: pStatServer.cxx:49
The overall manager of the network connections.
Definition: pStatServer.h:36
Represents a single TCP or UDP socket for input or output.
Definition: connection.h:29
void release_udp_port(int port)
Indicates that the given UDP port is once again free for use.