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 <atomic>
27 #include <cassert>
28 #include <memory>
29 #include <thread>
30 
31 namespace gnash {
32  class StreamProvider;
33  class IOChannel;
34  class URL;
35 }
36 
37 namespace gnash {
38 
39 // Exception thrown by LoadVariablesThread constructor if unable to connect
40 // to the stream input.
42 
44 //
49 {
50 public:
51  typedef std::map<std::string, std::string> ValuesMap;
52 
53  enum class Status : std::int8_t { STARTED = 0, FINISHED, CANCEL_REQUESTED };
54 
56  //
62  LoadVariablesThread(const StreamProvider& sp, const URL& url);
63 
67  //
76  LoadVariablesThread(const StreamProvider& sp, const URL& url,
77  const std::string& postdata);
78 
81 
83  ValuesMap getValues()
84  {
85  assert(completed());
86  return _vals;
87  }
88 
89  bool completed()
90  {
91  return static_cast<Status>(_status.load()) == Status::FINISHED;
92  }
93 
94 private:
95 
99 
100  void startThread(std::unique_ptr<IOChannel> stream);
101 
103  //
106  static ValuesMap completeLoad(std::unique_ptr<IOChannel> stream,
107  const std::atomic<int8_t>& status);
108 
109  ValuesMap _vals;
110 
111  std::thread _thread;
112  std::atomic<int8_t> _status; // enum class Status; int for compatibility.
113 };
114 
115 } // namespace gnash
116 
117 #endif // GNASH_LOADVARIABLESTHREAD_H
Status
Definition: LoadVariablesThread.h:53
bool operator==(const event_id &a, const event_id &b)
Return whether two event_ids are equal.
Definition: event_id.h:163
Anonymous namespace for callbacks, local functions, event handlers etc.
Definition: dbus_ext.cpp:40
std::map< std::string, std::string > ValuesMap
Definition: LoadVariablesThread.h:51
ValuesMap getValues()
Return the name,value map parsed out of the loaded stream.
Definition: LoadVariablesThread.h:83
A manager for loadVariable requests.
Definition: LoadVariablesThread.h:48
bool completed()
Definition: LoadVariablesThread.h:89
std::string url
Definition: gnash.cpp:59
A StreamProvider makes IOChannels available to the core on request.
Definition: StreamProvider.h:49
Definition: LoadVariablesThread.h:41
Uniform Resource Locator.
Definition: URL.h:34