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_INetAddress_hpp
38 #define anna_comm_INetAddress_hpp
40 #include <sys/types.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
47 #include <anna/core/RuntimeException.hpp>
60 Abstraccion de direcciones de red.
62 Facilita el uso de las direcciones de red.
69 INetAddress() : a_device(NULL), a_port(-1) {}
73 \param device Instancia del dispositivo.
74 \param port Numero de puerto.
76 INetAddress(const Device* device, const int port = -1) : a_device(device), a_port(port) {;}
80 \param other Direccin IP de la que obtener la informacin.
82 INetAddress(const INetAddress& other) : a_device(other.a_device) , a_port(other.a_port) {;}
85 Devuelve la direccion asociada a esta instancia.
86 \param exceptionWhenNull Indica si debemos lanzar una excepcion en caso de que el dispositivo
88 \return La direccion asociada a esta instancia.
90 const Device* getDevice(const bool exceptionWhenNull = true) const throw(RuntimeException);
93 Devuelve el puerto asociada a esta instancia.
94 \return El puerto asociada a esta instancia.
96 int getPort() const throw() { return a_port; }
99 Establece la direccion IP correspondiente a este objeto.
100 \param device Dispositivo de red asociado a este objeto.
102 void setAddress(const Device* device) throw() { a_device = device; }
105 Establece el puerto correspondiente a este objeto.
106 \param port Numero de puerto correspondiente a este objeto.
108 void setPort(const int port) throw() { a_port = port; }
112 \param right Direccin IP de la que obtener la informacin.
114 INetAddress& operator = (const INetAddress& right) throw() { a_device = right.a_device; a_port = right.a_port; return *this; }
117 Operador de comparacion.
118 \param right Direccion con la comparar.
119 @return \em true si la direccion recibida como parametro coincide con esta.
120 \em false en otro caso.
122 bool operator == (const INetAddress& right) const throw() { return a_device == right.a_device && a_port == right.a_port; }
125 Devuelve el estado de inicializacin de esta direccin de red.
126 @return \em true si no ha sido inicializa o \em false en otro caso.
128 bool isNull() const throw() { return (a_device == NULL || a_port == -1); }
131 Elimina el contenido de esta instancia.
133 void clear() throw() { a_device = NULL; a_port = -1; }
136 Devuelve una cadena la informacion mas relevante de esta instancia.
137 @return Una cadena la informacion mas relevante de esta instancia.
139 std::string asString() const throw();
142 Devuelve una cadena la informacion mas relevante de esta instancia en formato de bajo nivel.
143 @return Una cadena la informacion mas relevante de esta instancia en formato de bajo nivel.
145 std::string serialize() const throw();
148 Devuelve un documento XML con la informacion mas relevante de esta instancia.
149 \param parent Nodo XML del que deben depender los datos a crear.
150 @return Un documento XML con la informacion mas relevante de esta instancia.
152 xml::Node* asXML(xml::Node* parent) const throw(RuntimeException);
155 const Device* a_device;