Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GNASH_MOVIE_LOADER_H
00020 #define GNASH_MOVIE_LOADER_H
00021
00022 #include "URL.h"
00023 #include "as_object.h"
00024 #include "MovieClip.h"
00025
00026 #include <boost/intrusive_ptr.hpp>
00027 #include <list>
00028 #include <string>
00029 #include <boost/noncopyable.hpp>
00030 #include <boost/thread/thread.hpp>
00031 #include <boost/thread/condition.hpp>
00032 #include <boost/thread/barrier.hpp>
00033
00034
00035 namespace gnash {
00036 class movie_root;
00037 class movie_definition;
00038 }
00039
00040 namespace gnash {
00041
00043
00049 class DSOEXPORT MovieLoader : boost::noncopyable {
00050
00051 public:
00052
00053 MovieLoader(movie_root& mr);
00054
00055 ~MovieLoader();
00056
00058
00062
00074 void loadMovie(const std::string& url, const std::string& target,
00075 const std::string& data, MovieClip::VariablesMethod method,
00076 as_object* handler=0);
00077
00079 void clear();
00080
00082 void processCompletedRequests();
00083
00084 void setReachable() const;
00085
00086 private:
00087
00089 class Request : boost::noncopyable {
00090 public:
00094 Request(const URL& u, const std::string& t,
00095 const std::string* postdata, as_object* handler)
00096 :
00097 _target(t),
00098 _url(u),
00099 _usePost(false),
00100 _mdef(0),
00101 _mutex(),
00102 _handler(handler),
00103 _completed(false)
00104 {
00105 if ( postdata )
00106 {
00107 _postData = *postdata;
00108 _usePost = true;
00109 }
00110 }
00111
00112 const std::string& getTarget() const { return _target; }
00113 const URL& getURL() const { return _url; }
00114 const std::string& getPostData() const { return _postData; }
00115 bool usePost() const { return _usePost; }
00116 as_object* getHandler() const { return _handler; }
00117 void setReachable() const {
00118 if (_handler) _handler->setReachable();
00119 }
00120
00122
00134 bool getCompleted(boost::intrusive_ptr<movie_definition>& md) const
00135 {
00136 boost::mutex::scoped_lock lock(_mutex);
00137 md = _mdef;
00138 return _completed;
00139 }
00140
00142 bool pending() const
00143 {
00144 boost::mutex::scoped_lock lock(_mutex);
00145 return !_completed;
00146 }
00147
00149 bool completed() const
00150 {
00151 boost::mutex::scoped_lock lock(_mutex);
00152 return _completed;
00153 }
00154
00156
00162 void setCompleted(boost::intrusive_ptr<movie_definition> md)
00163 {
00164 boost::mutex::scoped_lock lock(_mutex);
00165 _mdef = md;
00166 _completed = true;
00167 }
00168
00169 private:
00170 std::string _target;
00171 URL _url;
00172 bool _usePost;
00173 std::string _postData;
00174 boost::intrusive_ptr<movie_definition> _mdef;
00175 mutable boost::mutex _mutex;
00176 as_object* _handler;
00177 bool _completed;
00178 };
00179
00181 typedef std::list<Request*> Requests;
00182 Requests _requests;
00183
00184 mutable boost::mutex _requestsMutex;
00185
00186 void processRequests();
00187 void processRequest(Request& r);
00188 void clearRequests();
00189
00191
00194 bool processCompletedRequest(const Request& r);
00195
00197 bool killed();
00198
00199 bool _killed;
00200
00201 boost::mutex _killMutex;
00202
00203 boost::condition _wakeup;
00204
00206 movie_root& _movieRoot;
00207
00208 std::auto_ptr<boost::thread> _thread;
00209
00210
00211
00212
00213 boost::barrier _barrier;
00214
00215 };
00216
00217 }
00218
00219 #endif // GNASH_MOVIE_LOADER_H