Skip to content

Commit

Permalink
Deprecate all versions of send_tuple
Browse files Browse the repository at this point in the history
  • Loading branch information
Neverlord committed Jan 27, 2015
1 parent 1a3de3f commit 98c77c1
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 56 deletions.
2 changes: 1 addition & 1 deletion libcaf_core/caf/detail/proper_actor.hpp
Expand Up @@ -301,7 +301,7 @@ class proper_actor<Base, Policies, true>
// auto e = this->new_mailbox_element(this, std::move(msg));
// this->m_mailbox.enqueue(e);
} else {
this->delayed_send_tuple(this, d, std::move(msg));
this->delayed_send(this, d, std::move(msg));
}
m_pending_timeouts.push_back(tid);
return tid;
Expand Down
90 changes: 54 additions & 36 deletions libcaf_core/caf/local_actor.hpp
Expand Up @@ -138,28 +138,16 @@ class local_actor : public extend<abstract_actor>::with<mixin::memory_cached> {
}

/**************************************************************************
* send asynchronous messages *
* send asynchronous messages *
**************************************************************************/

/**
* Sends `what` to the receiver specified in `dest`.
*/
void send_tuple(message_priority prio, const channel& whom, message what);

/**
* Sends `what` to the receiver specified in `dest`.
*/
inline void send_tuple(const channel& whom, message what) {
send_tuple(message_priority::normal, whom, std::move(what));
}

/**
* Sends `{what...} to `whom` using the priority `prio`.
*/
template <class... Ts>
inline void send(message_priority prio, const channel& whom, Ts&&... what) {
static_assert(sizeof...(Ts) > 0, "sizeof...(Ts) == 0");
send_tuple(prio, whom, make_message(std::forward<Ts>(what)...));
send_impl(prio, whom, make_message(std::forward<Ts>(what)...));
}

/**
Expand All @@ -168,8 +156,8 @@ class local_actor : public extend<abstract_actor>::with<mixin::memory_cached> {
template <class... Ts>
inline void send(const channel& whom, Ts&&... what) {
static_assert(sizeof...(Ts) > 0, "sizeof...(Ts) == 0");
send_tuple(message_priority::normal, whom,
make_message(std::forward<Ts>(what)...));
send_impl(message_priority::normal, whom,
make_message(std::forward<Ts>(what)...));
}

/**
Expand All @@ -181,8 +169,8 @@ class local_actor : public extend<abstract_actor>::with<mixin::memory_cached> {
detail::type_list<typename detail::implicit_conversions<
typename std::decay<Ts>::type
>::type...>{});
send_tuple(message_priority::normal, actor{whom.m_ptr.get()},
make_message(std::forward<Ts>(what)...));
send_impl(message_priority::normal, actor{whom.m_ptr.get()},
make_message(std::forward<Ts>(what)...));
}

/**
Expand All @@ -205,29 +193,14 @@ class local_actor : public extend<abstract_actor>::with<mixin::memory_cached> {
send_exit(whom.address(), reason);
}

/**
* Sends a message to `whom` with priority `prio`
* that is delayed by `rel_time`.
*/
void delayed_send_tuple(message_priority prio, const channel& whom,
const duration& rtime, message data);

/**
* Sends a message to `whom` that is delayed by `rel_time`.
*/
inline void delayed_send_tuple(const channel& whom, const duration& rtime,
message data) {
delayed_send_tuple(message_priority::normal, whom, rtime, std::move(data));
}

