Gnash  0.8.11dev
LoadVariablesThread.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 
20 
21 #ifndef GNASH_LOADVARIABLESTHREAD_H
22 #define GNASH_LOADVARIABLESTHREAD_H
23 
24 #include <string>
25 #include <map>
26 #include <future>
27 #include <atomic>
28 
29 
30 namespace gnash {
31  class StreamProvider;
32  class IOChannel;
33  class URL;
34 }
35 
36 namespace gnash {
37 
38 // Exception thrown by LoadVariablesThread constructor if unable to connect
39 // to the stream input.
41 
43 //
48 {
49 public:
50  typedef std::map<std::string, std::string> ValuesMap;
51 
53  //
59  LoadVariablesThread(const StreamProvider& sp, const URL& url);
60 
64  //
73  LoadVariablesThread(const StreamProvider& sp, const URL& url,
74  const std::string& postdata);
75 
78 
80  ValuesMap getValues()
81  {
82  return _vals.get();
83  }
84 
85  bool completed()
86  {
87  return _canceled;
88  }
89 
90 private:
91 
93  LoadVariablesThread& operator==(const LoadVariablesThread&);
95 
96  void startThread(std::unique_ptr<IOChannel> stream);
97 
99  //
102  static ValuesMap completeLoad(IOChannel* stream,
103  std::atomic<bool>& canceled);
104 
105  std::future<ValuesMap> _vals;
106 
110  std::atomic<bool> _canceled;
111 };
112 
113 } // namespace gnash
114 
115 #endif // GNASH_LOADVARIABLESTHREAD_H
A virtual IO channel.
Definition: IOChannel.h:42
LoadVariablesThread(const StreamProvider &sp, const URL &url)
Construct a LoadVariablesThread opening a stream for the given URL.
Definition: LoadVariablesThread.cpp:140
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
std::map< std::string, std::string > ValuesMap
Definition: LoadVariablesThread.h:50
ValuesMap getValues()
Return the name,value map parsed out of the loaded stream.
Definition: LoadVariablesThread.h:80
A manager for loadVariable requests.
Definition: LoadVariablesThread.h:47
bool completed()
Definition: LoadVariablesThread.h:85
~LoadVariablesThread()
Destroy the LoadVariablesThread, joining the thread if spawned.
Definition: LoadVariablesThread.cpp:160
std::string url
Definition: gnash.cpp:59
A StreamProvider makes IOChannels available to the core on request.
Definition: StreamProvider.h:49
Definition: LoadVariablesThread.h:40
Uniform Resource Locator.
Definition: URL.h:34