| 1 | /*
|
---|
| 2 | * endpoint_set.hpp
|
---|
| 3 | *
|
---|
| 4 | * Created on: 27.03.2013
|
---|
| 5 | * Author: mario
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #ifndef ENDPOINT_SET_HPP_
|
---|
| 9 | #define ENDPOINT_SET_HPP_
|
---|
| 10 |
|
---|
| 11 | // ariba
|
---|
| 12 | #include "endpoint.hpp"
|
---|
| 13 | #include "ariba/utility/transport/messages/shared_buffer.hpp"
|
---|
| 14 |
|
---|
| 15 | // boost
|
---|
| 16 | #include <boost/shared_ptr.hpp>
|
---|
| 17 | #include <boost/property_tree/ptree.hpp>
|
---|
| 18 |
|
---|
| 19 | // system
|
---|
| 20 | #include <vector>
|
---|
| 21 | #include <stdexcept>
|
---|
| 22 |
|
---|
| 23 | namespace ariba {
|
---|
| 24 |
|
---|
| 25 | using boost::property_tree::ptree;
|
---|
| 26 | using boost::shared_ptr;
|
---|
| 27 |
|
---|
| 28 | namespace addressing2 {
|
---|
| 29 |
|
---|
| 30 | /// forward declarations
|
---|
| 31 | class tcpip_endpoint;
|
---|
| 32 |
|
---|
| 33 | /**
|
---|
| 34 | * Holds a number of endpoints. (Usually of one particular node.)
|
---|
| 35 | */
|
---|
| 36 | class endpoint_set
|
---|
| 37 | {
|
---|
| 38 | public:
|
---|
| 39 |
|
---|
| 40 | // factories
|
---|
| 41 | static shared_ptr<endpoint_set> create_EndpointSet(const boost::property_tree::ptree& pt);
|
---|
| 42 | // static shared_ptr<endpoint_set> create_EndpointSet(const std::string& str);
|
---|
| 43 | static shared_ptr<endpoint_set> create_EndpointSet();
|
---|
| 44 |
|
---|
| 45 | endpoint_set();
|
---|
| 46 |
|
---|
| 47 | // endpoint_set(const std::string& str);
|
---|
| 48 | endpoint_set(const boost::property_tree::ptree& pt);
|
---|
| 49 | virtual ~endpoint_set();
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | /**
|
---|
| 53 | * Adds an endpoint to this set.
|
---|
| 54 | *
|
---|
| 55 | * (Ignores duplicates)
|
---|
| 56 | */
|
---|
| 57 | void add_endpoint(EndpointPtr endpoint);
|
---|
| 58 |
|
---|
| 59 | /**
|
---|
| 60 | * Adds all endpoints from the given set to this set.
|
---|
| 61 | *
|
---|
| 62 | * (Ignores duplicates)
|
---|
| 63 | */
|
---|
| 64 | void add_endpoints(const boost::shared_ptr<endpoint_set> endpoints);
|
---|
| 65 |
|
---|
| 66 | /**
|
---|
| 67 | * @return Human readable string representation of this endpoint-set.
|
---|
| 68 | */
|
---|
| 69 | std::string to_string() const;
|
---|
| 70 |
|
---|
| 71 | /**
|
---|
| 72 | * @return a vector of all tcpip_endpoints in this set
|
---|
| 73 | */
|
---|
| 74 | const std::vector<shared_ptr<tcpip_endpoint> >& get_tcpip_endpoints() const;
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | * This function serializes this endpoint_set with all its endpoints
|
---|
| 78 | * into a shared buffer, which then can be sent to another node.
|
---|
| 79 | *
|
---|
| 80 | * @return A byte-representation of this set saved into a shared_buffer.
|
---|
| 81 | */
|
---|
| 82 | reboost::shared_buffer_t serialize() const;
|
---|
| 83 |
|
---|
| 84 | /**
|
---|
| 85 | * Recreates an endpoint_set from a shared buffer.
|
---|
| 86 | *
|
---|
| 87 | * ---> Complementary to »endpoint_set::serialize_into_shared_buffer()«
|
---|
| 88 | *
|
---|
| 89 | * @return remaining sub-buffer
|
---|
| 90 | */
|
---|
| 91 | reboost::shared_buffer_t deserialize(reboost::shared_buffer_t buff);
|
---|
| 92 |
|
---|
| 93 |
|
---|
| 94 | /**
|
---|
| 95 | * @return total number of endpoints in this set
|
---|
| 96 | */
|
---|
| 97 | int count() const
|
---|
| 98 | {
|
---|
| 99 | return tcpip_endpoints.size();
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | private:
|
---|
| 103 | std::vector<shared_ptr<tcpip_endpoint> > tcpip_endpoints;
|
---|
| 104 | };
|
---|
| 105 |
|
---|
| 106 | typedef boost::shared_ptr<endpoint_set> EndpointSetPtr;
|
---|
| 107 | typedef boost::shared_ptr<const endpoint_set> const_EndpointSetPtr;
|
---|
| 108 |
|
---|
| 109 | }} /* namespace addressing2::ariba */
|
---|
| 110 | #endif /* ENDPOINT_SET_HPP_ */
|
---|