void handleRequest(const Wt::Http::Request& request, Wt::Http::Response& response) { WApplication::UpdateLock app_lock = app_->getUpdateLock(); WMouseEvent::Coordinates xy(-1, -1); const std::string* xy_str = request.getParameter("MapImageXY"); if (xy_str) { int comma_pos = xy_str->find(','); if (comma_pos != std::string::npos) { std::string x_str = xy_str->substr(1, comma_pos - 1); std::string y_str = xy_str->substr(comma_pos + 1); try { int x = boost::lexical_cast<int>(x_str); int y = boost::lexical_cast<int>(y_str); xy = WMouseEvent::Coordinates(x, y); } catch (...) { } } } map_image_->clicked().emit(xy); response.setMimeType("text/html"); response.out() << "<html><head>"; response.out() << "<meta http-equiv='refresh' "; response.out() << " content='0; url=" << redirect_to_ << "' />"; response.out() << "</head><body></body></html>"; }
virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) { int n; if (const std::string *queries = request.getParameter("queries")) { n = atoi(queries->c_str()); if (n < 1) n = 1; else if (n > 500) n = 500; } else { n = 1; } response.setMimeType("application/json"); response.addHeader("Server", "Wt"); DbStruct* db = dbStruct_.get(); if (!db) { db = new DbStruct(); dbStruct_.reset(db); } Wt::Dbo::Transaction transaction(db->session); std::vector<Wt::Dbo::ptr<World> > results; results.reserve(n); for (int i = 0; i < n; ++i) { results.push_back(db->session.load<World>(db->rand())); } Wt::Dbo::JsonSerializer writer(response.out()); writer.serialize(results); }
virtual void handleRequest(const Wt::Http::Request &request, Wt::Http::Response &response) { int n; if (const std::string *queries = request.getParameter("queries")) { n = atoi(queries->c_str()); if (n < 1) n = 1; else if (n > 500) n = 500; } else { n = 1; } response.setMimeType("application/json"); response.addHeader("Server", "Wt"); DbStruct* db = dbStruct_.get(); if (!db) { db = new DbStruct(); dbStruct_.reset(db); } std::vector<Wt::Dbo::ptr<World> > results; for (int i = 0; i < n; ++i) { bool success = false; while (!success) { try { Wt::Dbo::Transaction transaction(db->session); Wt::Dbo::ptr<World> world = db->session.load<World>(db->rand()); world.modify()->randomNumber = db->rand(); transaction.commit(); results.push_back(world); success = true; } catch (Wt::Dbo::Exception& e) { // Retry } } } Wt::Dbo::JsonSerializer writer(response.out()); writer.serialize(results); }