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
00020
00021 #ifndef GNASH_LOADVARIABLESTHREAD_H
00022 #define GNASH_LOADVARIABLESTHREAD_H
00023
00024 #include <string>
00025 #include <map>
00026 #include <boost/scoped_ptr.hpp>
00027 #include <boost/thread/thread.hpp>
00028 #include <boost/thread/mutex.hpp>
00029 #include <boost/bind.hpp>
00030
00031 #include "StreamProvider.h"
00032 #include "URL.h"
00033
00034 namespace gnash {
00035
00036
00037
00038 class NetworkException {};
00039
00041
00045 class LoadVariablesThread
00046 {
00047 public:
00048 typedef std::map<std::string, std::string> ValuesMap;
00049
00051
00057 LoadVariablesThread(const StreamProvider& sp, const URL& url);
00058
00062
00071 LoadVariablesThread(const StreamProvider& sp, const URL& url,
00072 const std::string& postdata);
00073
00075 ~LoadVariablesThread();
00076
00078 ValuesMap& getValues()
00079 {
00080 return _vals;
00081 }
00082
00084 void process()
00085 {
00086 assert(!_thread.get());
00087 assert(_stream.get());
00088 _thread.reset(new boost::thread(
00089 boost::bind(LoadVariablesThread::execLoadingThread, this)));
00090 }
00091
00093
00096 void cancel();
00097
00099 bool inProgress()
00100 {
00101
00102 return ( _thread.get() != NULL );
00103 }
00104
00106
00111 bool completed()
00112 {
00113 boost::mutex::scoped_lock lock(_mutex);
00114 if ( _completed && _thread.get() )
00115 {
00116 _thread->join();
00117 _thread.reset();
00118 }
00119 return _completed;
00120 }
00121
00122 size_t getBytesLoaded() const
00123 {
00124
00125 return _bytesLoaded;
00126 }
00127
00128 size_t getBytesTotal() const
00129 {
00130
00131 return _bytesTotal;
00132 }
00133
00134
00135 private:
00136
00138 LoadVariablesThread& operator==(const LoadVariablesThread&);
00139 LoadVariablesThread(const LoadVariablesThread&);
00140
00145 static void execLoadingThread(LoadVariablesThread* ptr)
00146 {
00147
00148 ptr->completeLoad();
00149
00150 }
00151
00152
00154 void setCompleted()
00155 {
00156 boost::mutex::scoped_lock lock(_mutex);
00157 _completed = true;
00158
00159 }
00160
00161
00163
00166 void completeLoad();
00167
00169
00179 size_t parse(const std::string& str)
00180 {
00181 URL::parse_querystring(str, _vals);
00182 return _vals.size();
00183 }
00184
00186
00189 bool cancelRequested();
00190
00191 size_t _bytesLoaded;
00192
00193 size_t _bytesTotal;
00194
00195 boost::scoped_ptr<IOChannel> _stream;
00196
00197 boost::scoped_ptr<boost::thread> _thread;
00198
00199 ValuesMap _vals;
00200
00201 bool _completed;
00202
00203 bool _canceled;
00204
00205 boost::mutex _mutex;
00206 };
00207
00208 }
00209
00210 #endif // GNASH_LOADVARIABLESTHREAD_H