1 //  Copyright (c) 2007-2013 Hartmut Kaiser
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #ifndef HPX_RUNTIME_NAMING_ADDRESS_HPP
7 #define HPX_RUNTIME_NAMING_ADDRESS_HPP
8 
9 #include <hpx/config.hpp>
10 #include <hpx/runtime/components/component_type.hpp>
11 #include <hpx/runtime/naming/name.hpp>
12 #include <hpx/runtime/naming_fwd.hpp>
13 #include <hpx/runtime/serialization/serialization_fwd.hpp>
14 #include <hpx/traits/is_bitwise_serializable.hpp>
15 
16 #include <cstdint>
17 #include <iosfwd>
18 
19 #include <hpx/config/warnings_prefix.hpp>
20 
21 ///////////////////////////////////////////////////////////////////////////////
22 //  address serialization format version
23 #define HPX_ADDRESS_VERSION 0x20
24 
25 ///////////////////////////////////////////////////////////////////////////////
26 namespace hpx { namespace naming
27 {
28     struct HPX_EXPORT address
29     {
30         typedef std::int32_t component_type;
31         typedef std::uint64_t address_type;
32 
33         ///////////////////////////////////////////////////////////////////////
addresshpx::naming::address34         address()
35           : locality_(), type_(components::component_invalid), address_(0)
36         {}
37 
addresshpx::naming::address38         explicit address(gid_type const& l,
39                 component_type t = components::component_invalid)
40           : locality_(l), type_(t), address_(0)
41         {}
42 
addresshpx::naming::address43         address(gid_type const& l, component_type t, void* lva)
44           : locality_(l), type_(t),
45             address_(reinterpret_cast<address_type>(lva))
46         {}
47 
addresshpx::naming::address48         address(gid_type const& l, component_type t, address_type a)
49           : locality_(l), type_(t), address_(a)
50         {}
51 
52         // local only addresses
addresshpx::naming::address53         explicit address(void* lva,
54                 component_type t = components::component_invalid)
55           : type_(t),
56             address_(reinterpret_cast<address_type>(lva))
57         {}
58 
addresshpx::naming::address59         explicit address(address_type a)
60           : type_(components::component_invalid), address_(a)
61         {}
62 
operator boolhpx::naming::address63         explicit operator bool() const noexcept
64         {
65             return !!locality_ &&
66                 (components::component_invalid != type_ || 0 != address_);
67         }
68 
operator ==(address const & lhs,address const & rhs)69         friend bool operator==(address const& lhs, address const& rhs)
70         {
71             return lhs.type_ == rhs.type_ && lhs.address_ == rhs.address_ &&
72                    lhs.locality_ == rhs.locality_;
73         }
74 
75         gid_type locality_;     /// locality: ip4 address/port number
76         component_type type_;   /// component type this address is referring to
77         address_type address_;  /// address (sequence number)
78 
79     private:
80         friend HPX_EXPORT std::ostream& operator<<(std::ostream&, address const&);
81 
82         // serialization support
83         friend class hpx::serialization::access;
84 
85         template <typename Archive>
86         void save(Archive& ar, const unsigned int version) const;
87 
88         template <typename Archive>
89         void load(Archive& ar, const unsigned int version);
90 
91         HPX_SERIALIZATION_SPLIT_MEMBER();
92     };
93 }}
94 
95 HPX_IS_BITWISE_SERIALIZABLE(hpx::naming::address)
96 
97 #include <hpx/config/warnings_suffix.hpp>
98 
99 #endif /*HPX_RUNTIME_NAMING_ADDRESS_HPP*/
100