1 // ANNA - Anna is Not Nothingness Anymore
3 // (c) Copyright 2005-2014 Eduardo Ramos Testillano & Francisco Ruiz Rayo
5 // http://redmine.teslayout.com/projects/anna-suite
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 the copyright holder 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_Device_hpp
38 #define anna_comm_Device_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 un dispositivo de Red.
61 Un Host puede tener asociado un numero indeterminado de dispositivos de red.
63 El metodo Network::find(in_addr_t) creara un nuevo dispositivo de red.
68 Estados en los que puede estar un dispositivo de red.
70 struct Status { enum _v { Down, Up }; };
73 Devuelve la direccion asociada a este instancia.
74 \return La direccion asociada a este instancia.
76 in_addr_t getAddress() const throw() { return a_address; }
79 Devuelve el estado asociado al dispositivo.
80 \return el estado asociado al dispositivo.
82 Status::_v getStatus() const throw() { return a_status; }
85 Establece el estado del dispositivo.
86 \param status Nuevo estado del dispositivo.
88 void setStatus(const Status::_v status) throw() { a_status = status; }
91 Operador de comparacion.
92 \param right Direccion con la comparar.
93 @return \em true si la direccion recibida como parametro coincide con esta.
94 \em false en otro caso.
96 bool operator == (const Device& right) const throw() { return a_address == right.a_address; }
99 Operador de comparacion.
100 \param right Direccion con la comparar.
101 @return \em true si la direccion recibida como parametro coincide con esta.
102 \em false en otro caso.
104 bool operator == (const in_addr_t& right) const throw() { return a_address == right; }
107 Operador de comparacion.
108 \param ip Direccion con la comparar. En formato A.B.C.D.
109 @return \em true si la direccion recibida como parametro coincide con esta.
110 \em false en otro caso.
112 bool operator == (const char* ip) const throw() { return a_address == inet_addr(ip); }
115 Operador de comparacion.
116 \param ip Direccion con la comparar. En formato A.B.C.D.
117 @return \em true si la direccion recibida como parametro coincide con esta.
118 \em false en otro caso.
120 bool operator == (const std::string& ip) const throw() { return a_address == inet_addr(ip.c_str()); }
124 @return \em true si la direccin recibida como par�etro coincide con �ta o
125 \em false en otro caso.
127 bool operator != (const Device& right) const throw() { return a_address != right.a_address; }
131 @return \em true si la direccin recibida como par�etro no coincide con �ta o
132 \em false en otro caso.
134 bool operator != (const in_addr_t right) const throw() { return a_address != right; }
137 Devuelve una cadena la informacion mas relevante de esta instancia.
138 @return una cadena la informacion mas relevante de esta instancia.
140 std::string asString() const throw();
143 Devuelve un documento XML con la informacion mas relevante de esta instancia.
144 \param parent Nodo XML del que deben depender los datos a crear.
145 @return Un documento XML con la informacion mas relevante de esta instancia.
147 xml::Node* asXML(xml::Node* parent) const throw(RuntimeException);
150 Incorpora los paremetros de esta instancia como atributos del nodo XML
151 recibido como parametro.
152 \param node Nodo del que dependen los atributos a crear.
154 void asAttribute(xml::Node* node) const throw(RuntimeException);
157 Devuelve el nombre de esta clase. Se puede invocar desde \code template <class T>::asString (const T*); \endcode
158 \return Devuelve el nombre de esta clase.
160 static const char* className() throw() { return "anna::comm::Device"; }
163 Devuelve la direccion INET recibida como parametro en formato cadena.
164 \param address Direccion INET a convertir.
165 \return la direccion INET recibida como parametro en formato cadena.
167 static std::string asString(const in_addr_t& address) throw();
170 Devuelve la dirección IP recibida como cadena en un tipo in_addr_t.
171 \return la dirección IP recibida como cadena en un tipo in_addr_t.
173 static in_addr_t asAddress(const std::string& ip) throw() { return inet_addr(ip.c_str()); }
178 \param ip Texto con la direccin IP en formato A.B.C.D.
180 Device(const char* ip) : a_address(inet_addr(ip)), a_status(Status::Up) {;}
184 \param ip Texto con la direccin IP en formato A.B.C.D.
186 Device(const std::string& ip) : a_address(inet_addr(ip.c_str())), a_status(Status::Up) {;}
190 \param address Direccin IP de esta instancia
192 Device(const in_addr_t& address) : a_address(address), a_status(Status::Up) {;}
196 \param other Dispositivo
198 Device(const Device& other) : a_address(other.a_address), a_status(Status::Up) {;}
201 const in_addr_t a_address;
204 friend class Network;