Gnash  0.8.10
ExecutableCode.h
Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 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 
00020 #ifndef GNASH_EXECUTABLECODE_H
00021 #define GNASH_EXECUTABLECODE_H
00022 
00023 #include <vector>
00024 #include <boost/noncopyable.hpp>
00025 
00026 #include "ActionExec.h"
00027 #include "Global_as.h"
00028 #include "fn_call.h"
00029 #include "ConstantPool.h"
00030 
00031 namespace gnash {
00032 
00034 class ExecutableCode : boost::noncopyable
00035 {
00036 public:
00037 
00038     ExecutableCode(DisplayObject* t) : _target(t) {}
00039 
00040     virtual void execute() = 0;
00041 
00042     virtual ~ExecutableCode() {}
00043 
00044     virtual void setReachable() const {}
00045 
00047     void markReachableResources() const {
00048         setReachable();
00049         if (_target) _target->setReachable();
00050     }
00051 
00052     DisplayObject* target() const { 
00053         return _target;
00054     }
00055 
00056 private:
00057 
00058     DisplayObject* _target;
00059 };
00060 
00062 class GlobalCode : public ExecutableCode
00063 {
00064 public:
00065 
00066     GlobalCode(const action_buffer& nBuffer, DisplayObject* nTarget)
00067         :
00068         ExecutableCode(nTarget),
00069         buffer(nBuffer)
00070     {}
00071 
00072     virtual void execute() {
00073         if (!target()->unloaded()) {
00074             ActionExec exec(buffer, target()->get_environment());
00075             exec();
00076         }
00077     }
00078 
00079 private:
00080     const action_buffer& buffer;
00081 };
00082 
00084 class EventCode : public ExecutableCode
00085 {
00086 public:
00087 
00088     typedef std::vector<const action_buffer*> BufferList;
00089 
00090     EventCode(DisplayObject* nTarget)
00091         :
00092         ExecutableCode(nTarget)
00093     {}
00094 
00095     EventCode(DisplayObject* nTarget, const BufferList& buffers)
00096         :
00097         ExecutableCode(nTarget),
00098         _buffers(buffers)
00099     {}
00100 
00102     //
00108     void addAction(const action_buffer& buffer) {
00109         // don't push actions for destroyed DisplayObjects, 
00110         // our opcode guard is bogus at the moment.
00111         if (!target()->isDestroyed()) {
00112             _buffers.push_back(&buffer);
00113         }
00114     }
00115 
00116     virtual void execute() {
00117         for (BufferList::iterator it = _buffers.begin(),
00118             itEnd = _buffers.end(); it != itEnd; ++it) {
00119 
00120             // onClipEvents code are guarded by isDestroyed(),
00121             // still might be also guarded by unloaded()
00122             if (target()->isDestroyed()) break;
00123 
00124             PoolGuard guard(getVM(target()->get_environment()), 0);
00125             ActionExec exec(*(*it), target()->get_environment(), false);
00126             exec();
00127         }
00128     }
00129 
00130 private:
00131     BufferList _buffers;
00132 };
00133 
00135 //
00145 class DelayedFunctionCall : public ExecutableCode
00146 {
00147 public:
00148 
00149     DelayedFunctionCall(DisplayObject* target,
00150             as_object* obj, const ObjectURI& name,
00151             const as_value& arg1, const as_value& arg2)
00152         :
00153         ExecutableCode(target),
00154         _obj(obj),
00155         _name(name),
00156         _arg1(arg1),
00157         _arg2(arg2)
00158     {}
00159 
00160     virtual void execute() {
00161         callMethod(_obj, _name, _arg1, _arg2);
00162     }
00163 
00165     virtual void setReachable() const {
00166         _obj->setReachable();
00167         _arg1.setReachable();
00168         _arg2.setReachable();
00169     }
00170 
00171 private:
00172     as_object* _obj;
00173     ObjectURI _name;
00174     as_value _arg1, _arg2;
00175 };
00176 
00177 
00178 
00179 } // namespace gnash
00180 
00181 #endif // GNASH_EXECUTABLECODE_H