1 // ANNA - Anna is Not 'N' Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // https://bitbucket.org/testillano/anna
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 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.
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 #ifndef anna_comm_functions_hpp
38 #define anna_comm_functions_hpp
40 #include <netinet/in.h>
44 #include <anna/app/functions.hpp>
55 functions - Metodos y variables
57 struct functions : public anna::app::functions {
59 Devuelve el nombre de la maquina sobre la que estamos ejecutando.
60 \return El nombre de la maquina sobre la que estamos ejecutando.
62 static std::string getHostName() throw(RuntimeException);
66 * Helper de uso externo que resuelve el nombre de la maquina recibido como parametro y devuelve
67 * la primera IP resuelta por el sistema. Tracea los aliases y sus direcciones IP, asi como el
68 * nombre oficial de la maquina.
70 * \param hostname Nombre logico del servidor que sera usado para resolver. Podria ser una cadena
71 * de la forma www.gopher.net
73 * \return Primera direccion IP retornadas por el sistema
75 * \see man gethostbyname.
77 static std::string resolveIP(const char* hostname) throw(RuntimeException); // EDU Nov 2012
80 Devuelve la referencia de la instancia de nuestra aplicación para trabajar en la
82 @return La referencia de la instancia de nuestra aplicación para trabajar en la
85 static comm::Application& getApp() throw(RuntimeException);
88 Codifica un entero de 32 bits en buffer que debe tener, al menos, 4 bytes de longitud.
89 @param result Buffer donde vamos a codificar el número.
90 @param n Nmero a codificar.
91 \return El buffer que contiene el número aplanado.
93 static const char* codeInteger(char* result, const int n) throw();
96 Codifica un entero de 16 bits en buffer que debe tener 2 bytes de longitud.
97 @param result Buffer donde vamos a codificar el número.
98 @param n Nmero a codificar.
99 \return El buffer que contiene el número aplanado.
101 static const char* codeShort(char* result, const short int n) throw();
104 Codifica un entero de 64 bits en buffer que debe tener, al menos, 8 bytes de longitud.
105 @param result Buffer donde vamos a codificar el numero.
106 @param n numero a codificar.
107 \return El buffer que contiene el numero aplanado.
109 static const char* codeInteger64(char* result, const Integer64 n) throw();
112 * Codifica un número en coma flotante de 32 bits según el estandard IEEE-754, en un buffer
113 * que debe tener, al menos, 4 bytes de longitud.
114 * @param result Buffer donde vamos a codificar el número.
115 * @param n Nmero a codificar.
116 * \return El buffer que contiene el número aplanado.
118 static const char* codeFloat(char* result, const float n) throw();
121 * Codifica un número en coma flotante de 64 bits según el estandard IEEE-754, en un buffer
122 * que debe tener, al menos, 8 bytes de longitud.
123 * @param result Buffer donde vamos a codificar el número.
124 * @param n Nmero a codificar.
125 * \return El buffer que contiene el número aplanado.
127 static const char* codeDouble(char* result, const double n) throw();
130 Decodifica un numero entero de 32 bits contenido en un buffer de 4 bytes.
131 @param data Buffer que contiene el numero aplanado.
132 @return El valor del numero contenido en el buffer.
134 static int decodeInteger(const char* data) throw();
137 Decodifica un numero entero de 16 bits contenido en un buffer de 2 bytes.
138 @param data Buffer que contiene el numero aplanado.
139 @return El valor del numero contenido en el buffer.
141 static short int decodeShort(const char* data) throw();
144 Decodifica un numero entero de 64 bits contenido en un buffer de 8 bytes.
145 @param data Buffer que contiene el numero aplanado.
146 @return El valor del numero contenido en el buffer.
148 static Integer64 decodeInteger64(const char* data) throw();
151 Decodifica un numero en coma flotante de 32 bits contenido en un buffer de 4 bytes, y codificado
152 según el estandard IEEE-754.
153 @param data Buffer que contiene el numero aplanado.
154 @return El valor del numero contenido en el buffer.
156 static float decodeFloat(const char* data) throw();
159 Decodifica un numero en coma flotante de 64 bits contenido en un buffer de 8 bytes, y codificado
160 según el estandard IEEE-754.
161 @param data Buffer que contiene el numero aplanado.
162 @return El valor del numero contenido en el buffer.
164 static double decodeDouble(const char* data) throw();