Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

SpikeStreamApplication.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   SpikeStream Application                                               *
00003  *   Copyright (C) 2007 by David Gamez                                     *
00004  *   david@davidgamez.eu                                                   *
00005  *   Version 0.1                                                           *
00006  *                                                                         *
00007  *   This program is free software; you can redistribute it and/or modify  *
00008  *   it under the terms of the GNU General Public License as published by  *
00009  *   the Free Software Foundation; either version 2 of the License, or     *
00010  *   (at your option) any later version.                                   *
00011  *                                                                         *
00012  *   This program is distributed in the hope that it will be useful,       *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU General Public License for more details.                          *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU General Public License     *
00018  *   along with this program; if not, write to the                         *
00019  *   Free Software Foundation, Inc.,                                       *
00020  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00021  ***************************************************************************/
00022 
00023 //SpikeStream includes
00024 #include "SpikeStreamApplication.h"
00025 #include "Debug.h"
00026 
00027 //Other includes
00028 #include <X11/Xlib.h>
00029 #include <iostream>
00030 using namespace std;
00031 
00032 
00033 /*! Constructor. */
00034 SpikeStreamApplication::SpikeStreamApplication(int argc, char ** argv) : QApplication(argc, argv){
00035         renderDuration_ms = 0;
00036         startRenderKeyEventTime = 0;
00037         rendering = false;
00038 }
00039 
00040 
00041 /*! Destructor. */
00042 SpikeStreamApplication::~SpikeStreamApplication(){
00043         #ifdef MEMORY_DEBUG
00044                 cout<<"DESTROYING SPIKE STREAM APPLICATION"<<endl;
00045         #endif//MEMORY_DEBUG
00046 }
00047 
00048 
00049 //--------------------------------------------------------------------------
00050 //-------------------------- PUBLIC METHODS --------------------------------
00051 //--------------------------------------------------------------------------
00052 
00053 /*! Returns true if the render is currently in progress. */
00054 bool SpikeStreamApplication::renderInProgress(){
00055         return rendering;
00056 }
00057 
00058 
00059 /*! Called when the network viewer starts the render and records the time
00060         at this point and the time of the last key event. */
00061 void SpikeStreamApplication::startRender(){
00062         rendering = true;
00063         gettimeofday(&startRenderTime, NULL);
00064         startRenderKeyEventTime = keyEventTime;
00065 }
00066 
00067 
00068 /*! Records the time at which the render completes and calculates the duration
00069         of the render. */
00070 void SpikeStreamApplication::stopRender(){
00071         rendering = false;
00072         gettimeofday(&stopRenderTime, NULL);
00073         renderDuration_ms = 1000 * (stopRenderTime.tv_sec - startRenderTime.tv_sec) + (stopRenderTime.tv_usec - startRenderTime.tv_usec) / 1000;
00074 }
00075 
00076 
00077 //---------------------------------------------------------------------------
00078 //------------------------- PROTECTED METHODS -------------------------------
00079 //---------------------------------------------------------------------------
00080 
00081 /*! Method inherited from QApplication that is called whenever an X11 XEvent is
00082         received by the application. Returning true filters the event, returning
00083         false passes the event on to the application. 
00084         This method filters events that are received whilst the NetworkViewer is
00085         rendering. Since display lists are used, have no control during the render
00086         so have to look for events that were generated during the time window of
00087         the render. This method is specific to Linux. */
00088 bool SpikeStreamApplication::x11EventFilter( XEvent * xEvent){
00089 
00090         //Look for events from the keyboard
00091         if(xEvent->type == KeyPress || xEvent->type == KeyRelease){
00092                 //Record time of key event
00093                 keyEventTime = xEvent->xkey.time;
00094 
00095                 //If the key event arrived during the render, ignore it.
00096                 if((keyEventTime - startRenderKeyEventTime) < renderDuration_ms){
00097                         return true;
00098                 }
00099         }
00100         return false;
00101 }
00102 
00103 
00104 

Generated on Mon Sep 3 22:29:04 2007 for SpikeStream Application by  doxygen 1.4.4