Gnash  0.8.11dev
DoABCTag.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 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 GNASH_SWF_DOABCTAG_H
20 #define GNASH_SWF_DOABCTAG_H
21 
22 #include <string>
23 #include "ControlTag.h" // for inheritance
24 #include "SWF.h" // for tag_type definition
25 #include "MovieClip.h" // for inlines
26 #include "SWFStream.h" // for inlines
27 #include "AbcBlock.h"
28 #include "Machine.h"
29 #include "VM.h"
30 
31 // Forward declarations
32 namespace gnash {
33  class movie_definition;
34 }
35 
36 namespace gnash {
37 namespace SWF {
38 
40 //
42 class DoABCTag : public ControlTag
43 {
44 public:
45 
46  virtual void executeActions(MovieClip* m, DisplayList& /* dlist */) const
47  {
48 
49  if (!_abc) {
50  log_debug("Not executing ABC tag because we failed to parse it");
51  return;
52  }
53 
54  VM& vm = getVM(*getObject(m));
55 
56  log_debug("getting machine.");
57  abc::Machine *mach = vm.getMachine();
58 
59  _abc->prepare(mach);
60 
61  log_debug("Begin execute AbcBlock.");
62  mach->initMachine(_abc);
63  log_debug("Executing machine...");
64  mach->execute();
65  }
66 
67  void read(SWFStream* /*in*/)
68  {
69  }
70 
71  static void loader(SWFStream& in, TagType tag, movie_definition& m,
72  const gnash::RunResources&)
73  {
74 
75  if (!m.isAS3()) {
77  log_swferror("SWF contains ABC tag, but is not an "
78  "AS3 SWF!");
79  );
80  throw ParserException("ABC tag found in non-AS3 SWF!");
81  }
82 
83  if (tag == SWF::DOABCDEFINE) {
84  in.ensureBytes(4);
85  static_cast<void> (in.read_u32());
86  std::string name;
87  in.read_string(name);
88  }
89 
90  std::auto_ptr<abc::AbcBlock> block(new abc::AbcBlock());
91  if (!block->read(in)) {
92  log_error("ABC parsing error while processing DoABCTag. This "
93  "tag will never be executed");
94  return;
95  }
96 
97  // _abc = block;
98  boost::intrusive_ptr<DoABCTag> ABCtag(new DoABCTag(block.release()));
99 
101  log_parse(_("tag %d: DoABCDefine"), tag);
102  log_parse(_("-- actions in frame %d"), m.get_loading_frame());
103  );
104 
105  m.addControlTag(ABCtag); // ownership transferred
106  }
107 
108 private:
109 
110  DoABCTag(abc::AbcBlock* block) : _abc(block) {}
111 
112  abc::AbcBlock* _abc;
113 
114 };
115 
116 } // namespace gnash::SWF
117 } // namespace gnash
118 
119 
120 #endif // GNASH_SWF_DOABCTAG_H
121 
122 
123 // Local Variables:
124 // mode: C++
125 // indent-tabs-mode: t
126 // End: