Zero  0.1.0
http.h
Go to the documentation of this file.
1 #ifndef __HTTP_H
2 #define __HTTP_H
3 
4 #include "command.h"
5 #include "kits_cmd.h"
6 #include "agglog.h"
7 #include <boost/asio.hpp>
8 #include <string>
9 #include <memory>
10 #include <mutex>
11 #include <thread>
12 #include <chrono>
13 
14 using namespace boost;
15 using namespace boost::system;
16 using namespace boost::asio;
17 
18 class HandleKits {
19 private:
21 
22  std::vector<sm_stats_t> stats;
23 
24  std::vector<sm_stats_t> stats_delta;
25 
26  std::unique_ptr<std::thread> statsThread;
27 
28  std::mutex stats_mutex;
29 
30 public:
31  HandleKits();
32 
33  int runKits(std::stringstream& options);
34 
35  void computeStats();
36 
37  void crash();
38 
39  void mediaFailure();
40 
41  void singlePageFailure();
42 
43  std::string getStats(bool);
44 
45  std::string isRunning();
46 
47  std::string redoProgress();
48 
49  std::string undoProgress();
50 
51  std::string logAnalysisProgress();
52 
53  std::string mediaRecoveryProgress();
54 
55  size_t getRedoPagesDirty();
56 
57  size_t getRedoPagesTotal();
58 };
59 
60 class http_headers {
61 private:
62  std::string method;
63 
64  std::string url;
65 
66  std::string version;
67 
68  std::map<std::string, std::string> headers;
69 
70 public:
71  std::stringstream options;
72 
73  http_headers();
74 
75  std::string get_response(HandleKits* kits);
76 
77  int content_length();
78 
79  void on_read_header(std::string line);
80 
81  void on_read_request_line(std::string line);
82 };
83 
84 class session {
85  asio::streambuf buff;
86 
88 
89  static void read_body(std::shared_ptr<session> pThis, HandleKits* kits);
90 
91  static void read_next_line(std::shared_ptr<session> pThis, HandleKits* kits);
92 
93  static void read_first_line(std::shared_ptr<session> pThis, HandleKits* kits);
94 
95 public:
96 
97  ip::tcp::socket socket;
98 
99  session(io_service& io_service)
100  : socket(io_service) {}
101 
102  static void interact(std::shared_ptr<session> pThis, HandleKits* kits);
103 };
104 
105 #endif // __HTTP_H
Definition: http.h:84
std::mutex stats_mutex
Definition: http.h:28
asio::streambuf buff
Definition: http.h:85
std::map< std::string, std::string > headers
Definition: http.h:68
Definition: http.h:18
Definition: http.h:60
KitsCommand * kits
Definition: http.h:20
ip::tcp::socket socket
Definition: http.h:97
Definition: kits_cmd.h:14
std::vector< sm_stats_t > stats_delta
Definition: http.h:24
std::string method
Definition: http.h:62
std::string url
Definition: http.h:64
std::unique_ptr< std::thread > statsThread
Definition: http.h:26
std::string version
Definition: http.h:66
std::vector< sm_stats_t > stats
Definition: http.h:22
std::stringstream options
Definition: http.h:71
http_headers headers
Definition: http.h:87
session(io_service &io_service)
Definition: http.h:99