Panda3D
Public Member Functions | Static Public Member Functions

PStatClient Class Reference

Manages the communications to report statistics via a network connection to a remote PStatServer. More...

Inheritance diagram for PStatClient:
ConnectionManager PStatsCallback

List of all members.

Public Member Functions

bool clientConnect (string hostname, int port)
 The nonstatic implementation of connect().
 clientDisconnect ()
 The nonstatic implementation of disconnect().
bool clientIsConnected ()
 The nonstatic implementation of is_connected().
 clientMainTick ()
 A convenience function to call new_frame() on the given PStatClient's main thread, and any other threads with a sync_name of "Main".
 clientResumeAfterPause ()
 Resumes the PStatClient after the simulation has been paused for a while.
 clientThreadTick (string sync_name)
 A convenience function to call new_frame() on all of the threads with the indicated sync name.
bool closeConnection (Connection connection)
 Terminates a UDP or TCP socket previously opened.
string getClientName ()
 Retrieves the name of the client as set.
PStatCollector getCollector (int index)
 Returns the nth collector.
PStatCollectorDef getCollectorDef (int index)
 Returns the definition body of the nth collector.
string getCollectorFullname (int index)
 Returns the "full name" of the indicated collector.
string getCollectorName (int index)
 Returns the name of the indicated collector.
list getCollectors ()
PStatThread getCurrentThread ()
 Returns a handle to the currently-executing thread.
PStatThread getMainThread ()
 Returns a handle to the client's Main thread.
float getMaxRate ()
 Returns the maximum number of packets that will be sent to the server per second, per thread.
int getNumCollectors ()
 Returns the total number of collectors the Client knows about.
int getNumThreads ()
 Returns the total number of threads the Client knows about.
double getRealTime ()
 Returns the time according to to the PStatClient's clock object.
PStatThread getThread (int index)
 Returns the nth thread.
string getThreadName (int index)
 Returns the name of the indicated thread.
Thread getThreadObject (int index)
 Returns the Panda Thread object associated with the indicated PStatThread.
list getThreads ()
string getThreadSyncName (int index)
 Returns the sync_name of the indicated thread.
Connection openTCPClientConnection (NetAddress const address, int timeout_ms)
 Attempts to establish a TCP client connection to a server at the indicated address.
Connection openTCPClientConnection (string hostname, int port, int timeout_ms)
 This is a shorthand version of the function to directly establish communications to a named host and port.
Connection openTCPServerRendezvous (string hostname, int port, int backlog)
 Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections.
Connection openTCPServerRendezvous (NetAddress const address, int backlog)
 Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections.
Connection openTCPServerRendezvous (int port, int backlog)
 Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections.
Connection openUDPConnection (int port)
 Opens a socket for sending and/or receiving UDP packets.
Connection openUDPConnection ()
 Opens a socket for sending and/or receiving UDP packets.
 setClientName (string name)
 Sets the name of the client.
 setMaxRate (float rate)
 Controls the number of packets that will be sent to the server.

Static Public Member Functions

static bool connect (string hostname, int port)
 Attempts to establish a connection to the indicated PStatServer.
static bool connect (string hostname)
 Attempts to establish a connection to the indicated PStatServer.
static bool connect ()
 Attempts to establish a connection to the indicated PStatServer.
static disconnect ()
 Closes the connection previously established.
static PStatClient getGlobalPstats ()
 Returns a pointer to the global PStatClient object.
static string getHostName ()
 Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined.
static bool isConnected ()
 Returns true if the client believes it is connected to a working PStatServer, false otherwise.
static mainTick ()
 A convenience function to call new_frame() on the global PStatClient's main thread, and any other threads with a sync_name of "Main".
static resumeAfterPause ()
 Resumes the PStatClient after the simulation has been paused for a while.
static threadTick (string sync_name)
 A convenience function to call new_frame() on any threads with the indicated sync_name.

Detailed Description

Manages the communications to report statistics via a network connection to a remote PStatServer.

Normally, there is only one PStatClient in the world, although it is possible to have multiple PStatClients if extraordinary circumstances require in. Since each PStatCollector registers itself with the PStatClient when it is created, having multiple PStatClients requires special care when constructing the various PStatCollectors.

If DO_PSTATS is not defined, we don't want to use stats at all. This class is therefore defined as a stub class.


Member Function Documentation

bool clientConnect ( string  hostname,
int  port 
)

The nonstatic implementation of connect().

clientDisconnect ( )

The nonstatic implementation of disconnect().

bool clientIsConnected ( )

The nonstatic implementation of is_connected().

clientMainTick ( )

A convenience function to call new_frame() on the given PStatClient's main thread, and any other threads with a sync_name of "Main".

clientResumeAfterPause ( )

Resumes the PStatClient after the simulation has been paused for a while.

This allows the stats to continue exactly where it left off, instead of leaving a big gap that would represent a chug.

clientThreadTick ( string  sync_name)

A convenience function to call new_frame() on all of the threads with the indicated sync name.

bool closeConnection ( Connection  connection) [inherited]

Terminates a UDP or TCP socket previously opened.

This also removes it from any associated ConnectionReader or ConnectionListeners.

The socket itself may not be immediately closed--it will not be closed until all outstanding pointers to it are cleared, including any pointers remaining in NetDatagrams recently received from the socket.

The return value is true if the connection was marked to be closed, or false if close_connection() had already been called (or the connection did not belong to this ConnectionManager). In neither case can you infer anything about whether the connection has actually* been closed yet based on the return value.

static bool connect ( string  hostname) [static]

Attempts to establish a connection to the indicated PStatServer.

