• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

MovieLoader.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 // Forward declarations
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         // Barrier to ensure that _thread
00211         // is initialized before the loader thread
00212         // continues execution
00213         boost::barrier _barrier;
00214 
00215 };
00216 
00217 } // namespace gnash
00218 
00219 #endif // GNASH_MOVIE_LOADER_H

Generated on Thu Sep 2 2010 for Gnash by  doxygen 1.7.1