00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00030
00031 static void signal_handler(int) {
00032 user_interrupted = true;
00033 }
00034
00035
00036
00037
00038
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
00059
00060
00061
00062 PStatMonitor *TextStats::
00063 make_monitor() {
00064 return new TextMonitor;
00065 }
00066
00067
00068
00069
00070
00071
00072
00073 void TextStats::
00074 run() {
00075
00076
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 }