Gnash  0.8.10
Timers.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
00003 //   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 "fn_call.h"
00024 
00025 #include <string>
00026 #include <limits>
00027 
00028 // Forward declarations
00029 namespace gnash {
00030     class as_function;
00031     class as_object;
00032 }
00033 
00034 namespace gnash {
00035   
00037 //
00050 class DSOEXPORT Timer
00051 {
00052 public:
00053       
00054     ~Timer();
00055 
00057     //
00076     Timer(as_function& method, unsigned long ms, as_object* this_ptr,
00077             const fn_call::Args& args, bool runOnce = false);
00078 
00080     //
00098     Timer(as_object* obj, const ObjectURI& methodName, unsigned long ms,
00099             const fn_call::Args& args, bool runOnce = false);
00100 
00102     //
00108     void clearInterval();
00109 
00111     // /// @param now
00120     bool expired(unsigned long now, unsigned long& elapsed); 
00121 
00123     //
00126     bool cleared() const {
00127           return _start == std::numeric_limits<unsigned long>::max();
00128     }
00129 
00131     //
00139     void executeAndReset();
00140 
00142     //
00149     void markReachableResources() const;
00150 
00151 private:
00152 
00154     void execute();
00155 
00157     void operator() () { execute(); }
00158     
00160     unsigned long getInterval() const { return _interval; }
00161 
00163     unsigned long getStart() const { return _start; }
00164 
00166     //
00169     void start();
00170 
00172     unsigned int _interval;
00173 
00175     //
00179     unsigned long _start;
00180 
00183     as_function* _function;
00184 
00185     ObjectURI _methodName;
00186 
00188     as_object* _object;
00189 
00191     //
00193     const fn_call::Args _args;
00194 
00196     bool _runOnce;
00197 };
00198   
00199 } // namespace gnash
00200 
00201 #endif