gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] gnash ChangeLog server/VirtualClock.h


From: Sandro Santilli
Subject: [Gnash-commit] gnash ChangeLog server/VirtualClock.h
Date: Sat, 24 May 2008 10:38:04 +0000

CVSROOT:        /sources/gnash
Module name:    gnash
Changes by:     Sandro Santilli <strk>  08/05/24 10:38:04

Modified files:
        .              : ChangeLog 
        server         : VirtualClock.h 

Log message:
        add interruptable wrapper for VirtualClocks.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/gnash/ChangeLog?cvsroot=gnash&r1=1.6696&r2=1.6697
http://cvs.savannah.gnu.org/viewcvs/gnash/server/VirtualClock.h?cvsroot=gnash&r1=1.2&r2=1.3

Patches:
Index: ChangeLog
===================================================================
RCS file: /sources/gnash/gnash/ChangeLog,v
retrieving revision 1.6696
retrieving revision 1.6697
diff -u -b -r1.6696 -r1.6697
--- ChangeLog   23 May 2008 21:15:15 -0000      1.6696
+++ ChangeLog   24 May 2008 10:38:03 -0000      1.6697
@@ -1,3 +1,7 @@
+2008-05-24 Sandro Santilli <address@hidden>
+
+       * server/VirtualClock.h: add interruptable wrapper for VirtualClocks.
+
 2008-05-23 Benjamin Wolsey <address@hidden>
 
        * server/vm/ActionExec.cpp: clean up using directives.

Index: server/VirtualClock.h
===================================================================
RCS file: /sources/gnash/gnash/server/VirtualClock.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- server/VirtualClock.h       21 Jan 2008 20:55:48 -0000      1.2
+++ server/VirtualClock.h       24 May 2008 10:38:04 -0000      1.3
@@ -24,6 +24,8 @@
 #include "gnashconfig.h"
 #endif
 
+#include <memory> // for InterruptableVirtualClock
+#include <cassert> // for InterruptableVirtualClock
 
 namespace gnash
 {
@@ -53,6 +55,70 @@
     virtual ~VirtualClock() {}
 };
 
+/// A VirtualClock wrapper adding pause/resume capabilities 
+class InterruptableVirtualClock : public VirtualClock
+{
+
+public:
+
+       /// Construct an InterruptableVirtualClock from a VirtualClock source
+       //
+       /// The interruptable virtual clock starts in 'stop' mode
+       ///
+       /// @param src
+       ///     A VirtualClock to use as source, ownership transferred
+       ///
+       InterruptableVirtualClock(VirtualClock* src)
+               :
+               _src(src),
+               _elapsed(0),
+               _offset(_src->elapsed()),
+               _paused(true)
+       {
+       }
+
+       /// Return elapsed time, taking interruptions in consideration
+       unsigned long int elapsed() const
+       {
+               if ( ! _paused ) // query source if not stopped
+                       _elapsed = _src->elapsed()-_offset;
+               return _elapsed;
+       }
+
+       void restart()
+       {
+               _elapsed = 0;
+               _offset = _src->elapsed();
+       }
+
+       void pause()
+       {
+               if ( _paused ) return; // nothing to do
+               _paused = true;
+       }
+
+       void resume()
+       {
+               if ( ! _paused ) return; // nothing to do
+               _paused = false;
+
+               unsigned long now = _src->elapsed();
+               _offset = ( now - _elapsed );
+               assert( now-_offset == _elapsed ); // check if we did the right 
thing
+       }
+
+private:
+
+       std::auto_ptr<VirtualClock> _src;
+
+       mutable unsigned long int _elapsed;
+
+       unsigned long int _offset;
+
+       bool _paused;
+};
+
+
 } // namespace gnash
 
 #endif // GNASH_VIRTUAL_CLOCK_H




reply via email to

[Prev in Thread] Current Thread [Next in Thread]