15 #include "pStatServer.h" 16 #include "pStatReader.h" 18 #include "config_pstats.h" 65 PT(
Connection) rendezvous = open_TCP_server_rendezvous(port, 5);
67 if (rendezvous.is_null()) {
75 if (_next_udp_port == 0) {
76 _next_udp_port = port + 1;
98 while (!_lost_readers.empty()) {
100 _lost_readers.pop_back();
105 while (!_removed_readers.empty()) {
107 _removed_readers.pop_back();
113 Readers::const_iterator ri = _readers.begin();
114 while (ri != _readers.end()) {
117 Readers::const_iterator rnext = ri;
143 while (interrupt_flag == (
bool *)NULL || !*interrupt_flag) {
157 _readers[connection] = reader;
167 Readers::iterator ri;
168 ri = _readers.find(connection);
169 if (ri == _readers.end() || (*ri).second != reader) {
170 nout <<
"Attempt to remove undefined reader.\n";
173 _removed_readers.push_back(reader);
187 if (_available_udp_ports.empty()) {
188 return _next_udp_port++;
190 int udp_port = _available_udp_ports.front();
191 _available_udp_ports.pop_front();
203 _available_udp_ports.push_back(port);
214 return _user_guide_bars.size();
224 nassertr(n >= 0 && n < (
int)_user_guide_bars.size(), 0.0f);
225 return _user_guide_bars[n];
235 nassertv(n >= 0 && n < (
int)_user_guide_bars.size());
236 _user_guide_bars[n] = height;
237 user_guide_bars_changed();
248 int n = (int)_user_guide_bars.size();
249 _user_guide_bars.push_back(height);
250 user_guide_bars_changed();
264 nassertv(n >= 0 && n < (
int)_user_guide_bars.size());
265 _user_guide_bars.erase(_user_guide_bars.begin() + n);
266 user_guide_bars_changed();
278 GuideBars::const_iterator gbi;
279 for (gbi = _user_guide_bars.begin();
280 gbi != _user_guide_bars.end();
282 double height = (*gbi);
283 if (height >= from_height && height <= to_height) {
284 return (
int)(gbi - _user_guide_bars.begin());
297 user_guide_bars_changed() {
298 Readers::iterator ri;
299 for (ri = _readers.begin(); ri != _readers.end(); ++ri) {
300 (*ri).second->get_monitor()->user_guide_bars_changed();
332 connection_reset(
const PT(
Connection) &connection,
bool okflag) {
337 Readers::iterator ri;
338 ri = _readers.find(connection);
339 if (ri != _readers.end()) {
346 _lost_readers.push_back(reader);
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.
int get_udp_port()
Returns a new port number that will probably be free to use as a UDP port.
void idle()
Called each frame to do what needs to be done for the monitor's user-defined idle routines...
int get_num_user_guide_bars() const
Returns the current number of user-defined guide bars.
void poll()
Explicitly polls the available sockets to see if any of them have any noise.
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...
This is the TCP rendezvous socket listener.
void lost_connection()
This is called by the PStatServer when it detects that the connection has been lost.
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. ...
void move_user_guide_bar(int n, double height)
Adjusts the height of the nth user-defined guide bar.
static void sleep(double seconds)
Suspends the current thread for at least the indicated amount of time.
virtual bool is_thread_safe()
This should be redefined to return true in derived classes that want to deal with multithreaded reade...
bool add_connection(Connection *connection)
Adds a new socket to the list of sockets the ConnectionReader will monitor.
bool listen(int port=-1)
Establishes a port number that the manager will listen on for TCP connections.
void main_loop(bool *interrupt_flag=NULL)
An alternative to repeatedly calling poll(), this function yields control of the program to the PStat...
Represents a single TCP or UDP socket for input or output.
void release_udp_port(int port)
Indicates that the given UDP port is once again free for use.
bool close_connection(const PT(Connection) &connection)
Terminates a UDP or TCP socket previously opened.