10 #ifndef _GCOMM_VIEW_HPP_
11 #define _GCOMM_VIEW_HPP_
14 #include "gcomm/uuid.hpp"
15 #include "gcomm/types.hpp"
34 ViewId(
const ViewType type = V_NONE,
35 const UUID& uuid = UUID::nil(),
36 const uint32_t seq = 0) :
42 ViewId(
const ViewType type,
51 ViewType type()
const {
return type_; }
53 const UUID& uuid()
const {
return uuid_; }
55 uint32_t seq()
const {
return seq_; }
57 size_t unserialize(
const gu::byte_t* buf,
size_t buflen,
size_t offset);
59 size_t serialize(gu::byte_t* buf,
size_t buflen,
size_t offset)
const;
61 static size_t serial_size()
63 return UUID::serial_size() +
sizeof(
reinterpret_cast<ViewId*
>(0)->seq_);
66 bool operator<(
const ViewId& cmp)
const
72 return (seq_ < cmp.seq_ ||
74 (cmp.uuid_.older(uuid_) ||
75 (uuid_ == cmp.uuid_ && type_ < cmp.type_) ) ) );
78 bool operator==(
const ViewId& cmp)
const
80 return (seq_ == cmp.seq_ &&
85 bool operator!=(
const ViewId& cmp)
const
87 return !(*
this == cmp);
96 std::ostream& operator<<(std::ostream&,
const ViewId&);
98 typedef uint8_t SegmentId;
103 Node(SegmentId segment) : segment_(segment)
105 SegmentId segment()
const {
return segment_; }
106 bool operator==(
const Node& cmp)
const {
return true; }
111 inline std::ostream& operator<<(std::ostream& os,
const Node& n)
113 return (os << static_cast<int>(n.segment()) );
132 View(
const ViewId& view_id,
bool bootstrap =
false) :
133 bootstrap_ (bootstrap),
143 void add_member (
const UUID& pid, SegmentId segment);
145 void add_members (NodeList::const_iterator begin,
146 NodeList::const_iterator end);
148 void add_joined (
const UUID& pid, SegmentId segment);
149 void add_left (
const UUID& pid, SegmentId segment);
150 void add_partitioned (
const UUID& pid, SegmentId segment);
155 const NodeList& partitioned ()
const;
157 NodeList& members() {
return members_; }
159 bool is_member(
const UUID& uuid)
const
160 {
return members_.find(uuid) != members_.end(); }
162 bool is_joining(
const UUID& uuid)
const
163 {
return joined_.find(uuid) != joined_.end(); }
165 bool is_leaving(
const UUID& uuid)
const
166 {
return left_.find(uuid) != left_.end(); }
168 bool is_partitioning(
const UUID& uuid)
const
169 {
return partitioned_.find(uuid) != partitioned_.end(); }
172 ViewType type ()
const;
173 const ViewId& id ()
const;
174 const UUID& representative ()
const;
176 bool is_empty()
const;
177 bool is_bootstrap()
const {
return bootstrap_; }
189 std::ostream& operator<<(std::ostream&,
const View&);
193 #endif // _GCOMM_VIEW_HPP_