1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_comm_INetAddress_hpp
10 #define anna_comm_INetAddress_hpp
12 #include <sys/types.h>
13 #include <sys/socket.h>
14 #include <netinet/in.h>
15 #include <arpa/inet.h>
19 #include <anna/core/RuntimeException.hpp>
32 Network address abstraction.
39 INetAddress() : a_device(NULL), a_port(-1) {}
43 \param device Instance for device (address).
44 \param port Port number.
46 INetAddress(const Device* device, const int port = -1) : a_device(device), a_port(port) {;}
50 \param other Source network address.
52 INetAddress(const INetAddress& other) : a_device(other.a_device) , a_port(other.a_port) {;}
55 Returns the device (address) associated to this instance.
56 \param exceptionWhenNull Exception is launched in case the device returned is NULL.
57 \return Device (address) associated to this instance.
59 const Device* getDevice(const bool exceptionWhenNull = true) const throw(RuntimeException);
62 Returns the port associated to this instance.
63 \return Port associated to this instance.
65 int getPort() const throw() { return a_port; }
68 Sets the address for this instance.
69 \param device Address provided.
71 void setAddress(const Device* device) throw() { a_device = device; }
74 Sets the port for this instance.
75 \param port Port provided.
77 void setPort(const int port) throw() { a_port = port; }
81 \param right Source address to be copied.
83 INetAddress& operator = (const INetAddress& right) throw() { a_device = right.a_device; a_port = right.a_port; return *this; }
87 \param right Source address to be compared.
88 @return \em true when address provided is equal to this \em false in other case.
90 bool operator == (const INetAddress& right) const throw() { return a_device == right.a_device && a_port == right.a_port; }
93 Returns the initialized state for this network address.
94 @return \em true when initialized, \em false when not.
96 bool isNull() const throw() { return (a_device == NULL || a_port == -1); }
99 Clear the content for this instance.
101 void clear() throw() { a_device = NULL; a_port = -1; }
104 Returns string with relevant information for this instance.
105 @return string with relevant information for this instance.
107 std::string asString() const throw();
110 Returns string with low-level format relevant information for this instance.
111 @return string with low-level format relevant information for this instance.
113 std::string serialize() const throw();
116 Returns XML document with relevant information for this instance.
117 \param parent XML node from which created data will depend on.
118 @return XML document with relevant information for this instance.
120 xml::Node* asXML(xml::Node* parent) const throw(RuntimeException);
123 const Device* a_device;