Make automated FSCommand invocation tests show player-side output.
[gnash.git] / libcore / Relay.h
blob53d0541f9d94c219d8c38b491812c060f18a0b0c
1 //
2 // Copyright (C) 2005, 2006, 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
19 #ifndef GNASH_RELAY_H
20 #define GNASH_RELAY_H
22 #include <boost/noncopyable.hpp>
24 namespace gnash {
25 class as_object;
28 namespace gnash {
30 /// This is the base class for type-specific object data.
32 /// A Relay is a polymorphic object that contains arbitrary native
33 /// type information. Native functions may access the Relay object, determine
34 /// its derived type, and change its state.
36 /// The base class does nothing. It provides a virtual function to mark
37 /// GC resources if necessary in subclasses.
39 /// The simplest native types, such as Boolean or String, inherit from this
40 /// base class directly. They have no GC resources and simply store a
41 /// C++ type such as a boolean, double, or std::string, which native functions
42 /// can access and manipulate.
44 /// More complex types may derive from a subclass of Relay that provides
45 /// specific functionality such as updates from the VM.
47 /// An as_object with a non-null _relay member is a native class, as this
48 /// information cannot be accessed by normal ActionScript functions.
49 class Relay : boost::noncopyable
51 public:
52 virtual ~Relay() = 0;
54 /// A Relay itself is not a GC object, but may point to GC resources.
55 virtual void setReachable() {}
57 /// Handle any cleanup necessary before the Relay is destroyed.
59 /// Only the replacement of one Relay by another should cause this
60 /// to happen. The cleanup may involve deregistration.
61 virtual void clean() {}
64 inline Relay::~Relay()
68 /// A native type that requires periodic updates from the core (movie_root).
70 /// Objects with this type of relay can be registered with movie_root, and
71 /// recieve a callback on every advance.
73 /// This type of Relay holds a reference to its parent as_object (owner).
74 /// If a reference to this ActiveRelay is held by another object,
75 /// it must be marked reachable so that its owner is not deleted by the GC.
77 /// The function setReachable() is called on every GC run. It calls
78 /// markReachableResources() and marks its owner.
79 class ActiveRelay : public Relay
81 public:
83 explicit ActiveRelay(as_object* owner)
85 _owner(owner)
88 /// Make sure we are removed from the list of callbacks on destruction.
89 virtual ~ActiveRelay();
91 /// ActiveRelay objects must have an update() method.
93 /// The method will be called at the heart-beat frequency.
94 ///
95 virtual void update() = 0;
97 /// Mark any other reachable resources, and finally mark our owner
99 /// Do not override this function.
100 virtual void setReachable();
102 /// Remove the ActiveRelay from movie_root's callback set.
104 /// This must be called before the Relay is destroyed!
105 virtual void clean();
107 /// Return the as_object that this Relay is attached to.
108 as_object& owner() const {
109 return *_owner;
112 protected:
114 /// Mark any reachable resources other than the owner.
116 /// Override this function if the subclass holds references to GC
117 /// resources other than the owner.
118 virtual void markReachableResources() const {}
120 private:
122 /// The as_object that owns this Relay.
124 /// Because we are deleted on destruction of the owner, this pointer will
125 /// never be invalid as long as 'this' is valid.
126 as_object* _owner;
130 } // namespace gnash
132 #endif