Gnash  0.8.10
DoABCTag.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 #ifndef GNASH_SWF_DOABCTAG_H
00020 #define GNASH_SWF_DOABCTAG_H
00021 
00022 #include <string>
00023 #include "ControlTag.h" // for inheritance
00024 #include "SWF.h" // for tag_type definition
00025 #include "MovieClip.h" // for inlines
00026 #include "SWFStream.h" // for inlines
00027 #include "AbcBlock.h"
00028 #include "Machine.h"
00029 #include "VM.h"
00030 
00031 // Forward declarations
00032 namespace gnash {
00033         class movie_definition;
00034 }
00035 
00036 namespace gnash {
00037 namespace SWF {
00038 
00040 //
00042 class DoABCTag : public ControlTag
00043 {
00044 public:
00045 
00046     virtual void executeActions(MovieClip* m, DisplayList& /* dlist */) const
00047         {
00048 
00049         if (!_abc) {
00050             log_debug("Not executing ABC tag because we failed to parse it");
00051             return;
00052         }
00053 
00054                 VM& vm = getVM(*getObject(m));
00055         
00056         log_debug("getting machine.");
00057         abc::Machine *mach = vm.getMachine();
00058                 
00059         _abc->prepare(mach);
00060 
00061                 log_debug("Begin execute AbcBlock.");
00062                 mach->initMachine(_abc);
00063                 log_debug("Executing machine...");
00064                 mach->execute();
00065         }
00066 
00067     void read(SWFStream* /*in*/)
00068     {
00069     }
00070         
00071         static void loader(SWFStream& in, TagType tag, movie_definition& m,
00072             const gnash::RunResources&)
00073         {
00074 
00075         if (!m.isAS3()) {
00076             IF_VERBOSE_MALFORMED_SWF(
00077                 log_swferror("SWF contains ABC tag, but is not an "
00078                     "AS3 SWF!");
00079             );
00080             throw ParserException("ABC tag found in non-AS3 SWF!");
00081         }
00082 
00083                 if (tag == SWF::DOABCDEFINE) {
00084                         in.ensureBytes(4);
00085                         static_cast<void> (in.read_u32());
00086                         std::string name;
00087                         in.read_string(name);
00088                 }
00089 
00090         std::auto_ptr<abc::AbcBlock> block(new abc::AbcBlock());
00091                 if (!block->read(in)) {
00092             log_error("ABC parsing error while processing DoABCTag. This "
00093                     "tag will never be executed");
00094             return;
00095         }
00096 
00097         // _abc = block;
00098                 boost::intrusive_ptr<DoABCTag> ABCtag(new DoABCTag(block.release()));
00099                 
00100                 IF_VERBOSE_PARSE (
00101             log_parse(_("tag %d: DoABCDefine"), tag);
00102             log_parse(_("-- actions in frame %d"), m.get_loading_frame());
00103                 );
00104 
00105                 m.addControlTag(ABCtag); // ownership transferred
00106         }
00107 
00108 private:
00109 
00110         DoABCTag(abc::AbcBlock* block) : _abc(block) {}
00111 
00112     abc::AbcBlock* _abc;
00113         
00114 };
00115 
00116 } // namespace gnash::SWF
00117 } // namespace gnash
00118 
00119 
00120 #endif // GNASH_SWF_DOABCTAG_H
00121 
00122 
00123 // Local Variables:
00124 // mode: C++
00125 // indent-tabs-mode: t
00126 // End: