<commit_before>// Filename: pStatMonitor.cxx
// Created by:  drose (09Jul00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#include "pStatMonitor.h"

#include "pStatCollectorDef.h"


////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::Constructor
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
PStatMonitor::
PStatMonitor(PStatServer *server) : _server(server) {
  _client_known = false;
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::Destructor
//       Access: Public, Virtual
//  Description:
////////////////////////////////////////////////////////////////////
PStatMonitor::
~PStatMonitor() {
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::hello_from
//       Access: Public
//  Description: Called shortly after startup time with the greeting
//               from the client.  This indicates the client's
//               reported hostname and program name.
////////////////////////////////////////////////////////////////////
void PStatMonitor::
hello_from(const string &hostname, const string &progname) {
  _client_known = true;
  _client_hostname = hostname;
  _client_progname = progname;
  got_hello();
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::bad_version
//       Access: Public
//  Description: Called shortly after startup time with the greeting
//               from the client.  In this case, the client seems to
//               have an incompatible version and will be
//               automatically disconnected; the server should issue a
//               message to that effect.
////////////////////////////////////////////////////////////////////
void PStatMonitor::
bad_version(const string &hostname, const string &progname,
            int client_major, int client_minor,
            int server_major, int server_minor) {
  _client_known = true;
  _client_hostname = hostname;
  _client_progname = progname;
  got_bad_version(client_major, client_minor,
                  server_major, server_minor);
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::set_client_data
//       Access: Public
//  Description: Called by the PStatServer at setup time to set the
//               new data pointer for the first time.
////////////////////////////////////////////////////////////////////
void PStatMonitor::
set_client_data(PStatClientData *client_data) {
  _client_data = client_data;
  initialized();
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::is_alive
//       Access: Public
//  Description: Returns true if the client is alive and connected,
//               false otherwise.
////////////////////////////////////////////////////////////////////
bool PStatMonitor::
is_alive() const {
  if (_client_data.is_null()) {
    // Not yet, but in a second probably.
    return false;
  }
  return _client_data->is_alive();
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::close
//       Access: Public
//  Description: Closes the client connection if it is active.
////////////////////////////////////////////////////////////////////
void PStatMonitor::
close() {
  if (!_client_data.is_null()) {
    _client_data->close();
  }
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::get_collector_color
//       Access: Public
//  Description: Returns the color associated with the indicated
//               collector.  If the collector has no associated color,
//               or is unknown, a new color will be made up on the
//               spot and associated with this collector for the rest
//               of the session.
////////////////////////////////////////////////////////////////////
const RGBColorf &PStatMonitor::
get_collector_color(int collector_index) {
  Colors::iterator ci;
  ci = _colors.find(collector_index);
  if (ci != _colors.end()) {
    return (*ci).second;
  }

  // Ask the client data about the color.
  if (!_client_data.is_null() &&
      _client_data->has_collector(collector_index)) {
    const PStatCollectorDef &def =
      _client_data->get_collector_def(collector_index);

    if (def._suggested_color != RGBColorf::zero()) {
      ci = _colors.insert(Colors::value_type(collector_index, def._suggested_color)).first;
      return (*ci).second;
    }
  }

  // We didn't have a color for the collector; make one up.<commit_msg>PStatCollectorDef no longer uses RGBColorf<commit_after>// Filename: pStatMonitor.cxx
// Created by:  drose (09Jul00)
//
////////////////////////////////////////////////////////////////////
//
// PANDA 3D SOFTWARE
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc.  All rights reserved
//
// All use of this software is subject to the terms of the Panda 3d
// Software license.  You should have received a copy of this license
// along with this source code; you will also find a current copy of
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
//
// To contact the maintainers of this program write to
// <EMAIL> .
//
////////////////////////////////////////////////////////////////////

#include "pStatMonitor.h"

#include "pStatCollectorDef.h"


////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::Constructor
//       Access: Public
//  Description:
////////////////////////////////////////////////////////////////////
PStatMonitor::
PStatMonitor(PStatServer *server) : _server(server) {
  _client_known = false;
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::Destructor
//       Access: Public, Virtual
//  Description:
////////////////////////////////////////////////////////////////////
PStatMonitor::
~PStatMonitor() {
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::hello_from
//       Access: Public
//  Description: Called shortly after startup time with the greeting
//               from the client.  This indicates the client's
//               reported hostname and program name.
////////////////////////////////////////////////////////////////////
void PStatMonitor::
hello_from(const string &hostname, const string &progname) {
  _client_known = true;
  _client_hostname = hostname;
  _client_progname = progname;
  got_hello();
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::bad_version
//       Access: Public
//  Description: Called shortly after startup time with the greeting
//               from the client.  In this case, the client seems to
//               have an incompatible version and will be
//               automatically disconnected; the server should issue a
//               message to that effect.
////////////////////////////////////////////////////////////////////
void PStatMonitor::
bad_version(const string &hostname, const string &progname,
            int client_major, int client_minor,
            int server_major, int server_minor) {
  _client_known = true;
  _client_hostname = hostname;
  _client_progname = progname;
  got_bad_version(client_major, client_minor,
                  server_major, server_minor);
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::set_client_data
//       Access: Public
//  Description: Called by the PStatServer at setup time to set the
//               new data pointer for the first time.
////////////////////////////////////////////////////////////////////
void PStatMonitor::
set_client_data(PStatClientData *client_data) {
  _client_data = client_data;
  initialized();
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::is_alive
//       Access: Public
//  Description: Returns true if the client is alive and connected,
//               false otherwise.
////////////////////////////////////////////////////////////////////
bool PStatMonitor::
is_alive() const {
  if (_client_data.is_null()) {
    // Not yet, but in a second probably.
    return false;
  }
  return _client_data->is_alive();
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::close
//       Access: Public
//  Description: Closes the client connection if it is active.
////////////////////////////////////////////////////////////////////
void PStatMonitor::
close() {
  if (!_client_data.is_null()) {
    _client_data->close();
  }
}

////////////////////////////////////////////////////////////////////
//     Function: PStatMonitor::get_collector_color
//       Access: Public
//  Description: Returns the color associated with the indicated
//               collector.  If the collector has no associated color,
//               or is unknown, a new color will be made up on the
//               spot and associated with this collector for the rest
//               of the session.
////////////////////////////////////////////////////////////////////
const RGBColorf &PStatMonitor::
get_collector_color(int collector_index) {
  Colors::iterator ci;
  ci = _colors.find(collector_index);
  if (ci != _colors.end()) {
    return (*ci).second;
  }

  // Ask the client data about the color.
  if (!_client_data.is_null() &&
      _client_data->has_collector(collector_index)) {
    const PStatCollectorDef &def =
      _client_data->get_collector_def(collector_index);

    RGBColorf sc(def._suggested_color.r,
                 def._suggested_color.b,
                 def._suggested_color.g);
    if (sc != RGBColorf::zero()) {
      ci = _colors.insert(Colors::value_type(collector_index, sc)).first;
      return (*ci).second;
    }
  }

  // We didn't have a color for the collector; make one up.
{'fraction_non_alphanumeric': 0.30717594781128865, 'fraction_numerical': 0.0028363430084144842, 'mean_word_length': 1.2940793754066362, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7138869', 'n_tokens_mistral': 2493, 'n_tokens_neox': 2409, 'n_words': 755}