15 #ifndef GCOMM_PROTOLAY_HPP
16 #define GCOMM_PROTOLAY_HPP
18 #include "gcomm/view.hpp"
21 #include "gcomm/datagram.hpp"
23 #include "gu_logger.hpp"
24 #include "gu_datetime.hpp"
25 #include "gu_config.hpp"
42 std::ostream& operator<<(std::ostream&,
const ProtoUpMeta&);
72 void connect(Protolay*, Protolay*);
73 void disconnect(Protolay*, Protolay*);
93 const uint8_t user_type = 0xff,
94 const Order order = O_DROP,
95 const int64_t to_seq = -1,
96 const int err_no = 0) :
98 source_view_id_ (source_view_id ),
99 user_type_ (user_type ),
103 view_ (view != 0 ?
new View(*view) : 0)
107 source_ (um.source_ ),
108 source_view_id_ (um.source_view_id_ ),
109 user_type_ (um.user_type_ ),
111 to_seq_ (um.to_seq_ ),
112 err_no_ (um.err_no_ ),
113 view_ (um.view_ ?
new View(*um.view_) : 0)
118 const UUID& source()
const {
return source_; }
120 const ViewId& source_view_id()
const {
return source_view_id_; }
122 uint8_t user_type()
const {
return user_type_; }
124 Order order()
const {
return order_; }
126 int64_t to_seq()
const {
return to_seq_; }
128 int err_no()
const {
return err_no_; }
130 bool has_view()
const {
return view_ != 0; }
132 const View& view()
const {
return *view_; }
138 ViewId const source_view_id_;
139 uint8_t
const user_type_;
141 int64_t
const to_seq_;
146 inline std::ostream& gcomm::operator<<(std::ostream& os,
const ProtoUpMeta& um)
148 os <<
"proto_up_meta: { ";
149 if (not (um.source() == UUID::nil()))
151 os <<
"source=" << um.source() <<
",";
153 if (um.source_view_id().type() != V_NONE)
155 os <<
"source_view_id=" << um.source_view_id() <<
",";
157 os <<
"user_type=" <<
static_cast<int>(um.user_type()) <<
",";
158 os <<
"to_seq=" << um.to_seq() <<
",";
159 if (um.has_view() ==
true)
161 os <<
"view=" << um.view();
172 const Order order = O_SAFE,
173 const UUID& uuid = UUID::nil(),
174 const int segment = 0) :
175 user_type_ (user_type),
181 uint8_t user_type()
const {
return user_type_; }
182 Order order()
const {
return order_; }
183 const UUID& source()
const {
return source_; }
184 int segment()
const {
return segment_; }
186 const uint8_t user_type_;
194 typedef std::list<Protolay*> CtxList;
196 CtxList down_context_;
216 virtual void connect(
bool) { }
217 virtual void close(
bool force =
false) { }
218 virtual void close(
const UUID& uuid) { }
226 if (std::find(up_context_.begin(),
228 up) != up_context_.end())
230 gu_throw_fatal <<
"up context already exists";
232 up_context_.push_back(up);
235 void set_down_context(
Protolay *down)
237 if (std::find(down_context_.begin(),
239 down) != down_context_.end())
241 gu_throw_fatal <<
"down context already exists";
243 down_context_.push_back(down);
249 if ((i = std::find(up_context_.begin(),
251 up)) == up_context_.end())
253 gu_throw_fatal <<
"up context does not exist";
255 up_context_.erase(i);
259 void unset_down_context(
Protolay* down)
262 if ((i = std::find(down_context_.begin(),
264 down)) == down_context_.end())
266 gu_throw_fatal <<
"down context does not exist";
268 down_context_.erase(i);
274 if (up_context_.empty() ==
true)
276 gu_throw_fatal <<
this <<
" up context(s) not set";
279 CtxList::iterator i, i_next;
280 for (i = up_context_.begin(); i != up_context_.end(); i = i_next)
282 i_next = i, ++i_next;
283 (*i)->handle_up(
this, dg, up_meta);
290 if (down_context_.empty() ==
true)
292 log_warn <<
this <<
" down context(s) not set";
297 for (CtxList::iterator i = down_context_.begin();
298 i != down_context_.end(); ++i)
300 const size_t hdr_offset(dg.header_offset());
301 int err = (*i)->handle_down(dg, down_meta);
304 if (hdr_offset != dg.header_offset())
316 virtual void handle_stable_view(
const View& view) { }
318 void set_stable_view(
const View& view)
320 for (CtxList::iterator i(down_context_.begin());
321 i != down_context_.end(); ++i)
323 (*i)->handle_stable_view(view);
327 virtual gu::datetime::Date handle_timers()
329 return gu::datetime::Date::max();
332 virtual bool set_param(
const std::string& key,
const std::string& val)
337 const Protolay* id()
const {
return this; }
348 gu_throw_fatal <<
"Toplay handle_down() called";
359 gu_throw_fatal <<
"Bottomlay handle_up() called";
365 down->set_up_context(up);
366 up->set_down_context(down);
369 inline void gcomm::disconnect(Protolay* down, Protolay* up)
371 down->unset_up_context(up);
372 up->unset_down_context(down);
Definition: protolay.hpp:352
Message order type enumeration.
GComm exception definitions.
Definition: protolay.hpp:341
Definition: protolay.hpp:192
Datagram container.
Definition: datagram.hpp:151