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
PStatServer::release_udp_port
void release_udp_port(int port)
Indicates that the given UDP port is once again free for use.
Definition: pStatServer.cxx:173
pvector< PStatReader * >
PStatServer
The overall manager of the network connections.
Definition: pStatServer.h:36
pmap
This is our own Panda specialization on the default STL map.
Definition: pmap.h:49
PStatServer::remove_user_guide_bar
void remove_user_guide_bar(int n)
Removes the user guide bar with the indicated index number.
Definition: pStatServer.cxx:221
Connection
Represents a single TCP or UDP socket for input or output.
Definition: connection.h:29
PStatServer::get_num_user_guide_bars
int get_num_user_guide_bars() const
Returns the current number of user-defined guide bars.
Definition: pStatServer.cxx:181
vector_stdfloat.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatServer::remove_reader
void remove_reader(Connection *connection, PStatReader *reader)
Removes the indicated reader.
Definition: pStatServer.cxx:143
PStatServer::get_user_guide_bar_height
double get_user_guide_bar_height(int n) const
Returns the height of the nth user-defined guide bar.
Definition: pStatServer.cxx:189
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatServer::poll
void poll()
Checks for any network activity and handles it, if appropriate, and then returns.
Definition: pStatServer.cxx:82
PStatServer::get_udp_port
int get_udp_port()
Returns a new port number that will probably be free to use as a UDP port.
Definition: pStatServer.cxx:160
pdeque< int >
PStatServer::add_reader
void add_reader(Connection *connection, PStatReader *reader)
Adds the newly-created PStatReader to the list of currently active readers.
Definition: pStatServer.cxx:135
PStatServer::main_loop
void main_loop(bool *interrupt_flag=nullptr)
An alternative to repeatedly calling poll(), this function yields control of the program to the PStat...
Definition: pStatServer.cxx:124
ConnectionManager
The primary interface to the low-level networking layer in this package.
Definition: connectionManager.h:41
PStatServer::listen
bool listen(int port=-1)
Establishes a port number that the manager will listen on for TCP connections.
Definition: pStatServer.cxx:49
pStatListener.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatServer::move_user_guide_bar
void move_user_guide_bar(int n, double height)
Adjusts the height of the nth user-defined guide bar.
Definition: pStatServer.cxx:198
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatServer::is_thread_safe
virtual bool is_thread_safe()
This should be redefined to return true in derived classes that want to deal with multithreaded reade...
Definition: pStatServer.cxx:269
connectionManager.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatMonitor
This is an abstract class that presents the interface to any number of different front-ends for the s...
Definition: pStatMonitor.h:39
PStatReader
This is the class that does all the work for handling communications from a single Panda client.
Definition: pStatReader.h:41
PStatServer::find_user_guide_bar
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...
Definition: pStatServer.cxx:233
PStatServer::add_user_guide_bar
int add_user_guide_bar(double height)
Creates a new user guide bar and returns its index number.
Definition: pStatServer.cxx:208
pdeque.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PStatListener
This is the TCP rendezvous socket listener.
Definition: pStatListener.h:29