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 <boost/intrusive_ptr.hpp>
23 #include <string>
24 #include <boost/ptr_container/ptr_list.hpp>
25 #include <boost/noncopyable.hpp>
26 #include <boost/thread/thread.hpp>
27 #include <boost/thread/condition.hpp>
28 #include <boost/thread/barrier.hpp>
29 
30 #include "URL.h"
31 #include "MovieClip.h"
32 
33 // Forward declarations
34 namespace gnash {
35  class movie_root;
36  class movie_definition;
37  class as_object;
38 }
39 
40 namespace gnash {
41 
43 //
49 class DSOEXPORT MovieLoader : boost::noncopyable {
50 
51 public:
52 
54 
55  ~MovieLoader();
56 
58  //
62  //
74  void loadMovie(const std::string& url, const std::string& target,
75  const std::string& data, MovieClip::VariablesMethod method,
76  as_object* handler=0);
77 
79  void clear();
80 
82  void processCompletedRequests();
83 
84  void setReachable() const;
85 
86 private:
87 
89  class Request : boost::noncopyable {
90  public:
94  Request(const URL& u, const std::string& t,
95  const std::string* postdata, as_object* handler)
96  :
97  _target(t),
98  _url(u),
99  _usePost(false),
100  _mdef(0),
101  _mutex(),
102  _handler(handler),
103  _completed(false)
104  {
105  if (postdata) {
106  _postData = *postdata;
107  _usePost = true;
108  }
109  }
110 
111  const std::string& getTarget() const { return _target; }
112  const URL& getURL() const { return _url; }
113  const std::string& getPostData() const { return _postData; }
114  bool usePost() const { return _usePost; }
115  as_object* getHandler() const { return _handler; }
116  void setReachable() const {
117  if (_handler) _handler->setReachable();
118  }
119 
121  //
133  bool getCompleted(boost::intrusive_ptr<movie_definition>& md) const
134  {
135  boost::mutex::scoped_lock lock(_mutex);
136  md = _mdef;
137  return _completed;
138  }
139 
141  bool pending() const
142  {
143  boost::mutex::scoped_lock lock(_mutex);
144  return !_completed;
145  }
146 
148  bool completed() const
149  {
150  boost::mutex::scoped_lock lock(_mutex);
151  return _completed;
152  }
153 
155  //
161  void setCompleted(boost::intrusive_ptr<movie_definition> md)
162  {
163  boost::mutex::scoped_lock lock(_mutex);
164  _mdef = md;
165  _completed = true;
166  }
167 
168  private:
169  std::string _target;
170  URL _url;
171  bool _usePost;
172  std::string _postData;
173  boost::intrusive_ptr<movie_definition> _mdef;
174  mutable boost::mutex _mutex;
176  bool _completed;
177  };
178 
180  typedef boost::ptr_list<Request> Requests;
181  Requests _requests;
182 
183  mutable boost::mutex _requestsMutex;
184 
185  void processRequests();
186  void processRequest(Request& r);
187  void clearRequests();
188 
190  //
193  bool processCompletedRequest(const Request& r);
194 
196  bool killed();
197 
198  bool _killed;
199 
200  boost::mutex _killMutex;
201 
202  boost::condition _wakeup;
203 
205  movie_root& _movieRoot;
206 
207  std::auto_ptr<boost::thread> _thread;
208 
209  // Barrier to ensure that _thread
210  // is initialized before the loader thread
211  // continues execution
212  boost::barrier _barrier;
213 
214 };
215 
216 } // namespace gnash
217 
218 #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:153
The base class for all ActionScript objects.
Definition: as_object.h:161
as_object & _target
Definition: ContextMenu_as.cpp:70
const URL _url
Definition: NetConnection_as.cpp:258
Definition: GnashKey.h:164
Definition: GnashKey.h:166
#define DSOEXPORT
Definition: dsodefs.h:55
Connection & _handler
Definition: NetConnection_as.cpp:208
std::string url
Definition: gnash.cpp:59
Movie loader.
Definition: MovieLoader.h:49
Uniform Resource Locator.
Definition: URL.h:34
This class represents the 'Stage' and top-level movie.
Definition: movie_root.h:150