Gnash  0.8.11dev
MovieLoader.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 #ifndef GNASH_MOVIE_LOADER_H
20 #define GNASH_MOVIE_LOADER_H
21 
22 #include <atomic>
23 #include <condition_variable>
24 #include <string>
25 #include <thread>
26 
27 #include <boost/intrusive_ptr.hpp>
28 #include <boost/noncopyable.hpp>
29 #include <boost/ptr_container/ptr_list.hpp>
30 
31 #include "URL.h"
32 #include "MovieClip.h"
33 
34 // Forward declarations
35 namespace gnash {
36  class movie_root;
37  class movie_definition;
38  class as_object;
39 }
40 
41 namespace gnash {
42 
44 //
50 class DSOEXPORT MovieLoader : boost::noncopyable {
51 
52 public:
53 
55 
56  ~MovieLoader();
57 
59  //
63  //
75  void loadMovie(const std::string& url, const std::string& target,
76  const std::string& data, MovieClip::VariablesMethod method,
77  as_object* handler=nullptr);
78 
80  void clear();
81 
83  void processCompletedRequests();
84 
85  void setReachable() const;
86 
87 private:
88 
90  class Request : boost::noncopyable {
91  public:
95  Request(URL u, std::string t,
96  const std::string* postdata, as_object* handler)
97  :
98  _target(std::move(t)),
99  _url(std::move(u)),
100  _usePost(false),
101  _mdef(nullptr),
102  _mutex(),
103  _handler(handler),
104  _completed(false)
105  {
106  if (postdata) {
107  _postData = *postdata;
108  _usePost = true;
109  }
110  }
111 
112  const std::string& getTarget() const { return _target; }
113  const URL& getURL() const { return _url; }
114  const std::string& getPostData() const { return _postData; }
115  bool usePost() const { return _usePost; }
116  as_object* getHandler() const { return _handler; }
117  void setReachable() const {
118  if (_handler) _handler->setReachable();
119  }
120 
122  //
134  bool getCompleted(boost::intrusive_ptr<movie_definition>& md) const
135  {
136  std::lock_guard<std::mutex> lock(_mutex);
137  md = _mdef;
138  return _completed;
139  }
140 
142  bool pending() const
143  {
144  std::lock_guard<std::mutex> lock(_mutex);
145  return !_completed;
146  }
147 
149  bool completed() const
150  {
151  std::lock_guard<std::mutex> lock(_mutex);
152  return _completed;
153  }
154 
156  //
162  void setCompleted(boost::intrusive_ptr<movie_definition> md)
163  {
164  std::lock_guard<std::mutex> lock(_mutex);
165  _mdef = md;
166  _completed = true;
167  }
168 
169  private:
170  std::string _target;
171  URL _url;
172  bool _usePost;
173  std::string _postData;
174  boost::intrusive_ptr<movie_definition> _mdef;
175  mutable std::mutex _mutex;
176  as_object* _handler;
177  bool _completed;
178  };
179 
181  typedef boost::ptr_list<Request> Requests;
182  Requests _requests;
183 
184  mutable std::mutex _requestsMutex;
185 
186  void processRequests();
187  void processRequest(Request& r);
188  void clearRequests();
189 
191  //
194  bool processCompletedRequest(const Request& r);
195 
197  std::atomic<bool> _killed;
198 
199  std::condition_variable _wakeup;
200 
202  movie_root& _movieRoot;
203 
204  std::thread _thread;
205 };
206 
207 } // namespace gnash
208 
209 #endif // GNASH_MOVIE_LOADER_H
gnash::isLevelTarget
bool isLevelTarget(int version, const std::string &name, unsigned int &levelno)
Return true if the given string can be interpreted as a _level name.
Definition: movie_root.cpp:2387
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
gnash::MovieLoader::loadMovie
void loadMovie(const std::string &url, const std::string &target, const std::string &data, MovieClip::VariablesMethod method, as_object *handler=nullptr)
Queue a request for loading a movie.
Definition: MovieLoader.cpp:397
ExecutableCode.h
gnash::as_object
The base class for all ActionScript objects.
Definition: as_object.h:162
as_object.h
gnash::MovieClip::METHOD_POST
@ METHOD_POST
Definition: MovieClip.h:422
gnash::DisplayObject::staticDepthOffset
static const int staticDepthOffset
Definition: DisplayObject.h:205
gnash::movie_root::findCharacterByTarget
DisplayObject * findCharacterByTarget(const std::string &tgtstr) const
Definition: movie_root.cpp:2142
gnash::NSV::PROP_BROADCAST_MESSAGE
@ PROP_BROADCAST_MESSAGE
Definition: namedStrings.h:139
gnash::log_debug
void log_debug(StringType msg, Args... args)
Definition: log.h:301
_
#define _(String)
Definition: log.h:44
gnash
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:41
gnash::VM::getGlobal
Global_as * getGlobal() const
Get a pointer to this VM's _global Object.
Definition: VM.cpp:149
gnash::movie_root::PRIORITY_DOACTION
@ PRIORITY_DOACTION
Frame actions, load handlers, unload handlers.
Definition: movie_root.h:539
gnash::MovieLoader::setReachable
void setReachable() const
Definition: MovieLoader.cpp:461
gnash::MovieLoader::~MovieLoader
~MovieLoader()
Definition: MovieLoader.cpp:453
as_value.h
gnash::MovieLoader::clear
void clear()
Drop all requests and kill the thread.
Definition: MovieLoader.cpp:152
gnash::movie_root::pushAction
void pushAction(std::unique_ptr< ExecutableCode > code, size_t lvl)
Push an executable code to the ActionQueue.
Definition: movie_root.cpp:1496
gnash::log_error
void log_error(StringType msg, Args... args)
Definition: log.h:283
gnash::movie_root::setLevel
void setLevel(unsigned int num, Movie *movie)
Put the given movie at the given level.
Definition: movie_root.cpp:316
gnash::MovieLoader::MovieLoader
MovieLoader(movie_root &mr)
Definition: MovieLoader.cpp:47
gnash::key::t
@ t
Definition: GnashKey.h:166
MovieFactory.h
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
gnash::key::r
@ r
Definition: GnashKey.h:164
gnash::renderer::opengl::for_each
void for_each(C &container, R(T::*pmf)(const A &), const A &arg)
Definition: Renderer_ogl.cpp:690
gnash::key::code
code
Definition: GnashKey.h:44
gnash::movie_root::getVM
VM & getVM()
Return the VM used by this movie_root.
Definition: movie_root.h:356
URL.h
MovieClip.h
gnash::MovieLoader::processCompletedRequests
void processCompletedRequests()
Process all completed movie load requests.
Definition: MovieLoader.cpp:329
gnash::VM::getSWFVersion
int getSWFVersion() const
Get SWF version context for the currently running actions.
Definition: VM.h:106
gnash::MovieLoader
Movie loader.
Definition: MovieLoader.h:50
gnash::key::_1
@ _1
Definition: GnashKey.h:95
gnash::MovieClip::VariablesMethod
VariablesMethod
The various methods for sending data in requests.
Definition: MovieClip.h:419
DisplayObject.h
log.h
gnash::getRoot
movie_root & getRoot(const as_environment &env)
Definition: as_environment.cpp:645
url
std::string url
Definition: gnash.cpp:59
gnash::getObject
as_object * getObject(const DisplayObject *d)
Return the as_object associated with a DisplayObject if it exists.
Definition: DisplayObject.h:1160
gnash::movie_root
This class represents the 'Stage' and top-level movie.
Definition: movie_root.h:151
namedStrings.h
RunResources.h
DSOEXPORT
#define DSOEXPORT
Definition: dsodefs.h:55
gnash::StreamProvider::baseURL
const URL & baseURL() const
The base URL that should be used to resolve all relative URLs.
Definition: StreamProvider.h:117
movie_definition.h
MovieLoader.h
gnash::MovieClip::METHOD_GET
@ METHOD_GET
Definition: MovieClip.h:421
gnash::URL
Uniform Resource Locator.
Definition: URL.h:35
StreamProvider.h
gnash::key::u
@ u
Definition: GnashKey.h:167
gnash::movie_root::runResources
const RunResources & runResources() const
Definition: movie_root.h:788
gnash::MovieClip::MovieVariables
std::map< std::string, std::string > MovieVariables
Definition: MovieClip.h:93
data
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
gnash::fontlib::clear
void clear()
Clean up the font library.
Definition: fontlib.cpp:36
gnash::RunResources::streamProvider
const StreamProvider & streamProvider() const
Get a StreamProvider instance.
Definition: RunResources.h:76