Commit 232033c4 authored by Dominik Charousset's avatar Dominik Charousset

Rename {dispatcher => write_packet_decorator}

parent aee508be
...@@ -22,70 +22,49 @@ namespace caf { ...@@ -22,70 +22,49 @@ namespace caf {
namespace net { namespace net {
/// Implements the interface for transport and application policies and /// Implements the interface for transport and application policies and
/// dispatches member functions either to `decorator` or `fallback`. /// dispatches member functions either to `decorator` or `parent`.
template <class Decorator, class Fallback> template <class Object, class Parent>
class dispatcher { class write_packet_decorator {
public: public:
dispatcher(Decorator& decorator, Fallback& fallback) dispatcher(Object& object, Parent& parent)
: decorator_(decorator), fallback_(fallback) { : object_(object), parent_(parent) {
// nop // nop
} }
template <class Header> template <class Header>
void write_packet(const Header& header, span<const byte> payload) { void write_packet(const Header& header, span<const byte> payload) {
decltype(write_packet_delegate_test<Decorator>(nullptr, header, payload)) x; object_.write_packet(parent_, header, payload);
write_packet_delegate(x, header, payload);
} }
actor_system& system() { actor_system& system() {
fallback_.system(); parent_.system();
} }
void cancel_timeout(atom_value type, uint64_t id) { 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) { 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() { typename parent::transport_type& transport() {
return fallback_.transport_; return parent_.transport_;
} }
typename Fallback::application_type& application() { typename parent::application_type& application() {
return fallback_.application_; return parent_.application_;
} }
private: private:
template <class U, class Header> Object& object_;
static auto write_packet_delegate_test(U* x, const Header& hdr, Parent& parent_;
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_;
}; };
template <class Decorator, class Fallback> template <class Object, class Parent>
dispatcher<Decorator, Fallback> make_dispatcher(Decorator& decorator, write_packet_decorator<Object, Parent>
Fallback& fallback) { make_write_packet_decorator(Object& object, Parent& parent) {
return {decorator, fallback}; return {object, parent};
} }
} // namespace net } // 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