Returns true if successful, false on failure.

static bool connect ( ) [static]

Attempts to establish a connection to the indicated PStatServer.

Returns true if successful, false on failure.

static bool connect ( string  hostname,
int  port 
) [static]

Attempts to establish a connection to the indicated PStatServer.

Returns true if successful, false on failure.

static disconnect ( ) [static]

Closes the connection previously established.

string getClientName ( )

Retrieves the name of the client as set.

PStatCollector getCollector ( int  index)

Returns the nth collector.

PStatCollectorDef getCollectorDef ( int  index)

Returns the definition body of the nth collector.

string getCollectorFullname ( int  index)

Returns the "full name" of the indicated collector.

This will be the concatenation of all of the collector's parents' names (except Frame) and the collector's own name.

string getCollectorName ( int  index)

Returns the name of the indicated collector.

list getCollectors ( )
PStatThread getCurrentThread ( )

Returns a handle to the currently-executing thread.

This is the thread that PStatCollectors will be counted in if they do not specify otherwise.

static PStatClient getGlobalPstats ( ) [static]

Returns a pointer to the global PStatClient object.

It's legal to declare your own PStatClient locally, but it's also convenient to have a global one that everyone can register with. This is the global one.

static string getHostName ( ) [static, inherited]

Returns the name of this particular machine on the network, if available, or the empty string if the hostname cannot be determined.

PStatThread getMainThread ( )

Returns a handle to the client's Main thread.

This is the thread that started the application.

float getMaxRate ( )

Returns the maximum number of packets that will be sent to the server per second, per thread.

See set_max_rate().

int getNumCollectors ( )

Returns the total number of collectors the Client knows about.

int getNumThreads ( )

Returns the total number of threads the Client knows about.

double getRealTime ( )

Returns the time according to to the PStatClient's clock object.

It keeps its own clock, instead of using the global clock object, so the stats won't get mucked up if you put the global clock in non-real-time mode or something.

PStatThread getThread ( int  index)

Returns the nth thread.

string getThreadName ( int  index)

Returns the name of the indicated thread.

Thread getThreadObject ( int  index)

Returns the Panda Thread object associated with the indicated PStatThread.

list getThreads ( )
string getThreadSyncName ( int  index)

Returns the sync_name of the indicated thread.

static bool isConnected ( ) [static]

Returns true if the client believes it is connected to a working PStatServer, false otherwise.

static mainTick ( ) [static]

A convenience function to call new_frame() on the global PStatClient's main thread, and any other threads with a sync_name of "Main".

Connection openTCPClientConnection ( string  hostname,
int  port,
int  timeout_ms 
) [inherited]

This is a shorthand version of the function to directly establish communications to a named host and port.

Connection openTCPClientConnection ( NetAddress const  address,
int  timeout_ms 
) [inherited]

Attempts to establish a TCP client connection to a server at the indicated address.

If the connection is not established within timeout_ms milliseconds, a null connection is returned.

Connection openTCPServerRendezvous ( int  port,
int  backlog 
) [inherited]

Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections.

The socket returned by this call should only be added to a ConnectionListener (not to a generic ConnectionReader).

This variant of this method accepts a single port, and will listen to that port on all available interfaces.

backlog is the maximum length of the queue of pending connections.

Connection openTCPServerRendezvous ( NetAddress const  address,
int  backlog 
) [inherited]

Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections.

The socket returned by this call should only be added to a ConnectionListener (not to a generic ConnectionReader).

This variant of this method accepts a NetAddress, which allows you to specify a specific interface to listen to.

backlog is the maximum length of the queue of pending connections.

Connection openTCPServerRendezvous ( string  hostname,
int  port,
int  backlog 
) [inherited]

Creates a socket to be used as a rendezvous socket for a server to listen for TCP connections.

The socket returned by this call should only be added to a ConnectionListener (not to a generic ConnectionReader).

This variant of this method accepts a "hostname", which is usually just an IP address in dotted notation, and a port number. It will listen on the interface indicated by the IP address. If the IP address is empty string, it will listen on all interfaces.

backlog is the maximum length of the queue of pending connections.

Connection openUDPConnection ( ) [inherited]

Opens a socket for sending and/or receiving UDP packets.

If the port number is greater than zero, the UDP connection will be opened for listening on the indicated port; otherwise, it will be useful only for sending.

Use a ConnectionReader and ConnectionWriter to handle the actual communication.

Connection openUDPConnection ( int  port) [inherited]

Opens a socket for sending and/or receiving UDP packets.

If the port number is greater than zero, the UDP connection will be opened for listening on the indicated port; otherwise, it will be useful only for sending.

Use a ConnectionReader and ConnectionWriter to handle the actual communication.

static resumeAfterPause ( ) [static]

Resumes the PStatClient after the simulation has been paused for a while.

This allows the stats to continue exactly where it left off, instead of leaving a big gap that would represent a chug.

setClientName ( string  name)

Sets the name of the client.

This is reported to the PStatsServer, and will presumably be written in the title bar or something.

setMaxRate ( float  rate)

Controls the number of packets that will be sent to the server.

Normally, one packet is sent per frame, but this can flood the server with more packets than it can handle if the frame rate is especially good (e.g. if nothing is onscreen at the moment). Set this parameter to a reasonable number to prevent this from happening.

This number specifies the maximum number of packets that will be sent to the server per second, per thread.

static threadTick ( string  sync_name) [static]

A convenience function to call new_frame() on any threads with the indicated sync_name.

 All Classes Namespaces Functions Variables Enumerations Enumerator Properties