Commit 2c5604c6 authored by Dominik Charousset's avatar Dominik Charousset

Rename {unexpected => default}_handler

Relates #444.
parent b86b6c30
......@@ -153,7 +153,7 @@ private:
);
},
// simply ignore all requests until we have a connection
others >> skip_message
others >> skip
};
*/
}
......
......@@ -81,6 +81,7 @@ set (LIBCAF_CORE_SRCS
src/serializer.cpp
src/sequencer.cpp
src/shared_spinlock.cpp
src/skip.cpp
src/splitter.cpp
src/sync_request_bouncer.cpp
src/try_match.cpp
......
......@@ -54,7 +54,7 @@
#include "caf/actor_system.hpp"
#include "caf/deserializer.hpp"
#include "caf/scoped_actor.hpp"
#include "caf/skip_message.hpp"
#include "caf/skip.hpp"
#include "caf/actor_ostream.hpp"
#include "caf/function_view.hpp"
#include "caf/index_mapping.hpp"
......
......@@ -34,7 +34,7 @@
#include "caf/message.hpp"
#include "caf/duration.hpp"
#include "caf/ref_counted.hpp"
#include "caf/skip_message.hpp"
#include "caf/skip.hpp"
#include "caf/response_promise.hpp"
#include "caf/timeout_definition.hpp"
#include "caf/typed_response_promise.hpp"
......@@ -55,9 +55,9 @@ namespace caf {
namespace detail {
template <class... Ts>
struct has_skip_message {
struct has_skip {
static constexpr bool value =
disjunction<std::is_same<Ts, skip_message_t>::value...>::value;
disjunction<std::is_same<Ts, skip_t>::value...>::value;
};
class behavior_impl : public ref_counted {
......
......@@ -72,7 +72,7 @@ struct ctm_cmp<typed_mpi<In, type_list<Ts...>>,
template <class In, class Out>
struct ctm_cmp<typed_mpi<In, Out>,
typed_mpi<In, type_list<skip_message_t>>>
typed_mpi<In, type_list<skip_t>>>
: std::true_type { };
template <class In, class... Ts>
......
......@@ -28,7 +28,7 @@
#include "caf/optional.hpp"
#include "caf/result.hpp"
#include "caf/message.hpp"
#include "caf/skip_message.hpp"
#include "caf/skip.hpp"
#include "caf/typed_continue_helper.hpp"
#include "caf/detail/int_list.hpp"
......@@ -120,15 +120,15 @@ public:
return true;
}
inline bool visit(skip_message_t&) {
inline bool visit(skip_t&) {
return false;
}
inline bool visit(const skip_message_t&) {
inline bool visit(const skip_t&) {
return false;
}
inline bool visit(optional<skip_message_t>& x) {
inline bool visit(optional<skip_t>& x) {
if (x)
return false;
(*this)(x);
......
......@@ -24,7 +24,7 @@
#include "caf/unit.hpp"
#include "caf/optional.hpp"
#include "caf/delegated.hpp"
#include "caf/skip_message.hpp"
#include "caf/skip.hpp"
#include "caf/static_visitor.hpp"
#include "caf/response_promise.hpp"
#include "caf/typed_response_promise.hpp"
......@@ -63,8 +63,8 @@ struct optional_message_visitor_enable_tpl {
typename std::remove_const<T>::type,
none_t,
unit_t,
skip_message_t,
optional<skip_message_t>
skip_t,
optional<skip_t>
>::value
&& ! is_message_id_wrapper<T>::value
&& ! is_response_promise<T>::value;
......@@ -80,7 +80,7 @@ public:
return none;
}
inline opt_msg operator()(const skip_message_t&) const {
inline opt_msg operator()(const skip_t&) const {
return none;
}
......@@ -88,7 +88,7 @@ public:
return message{};
}
inline opt_msg operator()(optional<skip_message_t>& val) const {
inline opt_msg operator()(optional<skip_t>& val) const {
if (val)
return none;
return message{};
......
......@@ -65,10 +65,10 @@ public:
}
return delegated<message>{};
};
set_unexpected_handler(g);
set_default_handler(g);
return delegated<message>{};
};
set_unexpected_handler(f);
set_default_handler(f);
return {
[] {
// nop
......
......@@ -39,6 +39,7 @@ template <class, class, int> class actor_cast_access;
// -- variadic templates -------------------------------------------------------
template <class...> class result;
template <class...> class delegated;
template <class...> class typed_actor;
template <class...> class typed_response_promise;
......
......@@ -85,32 +85,24 @@ struct make_response_promise_helper<response_promise> {
} // namespace detail
/// @relates local_actor
/// Default handler function for unexpected messages
/// that sends the message back to the sender.
result<message> reflect_unexpected(local_actor*, const type_erased_tuple*);
/// Default handler function that sends the message back to the sender.
result<message> reflect(local_actor*, const type_erased_tuple*);
/// @relates local_actor
/// Default handler function for unexpected messages
/// that sends the message back to the sender and then quits.
result<message> reflect_unexpected_and_quit(local_actor*,
/// Default handler function that sends
/// the message back to the sender and then quits.
result<message> reflect_and_quit(local_actor*,
const type_erased_tuple*);
/// @relates local_actor
/// Default handler function for unexpected messages that
/// skips an unexpected message in order to handle it again
/// after a behavior change.
result<message> skip_unexpected(local_actor*, const type_erased_tuple*);
/// @relates local_actor
/// Default handler function for unexpected messages that prints
/// an unexpected message via `aout` and drops it afterwards.
result<message> print_and_drop_unexpected(local_actor*,
/// Default handler function that prints messages
/// message via `aout` and drops them afterwards.
result<message> print_and_drop(local_actor*,
const type_erased_tuple*);
/// @relates local_actor
/// Default handler function for unexpected messages that
/// drops unexpected messages without printing them.
result<message> drop_unexpected(local_actor*, const type_erased_tuple*);
/// Default handler function that simply drops messages.
result<message> drop(local_actor*, const type_erased_tuple*);
/// Base class for actors running on this node, either
/// living in an own thread or cooperatively scheduled.
......@@ -318,7 +310,7 @@ public:
// -- miscellaneous actor operations -----------------------------------------
/// Sets a custom handler for unexpected messages.
inline void set_unexpected_handler(unexpected_handler fun) {
inline void set_default_handler(unexpected_handler fun) {
unexpected_handler_ = std::move(fun);
}
......
......@@ -26,7 +26,7 @@
#include "caf/param.hpp"
#include "caf/optional.hpp"
#include "caf/match_case.hpp"
#include "caf/skip_message.hpp"
#include "caf/skip.hpp"
#include "caf/detail/int_list.hpp"
#include "caf/detail/try_match.hpp"
......
......@@ -29,7 +29,7 @@
#include "caf/config.hpp"
#include "caf/optional.hpp"
#include "caf/make_counted.hpp"
#include "caf/skip_message.hpp"
#include "caf/skip.hpp"
#include "caf/index_mapping.hpp"
#include "caf/allowed_unsafe_message_type.hpp"
......
......@@ -21,10 +21,10 @@
#define CAF_RESULT_HPP
#include "caf/none.hpp"
#include "caf/skip.hpp"
#include "caf/error.hpp"
#include "caf/message.hpp"
#include "caf/delegated.hpp"
#include "caf/skip_message.hpp"
namespace caf {
......@@ -32,11 +32,11 @@ enum result_runtime_type {
rt_value,
rt_error,
rt_delegated,
rt_skip_message
rt_skip
};
template <class... Ts>
struct result {
class result {
public:
result(Ts... xs) : flag(rt_value), value(make_message(std::move(xs)...)) {
// nop
......@@ -62,7 +62,7 @@ public:
// nop
}
result(skip_message_t) : flag(rt_skip_message) {
result(skip_t) : flag(rt_skip) {
// nop
}
......@@ -106,7 +106,7 @@ public:
// nop
}
result(skip_message_t) : flag(rt_skip_message) {
result(skip_t) : flag(rt_skip) {
// nop
}
......
......@@ -17,31 +17,43 @@
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#ifndef CAF_SKIP_MESSAGE_HPP
#define CAF_SKIP_MESSAGE_HPP
#ifndef CAF_SKIP_HPP
#define CAF_SKIP_HPP
#include <ostream>
#include <functional>
#include "caf/fwd.hpp"
namespace caf {
/// Optional return type for functors used in pattern matching
/// expressions. This type is evaluated by the runtime system
/// and can be used to intentionally skip messages.
struct skip_message_t {
constexpr skip_message_t() {}
/// @relates local_actor
/// Default handler function that leaves messages in the mailbox.
/// Can also be used inside custom message handlers to signalize
/// skipping to the runtime.
class skip_t {
public:
using fun = std::function<result<message>(local_actor* self,
const type_erased_tuple*)>;
constexpr skip_t() {
// nop
}
constexpr skip_t operator()() const {
return *this;
}
operator fun() const;
private:
static result<message> skip_fun_impl(local_actor*, const type_erased_tuple*);
};
/// Tells the runtime system to skip a message when used as message
/// handler, i.e., causes the runtime to leave the message in
/// the mailbox of an actor.
constexpr skip_message_t skip_message() {
return {};
}
// implemented in string_serialization.cpp
std::ostream& operator<<(std::ostream&, skip_message_t);
constexpr skip_t skip = skip_t{};
} // namespace caf
#endif // CAF_SKIP_MESSAGE_HPP
#endif // CAF_SKIP_HPP
......@@ -41,17 +41,17 @@ struct input_only<detail::type_list<Ts...>> {
using type = detail::type_list<typename Ts::input_types...>;
};
using skip_list = detail::type_list<skip_message_t>;
using skip_list = detail::type_list<skip_t>;
template <class Input, class RepliesToWith>
struct same_input : std::is_same<Input, typename RepliesToWith::input_types> {};
template <class Output, class RepliesToWith>
struct same_output_or_skip_message_t {
struct same_output_or_skip_t {
using other = typename RepliesToWith::output_types;
static constexpr bool value =
std::is_same<Output, typename RepliesToWith::output_types>::value ||
std::is_same<Output, type_list<skip_message_t>>::value;
std::is_same<Output, type_list<skip_t>>::value;
};
template <class SList>
......@@ -72,7 +72,7 @@ struct valid_input_predicate {
"contains at least one pattern that is "
"not defined in the actor's type");
static constexpr bool value = tl_exists<
filtered_slist, tbind<same_output_or_skip_message_t,
filtered_slist, tbind<same_output_or_skip_t,
output_types>::template type>::value;
// check whether given output matches in the filtered list
static_assert(value,
......@@ -110,7 +110,7 @@ struct valid_input {
// check for each element in IList that there's an element in SList that
// (1) has an identical input type list
// (2) has an identical output type list
// OR the output of the element in IList is skip_message_t
// OR the output of the element in IList is skip_t
static_assert(detail::tl_is_distinct<IList>::value,
"given pattern is not distinct");
static constexpr bool value =
......
......@@ -28,7 +28,7 @@ namespace caf {
blocking_actor::blocking_actor(actor_config& sys) : super(sys) {
is_blocking(true);
set_unexpected_handler(skip_unexpected);
set_default_handler(skip);
}
blocking_actor::~blocking_actor() {
......
......@@ -169,7 +169,7 @@ public:
send_to_acquaintances(message::from(ptr));
return message{};
};
set_unexpected_handler(fwd);
set_default_handler(fwd);
// return behavior
return {
[=](join_atom, const actor& other) {
......@@ -329,7 +329,7 @@ behavior proxy_broker::make_behavior() {
context());
return message{};
};
set_unexpected_handler(fwd);
set_default_handler(fwd);
// return dummy behavior
return {
[](const down_msg&) {
......
......@@ -39,21 +39,17 @@
namespace caf {
result<message> reflect_unexpected(local_actor*, const type_erased_tuple* x) {
result<message> reflect(local_actor*, const type_erased_tuple* x) {
return message::from(x);
}
result<message> reflect_unexpected_and_quit(local_actor* self,
result<message> reflect_and_quit(local_actor* self,
const type_erased_tuple* x) {
self->quit();
return reflect_unexpected(self, x);
return reflect(self, x);
}
result<message> skip_unexpected(local_actor*, const type_erased_tuple*) {
return skip_message();
}
result<message> print_and_drop_unexpected(local_actor* self,
result<message> print_and_drop(local_actor* self,
const type_erased_tuple* x) {
CAF_LOG_WARNING("unexpected message" << CAF_ARG(*x));
aout(self) << "*** unexpected message [id: " << self->id()
......@@ -62,7 +58,7 @@ result<message> print_and_drop_unexpected(local_actor* self,
return sec::unexpected_message;
}
result<message> drop_unexpected(local_actor*,
result<message> drop(local_actor*,
const type_erased_tuple*) {
return sec::unexpected_message;
}
......@@ -76,7 +72,7 @@ local_actor::local_actor(actor_config& cfg)
planned_exit_reason_(exit_reason::not_exited),
timeout_id_(0),
initial_behavior_fac_(std::move(cfg.init_fun)),
unexpected_handler_(print_and_drop_unexpected) {
unexpected_handler_(print_and_drop) {
if (cfg.groups != nullptr)
for (auto& grp : *cfg.groups)
join(grp);
......@@ -86,7 +82,7 @@ local_actor::local_actor()
: monitorable_actor(abstract_channel::is_abstract_actor_flag),
planned_exit_reason_(exit_reason::not_exited),
timeout_id_(0),
unexpected_handler_(print_and_drop_unexpected) {
unexpected_handler_(print_and_drop) {
// nop
}
......@@ -94,7 +90,7 @@ local_actor::local_actor(int init_flags)
: monitorable_actor(init_flags),
planned_exit_reason_(exit_reason::not_exited),
timeout_id_(0),
unexpected_handler_(print_and_drop_unexpected) {
unexpected_handler_(print_and_drop) {
// nop
}
......@@ -532,7 +528,7 @@ invoke_message_result local_actor::invoke_message(mailbox_element_ptr& ptr,
has_timeout(true);
auto sres = unexpected_handler_(this,
current_element_->msg.cvals().get());
if (sres.flag != rt_skip_message)
if (sres.flag != rt_skip)
visitor.visit(sres);
else
skipped = true;
......
......@@ -244,9 +244,9 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
// store any occurred error in a temporary variable returned at the end
std::string error;
auto res = extract({
[&](const std::string& arg) -> optional<skip_message_t> {
[&](const std::string& arg) -> optional<skip_t> {
if (arg.empty() || arg.front() != '-') {
return skip_message();
return skip();
}
auto i = shorts.find(arg.substr(0, 2));
if (i != shorts.end()) {
......@@ -256,13 +256,13 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
// this short opt comes with a value (no space), e.g., -x2
if (! i->second->fun(arg.substr(2))) {
error = "invalid value for " + i->second->name + ": " + arg;
return skip_message();
return skip();
}
insert_opt_name(i->second);
return none;
}
// no value given, try two-argument form below
return skip_message();
return skip();
}
insert_opt_name(i->second);
return none;
......@@ -273,11 +273,11 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
if (j->second->fun) {
if (eq_pos == std::string::npos) {
error = "missing argument to " + arg;
return skip_message();
return skip();
}
if (! j->second->fun(arg.substr(eq_pos + 1))) {
error = "invalid value for " + j->second->name + ": " + arg;
return skip_message();
return skip();
}
insert_opt_name(j->second);
return none;
......@@ -286,12 +286,12 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
return none;
}
error = "unknown command line option: " + arg;
return skip_message();
return skip();
},
[&](const std::string& arg1,
const std::string& arg2) -> optional<skip_message_t> {
const std::string& arg2) -> optional<skip_t> {
if (arg1.size() < 2 || arg1[0] != '-' || arg1[1] == '-') {
return skip_message();
return skip();
}
auto i = shorts.find(arg1.substr(0, 2));
if (i != shorts.end()) {
......@@ -299,18 +299,18 @@ message::cli_res message::extract_opts(std::vector<cli_arg> xs,
// this short opt either expects no argument or comes with a value
// (no space), e.g., -x2, so we have to parse it with the
// one-argument form above
return skip_message();
return skip();
}
CAF_ASSERT(arg1.size() == 2);
if (! i->second->fun(arg2)) {
error = "invalid value for option " + i->second->name + ": " + arg2;
return skip_message();
return skip();
}
insert_opt_name(i->second);
return none;
}
error = "unknown command line option: " + arg1;
return skip_message();
return skip();
}
});
return {res, std::move(opts), std::move(helpstr), std::move(error)};
......
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright (C) 2011 - 2015 *
* Dominik Charousset <dominik.charousset (at) haw-hamburg.de> *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#include "caf/skip.hpp"
#include "caf/result.hpp"
#include "caf/message.hpp"
namespace caf {
result<message> skip_t::skip_fun_impl(local_actor*, const type_erased_tuple*) {
return skip();
}
skip_t::operator fun() const {
return skip_fun_impl;
}
} // namespace caf
......@@ -65,7 +65,7 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
);
return delegated<message>{};
};
self->set_unexpected_handler(f);
self->set_default_handler(f);
return [] {
// nop
};
......@@ -85,7 +85,7 @@ behavior fan_out_fan_in(stateful_actor<splitter_state>* self,
}
);
};
set_unexpected_handler(f);
set_default_handler(f);
return {
others >> [=](const message& msg) {
self->state.rp = self->make_response_promise();
......
......@@ -211,7 +211,7 @@ public:
}
behavior make_behavior() override {
set_unexpected_handler(reflect_unexpected);
set_default_handler(reflect);
return {
[] {
// nop
......@@ -231,7 +231,7 @@ public:
}
behavior make_behavior() override {
set_unexpected_handler(reflect_unexpected);
set_default_handler(reflect);
return {
[] {
// nop
......
......@@ -43,7 +43,7 @@ public:
behavior make_behavior() override {
// reflecting a message increases its reference count by one
set_unexpected_handler(reflect_unexpected_and_quit);
set_default_handler(reflect_and_quit);
return {
[] {
// nop
......
......@@ -49,7 +49,7 @@ CAF_TEST(metaprogramming) {
using if2 = type_list<replies_to<int>::with<int>,
replies_to<int, double>::with<void>>;
using if3 = type_list<replies_to<int, double>::with<void>>;
using if4 = type_list<replies_to<int>::with<skip_message_t>,
using if4 = type_list<replies_to<int>::with<skip_t>,
replies_to<int, double>::with<void>>;
CAF_CHECK_EQUAL((ctm<if1, if2>::value), -1);
CAF_CHECK_NOT_EQUAL((ctm<if1, if3>::value), -1);
......
......@@ -49,7 +49,7 @@ struct sync_mirror : event_based_actor {
}
behavior make_behavior() override {
set_unexpected_handler(reflect_unexpected);
set_default_handler(reflect);
return {
[] {
// nop
......@@ -82,7 +82,7 @@ public:
: event_based_actor(cfg),
buddy_(buddy_arg) {
// don't pollute unit test output with (provoked) warnings
set_unexpected_handler(drop_unexpected);
set_default_handler(drop);
}
inline const actor& buddy() const {
......@@ -145,7 +145,7 @@ class C : public event_based_actor {
public:
C(actor_config& cfg) : event_based_actor(cfg) {
// don't pollute unit test output with (provoked) warnings
set_unexpected_handler(drop_unexpected);
set_default_handler(drop);
}
behavior make_behavior() override {
......@@ -223,12 +223,12 @@ printf("server id: %d\n", (int) self->id());
return self->delegate(worker, task);
},
[](idle_atom) {
return skip_message();
return skip();
}
);
},
[](request_atom) {
return skip_message();
return skip();
}
};
}
......@@ -261,7 +261,7 @@ CAF_TEST(test_void_res) {
CAF_TEST(pending_quit) {
auto mirror = system.spawn([](event_based_actor* self) -> behavior {
self->set_unexpected_handler(reflect_unexpected);
self->set_default_handler(reflect);
return {
[] {
// nop
......
......@@ -42,7 +42,7 @@ using sub4_atom = atom_constant<atom("sub4")>;
CAF_TEST(test_serial_reply) {
actor_system system;
auto mirror_behavior = [=](event_based_actor* self) -> behavior {
self->set_unexpected_handler(reflect_unexpected);
self->set_default_handler(reflect);
return {
[] {
// nop
......
......@@ -74,9 +74,9 @@ struct fixture {
void await_down(const actor& x) {
self->monitor(x);
self->receive(
[&](const down_msg& dm) -> optional<skip_message_t> {
[&](const down_msg& dm) -> optional<skip_t> {
if (dm.source != x)
return skip_message();
return skip();
return none;
}
);
......
......@@ -192,10 +192,10 @@ public:
become(wait4int());
},
[](float) {
return skip_message();
return skip();
},
[](int) {
return skip_message();
return skip();
}
};
}
......@@ -210,10 +210,10 @@ public:
return 42;
},
[](float) {
return skip_message();
return skip();
},
[](const string&) {
return skip_message();
return skip();
}
};
}
......@@ -227,10 +227,10 @@ public:
become(wait4string());
},
[](const string&) {
return skip_message();
return skip();
},
[](int) {
return skip_message();
return skip();
}
};
}
......
......@@ -264,13 +264,13 @@ void basp_broker_state::learned_new_node(const node_id& nid) {
tmp = system().spawn<hidden>([=](event_based_actor* this_actor) -> behavior {
CAF_LOG_TRACE("");
// skip messages until we receive the initial ok_atom
this_actor->set_unexpected_handler(skip_unexpected);
this_actor->set_default_handler(skip);
return {
[=](ok_atom, const std::string& /* key == "info" */,
const actor_addr& config_serv_addr, const std::string& /* name */) {
CAF_LOG_TRACE(CAF_ARG(config_serv_addr));
// drop unexpected messages from this point on
this_actor->set_unexpected_handler(print_and_drop_unexpected);
this_actor->set_default_handler(print_and_drop);
auto config_serv = actor_cast<actor>(config_serv_addr);
this_actor->monitor(config_serv);
this_actor->become(
......
......@@ -644,7 +644,7 @@ CAF_TEST(remote_actor_and_send) {
CAF_TEST(actor_serialize_and_deserialize) {
auto testee_impl = [](event_based_actor* testee_self) -> behavior {
testee_self->set_unexpected_handler(reflect_unexpected_and_quit);
testee_self->set_default_handler(reflect_and_quit);
return {
[] {
// nop
......
......@@ -49,7 +49,7 @@ struct fixture {
};
behavior make_reflector_behavior(event_based_actor* self) {
self->set_unexpected_handler(reflect_unexpected_and_quit);
self->set_default_handler(reflect_and_quit);
return {
[] {
// nop
......@@ -85,7 +85,7 @@ struct await_reflector_reply_behavior {
// `grp` may be either local or remote
void make_client_behavior(event_based_actor* self,
actor server, group grp) {
self->set_unexpected_handler(skip_unexpected);
self->set_default_handler(skip);
self->spawn_in_group(grp, make_reflector_behavior);
self->spawn_in_group(grp, make_reflector_behavior);
self->request(server, infinite, spawn_atom::value, grp).then(
......
......@@ -37,7 +37,7 @@ using namespace caf;
namespace {
behavior mirror(event_based_actor* self) {
self->set_unexpected_handler(reflect_unexpected);
self->set_default_handler(reflect);
return {
[] {
// nop
......
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