PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 0ms

/libs/cgi/example/cgi/DebugServer2/TracebackServer.hpp

http://github.com/darrengarvey/cgi
C++ Header | 60 lines | 35 code | 9 blank | 16 comment | 0 complexity | 694eb76d5f8953767d04dd2745777bfc 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#include <ctemplate/template.h>
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 TracebackServer
25{
26    typedef boost::cgi::request               request_type;
27    typedef boost::cgi::response              response_type;
28    typedef boost::function<
29      int (request_type&, response_type&)>    callback_type;
30    //typedef Timer<boost::chrono::high_resolution_clock> timer_type;
31    typedef boost::chrono::process_timer      timer_type;
32    typedef ctemplate::Template               template_type;
33    typedef ctemplate::TemplateDictionary     dictionary_type;
34
35    timer_type timer_;
36    template_type* template_;
37    boost::chrono::process_times stop_times_;
38public: // member variables
39    bool show_times;
40public: // functions
41    TracebackServer(void);
42    ~TracebackServer(void);
43
44    bool run(callback_type const& callback);
45
46    void bomb_out(std::string const& error, response_type&, request_type&);
47    void bomb_out(boost::system::system_error* err, response_type&, request_type&);
48    void bomb_out(std::exception* e, response_type&, request_type&);
49    void bomb_out(std::exception& e, response_type&, request_type&);
50
51    //dictionary_type& new_dictionary(std::string const& name);
52    template<typename MapT>
53    void expand_map(dictionary_type& dict, MapT& data, std::string const& title);
54
55    void stop_timer();
56
57    // Add the running times to the dictionary.
58    void dump_times(dictionary_type& dict);
59};
60