Remove dynamic exceptions
[anna.git] / example / timex / ArithmeticHTTPServer / Context.cpp
1 // ANNA - Anna is Not Nothingness Anymore                                                         //
2 //                                                                                                //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo                         //
4 //                                                                                                //
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 //
7
8
9 #include <anna/core/tracing/Logger.hpp>
10 #include <anna/core/functions.hpp>
11
12 #include <anna/timex/Engine.hpp>
13
14 #include <anna/core/util/Millisecond.hpp>
15
16 #include "Context.hpp"
17 #include "Transaction.hpp"
18
19 using namespace std;
20 using namespace anna;
21 using namespace test;
22
23 http4comm::Context::Context (anna::timex::Engine& timeController, const Millisecond& timeout) : 
24    anna::timex::Context<S64> ("http4comm", timeController, timeout) 
25 {;}
26
27 void http4comm::Context::create (const S64 id, comm::ClientSocket& clientSocket) 
28    noexcept(false)
29 {   
30    http4comm::Transaction* transaction = static_cast <http4comm::Transaction*> (anna::timex::Context <S64>::open (id, 0));
31
32    transaction->setClientSocket (&clientSocket);
33    
34    LOGINFORMATION (
35       string msg ("http4comm::Context::create | Id: ");
36       msg += functions::asHexString (id);
37       msg += " | ";
38       msg += transaction->asString ();
39       Logger::information (msg, ANNA_FILE_LOCATION);
40    );
41 }
42
43 /**
44  * Si el fuera necesaria la instancia de una transación y no hay ninguna otra marcada como "no-usada" se
45  * crearía una nueva instancia.
46  */
47 anna::timex::Transaction* http4comm::Context::createTransaction (const int /*classType*/) 
48    
49 {
50    // Si nuestra aplicación tratara más de un tipo de transación tendríamos que obtenerla de
51    // distintos Recycler, uno para cada tipo de transacción.
52    return a_transactions.create ();
53 }
54
55 /**
56  * Cuando la instancia dela transación no se esté usando se marca como no-usada.
57  */
58 void http4comm::Context::releaseTransaction (anna::timex::Transaction* tt) 
59    
60 {
61    // Si nuestra aplicación tratata más de un tipo tendríamos que obtener el tipo 
62    // de la transación y liberar la transación en el Recycler adecuado.
63    http4comm::Transaction* aux = static_cast <http4comm::Transaction*> (tt);
64    a_transactions.release (aux);
65 }
66
67
68 /**
69  * Interpreta el identificador de la transación como cadena
70  */
71 string http4comm::Context::identifierAsString (const S64& id) const
72    
73 {
74    return functions::asHexString (id);
75 }
76
77 /*
78  * Interpreta el contexto de la transación para obtener su Id de aplicación.
79  */
80 const S64& http4comm::Context::contextAsIdentifier (const void* cc) const 
81    
82 {
83    return *((S64*) cc);
84 }