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
VariablesMethod
The various methods for sending data in requests.
Definition: MovieClip.h:418
void clear()
Clean up the font library.
Definition: fontlib.cpp:36
Definition: GnashKey.h:167
SimpleBuffer data
Definition: LocalConnection_as.cpp:151
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
The base class for all ActionScript objects.
Definition: as_object.h:161
Definition: GnashKey.h:164
Definition: GnashKey.h:166
#define DSOEXPORT
Definition: dsodefs.h:55
std::string url
Definition: gnash.cpp:59
Movie loader.
Definition: MovieLoader.h:50
Uniform Resource Locator.
Definition: URL.h:34
This class represents the &#39;Stage&#39; and top-level movie.
Definition: movie_root.h:150