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

pandatool/src/gtk-stats/gtkStatsMainWindow.cxx

Go to the documentation of this file.
00001 // Filename: gtkStatsMainWindow.cxx
00002 // Created by:  drose (14Jul00)
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 "gtkStatsMainWindow.h"
00020 #include "gtkStats.h"
00021 #include "gtkStatsServer.h"
00022 
00023 #include <string_utils.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: GtkStatsMainWindow::Constructor
00037 //       Access: Public
00038 //  Description:
00039 ////////////////////////////////////////////////////////////////////
00040 GtkStatsMainWindow::
00041 GtkStatsMainWindow(int port) : _port(port) {
00042   nassertv(GtkStats::_main_window == (GtkStatsMainWindow *)NULL);
00043   GtkStats::_main_window = this;
00044 
00045   // Set up a global signal handler to catch Interrupt (Control-C) so
00046   // we can clean up nicely if the user stops us.
00047   signal(SIGINT, &signal_handler);
00048 
00049   _server = new GtkStatsServer;
00050   if (!_server->listen(_port)) {
00051     nout << "Unable to open port.\n";
00052     exit(1);
00053   }
00054 
00055   layout_window();
00056   setup();
00057 
00058   Gtk::Main::timeout.
00059     connect(slot(this, &GtkStatsMainWindow::idle_callback), 200);
00060 }
00061 
00062 ////////////////////////////////////////////////////////////////////
00063 //     Function: GtkStatsMainWindow::Destructor
00064 //       Access: Public, Virtual
00065 //  Description:
00066 ////////////////////////////////////////////////////////////////////
00067 GtkStatsMainWindow::
00068 ~GtkStatsMainWindow() {
00069   nassertv(GtkStats::_main_window == this);
00070   GtkStats::_main_window = NULL;
00071 }
00072 
00073 ////////////////////////////////////////////////////////////////////
00074 //     Function: GtkStatsMainWindow::destruct
00075 //       Access: Public, Virtual
00076 //  Description:
00077 ////////////////////////////////////////////////////////////////////
00078 bool GtkStatsMainWindow::
00079 destruct() {
00080   if (BasicGtkWindow::destruct()) {
00081     nassertr(_server != (GtkStatsServer *)NULL, false);
00082     delete _server;
00083     GtkStats::quit();
00084   }
00085   return false;
00086 }
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: GtkStatsMainWindow::layout_window
00090 //       Access: Private
00091 //  Description:
00092 ////////////////////////////////////////////////////////////////////
00093 void GtkStatsMainWindow::
00094 layout_window() {
00095   set_title("Gtk Stats");
00096 
00097   Gtk::VBox *box1 = new Gtk::VBox;
00098   box1->show();
00099   box1->set_border_width(8);
00100   add(*manage(box1));
00101 
00102   Gtk::Label *listening =
00103     new Gtk::Label("Listening on port " + format_string(_port));
00104   listening->show();
00105   box1->pack_start(*manage(listening), true, false, 8);
00106 
00107   Gtk::HBox *box2 = new Gtk::HBox;
00108   box2->show();
00109   box1->pack_start(*manage(box2), false, false, 0);
00110 
00111   Gtk::Button *close = new Gtk::Button("Close");
00112   close->set_usize(80, 30);
00113   close->show();
00114   box2->pack_start(*manage(close), true, false, 0);
00115   close->clicked.connect(slot(this, &GtkStatsMainWindow::close_clicked));
00116 }
00117 
00118 ////////////////////////////////////////////////////////////////////
00119 //     Function: GtkStatsMainWindow::close_clicked
00120 //       Access: Private
00121 //  Description:
00122 ////////////////////////////////////////////////////////////////////
00123 void GtkStatsMainWindow::
00124 close_clicked() {
00125   destruct();
00126 }
00127 
00128 ////////////////////////////////////////////////////////////////////
00129 //     Function: GtkStatsMainWindow::idle_callback
00130 //       Access: Private
00131 //  Description:
00132 ////////////////////////////////////////////////////////////////////
00133 gint GtkStatsMainWindow::
00134 idle_callback() {
00135   if (user_interrupted) {
00136     destruct();
00137     return false;
00138   }
00139   _server->poll();
00140   return true;
00141 }

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