/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. #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 <boost/chrono/chrono.hpp>
  9. /// A server which catches some runtime errors in your app.
  10. /**
  11. * This server traces each request and dumps helpful info to a browser if
  12. * an error occurs. The errors which are acknowledged at the moment are
  13. * exceptions and your handler returning non-zero. You can fake an error
  14. * by appending 'debug=1' to the passed form variables.
  15. *
  16. * When an error is caught, details about that, the request that caused it and
  17. * the response (along with headers) are dumped to the client in a browser-
  18. * friendly way,
  19. *
  20. */
  21. class TracingServer
  22. {
  23. typedef boost::cgi::request request_type;
  24. typedef boost::cgi::response response_type;
  25. typedef boost::function<int (request_type&, response_type&)> callback_type;
  26. //typedef Timer<boost::chrono::high_resolution_clock> timer_type;
  27. typedef boost::chrono::process_timer timer_type;
  28. timer_type timer_;
  29. public:
  30. TracingServer(void);
  31. ~TracingServer(void);
  32. bool run(callback_type const& callback);
  33. void bomb_out(std::string const& error, response_type&, request_type&);
  34. void bomb_out(boost::system::system_error* err, response_type&, request_type&);
  35. void bomb_out(std::exception& e, response_type&, request_type&);
  36. };