Updated license
[anna.git] / include / anna / comm / TransportFactory.hpp
1 // ANNA - Anna is Not Nothingness Anymore
2 //
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
4 //
5 // https://bitbucket.org/testillano/anna
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions
9 // are met:
10 //
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
16 // distribution.
17 //     * Neither the name of Google Inc. 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.
20 //
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.
32 //
33 // Authors: eduardo.ramos.testillano@gmail.com
34 //          cisco.tierra@gmail.com
35
36
37 #ifndef anna_comm_TransportFactory_hpp
38 #define anna_comm_TransportFactory_hpp
39
40 #include <anna/core/RuntimeException.hpp>
41 #include <anna/core/mt/NRMutex.hpp>
42 #include <anna/core/functions.hpp>
43
44 namespace anna {
45
46 namespace xml {
47 class Node;
48 }
49
50 namespace comm {
51
52 class Transport;
53 class ClientSocket;
54
55 /**
56    Interfaz que deben cumplir los gestores de capas de transporte.
57 */
58 class TransportFactory : public NRMutex {
59 public:
60   /**
61      Devuelve el nombre logico de esta factoria de capas de transporte.
62      \return el nombre logico de esta factoria de capas de transporte.
63   */
64   const std::string& getName() const throw() { return a_name; }
65
66   /**
67      Devuelve la longitud maxima  que puede contener el buffer intermedio antes de cerrar el socket
68      por considerar que no puede sincronizarlo. Un valor 0 indica que no ha sido establecido
69      ningun valor maximo, por lo que el valor a usar sera el indicado por
70      anna::comm::Transport::DefaultMaxSize.
71   */
72   int getOverQuotaSize() const throw() { return a_overQuotaSize; }
73
74   /**
75      Establece la longitud maxima que puede contener el buffer intermedio antes de cerrar el socket
76      por considerar que no puede sincronizarlo.
77      \param overQuotaSize longitud maxima que puede contener el buffer intermedio antes de cerrar el socket
78      por considerar que no puede sincronizarlo.
79   */
80   void setOverQuotaSize(const int overQuotaSize) throw() { a_overQuotaSize = overQuotaSize; }
81
82   /**
83      Devuelve una cadena con la informacion relevante sobre esta instancia.
84      \return una cadena con la informacion relevante sobre esta instancia.
85   */
86   std::string asString() const throw();
87
88   /**
89      Devuelve un documento XML con la informacion relevante sobre esta instancia.
90      \param parent Nodo XML del que debe depender el documento generado.
91      \return un documento XML con la informacion relevante sobre esta instancia.
92   */
93   xml::Node* asXML(xml::Node* parent) const throw();
94
95 protected:
96   /**
97      Constructor
98      \param name Nombre logico de esta factoria de capas de transporte.
99   */
100   TransportFactory(const char* name) : a_name(name), a_overQuotaSize(0) {;}
101
102   /**
103      Crea una instancia del protocolo de transporte asociado a esta factoria.
104      \return La instancia de un nuevo protocolo de transporte.
105      \warning Cada uno de los transportes obtenidos debera ser liberado invocando a #release.
106   */
107   virtual Transport* create() throw()  = 0;
108
109   /**
110      Libera la instancia del transporte recibida como parametro.
111      \param transport Instancia del protocolo de transporte a liberar.
112      \warning El transporte recibido como parametro debera haberse obtenido mediante #create.
113   */
114   virtual void release(Transport* transport) throw()  = 0;
115
116 private:
117   const std::string a_name;
118   int a_overQuotaSize;
119
120   friend class ClientSocket;
121 };
122
123 }
124 }
125
126 #endif