Panda3D

Loading...
Searching...
No Matches
Public Member Functions | List of all members
PStatServer Class Referenceabstract

The overall manager of the network connections. More...

`#include "pStatServer.h"`

Inheritance diagram for PStatServer:

## Public Member Functions
void | add_reader (Connection *connection, PStatReader *reader)
| Adds the newly-created PStatReader to the list of currently active readers.
int | add_user_guide_bar (double height)
| Creates a new user guide bar and returns its index number.
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, or -1 if no user guide bars fall within the range.
int | get_num_user_guide_bars () const
| Returns the current number of user-defined guide bars.
int | get_udp_port ()
| Returns a new port number that will probably be free to use as a UDP port.
double | get_user_guide_bar_height (int n) const
| Returns the height of the nth user-defined guide bar.
virtual bool | is_thread_safe ()
| This should be redefined to return true in derived classes that want to deal with multithreaded readers and such.
bool | listen (int port=-1)
| Establishes a port number that the manager will listen on for TCP connections.
void | main_loop (bool *interrupt_flag=nullptr)
| An alternative to repeatedly calling poll(), this function yields control of the program to the PStatServer.
virtual PStatMonitor * | make_monitor ()=0
void | move_user_guide_bar (int n, double height)
| Adjusts the height of the nth user-defined guide bar.
void | poll ()
| Checks for any network activity and handles it, if appropriate, and then returns.
void | release_udp_port (int port)
| Indicates that the given UDP port is once again free for use.
void | remove_reader (Connection *connection, PStatReader *reader)
| Removes the indicated reader.
void | remove_user_guide_bar (int n)
| Removes the user guide bar with the indicated index number.
Public Member Functions inherited from ConnectionManager
PT(Connection) open_TCP_client_connection(const std bool | close_connection (const PT(Connection) &connection)
| Terminates a UDP or TCP socket previously opened.
const Interface & | get_interface (size_t n)
size_t | get_num_interfaces ()
| PT (Connection) open_TCP_client_connection(const NetAddress &address
PT(Connection) open_TCP_server_rendezvous(const std | PT (Connection) open_TCP_server_rendezvous(const NetAddress &address
PT(Connection) open_UDP_connection(const std | PT (Connection) open_TCP_server_rendezvous(uint16_t port
| PT (Connection) open_UDP_connection(uint16_t port=0)
void | scan_interfaces ()
| Repopulates the list reported by get_num_interface()/get_interface().
bool | wait_for_readers (double timeout)
| Blocks the process for timeout number of seconds, or until any data is available on any of the non-threaded ConnectionReaders or ConnectionListeners, whichever comes first.

## Additional Inherited Members
Static Public Member Functions inherited from ConnectionManager
static std::string | get_host_name ()
Public Attributes inherited from ConnectionManager
PT(Connection) open_UDP_connection(const std int | backlog
PT(Connection) open_TCP_server_rendezvous(const std int | backlog
| get_host_name
| Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined.
| get_interface
| Returns the nth usable network interface detected on this machine.
| get_num_interfaces
| This returns the number of usable network interfaces detected on this machine.
int | timeout_ms

## Detailed Description

The overall manager of the network connections.

This class gets the ball rolling; to use this package, you need to derive from this and define make_monitor() to allocate and return a PStatMonitor of the suitable type.

Then create just one PStatServer object and call listen() with the port(s) you would like to listen on. It will automatically create PStatMonitors as connections are established and mark the connections closed as they are lost.

Definition at line 36 of file pStatServer.h.

## Constructor & Destructor Documentation

## ◆ PStatServer()

PStatServer::PStatServer | ( |  | ) |

Definition at line 22 of file pStatServer.cxx.

## ◆ ~PStatServer()

PStatServer::~PStatServer | ( |  | ) |

Definition at line 31 of file pStatServer.cxx.

## Member Function Documentation

## ◆ add_reader()

void PStatServer::add_reader | ( | Connection * | connection,
|  | PStatReader * | reader )

Adds the newly-created PStatReader to the list of currently active readers.

Definition at line 134 of file pStatServer.cxx.

## ◆ add_user_guide_bar()

int PStatServer::add_user_guide_bar | ( | double | height | ) |

Creates a new user guide bar and returns its index number.

Definition at line 207 of file pStatServer.cxx.

## ◆ find_user_guide_bar()

int PStatServer::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, or -1 if no user guide bars fall within the range.

Definition at line 232 of file pStatServer.cxx.

## ◆ get_num_user_guide_bars()

int PStatServer::get_num_user_guide_bars | ( |  | ) | const

Returns the current number of user-defined guide bars.

Definition at line 180 of file pStatServer.cxx.

## ◆ get_udp_port()

int PStatServer::get_udp_port | ( |  | ) |

Returns a new port number that will probably be free to use as a UDP port.

The caller should be prepared to accept the possibility that it will be already in use by another process, however.

Definition at line 159 of file pStatServer.cxx.

## ◆ get_user_guide_bar_height()

double PStatServer::get_user_guide_bar_height | ( | int | n | ) | const

Returns the height of the nth user-defined guide bar.

Definition at line 188 of file pStatServer.cxx.

## ◆ is_thread_safe()

bool PStatServer::is_thread_safe | ( |  | ) |
| virtual

This should be redefined to return true in derived classes that want to deal with multithreaded readers and such.

If this returns true, the manager will create the listener in its own thread, and thus the PStatReader constructors at least will run in a different thread.

This is not related to the question of whether the reader can handle multiple different PStatThreadDatas; it's strictly a question of whether the readers themselves can run in a separate thread.

Definition at line 268 of file pStatServer.cxx.

## ◆ listen()

bool PStatServer::listen | ( | int | port = -1 | ) |

Establishes a port number that the manager will listen on for TCP connections.

This may be called more than once to listen simulataneously on multiple connections, as if that were at all useful.

The default parameter, -1, indicates the use of whatever port number has been indicated in the Config file.

This function returns true if the port was successfully opened, or false if it could not open the port.

Definition at line 48 of file pStatServer.cxx.

## ◆ main_loop()

void PStatServer::main_loop | ( | bool * | interrupt_flag = nullptr | ) |

An alternative to repeatedly calling poll(), this function yields control of the program to the PStatServer.

It does not return until the program is done.

If interrupt_flag is non-NULL, it is the address of a bool variable that is initially false, and may be asynchronously set true to indicate the loop should terminate.

Definition at line 123 of file pStatServer.cxx.

References poll(), and Thread::sleep().

## ◆ move_user_guide_bar()

void PStatServer::move_user_guide_bar | ( | int | n,
|  | double | height )

Adjusts the height of the nth user-defined guide bar.

Definition at line 197 of file pStatServer.cxx.

## ◆ poll()

void PStatServer::poll | ( |  | ) |

Checks for any network activity and handles it, if appropriate, and then returns.

This must be called periodically unless is_thread_safe() is redefined to return true on this class and also on all PStatMonitors in use.

Alternatively, a program may call main_loop() and yield control of the program entirely to the PStatServer.

Definition at line 81 of file pStatServer.cxx.

References PStatReader::idle(), PStatReader::lost_connection(), and ConnectionReader::poll().

Referenced by main_loop().

## ◆ release_udp_port()

void PStatServer::release_udp_port | ( | int | port | ) |

Indicates that the given UDP port is once again free for use.

Definition at line 172 of file pStatServer.cxx.

## ◆ remove_reader()

void PStatServer::remove_reader | ( | Connection * | connection,
|  | PStatReader * | reader )

Removes the indicated reader.

Definition at line 142 of file pStatServer.cxx.

## ◆ remove_user_guide_bar()

void PStatServer::remove_user_guide_bar | ( | int | n | ) |

Removes the user guide bar with the indicated index number.

All subsequent index numbers are adjusted down one.

Definition at line 220 of file pStatServer.cxx.

The documentation for this class was generated from the following files:

- pandatool/src/pstatserver/pStatServer.h
- pandatool/src/pstatserver/pStatServer.cxx