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::unique_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:
Client program&#39;s interface to the definition of a movie or sprite.
Definition: movie_definition.h:95
The ActionScript bytecode of a single ABC tag in a SWF.
Definition: AbcBlock.h:208
A MovieClip is a container for DisplayObjects.
Definition: MovieClip.h:83
void read_string(std::string &to)
Reads a null-terminated string from the given file and assigns it to the given std::string, overriding any previous value of it.
Definition: SWFStream.cpp:395
TagType
SWF tag types. Symbolic names copied from Ming.
Definition: SWF.h:30
An SWF parsing exception.
Definition: GnashException.h:89
void initMachine(AbcBlock *pool_block)
Definition: Machine.cpp:3154
virtual size_t get_loading_frame() const =0
Returns 1 based index. Ex: if 1 then 1st frame as been fully loaded.
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
static void loader(SWFStream &in, TagType tag, movie_definition &m, const gnash::RunResources &)
Definition: DoABCTag.h:71
#define IF_VERBOSE_MALFORMED_SWF(x)
Definition: log.h:404
void prepare(Machine *mach)
Definition: AbcBlock.cpp:322
#define IF_VERBOSE_PARSE(x)
Definition: log.h:378
Control tags are swf tags that control the operation of the movie.
Definition: ControlTag.h:43
void log_parse(StringType msg, Args... args)
Definition: log.h:313
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
#define _(String)
Definition: log.h:44
void execute()
Definition: Machine.cpp:381
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:53
void log_error(StringType msg, Args... args)
Definition: log.h:283
void log_swferror(StringType msg, Args... args)
Definition: log.h:325
virtual bool isAS3() const
True if the SWFMovie should use AVM2.
Definition: movie_definition.h:410
The virtual machine for executing ABC (ActionScript Bytecode).
Definition: Machine.h:73
The AVM1 virtual machine.
Definition: VM.h:71
Definition: SWF.h:109
Definition: GnashKey.h:159
std::uint32_t read_u32()
Read a aligned unsigned 32-bit value from the stream.
Definition: SWFStream.cpp:361
void log_debug(StringType msg, Args... args)
Definition: log.h:301
virtual void executeActions(MovieClip *m, DisplayList &) const
Execute Action tags.
Definition: DoABCTag.h:46
virtual void addControlTag(boost::intrusive_ptr< SWF::ControlTag >)
Add an ControlTag to this movie_definition&#39;s playlist.
Definition: movie_definition.h:273
A list of on-stage DisplayObjects, ordered by depth.
Definition: DisplayList.h:64
std::string name
Definition: LocalConnection_as.cpp:149
Definition: GnashKey.h:331
as_object * getObject(const DisplayObject *d)
Return the as_object associated with a DisplayObject if it exists.
Definition: DisplayObject.h:1160
SWF stream wrapper class.
Definition: SWFStream.h:58
void read(SWFStream *)
Definition: DoABCTag.h:67
SWF Tag DoABC (72)
Definition: DoABCTag.h:42
void ensureBytes(unsigned long needed)
Ensure the requested number of bytes are available for an aligned read in the currently opened tag...
Definition: SWFStream.cpp:50