Gnash 0.8.9

ExecutableCode.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 // 
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00017 
00018 
00019 #ifndef GNASH_EXECUTABLECODE_H
00020 #define GNASH_EXECUTABLECODE_H
00021 
00022 #include <vector>
00023 #include <boost/noncopyable.hpp>
00024 
00025 #include "smart_ptr.h" 
00026 #include "ActionExec.h"
00027 #include "Global_as.h"
00028 #include "fn_call.h"
00029 
00030 namespace gnash {
00031 
00033 class ExecutableCode : boost::noncopyable
00034 {
00035 public:
00036 
00037     ExecutableCode(DisplayObject* t) : _target(t) {}
00038 
00039     virtual void execute() = 0;
00040 
00041     virtual ~ExecutableCode() {}
00042 
00043     virtual void setReachable() const {}
00044 
00046     void markReachableResources() const {
00047         setReachable();
00048         if (_target) _target->setReachable();
00049     }
00050 
00051     DisplayObject* target() const { 
00052         return _target;
00053     }
00054 
00055 private:
00056 
00057     DisplayObject* _target;
00058 };
00059 
00061 class GlobalCode : public ExecutableCode
00062 {
00063 public:
00064 
00065     GlobalCode(const action_buffer& nBuffer, DisplayObject* nTarget)
00066         :
00067         ExecutableCode(nTarget),
00068         buffer(nBuffer)
00069     {}
00070 
00071     virtual void execute() {
00072         if (!target()->unloaded()) {
00073             ActionExec exec(buffer, target()->get_environment());
00074             exec();
00075         }
00076     }
00077 
00078 private:
00079     const action_buffer& buffer;
00080 };
00081 
00083 class EventCode : public ExecutableCode
00084 {
00085 public:
00086 
00087     typedef std::vector<const action_buffer*> BufferList;
00088 
00089     EventCode(DisplayObject* nTarget)
00090         :
00091         ExecutableCode(nTarget)
00092     {}
00093 
00094     EventCode(DisplayObject* nTarget, const BufferList& buffers)
00095         :
00096         ExecutableCode(nTarget),
00097         _buffers(buffers)
00098     {}
00099 
00101     //
00107     void addAction(const action_buffer& buffer) {
00108         // don't push actions for destroyed DisplayObjects, 
00109         // our opcode guard is bogus at the moment.
00110         if (!target()->isDestroyed()) {
00111             _buffers.push_back(&buffer);
00112         }
00113     }
00114 
00115     virtual void execute() {
00116         for (BufferList::iterator it = _buffers.begin(),
00117             itEnd = _buffers.end(); it != itEnd; ++it) {
00118 
00119             // onClipEvents code are guarded by isDestroyed(),
00120             // still might be also guarded by unloaded()
00121             if (target()->isDestroyed()) break;
00122 
00123             ActionExec exec(*(*it), target()->get_environment(), false);
00124             exec();
00125         }
00126     }
00127 
00128 private:
00129     BufferList _buffers;
00130 };
00131 
00133 class QueuedEvent : public ExecutableCode
00134 {
00135 public:
00136 
00137     QueuedEvent(DisplayObject* nTarget, const event_id& id)
00138         :
00139         ExecutableCode(nTarget),
00140         _eventId(id)
00141     {}
00142 
00143     virtual void execute() {
00144         // don't execute any events for destroyed DisplayObject.
00145         if (!target()->isDestroyed()) {
00146             target()->notifyEvent(_eventId);
00147         }
00148     }
00149 
00150 private:
00151     const event_id _eventId;
00152 };
00153 
00155 //
00165 class DelayedFunctionCall : public ExecutableCode
00166 {
00167 public:
00168 
00169     DelayedFunctionCall(DisplayObject* target,
00170             as_object* obj, const ObjectURI& name,
00171             const as_value& arg1, const as_value& arg2)
00172         :
00173         ExecutableCode(target),
00174         _obj(obj),
00175         _name(name),
00176         _arg1(arg1),
00177         _arg2(arg2)
00178     {}
00179 
00180     virtual void execute() {
00181         callMethod(_obj, _name, _arg1, _arg2);
00182     }
00183 
00185     virtual void setReachable() const {
00186         _obj->setReachable();
00187         _arg1.setReachable();
00188         _arg2.setReachable();
00189     }
00190 
00191 private:
00192     as_object* _obj;
00193     ObjectURI _name;
00194     as_value _arg1, _arg2;
00195 };
00196 
00197 
00198 
00199 } // namespace gnash
00200 
00201 #endif // GNASH_EXECUTABLECODE_H