Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

DelayedEvent.h

00001 /*
00002  * Copyright 2003 Michael A. Marsh, Cornell University. All rights reserved.
00003  * This software is released under the modified BSD license.
00004  * See the file LICENSE in the top-level directory for details.
00005  */
00006 //
00007 // $Id: DelayedEvent.h,v 1.4 2005/01/21 19:44:16 mmarsh Exp $
00008 //
00009 // $Log: DelayedEvent.h,v $
00010 // Revision 1.4  2005/01/21 19:44:16  mmarsh
00011 // Updated for compatibility with Doxygen 1.4.1
00012 //
00013 // Revision 1.3  2004/05/19 15:56:50  mmarsh
00014 // *** empty log message ***
00015 //
00016 // Revision 1.2  2003/11/04 22:10:41  mmarsh
00017 // Added documentation for class DelayedEvent.
00018 //
00019 //
00020 
00021 #ifndef __CODEX_EVENTS_DELAYEDEVENT_H__
00022 #define __CODEX_EVENTS_DELAYEDEVENT_H__
00023 
00024 #include "Event.h"
00025 #include <sys/time.h>
00026 
00027 namespace CODEX_Events
00028 {
00038    class DelayedEvent : public EventBase
00039    {
00040       public :
00046          DelayedEvent( EventBase* evt ) :
00047             EventBase( 0 ),
00048             m_evt( evt ),
00049             m_aged( false )
00050          {
00051             gettimeofday( &m_enqueuedStart, 0 );
00052          }
00053 
00055          virtual ~DelayedEvent()
00056          {
00057             if ( 0 != m_evt ) delete m_evt;
00058          }
00059 
00074          bool handle()
00075          {
00076             if ( 0 == m_evt )
00077             {
00078                // There's no event, so don't keep clutter around.
00079                return true;
00080             }
00081             if ( ! m_aged )
00082             {
00083                struct timeval tv;
00084                gettimeofday( &tv, 0 );
00085                tv.tv_usec -= m_enqueuedStart.tv_usec;
00086                tv.tv_sec -= m_enqueuedStart.tv_sec;
00087                if ( tv.tv_usec < 0 )
00088                {
00089                   tv.tv_usec += 1000000;
00090                   tv.tv_sec -= 1;
00091                }
00092                if ( tv.tv_sec < sDelay )
00093                {
00094                   return false;
00095                }
00096                if ( ( tv.tv_sec == sDelay ) && ( tv.tv_usec < usDelay ) )
00097                {
00098                   return false;
00099                }
00100                m_aged = true;
00101             }
00102             return m_evt->handle();
00103          }
00104 
00106          static long int  sDelay;
00108          static long int  usDelay;
00109 
00110       private :
00111          EventBase*      m_evt;
00112          bool            m_aged;
00113          struct timeval  m_enqueuedStart;
00114    };
00115 }
00116 
00117 #endif /* __CODEX_EVENTS_DELAYEDEVENT_H__ */

Generated on Fri May 6 17:38:58 2005 for COrnell Data EXchange (CODEX) by  doxygen 1.4.1