Commit b09edcb0 authored by Jakob Otto's avatar Jakob Otto

Merge branch 'master' into topic/span-refactoring

parents bd83338c a0192a41
......@@ -22,70 +22,49 @@ namespace caf {
namespace net {
/// Implements the interface for transport and application policies and
/// dispatches member functions either to `decorator` or `fallback`.
template <class Decorator, class Fallback>
class dispatcher {
/// dispatches member functions either to `decorator` or `parent`.
template <class Object, class Parent>
class write_packet_decorator {
public:
dispatcher(Decorator& decorator, Fallback& fallback)
: decorator_(decorator), fallback_(fallback) {
dispatcher(Object& object, Parent& parent)
: object_(object), parent_(parent) {
// nop
}
template <class Header>
void write_packet(const Header& header, span<const byte> payload) {
decltype(write_packet_delegate_test<Decorator>(nullptr, header, payload)) x;
write_packet_delegate(x, header, payload);
object_.write_packet(parent_, header, payload);
}
actor_system& system() {
fallback_.system();
parent_.system();
}
void cancel_timeout(atom_value type, uint64_t id) {
fallback_.cancel_timeout(type, id);
parent_.cancel_timeout(type, id);
}
void set_timeout(timestamp tout, atom_value type, uint64_t id) {
fallback_.set_timeout(tout, type, id);
parent_.set_timeout(tout, type, id);
}
typename Fallback::transport_type& transport() {
return fallback_.transport_;
typename parent::transport_type& transport() {
return parent_.transport_;
}
typename Fallback::application_type& application() {
return fallback_.application_;
typename parent::application_type& application() {
return parent_.application_;
}
private:
template <class U, class Header>
static auto write_packet_delegate_test(U* x, const Header& hdr,
span<const byte> payload)
-> decltype(x->write_packet(hdr, payload), std::true_type());
template <class U>
static auto write_packet_delegate_test(...) -> std::false_type;
template <class Header>
void write_packet_delegate(std::true_type, const Header& header,
span<const byte> payload) {
decorator_.write_packet(header, payload);
}
template <class Header>
void write_packet_delegate(std::false_type, const Header& header,
span<const byte> payload) {
fallback_.write_packet(header, payload);
}
Object& decorator_;
Fallback& fallback_;
Object& object_;
Parent& parent_;
};
template <class Decorator, class Fallback>
dispatcher<Decorator, Fallback> make_dispatcher(Decorator& decorator,
Fallback& fallback) {
return {decorator, fallback};
template <class Object, class Parent>
write_packet_decorator<Object, Parent>
make_write_packet_decorator(Object& object, Parent& parent) {
return {object, parent};
}
} // namespace net
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment