From 548cb7767e8f33d34dce20a11a2d3fcc273c021d Mon Sep 17 00:00:00 2001 From: David Rose Date: Mon, 20 Nov 2000 22:29:33 +0000 Subject: [PATCH] *** empty log message *** --- panda/src/pstatclient/pStatClient.cxx | 202 +++++++++++++------------- panda/src/pstatclient/pStatClient.h | 12 +- 2 files changed, 108 insertions(+), 106 deletions(-) diff --git a/panda/src/pstatclient/pStatClient.cxx b/panda/src/pstatclient/pStatClient.cxx index 4bfcd03f0d..dfad84e5cd 100644 --- a/panda/src/pstatclient/pStatClient.cxx +++ b/panda/src/pstatclient/pStatClient.cxx @@ -171,101 +171,6 @@ get_thread_name(int index) const { return _threads[index]._name; } -//////////////////////////////////////////////////////////////////// -// Function: PStatClient::connect -// Access: Public -// Description: Attempts to establish a connection to the indicated -// PStatServer. Returns true if successful, false on -// failure. -//////////////////////////////////////////////////////////////////// -bool PStatClient:: -connect(string hostname, int port) { - disconnect(); - - if (hostname.empty()) { - hostname = pstats_host; - } - if (port < 0) { - port = pstats_port; - } - - if (!_server.set_host(hostname, port)) { - pstats_cat.error() - << "Unknown host: " << hostname << "\n"; - return false; - } - - _tcp_connection = open_TCP_client_connection(_server, 5000); - - if (_tcp_connection.is_null()) { - pstats_cat.error() - << "Couldn't connect to PStatServer at " << hostname << ":" - << port << "\n"; - return false; - } - - _reader.add_connection(_tcp_connection); - _is_connected = true; - - _udp_connection = open_UDP_connection(); - - send_hello(); - - return _is_connected; -} - -//////////////////////////////////////////////////////////////////// -// Function: PStatClient::disconnect -// Access: Public -// Description: Closes the connection previously established. -//////////////////////////////////////////////////////////////////// -void PStatClient:: -disconnect() { - if (_is_connected) { - _reader.remove_connection(_tcp_connection); - close_connection(_tcp_connection); - close_connection(_udp_connection); - } - - _tcp_connection.clear(); - _udp_connection.clear(); - - _is_connected = false; - _got_udp_port = false; - - _collectors_reported = 0; - _threads_reported = 0; - - Threads::iterator ti; - for (ti = _threads.begin(); ti != _threads.end(); ++ti) { - (*ti)._frame_number = 0; - (*ti)._is_active = false; - (*ti)._last_packet = 0.0; - (*ti)._frame_data.clear(); - } - - Collectors::iterator ci; - for (ci = _collectors.begin(); ci != _collectors.end(); ++ci) { - vector_int::iterator ii; - for (ii = (*ci)._nested_count.begin(); - ii != (*ci)._nested_count.end(); - ++ii) { - (*ii) = 0; - } - } -} - -//////////////////////////////////////////////////////////////////// -// Function: PStatClient::is_connected -// Access: Public -// Description: Returns true if the client believes it is connected -// to a working PStatServer, false otherwise. -//////////////////////////////////////////////////////////////////// -bool PStatClient:: -is_connected() const { - return _is_connected; -} - //////////////////////////////////////////////////////////////////// // Function: PStatClient::get_clock // Access: Public @@ -433,6 +338,17 @@ make_thread(const string &name) { return PStatThread(this, new_index); } +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::main_tick +// Access: Public, Static +// Description: A convenience function to call new_frame() on the +// global PStatClient's main thread. +//////////////////////////////////////////////////////////////////// +void PStatClient:: +main_tick() { + get_global_pstats()->get_main_thread().new_frame(); +} + //////////////////////////////////////////////////////////////////// // Function: PStatClient::get_global_pstats // Access: Public, Static @@ -450,14 +366,98 @@ get_global_pstats() { } //////////////////////////////////////////////////////////////////// -// Function: PStatClient::main_tick -// Access: Public, Static -// Description: A convenience function to call new_frame() on the -// global PStatClient's main thread. +// Function: PStatClient::connect +// Access: Public +// Description: Attempts to establish a connection to the indicated +// PStatServer. Returns true if successful, false on +// failure. +//////////////////////////////////////////////////////////////////// +bool PStatClient:: +connect(string hostname, int port) { + disconnect(); + + if (hostname.empty()) { + hostname = pstats_host; + } + if (port < 0) { + port = pstats_port; + } + + if (!_server.set_host(hostname, port)) { + pstats_cat.error() + << "Unknown host: " << hostname << "\n"; + return false; + } + + _tcp_connection = open_TCP_client_connection(_server, 5000); + + if (_tcp_connection.is_null()) { + pstats_cat.error() + << "Couldn't connect to PStatServer at " << hostname << ":" + << port << "\n"; + return false; + } + + _reader.add_connection(_tcp_connection); + _is_connected = true; + + _udp_connection = open_UDP_connection(); + + send_hello(); + + return _is_connected; +} + +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::disconnect +// Access: Public +// Description: Closes the connection previously established. //////////////////////////////////////////////////////////////////// void PStatClient:: -main_tick() { - get_global_pstats()->get_main_thread().new_frame(); +disconnect() { + if (_is_connected) { + _reader.remove_connection(_tcp_connection); + close_connection(_tcp_connection); + close_connection(_udp_connection); + } + + _tcp_connection.clear(); + _udp_connection.clear(); + + _is_connected = false; + _got_udp_port = false; + + _collectors_reported = 0; + _threads_reported = 0; + + Threads::iterator ti; + for (ti = _threads.begin(); ti != _threads.end(); ++ti) { + (*ti)._frame_number = 0; + (*ti)._is_active = false; + (*ti)._last_packet = 0.0; + (*ti)._frame_data.clear(); + } + + Collectors::iterator ci; + for (ci = _collectors.begin(); ci != _collectors.end(); ++ci) { + vector_int::iterator ii; + for (ii = (*ci)._nested_count.begin(); + ii != (*ci)._nested_count.end(); + ++ii) { + (*ii) = 0; + } + } +} + +//////////////////////////////////////////////////////////////////// +// Function: PStatClient::is_connected +// Access: Public +// Description: Returns true if the client believes it is connected +// to a working PStatServer, false otherwise. +//////////////////////////////////////////////////////////////////// +bool PStatClient:: +is_connected() const { + return _is_connected; } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pstatclient/pStatClient.h b/panda/src/pstatclient/pStatClient.h index 2ec5ee4ff1..1498b1be3b 100644 --- a/panda/src/pstatclient/pStatClient.h +++ b/panda/src/pstatclient/pStatClient.h @@ -56,16 +56,18 @@ public: PStatThread get_thread(int index) const; string get_thread_name(int index) const; - bool connect(string hostname = string(), int port = -1); - void disconnect(); - - bool is_connected() const; const ClockObject &get_clock() const; PStatThread get_main_thread() const; - static PStatClient *get_global_pstats(); static void main_tick(); +PUBLISHED: + static PStatClient *get_global_pstats(); + + bool connect(string hostname = string(), int port = -1); + void disconnect(); + bool is_connected() const; + private: PStatCollector make_collector(int parent_index, const string &fullname); PStatCollector make_collector(int parent_index, const string &fullname,