| 1 | /*
|
---|
| 2 | * tcpip_endpoint.h
|
---|
| 3 | *
|
---|
| 4 | * Created on: 26.03.2013
|
---|
| 5 | * Author: mario
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef TCPIP_ENDPOINT_HPP_
|
---|
| 9 | #define TCPIP_ENDPOINT_HPP_
|
---|
| 10 |
|
---|
| 11 | // TODO: maybe move this class ariba/utility/transport.. ?
|
---|
| 12 |
|
---|
| 13 | #include "endpoint.hpp"
|
---|
| 14 |
|
---|
| 15 | // boost
|
---|
| 16 | #include <boost/asio/ip/tcp.hpp>
|
---|
| 17 | #include <boost/shared_ptr.hpp>
|
---|
| 18 |
|
---|
| 19 | using boost::shared_ptr;
|
---|
| 20 |
|
---|
| 21 | namespace ariba {
|
---|
| 22 | namespace addressing2 {
|
---|
| 23 |
|
---|
| 24 | class tcpip_endpoint: public endpoint
|
---|
| 25 | {
|
---|
| 26 | public:
|
---|
| 27 | /**
|
---|
| 28 | * Implements »endpoint«
|
---|
| 29 | * @see endpoint.h
|
---|
| 30 | *
|
---|
| 31 | * NOTE: An endpoint is designed as an unmutable object!
|
---|
| 32 | */
|
---|
| 33 |
|
---|
| 34 | /// factories
|
---|
| 35 | static boost::shared_ptr<tcpip_endpoint> create_TcpIP_Endpoint(
|
---|
| 36 | const boost::asio::ip::tcp::endpoint& asio_endpoint);
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | /// constructors
|
---|
| 40 |
|
---|
| 41 | /**
|
---|
| 42 | * Creates a new »tcpip_endpoint« from a string representation.
|
---|
| 43 | * ---> NOT complementary to »to_string()«
|
---|
| 44 | */
|
---|
| 45 | tcpip_endpoint(const std::string& ip_addr, const int port);
|
---|
| 46 |
|
---|
| 47 | /**
|
---|
| 48 | * Creates a new »tcpip_endpoint« from a byte array.
|
---|
| 49 | * ---> Complementary to »to_byte_array()«
|
---|
| 50 | *
|
---|
| 51 | * May throw »invalid_argument« exception.
|
---|
| 52 | */
|
---|
| 53 | tcpip_endpoint(const ENDPOINT_TYPE type, const uint8_t* const byte_array, const int read_max);
|
---|
| 54 |
|
---|
| 55 | /**
|
---|
| 56 | * Creates a new »tcpip_endpoint« from an ASIO tcp::endpoint.
|
---|
| 57 | * ---> Complementary to »tcpip_endpoint::to_asio()«
|
---|
| 58 | */
|
---|
| 59 | tcpip_endpoint(const boost::asio::ip::tcp::endpoint& asio_endpoint);
|
---|
| 60 |
|
---|
| 61 | virtual ~tcpip_endpoint();
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /// from superclass
|
---|
| 65 | virtual ENDPOINT_CATEGORY get_category() const;
|
---|
| 66 | virtual ENDPOINT_TYPE get_type() const;
|
---|
| 67 | virtual std::string to_string() const;
|
---|
| 68 | virtual size_t to_byte_array(uint8_t* buffer) const;
|
---|
| 69 | virtual int size() const;
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | /**
|
---|
| 73 | * @return An equivalent ASIO tcp::endpoint
|
---|
| 74 | */
|
---|
| 75 | const boost::asio::ip::tcp::endpoint& to_asio() const;
|
---|
| 76 |
|
---|
| 77 | /**
|
---|
| 78 | * @return »true« if rhs points to the same Address:Port pair,
|
---|
| 79 | * otherwise returns »false«.
|
---|
| 80 | */
|
---|
| 81 | bool equals(const shared_ptr<tcpip_endpoint>& rhs) const;
|
---|
| 82 |
|
---|
| 83 |
|
---|
| 84 | private:
|
---|
| 85 | boost::asio::ip::tcp::endpoint asio_endpoint;
|
---|
| 86 | };
|
---|
| 87 |
|
---|
| 88 | typedef boost::shared_ptr<tcpip_endpoint> TcpIP_EndpointPtr;
|
---|
| 89 | //typedef boost::shared_ptr<const tcpip_endpoint> const_TcpIP_EndpointPtr;
|
---|
| 90 |
|
---|
| 91 | }} /* namespace ariba::addressing2 */
|
---|
| 92 | #endif /* TCPIP_ENDPOINT_HPP_ */
|
---|