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 - Methods and variables
57 struct functions : public anna::app::functions {
59 Returns the host name over which we are executing our process.
60 @return host name over which we are executing our process.
62 static std::string getHostName() throw(RuntimeException);
66 Resolves the host name provided with the first IP returned by the system.
67 Aliases and their addresses are traced as well as the official host name.
69 @param hostname Logical name for the server used to resolve (could be www.gopher.net i.e.).
71 @return First IP address returned by the system.
73 \see man gethostbyname.
75 static std::string resolveIP(const char* hostname) throw(RuntimeException);
78 Returns our application instance on anna.comm layer.
79 @return Reference to our application instance on anna.comm layer.
81 static comm::Application& getApp() throw(RuntimeException);
84 Encodes an integer number with 32 bits over a buffer with at least 4 bytes of length.
85 @param result Buffer where the number is encoded.
86 @param n Number to encode.
87 \return Buffer with the encoded number.
89 static const char* codeInteger(char* result, const int n) throw();
92 Encodes an integer number with 16 bits over a buffer with at least 2 bytes of length.
93 @param result Buffer where the number is encoded.
94 @param n Number to encode.
95 \return Buffer with the encoded number.
97 static const char* codeShort(char* result, const short int n) throw();
100 Encodes an integer number with 64 bits over a buffer with at least 8 bytes of length.
101 @param result Buffer where the number is encoded.
102 @param n Number to encode.
103 \return Buffer with the encoded number.
105 static const char* codeInteger64(char* result, const Integer64 n) throw();
108 Encodes a floating number with 32 bits (according to the standard IEEE-754) over a buffer with at least 4 bytes of length.
109 @param result Buffer where the number is encoded.
110 @param n Number to encode.
111 \return Buffer with the encoded number.
113 static const char* codeFloat(char* result, const float n) throw();
116 Encodes a floating number with 64 bits (according to the standard IEEE-754) over a buffer with at least 8 bytes of length.
117 @param result Buffer where the number is encoded.
118 @param n Number to encode.
119 \return Buffer with the encoded number.
121 static const char* codeDouble(char* result, const double n) throw();
124 Decodes an 32 bits integer number contained in a 4-bytes buffer.
125 @param data Buffer with the encoded number.
126 @return Value for the number contained in the buffer.
128 static int decodeInteger(const char* data) throw();
131 Decodes an 16 bits integer number contained in a 2-bytes buffer.
132 @param data Buffer with the encoded number.
133 @return Value for the number contained in the buffer.
135 static short int decodeShort(const char* data) throw();
138 Decodes an 64 bits integer number contained in a 8-bytes buffer.
139 @param data Buffer with the encoded number.
140 @return Value for the number contained in the buffer.
142 static Integer64 decodeInteger64(const char* data) throw();
145 Decodes an 32 bits floating number (according to the standard IEEE-754) contained in a 4-bytes buffer.
146 @param data Buffer with the encoded number.
147 @return Value for the number contained in the buffer.
149 static float decodeFloat(const char* data) throw();
152 Decodes an 64 bits floating number (according to the standard IEEE-754) contained in a 8-bytes buffer.
153 @param data Buffer with the encoded number.
154 @return Value for the number contained in the buffer.
156 static double decodeDouble(const char* data) throw();