PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 4ms RepoModel.GetById 36ms app.codeStats 0ms

/libs/cgi/example/cgi/DebugServer/TracingServer.hpp

http://github.com/darrengarvey/cgi
C++ Header | 42 lines | 22 code | 6 blank | 14 comment | 0 complexity | 494e3e1160499f5ce212d9e2282e2925 MD5 | raw file
 1#pragma once
 2
 3#include <iostream>
 4#include <boost/function.hpp>
 5#include <boost/cgi/cgi.hpp>
 6#undef min
 7#undef max
 8#include <boost/chrono/process_times.hpp>
 9
10//#include <boost/chrono/chrono.hpp>
11
12/// A server which catches some runtime errors in your app.
13/**
14 * This server traces each request and dumps helpful info to a browser if
15 * an error occurs. The errors which are acknowledged at the moment are
16 * exceptions and your handler returning non-zero. You can fake an error
17 * by appending 'debug=1' to the passed form variables.
18 *
19 * When an error is caught, details about that, the request that caused it and
20 * the response (along with headers) are dumped to the client in a browser-
21 * friendly way, 
22 *
23 */
24class TracingServer
25{
26    typedef boost::cgi::request request_type;
27    typedef boost::cgi::response response_type;
28    typedef boost::function<int (request_type&, response_type&)> callback_type;
29    //typedef Timer<boost::chrono::high_resolution_clock> timer_type;
30    typedef boost::chrono::process_timer timer_type;
31
32    timer_type timer_;
33public:
34    TracingServer(void);
35    ~TracingServer(void);
36
37    bool run(callback_type const& callback);
38
39    void bomb_out(std::string const& error, response_type&, request_type&);
40    void bomb_out(boost::system::system_error* err, response_type&, request_type&);
41    void bomb_out(std::exception& e, response_type&, request_type&);
42};