Gnash  0.8.11dev
Timers.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 // Free Software Foundation, Inc
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 #ifndef HAVE_TIMERS_H
20 #define HAVE_TIMERS_H
21 
22 #include "dsodefs.h"
23 #include "fn_call.h"
24 
25 #include <string>
26 #include <limits>
27 
28 // Forward declarations
29 namespace gnash {
30  class as_function;
31  class as_object;
32 }
33 
34 namespace gnash {
35 
37 //
51 {
52 public:
53 
54  ~Timer();
55 
57  //
76  Timer(as_function& method, unsigned long ms, as_object* this_ptr,
77  const fn_call::Args& args, bool runOnce = false);
78 
80  //
98  Timer(as_object* obj, const ObjectURI& methodName, unsigned long ms,
99  const fn_call::Args& args, bool runOnce = false);
100 
102  //
108  void clearInterval();
109 
111  // /// @param now
120  bool expired(unsigned long now, unsigned long& elapsed);
121 
123  //
126  bool cleared() const {
127  return _start == std::numeric_limits<unsigned long>::max();
128  }
129 
131  //
139  void executeAndReset();
140 
142  //
149  void markReachableResources() const;
150 
151 private:
152 
154  void execute();
155 
157  void operator() () { execute(); }
158 
160  unsigned long getInterval() const { return _interval; }
161 
163  unsigned long getStart() const { return _start; }
164 
166  //
169  void start();
170 
172  unsigned int _interval;
173 
175  //
179  unsigned long _start;
180 
183  as_function* _function;
184 
185  ObjectURI _methodName;
186 
188  as_object* _object;
189 
191  //
193  const fn_call::Args _args;
194 
196  bool _runOnce;
197 };
198 
199 } // namespace gnash
200 
201 #endif