1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
11 // * Redistributions of source code must retain the above copyright
12 // notice, this list of conditions and the following disclaimer.
13 // * Redistributions in binary form must reproduce the above
14 // copyright notice, this list of conditions and the following disclaimer
15 // in the documentation and/or other materials provided with the
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 // Authors: eduardo.ramos.testillano@gmail.com
34 // cisco.tierra@gmail.com
37 #include <anna/core/tracing/TraceMethod.hpp>
39 #include <anna/app/functions.hpp>
40 #include <anna/app/Application.hpp>
42 #include <anna/comm/Communicator.hpp>
43 #include <anna/comm/IndexedDelivery.hpp>
44 #include <anna/comm/CongestionController.hpp>
46 #include <anna/http/Request.hpp>
48 #include "Application.hpp"
49 #include "Request.hpp"
50 #include "Acceptor.hpp"
51 #include "Context.hpp"
57 void http4comm::Acceptor::initialize ()
58 throw (RuntimeException)
62 void http4comm::Acceptor::evRequest (comm::ClientSocket& clientSocket, const http::Request& request)
63 throw (RuntimeException)
65 LOGMETHOD (TraceMethod tm ("http4comm::Acceptor", "evRequest", ANNA_FILE_LOCATION));
67 comm::CongestionController& ccgg = comm::CongestionController::instantiate ();
69 if (ccgg.getAdvice (clientSocket) == comm::CongestionController::Advice::Discard)
72 const DataBlock& body = request.getBody ();
74 if (body.getSize () == 0)
75 throw RuntimeException ("La peticion no incorpora los parametros de operacion", ANNA_FILE_LOCATION);
78 string msg ("Body recibido: ");
79 msg += anna::functions::asString (body);
80 Logger::information (msg, ANNA_FILE_LOCATION);
83 if (comm::Codec::getType (body) != Request::Id)
84 throw RuntimeException ("El mensaje recibido no es una peticion aritmetica", ANNA_FILE_LOCATION);
88 a_testRequest.decode (body);
90 comm::IndexedDelivery* delivery = static_cast <Application&> (app::functions::getApp ()).getService ();
93 switch (a_testRequest.op) {
94 case '+': index = 0; break;
95 case '-': index = 1; break;
96 case '*': index = 2; break;
97 case '/': index = 3; break;
99 delivery->prepare (index);
100 delivery->send (a_testRequest);
102 http4comm::Application& app = static_cast <http4comm::Application&> (app::functions::getApp ());
103 app.getContext ()->create (a_testRequest.initTime, clientSocket);
105 catch (RuntimeException& ex) {