Gnash  0.8.11dev
Property.h
Go to the documentation of this file.
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
18 
19 
20 #ifndef GNASH_PROPERTY_H
21 #define GNASH_PROPERTY_H
22 
23 #include <boost/variant.hpp>
24 #include <cassert>
25 #include <functional>
26 #include <typeinfo>
27 
28 #include "PropFlags.h"
29 #include "as_value.h"
30 #include "ObjectURI.h"
31 #include "dsodefs.h" // for DSOTEXPORT
32 
33 namespace gnash {
34  typedef as_value (*as_c_function_ptr)(const fn_call& fn);
35  class as_function;
36 }
37 
38 namespace gnash {
39 
41 //
45 {
46  class NativeGetterSetter;
47 
48  // The following helper structs define common operations on the
49  // Two types of GetterSetter. Some operations are applicable only to
50  // one type.
51 
53  //
57  template<typename Arg, typename S>
58  struct GetSetVisitor : boost::static_visitor<typename S::result_type>
59  {
60  GetSetVisitor(const Arg& arg) : _arg(arg) {}
61  template<typename T> typename S::result_type operator()(T& t) const {
62  return S()(t, _arg);
63  }
64  private:
65  const Arg& _arg;
66  };
67 
69  struct Set
70  {
71  typedef void result_type;
72  template<typename T, typename Arg>
73  result_type operator()(T& t, Arg& a) const {
74  t.set(a);
75  }
76  };
77 
79  struct Get
80  {
81  typedef as_value result_type;
82  template<typename T, typename Arg>
83  result_type operator()(T& t, Arg& a) const {
84  return t.get(a);
85  }
86  };
87 
89  //
91  struct SetUnderlying : boost::static_visitor<>
92  {
93  template<typename T>
94  result_type operator()(T& gs, const as_value& val) const {
95  gs.setUnderlying(val);
96  }
97  result_type operator()(NativeGetterSetter&, const as_value&) const {}
98  };
99 
101  //
103  struct GetUnderlying : boost::static_visitor<as_value>
104  {
105  template<typename T>
106  result_type operator()(const T& gs) const {
107  return gs.getUnderlying();
108  }
109  result_type operator()(const NativeGetterSetter&) const {
110  return result_type();
111  }
112  };
113 
115  struct MarkReachable : boost::static_visitor<>
116  {
117  template<typename T>
118  result_type operator()(const T& gs) const {
119  gs.markReachableResources();
120  }
121  };
122 
123 public:
124 
127  :
128  _getset(UserDefinedGetterSetter(getter, setter))
129  {}
130 
133  :
134  _getset(NativeGetterSetter(getter, setter))
135  {}
136 
138  as_value get(fn_call& fn) const {
139  GetSetVisitor<const fn_call, Get> s(fn);
140  return boost::apply_visitor(s, _getset);
141  }
142 
144  void set(const fn_call& fn) {
145  GetSetVisitor<fn_call, Set> s(fn);
146  boost::apply_visitor(s, _getset);
147  }
148 
150  void setCache(const as_value& v) {
151  boost::apply_visitor(
152  std::bind(SetUnderlying(), std::placeholders::_1, v), _getset);
153  }
154 
156  as_value getCache() const {
157  return boost::apply_visitor(GetUnderlying(), _getset);
158  }
159 
160  void markReachableResources() const {
161  boost::apply_visitor(MarkReachable(), _getset);
162  }
163 
164 private:
165 
167  class UserDefinedGetterSetter
168  {
169  public:
170 
171  UserDefinedGetterSetter(as_function* get, as_function* set)
172  :
173  _getter(get),
174  _setter(set),
175  _underlyingValue(),
176  _beingAccessed(false)
177  {}
178 
180  as_value get(const fn_call& fn) const;
181 
183  void set(const fn_call& fn);
184 
186  const as_value& getUnderlying() const { return _underlyingValue; }
187 
189  void setUnderlying(const as_value& v) { _underlyingValue = v; }
190 
191  void markReachableResources() const;
192 
193  private:
194 
198  //
201  class ScopedLock : boost::noncopyable
202  {
203  public:
204 
205  explicit ScopedLock(const UserDefinedGetterSetter& na)
206  :
207  _a(na),
208  _obtainedLock(_a._beingAccessed ? false : true)
209  {
210  // If we didn't obtain the lock it would be true anyway,
211  // but it's probably polite to avoid touching it.
212  if (_obtainedLock) _a._beingAccessed = true;
213  }
214 
215  ~ScopedLock() { if ( _obtainedLock) _a._beingAccessed = false; }
216 
218  //
223  bool obtainedLock() const { return _obtainedLock; }
224 
225  private:
226 
227  const UserDefinedGetterSetter& _a;
228  bool _obtainedLock;
229 
230  };
231 
232  as_function* _getter;
233  as_function* _setter;
234  as_value _underlyingValue;
235  mutable bool _beingAccessed;
236  };
237 
239  class NativeGetterSetter
240  {
241  public:
242 
243  NativeGetterSetter(as_c_function_ptr get, as_c_function_ptr set)
244  :
245  _getter(get), _setter(set) {}
246 
248  as_value get(const fn_call& fn) const {
249  return _getter(fn);
250  }
251 
253  void set(const fn_call& fn) {
254  _setter(fn);
255  }
256 
258  void markReachableResources() const {}
259 
260  private:
261  as_c_function_ptr _getter;
262  as_c_function_ptr _setter;
263  };
264 
265  boost::variant<UserDefinedGetterSetter, NativeGetterSetter> _getset;
266 
267 };
268 
270 //
272 //
276 class Property
277 {
278 
280  struct SetReachable : boost::static_visitor<>
281  {
282  result_type operator()(const as_value& val) const {
283  val.setReachable();
284  }
285  result_type operator()(const GetterSetter& gs) const {
286  return gs.markReachableResources();
287  }
288  };
289 
290 public:
291 
293  PropFlags flags)
294  :
295  _bound(value),
296  _uri(std::move(uri)),
297  _flags(std::move(flags)),
298  _destructive(false)
299  {}
300 
302  as_function* getter, as_function* setter,
303  PropFlags flags, bool destroy = false)
304  :
305  _bound(GetterSetter(getter, setter)),
306  _uri(std::move(uri)),
307  _flags(std::move(flags)),
308  _destructive(destroy)
309  {}
310 
312  as_c_function_ptr setter, PropFlags flags,
313  bool destroy = false)
314  :
315  _bound(GetterSetter(getter, setter)),
316  _uri(std::move(uri)),
317  _flags(std::move(flags)),
318  _destructive(destroy)
319  {}
320 
322  const PropFlags& getFlags() const { return _flags; }
323 
325  void setFlags(const PropFlags& flags) const {
326  _flags = flags;
327  }
328 
330  //
338  DSOTEXPORT as_value getValue(const as_object& this_ptr) const;
339 
341  //
347  as_value getCache() const;
348 
350  //
356  void setCache(const as_value& v);
357 
359  //
374  bool setValue(as_object& this_ptr, const as_value &value) const;
375 
377  bool isGetterSetter() const {
378  return _bound.type() == typeid(GetterSetter);
379  }
380 
382  void clearVisible(int swfVersion) { _flags.clear_visible(swfVersion); }
383 
385  const ObjectURI& uri() const {
386  return _uri;
387  }
388 
390  void setReachable() const {
391  return boost::apply_visitor(SetReachable(), _bound);
392  }
393 
394 private:
395 
396  // Store the various types of things that can be held.
397  typedef boost::variant<as_value, GetterSetter> BoundType;
398 
400  mutable BoundType _bound;
401 
403  ObjectURI _uri;
404 
406  mutable PropFlags _flags;
407 
408  // If true, as soon as getValue has been invoked once, the
409  // returned value becomes a fixed return (though it can be
410  // overwritten if not readOnly)
411  mutable bool _destructive;
412 
413 };
414 
416 inline bool
417 readOnly(const Property& prop) {
418  return prop.getFlags().test<PropFlags::readOnly>();
419 }
420 
422 inline bool
423 visible(const Property& prop, int version) {
424  return prop.getFlags().get_visible(version);
425 }
426 
427 } // namespace gnash
428 
429 #endif // GNASH_PROPERTY_H
Renderer_agg.h
gnash::LogFile::getDefaultInstance
static LogFile & getDefaultInstance()
Definition: log.cpp:77
gnash::Property::setFlags
void setFlags(const PropFlags &flags) const
Set the flags of the property.
Definition: Property.h:325
gnash::FsCallback
Abstract base class for FS handlers.
Definition: HostInterface.h:200
gnash::GetterSetter::getCache
as_value getCache() const
Get the cache value (for user-defined getter-setters)
Definition: Property.h:156
path
VGPath path
Definition: testr_gtk.cpp:84
gnash::HostInterface::Message
boost::variant< HostMessage, CustomMessage > Message
Definition: HostInterface.h:213
gnash::create_Renderer_agg
DSOEXPORT Renderer_agg_base * create_Renderer_agg(const char *pixelformat)
Create a render handler.
Definition: Renderer_agg.cpp:2048
Movie.h
movie_root.h
gnash::MovieFactory::makeMovie
static DSOEXPORT boost::intrusive_ptr< movie_definition > makeMovie(const URL &url, const RunResources &runResources, const char *real_url=nullptr, bool startLoaderThread=true, const std::string *postdata=nullptr)
Create a gnash::movie_definition from the given URL.
Definition: MovieFactory.cpp:109
name
std::string name
Definition: LocalConnection_as.cpp:149
gnash::Property::setCache
void setCache(const as_value &v)
Set internal cached value of this property.
Definition: Property.cpp:172
gnash::visible
bool visible(const Property &prop, int version)
Is this member supposed to be visible by a VM of given version ?
Definition: Property.h:423
gnash::LogFile::removeLog
bool removeLog()
Remove the log file.
Definition: log.cpp:365
gnash::RunResources::setTagLoaders
void setTagLoaders(std::shared_ptr< const SWF::TagLoadersTable > loaders)
Set the loader functions for SWF parsing.
Definition: RunResources.h:121
noseek_fd_adapter.h
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
gnash::GnashException
Top-level gnash exception.
Definition: GnashException.h:31
ObjectURI.h
gnash::key::T
@ T
Definition: GnashKey.h:132
gnash::RunResources::setStreamProvider
void setStreamProvider(std::shared_ptr< StreamProvider > sp)
Set the StreamProvider.
Definition: RunResources.h:66
dsodefs.h
gnash::sound::sound_handler::fetchSamples
virtual void fetchSamples(std::int16_t *to, unsigned int nSamples)
Fetch mixed samples.
Definition: sound_handler.cpp:646
gnash::GetterSetter::set
void set(const fn_call &fn)
Invoke the setter.
Definition: Property.h:144
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
ManualClock.h
HostInterface.h
gnash::LogFile
Definition: log.h:64
TagLoadersTable.h
gnash::RunResources::setSoundHandler
void setSoundHandler(std::shared_ptr< sound::sound_handler > s)
Set the sound::sound_handler.
Definition: RunResources.h:88
rc.h
_
#define _(String)
Definition: log.h:44
gnash::LogFile::setLogFilename
void setLogFilename(const std::string &fname)
Set log filename.
Definition: log.cpp:274
Renderer.h
gnash::ManualClock
A manually advanced clock.
Definition: ManualClock.h:31
resetLastAdvanceTimer
void resetLastAdvanceTimer()
Definition: processor.cpp:130
gnash::as_environment
Provides information about timeline context.
Definition: as_environment.h:51
MediaHandler.h
gnash::GetterSetter
Holder for getter/setter functions.
Definition: Property.h:45
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
DefaultTagLoaders.h
gnash::PropFlags::clear_visible
void clear_visible(int swfVersion)
Definition: PropFlags.h:108
gnash::HostInterface
Abstract base class for hosting app handler.
Definition: HostInterface.h:208
getopt
int getopt(int, char *const *, const char *)
optind
int optind
GnashFactory.h
boost
Definition: gui.h:74
PACKAGE
#define PACKAGE
Definition: gnashconfig.h:556
gnash::key::m
@ m
Definition: GnashKey.h:159
execFsCommand
FsCommandExecutor execFsCommand
Definition: processor.cpp:220
gnash::key::s
@ s
Definition: GnashKey.h:165
as_value.h
gnash::key::n
@ n
Definition: GnashKey.h:160
gnash::Property::Property
Property(ObjectURI uri, const as_value &value, PropFlags flags)
Definition: Property.h:292
gnash::HostMessage::SCREEN_COLOR
@ SCREEN_COLOR
Definition: HostInterface.h:160
optarg
char * optarg
gnash::getVM
VM & getVM(const as_environment &env)
Definition: as_environment.h:222
as_function.h
gnash::HostMessage::SET_CLIPBOARD
@ SET_CLIPBOARD
Definition: HostInterface.h:130
secondsSinceLastAdvance
double secondsSinceLastAdvance()
Definition: processor.cpp:137
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::GetterSetter::GetterSetter
GetterSetter(as_function *getter, as_function *setter)
Construct a user-defined getter-setter.
Definition: Property.h:126
gnash::RunResources::setRenderer
void setRenderer(std::shared_ptr< Renderer > r)
Definition: RunResources.h:108
optopt
int optopt
gnash::MovieFactory::clear
static DSOEXPORT void clear()
Clear the MovieFactory resources.
Definition: MovieFactory.cpp:157
bindtextdomain
#define bindtextdomain(Domainname, Dirname)
Definition: gettext.h:66
gnash::fn_call
Parameters/environment for builtin or user-defined functions callable from ActionScript.
Definition: fn_call.h:118
gnash::key::t
@ t
Definition: GnashKey.h:166
gnash::clocktime::getTicks
DSOEXPORT std::uint64_t getTicks()
Wall clock timer, returns current POSIX time in milliseconds.
Definition: ClockTime.cpp:61
MovieFactory.h
ClockTime.h
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::Property::isGetterSetter
bool isGetterSetter() const
Is this a getter/setter property?
Definition: Property.h:377
VERBOSE_ACTION
#define VERBOSE_ACTION
Definition: log.h:359
gnash::PropFlags::get_visible
bool get_visible(int swfVersion) const
Get version-based visibility.
Definition: PropFlags.h:99
GnashSleep.h
textdomain
#define textdomain(Domainname)
Definition: gettext.h:65
gnash::key::a
@ a
Definition: GnashKey.h:147
gnash::HostMessage::arg
const boost::any & arg() const
Definition: HostInterface.h:191
gnash::amf::Type
Type
Definition: AMF.h:45
gnash::HostMessage::event
KnownEvent event() const
Definition: HostInterface.h:190
lastAdvanceTimer
double lastAdvanceTimer
Definition: processor.cpp:127
gnash::GetterSetter::GetterSetter
GetterSetter(as_c_function_ptr getter, as_c_function_ptr setter)
Construct a native getter-setter.
Definition: Property.h:132
gnash::PropFlags
Flags defining the level of protection of a member.
Definition: PropFlags.h:29
StringPredicates.h
gnash::LogFile::setActionDump
void setActionDump(int x)
Definition: log.h:135
gnash::Property::setReachable
void setReachable() const
Mark this property as being reachable (for the GC)
Definition: Property.h:390
Property.h
gnash::FunctionArgs
A class to contain transferable arguments for a fn_call.
Definition: fn_call.h:57
gnash::get
T * get(as_object *o)
Extract the DisplayObject attached to an object.
Definition: as_object.h:842
main
int main(int argc, char *argv[])
Definition: processor.cpp:223
gnash::StringNoCaseEqual
A case-insensitive string equality operator.
Definition: StringPredicates.h:42
gnash::Property
An abstract property.
Definition: Property.h:277
gnash::sound::NullSoundHandler
Null sound_handler, for testing or manual fetching of samples.
Definition: NullSoundHandler.h:37
infiles
std::vector< std::string > infiles
Definition: gnash.cpp:58
URL.h
MovieClip.h
gnash::Property::getValue
DSOTEXPORT as_value getValue(const as_object &this_ptr) const
Get value of this property.
Definition: Property.cpp:98
gnash::ManualClock::advance
void advance(unsigned long amount)
Advance the clock by the given amount of milliseconds.
Definition: ManualClock.h:53
gnash::HostMessage::PLAYER_TYPE
@ PLAYER_TYPE
Definition: HostInterface.h:154
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::GetterSetter::setCache
void setCache(const as_value &v)
Set the cache value (for user-defined getter-setters)
Definition: Property.h:150
gnash::GetterSetter::markReachableResources
void markReachableResources() const
Definition: Property.h:160
NullSoundHandler.h
gnash::RunResources
Class to group together per-run and external resources for Gnash.
Definition: RunResources.h:54
gnash::as_value
ActionScript value type.
Definition: as_value.h:95
gnash::as_c_function_ptr
as_value(* as_c_function_ptr)(const fn_call &fn)
Definition: Property.h:34
gnash::sound::sound_handler::reset
virtual void reset()
Discard all sound inputs (slots and aux streamers) and clear scheduling.
Definition: sound_handler.cpp:812
gnash::HostMessage::PIXEL_ASPECT_RATIO
@ PIXEL_ASPECT_RATIO
Definition: HostInterface.h:148
VM.h
gnash::key::S
@ S
Definition: GnashKey.h:131
gnash::Property::uri
const ObjectURI & uri() const
The name-namespace pair (ObjectURI) of this Property.
Definition: Property.h:385
log.h
gnash::as_value::setReachable
void setReachable() const
Set any object value as reachable (for the GC)
Definition: as_value.cpp:691
gnash::gnashSleep
void gnashSleep(time_t useconds)
Sleep compatibly for the specified number of microseconds.
Definition: GnashSleep.h:35
gnash::Property::Property
Property(ObjectURI uri, as_function *getter, as_function *setter, PropFlags flags, bool destroy=false)
Definition: Property.h:301
gnash::MovieClip::PLAYSTATE_PLAY
@ PLAYSTATE_PLAY
Definition: MovieClip.h:99
fn_call.h
gnash::Property::Property
Property(ObjectURI uri, as_c_function_ptr getter, as_c_function_ptr setter, PropFlags flags, bool destroy=false)
Definition: Property.h:311
gnash::Property::clearVisible
void clearVisible(int swfVersion)
Clear visibility flags.
Definition: Property.h:382
gnash::GetterSetter::get
as_value get(fn_call &fn) const
Invoke the getter.
Definition: Property.h:138
gnash::sound::sound_handler
Sound mixer.
Definition: sound_handler.h:88
url
std::string url
Definition: gnash.cpp:59
as_environment.h
gnash::dbglogfile
LogFile & dbglogfile
Definition: fileio.cpp:76
gnash::HostMessage::SCREEN_RESOLUTION
@ SCREEN_RESOLUTION
Definition: HostInterface.h:136
gnashconfig.h
gnash::RcInitFile::getDefaultInstance
static RcInitFile & getDefaultInstance()
Return the default instance of RC file.
Definition: rc.cpp:61
gnash::movie_root
This class represents the 'Stage' and top-level movie.
Definition: movie_root.h:151
DSOTEXPORT
#define DSOTEXPORT
Definition: dsodefs.h:63
gnash::HostMessage
Built-in forms of communication with the host application.
Definition: HostInterface.h:86
gnash::GnashFactory::instance
static GnashFactory & instance()
Get the GnashFactory singleton.
Definition: GnashFactory.h:78
RunResources.h
PropFlags.h
gnash::key::c
@ c
Definition: GnashKey.h:149
gnash::Property::getCache
as_value getCache() const
Get internal cached value of this property.
Definition: Property.cpp:127
eventCallback
EventCallback eventCallback
Definition: processor.cpp:219
gnash::HostMessage::SHOW_MOUSE
@ SHOW_MOUSE
Definition: HostInterface.h:98
gnash::Property::getFlags
const PropFlags & getFlags() const
accessor to the properties flags
Definition: Property.h:322
VERSION
#define VERSION
Definition: gnashconfig.h:731
GPROC_VERSION
const char * GPROC_VERSION
Definition: processor.cpp:108
movie_definition.h
gnash::RunResources::soundHandler
sound::sound_handler * soundHandler() const
Get a pointer to a sound::sound_handler set by a hosting application.
Definition: RunResources.h:96
gnash::LogFile::setNetwork
void setNetwork(int x)
Definition: log.h:139
gnash::URL
Uniform Resource Locator.
Definition: URL.h:35
gnash::noseek_fd_adapter::make_stream
IOChannel * make_stream(int fd, const char *cachefilename)
Returns a read-only IOChannel that fetches data from an file descriptor open for read.
Definition: noseek_fd_adapter.cpp:364
StreamProvider.h
gnash::PropFlags::readOnly
@ readOnly
Protect from assigning a value.
Definition: PropFlags.h:42
gnash::key::u
@ u
Definition: GnashKey.h:167
gnash::ObjectURI
A URI for describing as_objects.
Definition: ObjectURI.h:45
gnash::RunResources::setMediaHandler
void setMediaHandler(std::shared_ptr< media::MediaHandler > s)
Definition: RunResources.h:100
gnash::ManualClock::elapsed
unsigned long elapsed() const
Return number of milliseconds elapsed since start.
Definition: ManualClock.h:41
VERBOSE_PARSE
#define VERBOSE_PARSE
Definition: log.h:354
GnashException.h
gnash::PropFlags::test
bool test() const
Definition: PropFlags.h:94
gnash::LogFile::setVerbosity
void setVerbosity()
Definition: log.h:123
gnash::LogFile::setWriteDisk
void setWriteDisk(bool b)
Set whether to write logs to file.
Definition: log.cpp:281
gnash::MovieClip::MovieVariables
std::map< std::string, std::string > MovieVariables
Definition: MovieClip.h:93
gnash::SWF::addDefaultLoaders
void addDefaultLoaders(TagLoadersTable &table)
Add the default parsing functions for SWF files to a TagLoadersTable.
Definition: DefaultTagLoaders.cpp:107
gnash::HostMessage::SCREEN_DPI
@ SCREEN_DPI
Definition: HostInterface.h:142
test.v
v
Definition: test.py:11
IOChannel.h
gnash::key::e
@ e
Definition: GnashKey.h:151
gnash::HostMessage::QUERY
@ QUERY
Definition: HostInterface.h:172
gnash::LogFile::setParserDump
void setParserDump(int x)
Definition: log.h:151
gnash::readOnly
bool readOnly(const Property &prop)
is this a read-only member ?
Definition: Property.h:417
gnash::Property::setValue
bool setValue(as_object &this_ptr, const as_value &value) const
Set value of this property.
Definition: Property.cpp:133
gnash::RcInitFile
Definition: rc.h:44
gnash::HostMessage::KnownEvent
KnownEvent
The messages that a hosting application should handle.
Definition: HostInterface.h:92
gnash::as_function
ActionScript Function, either builtin or SWF-defined.
Definition: as_function.h:63