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 "StreamProvider.h"
00025 #include "URL.h"
00026
00027
00028 #include <string>
00029 #include <map>
00030 #include <memory>
00031 #include <boost/thread/thread.hpp>
00032 #include <boost/thread/mutex.hpp>
00033 #include <boost/bind.hpp>
00034
00035
00036 namespace gnash {
00037
00038 }
00039
00040 namespace gnash {
00041
00042
00043
00044 class NetworkException {};
00045
00047
00051 class LoadVariablesThread
00052 {
00053 public:
00054 typedef std::map<std::string, std::string> ValuesMap;
00055
00057
00063 LoadVariablesThread(const StreamProvider& sp, const URL& url);
00064
00068
00077 LoadVariablesThread(const StreamProvider& sp, const URL& url,
00078 const std::string& postdata);
00079
00081 ~LoadVariablesThread();
00082
00084 ValuesMap& getValues()
00085 {
00086 return _vals;
00087 }
00088
00090 void process()
00091 {
00092 assert(!_thread.get());
00093 assert(_stream.get());
00094 _thread.reset(new boost::thread(
00095 boost::bind(LoadVariablesThread::execLoadingThread, this)));
00096 }
00097
00099
00102 void cancel();
00103
00105 bool inProgress()
00106 {
00107
00108 return ( _thread.get() != NULL );
00109 }
00110
00112
00117 bool completed()
00118 {
00119 boost::mutex::scoped_lock lock(_mutex);
00120 if ( _completed && _thread.get() )
00121 {
00122 _thread->join();
00123 _thread.reset();
00124 }
00125 return _completed;
00126 }
00127
00128 size_t getBytesLoaded() const
00129 {
00130
00131 return _bytesLoaded;
00132 }
00133
00134 size_t getBytesTotal() const
00135 {
00136
00137 return _bytesTotal;
00138 }
00139
00140
00141 private:
00142
00144 LoadVariablesThread& operator==(const LoadVariablesThread&);
00145 LoadVariablesThread(const LoadVariablesThread&);
00146
00151 static void execLoadingThread(LoadVariablesThread* ptr)
00152 {
00153
00154 ptr->completeLoad();
00155
00156 }
00157
00158
00160 void setCompleted()
00161 {
00162 boost::mutex::scoped_lock lock(_mutex);
00163 _completed = true;
00164
00165 }
00166
00167
00169
00172 void completeLoad();
00173
00175
00185 size_t parse(const std::string& str)
00186 {
00187 URL::parse_querystring(str, _vals);
00188 return _vals.size();
00189 }
00190
00192
00195 bool cancelRequested();
00196
00197 size_t _bytesLoaded;
00198
00199 size_t _bytesTotal;
00200
00201 std::auto_ptr<IOChannel> _stream;
00202
00203 std::auto_ptr<boost::thread> _thread;
00204
00205 ValuesMap _vals;
00206
00207 bool _completed;
00208
00209 bool _canceled;
00210
00211 boost::mutex _mutex;
00212 };
00213
00214 }
00215
00216 #endif // GNASH_LOADVARIABLESTHREAD_H