Gnash 0.8.9

Timers.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
00003 //   2011 Free Software Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef HAVE_TIMERS_H
00020 #define HAVE_TIMERS_H
00021 
00022 #include "dsodefs.h"
00023 #include "smart_ptr.h"
00024 #include "fn_call.h"
00025 
00026 #include <string>
00027 #include <limits>
00028 
00029 // Forward declarations
00030 namespace gnash {
00031     class as_function;
00032     class as_object;
00033 }
00034 
00035 namespace gnash {
00036   
00038 //
00051 class DSOEXPORT Timer
00052 {
00053 public:
00054       
00055     ~Timer();
00056 
00058     //
00077     Timer(as_function& method, unsigned long ms, as_object* this_ptr,
00078             const fn_call::Args& args, bool runOnce = false);
00079 
00081     //
00099     Timer(as_object* obj, const ObjectURI& methodName, unsigned long ms,
00100             const fn_call::Args& args, bool runOnce = false);
00101 
00103     //
00109     void clearInterval();
00110 
00112     // /// @param now
00121     bool expired(unsigned long now, unsigned long& elapsed); 
00122 
00124     //
00127     bool cleared() const {
00128           return _start == std::numeric_limits<unsigned long>::max();
00129     }
00130 
00132     //
00140     void executeAndReset();
00141 
00143     //
00150     void markReachableResources() const;
00151 
00152 private:
00153 
00155     void execute();
00156 
00158     void operator() () { execute(); }
00159     
00161     unsigned long getInterval() const { return _interval; }
00162 
00164     unsigned long getStart() const { return _start; }
00165 
00167     //
00170     void start();
00171 
00173     unsigned int _interval;
00174 
00176     //
00180     unsigned long _start;
00181 
00184     as_function* _function;
00185 
00186     ObjectURI _methodName;
00187 
00189     as_object* _object;
00190 
00192     //
00194     const fn_call::Args _args;
00195 
00197     bool _runOnce;
00198 };
00199   
00200 } // namespace gnash
00201 
00202 #endif