Gnash  0.8.11dev
ExecutableCode.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 
20 #ifndef GNASH_EXECUTABLECODE_H
21 #define GNASH_EXECUTABLECODE_H
22 
23 #include <vector>
24 #include <boost/noncopyable.hpp>
25 
26 #include "ActionExec.h"
27 #include "Global_as.h"
28 #include "fn_call.h"
29 #include "ConstantPool.h"
30 
31 namespace gnash {
32 
34 class ExecutableCode : boost::noncopyable
35 {
36 public:
37 
38  ExecutableCode(DisplayObject* t) : _target(t) {}
39 
40  virtual void execute() = 0;
41 
42  virtual ~ExecutableCode() {}
43 
44  virtual void setReachable() const {}
45 
47  void markReachableResources() const {
48  setReachable();
49  if (_target) _target->setReachable();
50  }
51 
52  DisplayObject* target() const {
53  return _target;
54  }
55 
56 private:
57 
58  DisplayObject* _target;
59 };
60 
62 class GlobalCode : public ExecutableCode
63 {
64 public:
65 
66  GlobalCode(const action_buffer& nBuffer, DisplayObject* nTarget)
67  :
68  ExecutableCode(nTarget),
69  buffer(nBuffer)
70  {}
71 
72  virtual void execute() {
73  if (!target()->unloaded()) {
74  ActionExec exec(buffer, target()->get_environment());
75  exec();
76  }
77  }
78 
79 private:
80  const action_buffer& buffer;
81 };
82 
84 class EventCode : public ExecutableCode
85 {
86 public:
87 
88  typedef std::vector<const action_buffer*> BufferList;
89 
91  :
92  ExecutableCode(nTarget)
93  {}
94 
95  EventCode(DisplayObject* nTarget, BufferList buffers)
96  :
97  ExecutableCode(nTarget),
98  _buffers(std::move(buffers))
99  {}
100 
102  //
108  void addAction(const action_buffer& buffer) {
109  // don't push actions for destroyed DisplayObjects,
110  // our opcode guard is bogus at the moment.
111  if (!target()->isDestroyed()) {
112  _buffers.push_back(&buffer);
113  }
114  }
115 
116  virtual void execute() {
117  for (const action_buffer* buffer : _buffers) {
118 
119  // onClipEvents code are guarded by isDestroyed(),
120  // still might be also guarded by unloaded()
121  if (target()->isDestroyed()) break;
122 
123  PoolGuard guard(getVM(target()->get_environment()), nullptr);
124  ActionExec exec(*buffer, target()->get_environment(), false);
125  exec();
126  }
127  }
128 
129 private:
130  BufferList _buffers;
131 };
132 
134 //
145 {
146 public:
147 
149  as_object* obj, ObjectURI name,
150  as_value arg1, as_value arg2)
151  :
153  _obj(obj),
154  _name(std::move(name)),
155  _arg1(std::move(arg1)),
156  _arg2(std::move(arg2))
157  {}
158 
159  virtual void execute() {
160  callMethod(_obj, _name, _arg1, _arg2);
161  }
162 
164  virtual void setReachable() const {
165  _obj->setReachable();
166  _arg1.setReachable();
167  _arg2.setReachable();
168  }
169 
170 private:
171  as_object* _obj;
172  ObjectURI _name;
173  as_value _arg1, _arg2;
174 };
175 
176 
177 
178 } // namespace gnash
179 
180 #endif // GNASH_EXECUTABLECODE_H
gnash::key::G
@ G
Definition: GnashKey.h:119
gnash::LogFile::getDefaultInstance
static LogFile & getDefaultInstance()
Definition: log.cpp:77
gnash::key::GNASH_MOD_CONTROL
@ GNASH_MOD_CONTROL
Definition: GnashKey.h:37
gnash::key::R
@ R
Definition: GnashKey.h:130
gnash::key::L
@ L
Definition: GnashKey.h:124
relatives
char * relatives[REL_MAX+1]
Definition: evtest.c:286
gnash::key::DOWN
@ DOWN
Definition: GnashKey.h:207
gnash::key::l
@ l
Definition: GnashKey.h:158
gnash::key::KP_ADD
@ KP_ADD
Definition: GnashKey.h:216
gnash::EventCode::EventCode
EventCode(DisplayObject *nTarget)
Definition: ExecutableCode.h:90
gnash::InputDevice::input_data_t::tiltY
int tiltY
Definition: InputDevice.h:92
gnash::ExecutableCode::ExecutableCode
ExecutableCode(DisplayObject *t)
Definition: ExecutableCode.h:38
gnash::key::BACKSPACE
@ BACKSPACE
Definition: GnashKey.h:53
gnash::DelayedFunctionCall
This class is used to queue a function call action.
Definition: ExecutableCode.h:145
gnash::InputDevice::input_data_t::x
int x
Definition: InputDevice.h:76
name
std::string name
Definition: LocalConnection_as.cpp:149
keys
char * keys[KEY_MAX+1]
Definition: evtest.c:55
gnash::InputDevice::input_data_t
Definition: InputDevice.h:72
gnash::InputDevice::input_data_t::modifier
int modifier
Definition: InputDevice.h:75
gnash::key::d
@ d
Definition: GnashKey.h:150
events
char * events[EV_MAX+1]
Definition: evtest.c:45
gnash::key::F2
@ F2
Definition: GnashKey.h:191
gnash::key::KP_DECIMAL
@ KP_DECIMAL
Definition: GnashKey.h:220
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::InputDevice::input_data_t::key
gnash::key::code key
Definition: InputDevice.h:74
gnash::key::F9
@ F9
Definition: GnashKey.h:198
gnash::ExecutableCode
Any executable code.
Definition: ExecutableCode.h:35
gnash::key::U
@ U
Definition: GnashKey.h:133
gnash::key::KP_1
@ KP_1
Definition: GnashKey.h:180
gnash::key::KP_MULTIPLY
@ KP_MULTIPLY
Definition: GnashKey.h:218
gnash::InputDevice::input_data_t::volumne
int volumne
Definition: InputDevice.h:82
gnash::key::T
@ T
Definition: GnashKey.h:132
gnash::InputDevice::input_data_t::pressed
bool pressed
Definition: InputDevice.h:73
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
gnash::InputDevice::KEYBOARD
@ KEYBOARD
Definition: InputDevice.h:96
gnash::key::i
@ i
Definition: GnashKey.h:155
gnash::EventDevice::init
virtual bool init()
Definition: EventDevice.cpp:53
gnash::key::KP_SUBTRACT
@ KP_SUBTRACT
Definition: GnashKey.h:217
gnash::key::PAREN_RIGHT
@ PAREN_RIGHT
Definition: GnashKey.h:86
_
#define _(String)
Definition: log.h:44
gnash::key::AMPERSAND
@ AMPERSAND
Definition: GnashKey.h:83
gnash::key::J
@ J
Definition: GnashKey.h:122
gnash::key::SINGLE_QUOTE
@ SINGLE_QUOTE
Definition: GnashKey.h:84
gnash::key::x
@ x
Definition: GnashKey.h:170
gnash::EventCode
Event code.
Definition: ExecutableCode.h:85
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
ActionExec.h
gnash::key::DELETEKEY
@ DELETEKEY
Definition: GnashKey.h:177
gnash::key::CONTROL
@ CONTROL
Definition: GnashKey.h:62
gnash::key::CAPSLOCK
@ CAPSLOCK
Definition: GnashKey.h:65
gnash::key::g
@ g
Definition: GnashKey.h:153
gnash::InputDevice::input_data_t::y
int y
Definition: InputDevice.h:77
gnash::key::LEFT_BRACE
@ LEFT_BRACE
Definition: GnashKey.h:173
gnash::key::F1
@ F1
Definition: GnashKey.h:190
gnash::InputDevice::input_data_t::rz
int rz
Definition: InputDevice.h:86
gnash::key::F4
@ F4
Definition: GnashKey.h:193
gnash::ExecutableCode::~ExecutableCode
virtual ~ExecutableCode()
Definition: ExecutableCode.h:42
gnash::key::Z
@ Z
Definition: GnashKey.h:138
gnash::InputDevice::readData
std::unique_ptr< std::uint8_t[]> readData(size_t size)
Definition: InputDevice.cpp:112
gnash::key::Q
@ Q
Definition: GnashKey.h:129
gnash::key::m
@ m
Definition: GnashKey.h:159
gnash::key::s
@ s
Definition: GnashKey.h:165
gnash::key::GNASH_MOD_NONE
@ GNASH_MOD_NONE
Definition: GnashKey.h:35
gnash::InputDevice::input_data_t::z
int z
Definition: InputDevice.h:78
gnash::InputDevice::input_data_t::ry
int ry
Definition: InputDevice.h:85
gnash::key::n
@ n
Definition: GnashKey.h:160
gnash::key::KP_8
@ KP_8
Definition: GnashKey.h:187
Global_as.h
gnash::ActionExec
Executor of an action_buffer.
Definition: ActionExec.h:119
gnash::key::KP_7
@ KP_7
Definition: GnashKey.h:186
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
gnash::InputDevice::input_data_t::throttle
int throttle
Definition: InputDevice.h:87
gnash::InputDevice::input_data_t::rx
int rx
Definition: InputDevice.h:84
gnash::key::KP_0
@ KP_0
Definition: GnashKey.h:179
gnash::key::_7
@ _7
Definition: GnashKey.h:101
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::key::_5
@ _5
Definition: GnashKey.h:99
gnash::key::PGUP
@ PGUP
Definition: GnashKey.h:213
gnash::key::LEFT
@ LEFT
Definition: GnashKey.h:209
gnash::key::k
@ k
Definition: GnashKey.h:157
gnash::InputDevice::_filespec
std::string _filespec
Definition: InputDevice.h:156
gnash::key::RIGHT
@ RIGHT
Definition: GnashKey.h:208
gnash::EventCode::EventCode
EventCode(DisplayObject *nTarget, BufferList buffers)
Definition: ExecutableCode.h:95
gnash::key::H
@ H
Definition: GnashKey.h:120
gnash::key::KP_5
@ KP_5
Definition: GnashKey.h:184
gnash::key::PAREN_LEFT
@ PAREN_LEFT
Definition: GnashKey.h:85
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::key::O
@ O
Definition: GnashKey.h:127
gnash::callMethod
as_value callMethod(fn_call::Args &args, as_object *obj, const ObjectURI &uri)
Call a member function of this object in an AS-compatible way.
Definition: Global_as.h:219
misc
char * misc[MSC_MAX+1]
Definition: evtest.c:330
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::key::K
@ K
Definition: GnashKey.h:123
gnash::InputDevice::UMOUSE
@ UMOUSE
Definition: InputDevice.h:97
gnash::InputDevice::input_data_t::pressure
int pressure
Definition: InputDevice.h:81
gnash::key::a
@ a
Definition: GnashKey.h:147
test_bit
#define test_bit(bit, array)
Definition: evtest.c:370
absval
char * absval[6]
Definition: evtest.c:284
gnash::key::GNASH_MOD_SHIFT
@ GNASH_MOD_SHIFT
Definition: GnashKey.h:36
NBITS
#define NBITS(x)
Definition: evtest.c:366
gnash::key::KP_6
@ KP_6
Definition: GnashKey.h:185
gnash::key::INSERT
@ INSERT
Definition: GnashKey.h:210
gnash::key::F
@ F
Definition: GnashKey.h:118
gnash::key::ALT
@ ALT
Definition: GnashKey.h:63
gnash::key::COMMA
@ COMMA
Definition: GnashKey.h:89
gnash::InputDevice::input_data_t::tiltX
int tiltX
Definition: InputDevice.h:91
gnash::key::PGDN
@ PGDN
Definition: GnashKey.h:214
gnash::key::END
@ END
Definition: GnashKey.h:212
gnash::key::type
type
Definition: GnashKey.h:330
gnash::InputDevice::input_data_t::rudder
int rudder
Definition: InputDevice.h:88
gnash::key::code
code
Definition: GnashKey.h:44
gnash::key::B
@ B
Definition: GnashKey.h:114
gnash::InputDevice::_fd
int _fd
Definition: InputDevice.h:157
gnash::key::_0
@ _0
Definition: GnashKey.h:94
gnash::key::X
@ X
Definition: GnashKey.h:136
gnash::key::ENTER
@ ENTER
Definition: GnashKey.h:58
gnash::key::h
@ h
Definition: GnashKey.h:154
gnash::InputDevice::SERIALUSB
@ SERIALUSB
Definition: InputDevice.h:104
gnash::InputDevice::POWERBUTTON
@ POWERBUTTON
Definition: InputDevice.h:102
gnash::key::EXCLAM
@ EXCLAM
Definition: GnashKey.h:78
gnash::ExecutableCode::execute
virtual void execute()=0
gnash::key::TAB
@ TAB
Definition: GnashKey.h:54
gnash::key::y
@ y
Definition: GnashKey.h:171
gnash::InputDevice::input_data_t::brake
int brake
Definition: InputDevice.h:90
EV_SYN
#define EV_SYN
Definition: evtest.c:42
gnash::InputDevice::MOUSE
@ MOUSE
Definition: InputDevice.h:98
gnash::key::z
@ z
Definition: GnashKey.h:172
gnash::key::INVALID
@ INVALID
Definition: GnashKey.h:45
gnash::key::DOUBLE_QUOTE
@ DOUBLE_QUOTE
Definition: GnashKey.h:79
gnash::key::_3
@ _3
Definition: GnashKey.h:97
gnash::EventDevice::EventDevice
EventDevice()
Definition: EventDevice.cpp:40
gnash::key::p
@ p
Definition: GnashKey.h:162
gnash::key::F3
@ F3
Definition: GnashKey.h:192
gnash::key::SHIFT
@ SHIFT
Definition: GnashKey.h:61
gnash::key::KP_2
@ KP_2
Definition: GnashKey.h:181
gnash::InputDevice::input_data_t::distance
int distance
Definition: InputDevice.h:83
gnash::key::C
@ C
Definition: GnashKey.h:115
gnash::key::q
@ q
Definition: GnashKey.h:163
gnash::key::UP
@ UP
Definition: GnashKey.h:206
gnash::key::F7
@ F7
Definition: GnashKey.h:196
gnash::key::HOME
@ HOME
Definition: GnashKey.h:211
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::key::w
@ w
Definition: GnashKey.h:169
gnash::key::KP_4
@ KP_4
Definition: GnashKey.h:183
gnash::EventDevice::check
virtual bool check()
Definition: EventDevice.cpp:253
gnash::key::KP_3
@ KP_3
Definition: GnashKey.h:182
gnash::key::F5
@ F5
Definition: GnashKey.h:194
names
char ** names[EV_MAX+1]
Definition: evtest.c:357
gnash::key::F8
@ F8
Definition: GnashKey.h:197
gnash::EventDevice::scanForDevices
static std::vector< std::shared_ptr< InputDevice > > scanForDevices()
Definition: EventDevice.cpp:679
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
gnash::DelayedFunctionCall::execute
virtual void execute()
Definition: ExecutableCode.h:159
leds
char * leds[LED_MAX+1]
Definition: evtest.c:337
gnash::EventDevice::scancode_to_gnash_key
gnash::key::code scancode_to_gnash_key(int code, bool shift)
Definition: EventDevice.cpp:559
gnash::key::KP_9
@ KP_9
Definition: GnashKey.h:188
gnash::key::j
@ j
Definition: GnashKey.h:156
gnash::key::RIGHT_BRACE
@ RIGHT_BRACE
Definition: GnashKey.h:175
gnash::key::S
@ S
Definition: GnashKey.h:131
gnash::GlobalCode
Global code (out of any function)
Definition: ExecutableCode.h:63
gnash::key::D
@ D
Definition: GnashKey.h:116
gnash::InputDevice::_data
std::queue< std::shared_ptr< input_data_t > > _data
Definition: InputDevice.h:161
ConstantPool.h
InputDevice.h
gnash::InputDevice::_screen_width
int _screen_width
Definition: InputDevice.h:162
log.h
gnash::as_value::setReachable
void setReachable() const
Set any object value as reachable (for the GC)
Definition: as_value.cpp:691
absolutes
char * absolutes[ABS_MAX+1]
Definition: evtest.c:294
gnash::InputDevice::_type
devicetype_e _type
Definition: InputDevice.h:155
gnash::key::F6
@ F6
Definition: GnashKey.h:195
gnash::GlobalCode::GlobalCode
GlobalCode(const action_buffer &nBuffer, DisplayObject *nTarget)
Definition: ExecutableCode.h:66
fn_call.h
gnash::GlobalCode::execute
virtual void execute()
Definition: ExecutableCode.h:72
gnash::key::V
@ V
Definition: GnashKey.h:134
sounds
char * sounds[SND_MAX+1]
Definition: evtest.c:351
gnash::key::_6
@ _6
Definition: GnashKey.h:100
gnash::key::ESCAPE
@ ESCAPE
Definition: GnashKey.h:72
gnash::key::F10
@ F10
Definition: GnashKey.h:199
gnash::dbglogfile
LogFile & dbglogfile
Definition: fileio.cpp:76
gnash::DelayedFunctionCall::DelayedFunctionCall
DelayedFunctionCall(DisplayObject *target, as_object *obj, ObjectURI name, as_value arg1, as_value arg2)
Definition: ExecutableCode.h:148
gnash::key::f
@ f
Definition: GnashKey.h:152
gnashconfig.h
gnash::key::F11
@ F11
Definition: GnashKey.h:200
gnash::InputDevice::input_data_t::position
int position
Definition: InputDevice.h:80
gnash::ExecutableCode::markReachableResources
void markReachableResources() const
Mark reachable resources (for the GC)
Definition: ExecutableCode.h:47
gnash::key::MINUS
@ MINUS
Definition: GnashKey.h:90
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::key::EQUALS
@ EQUALS
Definition: GnashKey.h:108
gnash::key::HASH
@ HASH
Definition: GnashKey.h:80
gnash::key::KP_ENTER
@ KP_ENTER
Definition: GnashKey.h:221
gnash::key::F12
@ F12
Definition: GnashKey.h:201
gnash::key::BACKSLASH
@ BACKSLASH
Definition: GnashKey.h:141
gnash::key::_9
@ _9
Definition: GnashKey.h:103
gnash::ExecutableCode::target
DisplayObject * target() const
Definition: ExecutableCode.h:52
gnash::ExecutableCode::setReachable
virtual void setReachable() const
Definition: ExecutableCode.h:44
gnash::PoolGuard
Definition: ConstantPool.h:35
repeats
char * repeats[REP_MAX+1]
Definition: evtest.c:346
main
int main(int argc, char **argv)
Definition: evtest.c:372
gnash::InputDevice::TABLET
@ TABLET
Definition: InputDevice.h:99
gnash::EventCode::BufferList
std::vector< const action_buffer * > BufferList
Definition: ExecutableCode.h:88
gnash::key::v
@ v
Definition: GnashKey.h:168
gnash::DelayedFunctionCall::setReachable
virtual void setReachable() const
Mark reachable resources (for the GC)
Definition: ExecutableCode.h:164
gnash::InputDevice::_input_data
input_data_t _input_data
Definition: InputDevice.h:158
gnash::DisplayObject
DisplayObject is the base class for all DisplayList objects.
Definition: DisplayObject.h:169
gnash::action_buffer
A code segment.
Definition: action_buffer.h:50
gnash::key::GNASH_MOD_ALT
@ GNASH_MOD_ALT
Definition: GnashKey.h:38
gnash::key::_4
@ _4
Definition: GnashKey.h:98
gnash::InputDevice::TOUCHMOUSE
@ TOUCHMOUSE
Definition: InputDevice.h:101
gnash::key::PERCENT
@ PERCENT
Definition: GnashKey.h:82
gnash::key::DOLLAR
@ DOLLAR
Definition: GnashKey.h:81
gnash::key::SLASH
@ SLASH
Definition: GnashKey.h:92
gnash::key::SPACE
@ SPACE
Definition: GnashKey.h:77
gnash::InputDevice::_screen_height
int _screen_height
Definition: InputDevice.h:163
gnash::key::E
@ E
Definition: GnashKey.h:117
gnash::key::o
@ o
Definition: GnashKey.h:161
gnash::key::P
@ P
Definition: GnashKey.h:128
gnash::InputDevice::input_data_t::gas
int gas
Definition: InputDevice.h:89
gnash::log_unimpl
void log_unimpl(StringType msg, Args... args)
Definition: log.h:289
gnash::InputDevice::INFRARED
@ INFRARED
Definition: InputDevice.h:105
gnash::EventCode::execute
virtual void execute()
Definition: ExecutableCode.h:116
gnash::key::N
@ N
Definition: GnashKey.h:126
gnash::key::u
@ u
Definition: GnashKey.h:167
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::key::SEMICOLON
@ SEMICOLON
Definition: GnashKey.h:106
gnash::key::_8
@ _8
Definition: GnashKey.h:102
gnash::EventCode::addAction
void addAction(const action_buffer &buffer)
Add an action buffer to this event handler.
Definition: ExecutableCode.h:108
gnash::LogFile::setVerbosity
void setVerbosity()
Definition: log.h:123
gnash::key::b
@ b
Definition: GnashKey.h:148
gnash::key::W
@ W
Definition: GnashKey.h:135
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::key::I
@ I
Definition: GnashKey.h:121
gnash::InputDevice::input_data_t::button
int button
Definition: InputDevice.h:79
gnash::key::M
@ M
Definition: GnashKey.h:125
gnash::key::ASTERISK
@ ASTERISK
Definition: GnashKey.h:87
gnash::key::_2
@ _2
Definition: GnashKey.h:96
gnash::GcResource::setReachable
void setReachable() const
Mark this resource as being reachable.
Definition: GC.h:92
gnash::key::A
@ A
Definition: GnashKey.h:113
gnash::key::NUM_LOCK
@ NUM_LOCK
Definition: GnashKey.h:223
gnash::key::Y
@ Y
Definition: GnashKey.h:137