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

Language C/C++ Header Lines 61
MD5 Hash 694eb76d5f8953767d04dd2745777bfc Estimated Cost $800 (why?)
Repository git://github.com/darrengarvey/cgi.git View Raw File
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once

#include <iostream>
#include <boost/function.hpp>
#include <boost/cgi/cgi.hpp>
#undef min
#undef max
#include <boost/chrono/process_times.hpp>
#include <ctemplate/template.h>
//#include <boost/chrono/chrono.hpp>

/// A server which catches some runtime errors in your app.
/**
 * This server traces each request and dumps helpful info to a browser if
 * an error occurs. The errors which are acknowledged at the moment are
 * exceptions and your handler returning non-zero. You can fake an error
 * by appending 'debug=1' to the passed form variables.
 *
 * When an error is caught, details about that, the request that caused it and
 * the response (along with headers) are dumped to the client in a browser-
 * friendly way, 
 *
 */
class TracebackServer
{
    typedef boost::cgi::request               request_type;
    typedef boost::cgi::response              response_type;
    typedef boost::function<
      int (request_type&, response_type&)>    callback_type;
    //typedef Timer<boost::chrono::high_resolution_clock> timer_type;
    typedef boost::chrono::process_timer      timer_type;
    typedef ctemplate::Template               template_type;
    typedef ctemplate::TemplateDictionary     dictionary_type;

    timer_type timer_;
    template_type* template_;
    boost::chrono::process_times stop_times_;
public: // member variables
    bool show_times;
public: // functions
    TracebackServer(void);
    ~TracebackServer(void);

    bool run(callback_type const& callback);

    void bomb_out(std::string const& error, response_type&, request_type&);
    void bomb_out(boost::system::system_error* err, response_type&, request_type&);
    void bomb_out(std::exception* e, response_type&, request_type&);
    void bomb_out(std::exception& e, response_type&, request_type&);

    //dictionary_type& new_dictionary(std::string const& name);
    template<typename MapT>
    void expand_map(dictionary_type& dict, MapT& data, std::string const& title);

    void stop_timer();

    // Add the running times to the dictionary.
    void dump_times(dictionary_type& dict);
};
Back to Top