Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pandatool/src/text-stats/textStats.cxx

Go to the documentation of this file.
00001 // Filename: textStats.cxx
00002 // Created by:  drose (12Jul00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "textStats.h"
00020 #include "textMonitor.h"
00021 
00022 #include <pStatServer.h>
00023 #include <config_pstats.h>
00024 
00025 #include <signal.h>
00026 
00027 static bool user_interrupted = false;
00028 
00029 // This simple signal handler lets us know when the user has pressed
00030 // control-C, so we can clean up nicely.
00031 static void signal_handler(int) {
00032   user_interrupted = true;
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: TextStats::Constructor
00037 //       Access: Public
00038 //  Description:
00039 ////////////////////////////////////////////////////////////////////
00040 TextStats::
00041 TextStats() {
00042   set_program_description
00043     ("This is a simple PStats server that listens on a TCP port for a "
00044      "connection from a PStatClient in a Panda player.  It will then report "
00045      "frame rate and timing information sent by the player.");
00046 
00047   add_option
00048     ("p", "port", 0,
00049      "Specify the TCP port to listen for connections on.  By default, this "
00050      "is taken from the pstats-host Config variable.",
00051      &TextStats::dispatch_int, NULL, &_port);
00052 
00053   _port = pstats_port;
00054 }
00055 
00056 
00057 ////////////////////////////////////////////////////////////////////
00058 //     Function: TextStats::make_monitor
00059 //       Access: Public
00060 //  Description:
00061 ////////////////////////////////////////////////////////////////////
00062 PStatMonitor *TextStats::
00063 make_monitor() {
00064   return new TextMonitor;
00065 }
00066 
00067 
00068 ////////////////////////////////////////////////////////////////////
00069 //     Function: TextStats::run
00070 //       Access: Public
00071 //  Description:
00072 ////////////////////////////////////////////////////////////////////
00073 void TextStats::
00074 run() {
00075   // Set up a global signal handler to catch Interrupt (Control-C) so
00076   // we can clean up nicely if the user stops us.
00077   signal(SIGINT, &signal_handler);
00078 
00079   if (!listen(_port)) {
00080     nout << "Unable to open port.\n";
00081     exit(1);
00082   }
00083 
00084   nout << "Listening for connections.\n";
00085 
00086   main_loop(&user_interrupted);
00087   nout << "Exiting.\n";
00088 }
00089 
00090 
00091 int main(int argc, char *argv[]) {
00092   TextStats prog;
00093   prog.parse_command_line(argc, argv);
00094   prog.run();
00095   return 0;
00096 }

Generated on Fri May 2 03:21:50 2003 for Panda-Tool by doxygen1.3