/**
* Sends a message to `whom` using priority `prio`
* that is delayed by `rel_time`.
*/
template <class... Ts>
void delayed_send(message_priority prio, const channel& whom,
const duration& rtime, Ts&&... args) {
delayed_send_tuple(prio, whom, rtime,
delayed_send_impl(prio, whom, rtime,
make_message(std::forward<Ts>(args)...));
}

Expand All @@ -236,8 +209,8 @@ class local_actor : public extend<abstract_actor>::with<mixin::memory_cached> {
*/
template <class... Ts>
void delayed_send(const channel& whom, const duration& rtime, Ts&&... args) {
delayed_send_tuple(message_priority::normal, whom, rtime,
make_message(std::forward<Ts>(args)...));
delayed_send_impl(message_priority::normal, whom, rtime,
make_message(std::forward<Ts>(args)...));
}

/**************************************************************************
Expand Down Expand Up @@ -433,6 +406,24 @@ class local_actor : public extend<abstract_actor>::with<mixin::memory_cached> {
attach(attachable_ptr{new functor_attachable(std::move(f))});
}

/**************************************************************************
* outdated member functions *
**************************************************************************/

// <backward_compatibility version="0.9">
inline void send_tuple(message_priority prio, const channel& whom,
message what) CAF_DEPRECATED;

inline void send_tuple(const channel& whom, message what) CAF_DEPRECATED;

inline void delayed_send_tuple(message_priority prio, const channel& whom,
const duration& rtime,
message data) CAF_DEPRECATED;

inline void delayed_send_tuple(const channel& whom, const duration& rtime,
message data) CAF_DEPRECATED;
// </backward_compatibility>

/**************************************************************************
* here be dragons: end of public interface *
**************************************************************************/
Expand Down Expand Up @@ -561,6 +552,9 @@ class local_actor : public extend<abstract_actor>::with<mixin::memory_cached> {
/** @endcond */

private:
void send_impl(message_priority prio, const channel& dest, message&& what);
void delayed_send_impl(message_priority prio, const channel& whom,
const duration& rtime, message data);
using super = combined_type;
std::function<void()> m_sync_failure_handler;
std::function<void()> m_sync_timeout_handler;
Expand All @@ -572,6 +566,30 @@ class local_actor : public extend<abstract_actor>::with<mixin::memory_cached> {
*/
using local_actor_ptr = intrusive_ptr<local_actor>;

// <backward_compatibility version="0.9">
inline void local_actor::send_tuple(message_priority prio, const channel& whom,
message what) {
send_impl(prio, whom, std::move(what));
}

inline void local_actor::send_tuple(const channel& whom, message what) {
send_impl(message_priority::normal, whom, std::move(what));
}

inline void local_actor::delayed_send_tuple(message_priority prio,
const channel& whom,
const duration& rtime,
message data) {
delayed_send_impl(prio, whom, rtime, std::move(data));
}

inline void local_actor::delayed_send_tuple(const channel& whom,
const duration& rtime,
message data) {
delayed_send_impl(message_priority::normal, whom, rtime, std::move(data));
}
// </backward_compatibility>

} // namespace caf

#endif // CAF_CONTEXT_HPP
2 changes: 1 addition & 1 deletion libcaf_core/caf/mixin/single_timeout.hpp
Expand Up @@ -54,7 +54,7 @@ class single_timeout : public Base {
this->enqueue(this->address(), invalid_message_id,
std::move(msg), this->host());
} else
this->delayed_send_tuple(this, d, std::move(msg));
this->delayed_send(this, d, std::move(msg));
} else
this->has_timeout(false);
}
Expand Down
2 changes: 1 addition & 1 deletion libcaf_core/caf/response_handle.hpp
Expand Up @@ -76,7 +76,7 @@ class response_handle<Self, message, nonblocking_response_handle_tag> {
std::forward<Ts>(args)...,
on<sync_timeout_msg>() >> [selfptr]() -> skip_message_t {
selfptr->handle_sync_timeout();
return {};
return skip_message();
}
};
m_self->bhvr_stack().push_back(std::move(bhvr), m_mid);
Expand Down
37 changes: 29 additions & 8 deletions libcaf_core/caf/send.hpp
Expand Up @@ -33,6 +33,18 @@

namespace caf {

// mark outdated functions as deprecated
inline void send_tuple_as(const actor& from, const channel& to,
message msg) CAF_DEPRECATED;

inline void send_tuple_as(const actor& from, const channel& to,
message_priority prio, message msg) CAF_DEPRECATED;

inline void anon_send_tuple(const channel& to, message msg) CAF_DEPRECATED;

inline void anon_send_tuple(const channel& to, message_priority prio,
message msg) CAF_DEPRECATED;

/**
* Sends `to` a message under the identity of `from`.
*/
Expand All @@ -54,29 +66,38 @@ inline void send_tuple_as(const actor& from, const channel& to,
}

/**
* Sends `to` a message under the identity of `from`.
* Sends `to` a message under the identity of `from` with priority `prio`.
*/
template <class... Ts>
void send_as(const actor& from, const channel& to, Ts&&... args) {
send_tuple_as(from, to, make_message(std::forward<Ts>(args)...));
void send_as(const actor& from, message_priority prio, const channel& to,
Ts&&... args) {
if (!to) {
return;
}
message_id mid;
to->enqueue(from.address(),
prio == message_priority::high ? mid.with_high_priority() : mid,
make_message(std::forward<Ts>(args)...), nullptr);
}

/**
* Sends `to` a message under the identity of `from`.
*/
template <class... Ts>
void send_as(const actor& from, const channel& to, message_priority prio,
Ts&&... args) {
send_tuple_as(from, to, prio, make_message(std::forward<Ts>(args)...));
void send_as(const actor& from, const channel& to, Ts&&... args) {
send_as(from, to, make_message(std::forward<Ts>(args)...));
}

/**
* Anonymously sends `to` a message.
*/
inline void anon_send_tuple(const channel& to, message msg) {
send_tuple_as(invalid_actor, to, std::move(msg));
send_as(invalid_actor, to, std::move(msg));
}

inline void anon_send_tuple(const channel& to, message_priority prio,
message msg) {
send_tuple_as(invalid_actor, to, prio, std::move(msg));
send_as(invalid_actor, to, prio, std::move(msg));
}

/**
Expand Down
10 changes: 5 additions & 5 deletions libcaf_core/src/local_actor.cpp
Expand Up @@ -105,7 +105,7 @@ void local_actor::reply_message(message&& what) {
}
auto& mid = m_current_node->mid;
if (mid.valid() == false || mid.is_response()) {
send_tuple(actor_cast<channel>(whom), std::move(what));
send(actor_cast<channel>(whom), std::move(what));
} else if (!mid.is_answered()) {
auto ptr = actor_cast<actor>(whom);
ptr->enqueue(address(), mid.response_id(), std::move(what), host());
Expand All @@ -125,8 +125,8 @@ void local_actor::forward_message(const actor& dest, message_priority prio) {
m_current_node->mid = invalid_message_id;
}

void local_actor::send_tuple(message_priority prio, const channel& dest,
message what) {
void local_actor::send_impl(message_priority prio, const channel& dest,
message&& what) {
if (!dest) {
return;
}
Expand All @@ -141,8 +141,8 @@ void local_actor::send_exit(const actor_addr& whom, uint32_t reason) {
send(actor_cast<actor>(whom), exit_msg{address(), reason});
}

void local_actor::delayed_send_tuple(message_priority prio, const channel& dest,
const duration& rel_time, message msg) {
void local_actor::delayed_send_impl(message_priority prio, const channel& dest,
const duration& rel_time, message msg) {
message_id mid;
if (prio == message_priority::high) {
mid = mid.with_high_priority();
Expand Down
8 changes: 4 additions & 4 deletions unit_testing/test_spawn.cpp
Expand Up @@ -283,7 +283,7 @@ void test_spawn() {
CAF_PRINT("test self->send()");
self->send(self, 1, 2, 3, true);
self->receive(on(1, 2, 3, true) >> [] { });
self->send_tuple(self, message{});
self->send(self, message{});
self->receive(on() >> [] { });
self->await_all_other_actors_done();
CAF_CHECKPOINT();
Expand Down Expand Up @@ -472,8 +472,8 @@ void test_spawn() {
);
// kill joe and bob
auto poison_pill = make_message(atom("done"));
anon_send_tuple(joe, poison_pill);
anon_send_tuple(bob, poison_pill);
anon_send(joe, poison_pill);
anon_send(bob, poison_pill);
self->await_all_other_actors_done();

function<actor (const string&, const actor&)> spawn_next;
Expand All @@ -489,7 +489,7 @@ void test_spawn() {
s->become (
others() >> [=] {
// forward message and die
s->send_tuple(pal, s->last_dequeued());
s->send(pal, s->last_dequeued());
s->quit();
}
);
Expand Down

0 comments on commit 98c77c1

Please sign in to comment.