1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #include <anna/core/tracing/TraceMethod.hpp>
11 #include <anna/app/functions.hpp>
12 #include <anna/app/Application.hpp>
14 #include <anna/comm/Communicator.hpp>
15 #include <anna/comm/IndexedDelivery.hpp>
16 #include <anna/comm/CongestionController.hpp>
18 #include <anna/http/Request.hpp>
20 #include "Application.hpp"
21 #include "Request.hpp"
22 #include "Acceptor.hpp"
23 #include "Context.hpp"
29 void http4comm::Acceptor::initialize ()
30 throw (RuntimeException)
34 void http4comm::Acceptor::evRequest (comm::ClientSocket& clientSocket, const http::Request& request)
35 throw (RuntimeException)
37 LOGMETHOD (TraceMethod tm ("http4comm::Acceptor", "evRequest", ANNA_FILE_LOCATION));
39 comm::CongestionController& ccgg = comm::CongestionController::instantiate ();
41 if (ccgg.getAdvice (clientSocket) == comm::CongestionController::Advice::Discard)
44 const DataBlock& body = request.getBody ();
46 if (body.getSize () == 0)
47 throw RuntimeException ("La peticion no incorpora los parametros de operacion", ANNA_FILE_LOCATION);
50 string msg ("Body recibido: ");
51 msg += anna::functions::asString (body);
52 Logger::information (msg, ANNA_FILE_LOCATION);
55 if (comm::Codec::getType (body) != Request::Id)
56 throw RuntimeException ("El mensaje recibido no es una peticion aritmetica", ANNA_FILE_LOCATION);
60 a_testRequest.decode (body);
62 comm::IndexedDelivery* delivery = static_cast <Application&> (app::functions::getApp ()).getService ();
65 switch (a_testRequest.op) {
66 case '+': index = 0; break;
67 case '-': index = 1; break;
68 case '*': index = 2; break;
69 case '/': index = 3; break;
71 delivery->prepare (index);
72 delivery->send (a_testRequest);
74 http4comm::Application& app = static_cast <http4comm::Application&> (app::functions::getApp ());
75 app.getContext ()->create (a_testRequest.initTime, clientSocket);
77 catch (RuntimeException& ex) {