PageRenderTime 31ms CodeModel.GetById 11ms RepoModel.GetById 0ms 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. #include <iostream>
  3. #include <boost/function.hpp>
  4. #include <boost/cgi/cgi.hpp>
  5. #undef min
  6. #undef max
  7. #include <boost/chrono/process_times.hpp>
  8. #include <ctemplate/template.h>
  9. //#include <boost/chrono/chrono.hpp>
  10. /// A server which catches some runtime errors in your app.
  11. /**
  12. * This server traces each request and dumps helpful info to a browser if
  13. * an error occurs. The errors which are acknowledged at the moment are
  14. * exceptions and your handler returning non-zero. You can fake an error
  15. * by appending 'debug=1' to the passed form variables.
  16. *
  17. * When an error is caught, details about that, the request that caused it and
  18. * the response (along with headers) are dumped to the client in a browser-
  19. * friendly way,
  20. *
  21. */
  22. class TracebackServer
  23. {
  24. typedef boost::cgi::request request_type;
  25. typedef boost::cgi::response response_type;
  26. typedef boost::function<
  27. int (request_type&, response_type&)> callback_type;
  28. //typedef Timer<boost::chrono::high_resolution_clock> timer_type;
  29. typedef boost::chrono::process_timer timer_type;
  30. typedef ctemplate::Template template_type;
  31. typedef ctemplate::TemplateDictionary dictionary_type;
  32. timer_type timer_;
  33. template_type* template_;
  34. boost::chrono::process_times stop_times_;
  35. public: // member variables
  36. bool show_times;
  37. public: // functions
  38. TracebackServer(void);
  39. ~TracebackServer(void);
  40. bool run(callback_type const& callback);
  41. void bomb_out(std::string const& error, response_type&, request_type&);
  42. void bomb_out(boost::system::system_error* err, response_type&, request_type&);
  43. void bomb_out(std::exception* e, response_type&, request_type&);
  44. void bomb_out(std::exception& e, response_type&, request_type&);
  45. //dictionary_type& new_dictionary(std::string const& name);
  46. template<typename MapT>
  47. void expand_map(dictionary_type& dict, MapT& data, std::string const& title);
  48. void stop_timer();
  49. // Add the running times to the dictionary.
  50. void dump_times(dictionary_type& dict);
  51. };