Commit 89cee7a7 authored by Dominik Charousset's avatar Dominik Charousset

Deprecate replies_to and reacts_to

parent 35aea2c1
......@@ -12,6 +12,11 @@ is based on [Keep a Changelog](https://keepachangelog.com).
destructor of the promise now checks for this case.
- Accessing URI fields now always returns the normalized string.
### Deprecated
- The obsolete meta-programming utilities `replies_to` and `reacts_to` no longer
serve any purpose and are thus deprecated.
## [0.18.6]
### Added
......
......@@ -4,10 +4,8 @@
#pragma once
#include "caf/fwd.hpp"
#include "caf/replies_to.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/fwd.hpp"
namespace caf {
......
......@@ -6,7 +6,6 @@
#include "caf/detail/type_list.hpp"
#include "caf/fwd.hpp"
#include "caf/replies_to.hpp"
namespace caf {
......
......@@ -9,7 +9,6 @@
#include "caf/detail/implicit_conversions.hpp"
#include "caf/expected.hpp"
#include "caf/fwd.hpp"
#include "caf/replies_to.hpp"
namespace caf::detail {
......
......@@ -8,7 +8,6 @@
#include "caf/delegated.hpp"
#include "caf/fwd.hpp"
#include "caf/replies_to.hpp"
#include "caf/response_promise.hpp"
#include "caf/system_messages.hpp"
#include "caf/typed_response_promise.hpp"
......
......@@ -4,10 +4,8 @@
#pragma once
#include "caf/fwd.hpp"
#include "caf/replies_to.hpp"
#include "caf/detail/type_list.hpp"
#include "caf/fwd.hpp"
namespace caf::detail {
......
......@@ -17,12 +17,15 @@ replies_to_type_name(size_t input_size, const std::string* input,
size_t output_size, const std::string* output);
template <class... Is>
struct replies_to {
struct [[deprecated("write 'result<foo>(bar)' instead of "
"'replies_to<bar>::with<foo>'")]] replies_to {
template <class... Os>
using with = result<Os...>(Is...);
};
template <class... Is>
using reacts_to = result<void>(Is...);
using reacts_to
[[deprecated("write 'result<void>(foo)' instead of 'reacts_to<foo>'")]]
= result<void>(Is...);
} // namespace caf
......@@ -8,7 +8,6 @@
#include "caf/detail/type_list.hpp"
#include "caf/fwd.hpp"
#include "caf/replies_to.hpp"
namespace caf {
......
......@@ -15,7 +15,6 @@
#include "caf/fwd.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/make_actor.hpp"
#include "caf/replies_to.hpp"
#include "caf/stateful_actor.hpp"
#include "caf/type_id_list.hpp"
#include "caf/typed_actor_view_base.hpp"
......
......@@ -77,10 +77,10 @@ template <class T>
struct is_system_msg_handler : std::false_type {};
template <>
struct is_system_msg_handler<reacts_to<exit_msg>> : std::true_type {};
struct is_system_msg_handler<void(exit_msg)> : std::true_type {};
template <>
struct is_system_msg_handler<reacts_to<down_msg>> : std::true_type {};
struct is_system_msg_handler<void(down_msg)> : std::true_type {};
// Tests whether the input list (IList) matches the
// signature list (SList) for a typed actor behavior
......
......@@ -4,15 +4,13 @@
#pragma once
#include "caf/replies_to.hpp"
#include "caf/actor_system.hpp"
#include "caf/local_actor.hpp"
#include "caf/mixin/behavior_changer.hpp"
#include "caf/mixin/requester.hpp"
#include "caf/scheduled_actor.hpp"
#include "caf/typed_actor.hpp"
#include "caf/actor_system.hpp"
#include "caf/typed_behavior.hpp"
#include "caf/scheduled_actor.hpp"
#include "caf/mixin/requester.hpp"
#include "caf/mixin/behavior_changer.hpp"
namespace caf {
......
......@@ -2,7 +2,6 @@
// the main distribution directory for license terms and copyright or visit
// https://github.com/actor-framework/actor-framework/blob/master/LICENSE.
#include "caf/replies_to.hpp"
#include "caf/string_algorithms.hpp"
namespace caf {
......
#include "caf/fwd.hpp"
#include "caf/result.hpp"
#include "caf/test/bdd_dsl.hpp"
#include "caf/type_id.hpp"
#include "caf/typed_actor.hpp"
......@@ -10,13 +11,13 @@
// -- forward declarations for all unit test suites ----------------------------
using float_actor = caf::typed_actor<caf::reacts_to<float>>;
using float_actor = caf::typed_actor<caf::result<void>(float)>;
using int_actor = caf::typed_actor<caf::replies_to<int32_t>::with<int32_t>>;
using int_actor = caf::typed_actor<caf::result<int32_t>(int32_t)>;
using foo_actor
= caf::typed_actor<caf::replies_to<int32_t, int32_t, int32_t>::with<int32_t>,
caf::replies_to<double>::with<double, double>>;
= caf::typed_actor<caf::result<int32_t>(int32_t, int32_t, int32_t),
caf::result<double, double>(double)>;
// A simple POD type.
struct dummy_struct {
......
......@@ -23,8 +23,8 @@ behavior testee(event_based_actor* self) {
};
}
using first_stage = typed_actor<replies_to<int>::with<double, double>>;
using second_stage = typed_actor<replies_to<double, double>::with<double>>;
using first_stage = typed_actor<result<double, double>(int)>;
using second_stage = typed_actor<result<double>(double, double)>;
first_stage::behavior_type typed_first_stage() {
return {
......
......@@ -367,7 +367,7 @@ CAF_TEST(function_spawn) {
self->send_exit(a2, exit_reason::user_shutdown);
}
using typed_testee = typed_actor<replies_to<abc_atom>::with<std::string>>;
using typed_testee = typed_actor<result<std::string>(abc_atom)>;
typed_testee::behavior_type testee() {
return {[](abc_atom) {
......
......@@ -15,7 +15,7 @@ using namespace caf;
namespace {
using calculator = typed_actor<replies_to<int, int>::with<int>>;
using calculator = typed_actor<result<int>(int, int)>;
calculator::behavior_type adder() {
return {
......@@ -39,7 +39,7 @@ calculator::behavior_type divider() {
};
}
using doubler = typed_actor<replies_to<int>::with<int, int>>;
using doubler = typed_actor<result<int, int>(int)>;
doubler::behavior_type simple_doubler() {
return {
......@@ -49,8 +49,7 @@ doubler::behavior_type simple_doubler() {
};
}
using cell
= typed_actor<reacts_to<put_atom, int>, replies_to<get_atom>::with<int>>;
using cell = typed_actor<result<void>(put_atom, int), result<int>(get_atom)>;
struct cell_state {
int value = 0;
......
......@@ -17,8 +17,8 @@ using namespace caf;
namespace {
// Simple int32_terface for testee actors.
using testee_actor = typed_actor<replies_to<int32_t>::with<int32_t>>;
// Simple int32 interface for testee actors.
using testee_actor = typed_actor<result<int32_t>(int32_t)>;
// Dynamically typed testee.
behavior dt_testee() {
......
......@@ -143,8 +143,7 @@ ostream& operator<<(ostream& out, const pair<bool, int>& x) {
} // namespace std
CAF_TEST(typed_behavior_assignment) {
using bh1 = typed_beh<replies_to<int>::with<double>,
replies_to<double, double>::with<int, int>>;
using bh1 = typed_beh<result<double>(int), result<int, int>(double, double)>;
// compatible handlers resulting in perfect match
auto f1 = [=](int) { return 0.; };
auto f2 = [=](double, double) -> result<int, int> { return {0, 0}; };
......@@ -171,14 +170,16 @@ CAF_TEST(typed_behavior_assignment) {
CHECK_EQ(bi_pair(false, 0), tb_assign<bh1>(e2, f2));
CHECK_EQ(bi_pair(false, 0), tb_assign<bh1>(e2, e1));
using bh2
= typed_beh<reacts_to<int>, reacts_to<int, int>, reacts_to<int, int, int>,
reacts_to<int, int, int, int>,
reacts_to<int, int, int, int, int>,
reacts_to<int, int, int, int, int, int>,
reacts_to<int, int, int, int, int, int, int>,
reacts_to<int, int, int, int, int, int, int, int>,
reacts_to<int, int, int, int, int, int, int, int, int>,
reacts_to<int, int, int, int, int, int, int, int, int, int>>;
= typed_beh<result<void>(int), //
result<void>(int, int), //
result<void>(int, int, int), //
result<void>(int, int, int, int),
result<void>(int, int, int, int, int),
result<void>(int, int, int, int, int, int),
result<void>(int, int, int, int, int, int, int),
result<void>(int, int, int, int, int, int, int, int),
result<void>(int, int, int, int, int, int, int, int, int),
result<void>(int, int, int, int, int, int, int, int, int, int)>;
auto h0 = [](int) {};
auto h1 = [](int, int) {};
auto h2 = [](int, int, int) {};
......
......@@ -12,29 +12,23 @@
#include "caf/event_based_actor.hpp"
#include "caf/policy/select_all.hpp"
#include "caf/result.hpp"
using namespace caf;
namespace {
using discarding_server_type = typed_actor<replies_to<int, int>::with<void>>;
using discarding_server_type = typed_actor<result<void>(int, int)>;
using adding_server_type = typed_actor<replies_to<int, int>::with<int>>;
using adding_server_type = typed_actor<result<int>(int, int)>;
using result_type = variant<none_t, unit_t, int>;
struct fixture : test_coordinator_fixture<> {
fixture() {
result = std::make_shared<result_type>(none);
discarding_server = make_server([](int, int) {});
adding_server = make_server([](int x, int y) { return x + y; });
run();
}
template <class F>
auto make_server(F f)
-> typed_actor<replies_to<int, int>::with<decltype(f(1, 2))>> {
using impl = typed_actor<replies_to<int, int>::with<decltype(f(1, 2))>>;
auto make_server(F f) {
using res_t = caf::result<decltype(f(1, 2))>;
using impl = typed_actor<res_t(int, int)>;
auto init = [f]() -> typename impl::behavior_type {
return {
[f](int x, int y) { return f(x, y); },
......@@ -43,6 +37,13 @@ struct fixture : test_coordinator_fixture<> {
return sys.spawn(init);
}
fixture() {
result = std::make_shared<result_type>(none);
discarding_server = make_server([](int, int) {});
adding_server = make_server([](int x, int y) { return x + y; });
run();
}
template <class T>
T make_delegator(T dest) {
auto f = [=](typename T::pointer self) -> typename T::behavior_type {
......
......@@ -19,7 +19,7 @@ namespace {
using ms = std::chrono::milliseconds;
using timer = typed_actor<reacts_to<reset_atom>>;
using timer = typed_actor<result<void>(reset_atom)>;
struct timer_state {
bool had_reset = false;
......
......@@ -16,9 +16,8 @@
using namespace caf;
CAF_TEST(make_typed_behavior automatically deduces its types) {
using handle
= typed_actor<reacts_to<std::string>, replies_to<int32_t>::with<int32_t>,
replies_to<double>::with<double>>;
using handle = typed_actor<result<void>(std::string),
result<int32_t>(int32_t), result<double>(double)>;
auto bhvr = make_typed_behavior([](const std::string&) {},
[](int32_t x) { return x; },
[](double x) { return x; });
......
......@@ -24,11 +24,6 @@ using namespace std::string_literals;
namespace {
static_assert(std::is_same<reacts_to<int, int>, result<void>(int, int)>::value);
static_assert(std::is_same<replies_to<double>::with<double>,
result<double>(double)>::value);
// check invariants of type system
using dummy1 = typed_actor<result<void>(int, int), result<double>(double)>;
......@@ -38,7 +33,7 @@ static_assert(std::is_convertible<dummy2, dummy1>::value,
"handle not assignable to narrower definition");
using dummy3 = typed_actor<reacts_to<float, int>>;
using dummy4 = typed_actor<replies_to<int>::with<double>>;
using dummy4 = typed_actor<result<double>(int)>;
using dummy5 = dummy4::extend_with<dummy3>;
static_assert(std::is_convertible<dummy5, dummy3>::value,
......@@ -51,7 +46,7 @@ static_assert(std::is_convertible<dummy5, dummy4>::value,
* simple request/response test *
******************************************************************************/
using server_type = typed_actor<replies_to<my_request>::with<bool>>;
using server_type = typed_actor<result<bool>(my_request)>;
server_type::behavior_type typed_server1() {
return {
......@@ -91,9 +86,8 @@ void client(event_based_actor* self, const actor& parent,
******************************************************************************/
using event_testee_type
= typed_actor<replies_to<get_state_atom>::with<string>,
replies_to<string>::with<void>, replies_to<float>::with<void>,
replies_to<int>::with<int>>;
= typed_actor<result<string>(get_state_atom), result<void>(string),
result<void>(float), result<int>(int)>;
class event_testee : public event_testee_type::base {
public:
......@@ -137,7 +131,7 @@ public:
* simple 'forwarding' chain *
******************************************************************************/
using string_actor = typed_actor<replies_to<string>::with<string>>;
using string_actor = typed_actor<result<string>(string)>;
string_actor::behavior_type string_reverter() {
return {
......@@ -160,8 +154,7 @@ string_actor::behavior_type string_delegator(string_actor::pointer self,
};
}
using maybe_string_actor
= typed_actor<replies_to<string>::with<ok_atom, string>>;
using maybe_string_actor = typed_actor<result<ok_atom, string>(string)>;
maybe_string_actor::behavior_type maybe_string_reverter() {
return {
......@@ -285,7 +278,7 @@ CAF_TEST(typed_spawns) {
CAF_TEST(event_testee_series) {
auto et = self->spawn<event_testee>();
MESSAGE("et->message_types() returns an interface description");
typed_actor<replies_to<get_state_atom>::with<string>> sub_et = et;
typed_actor<result<string>(get_state_atom)> sub_et = et;
std::set<string> iface{"(get_state_atom) -> (std::string)",
"(std::string) -> (void)", "(float) -> (void)",
"(int32_t) -> (int32_t)"};
......@@ -350,7 +343,7 @@ CAF_TEST(sending_typed_actors_and_down_msg) {
}
CAF_TEST(check_signature) {
using foo_type = typed_actor<replies_to<put_atom>::with<ok_atom>>;
using foo_type = typed_actor<result<ok_atom>(put_atom)>;
using foo_result_type = result<ok_atom>;
using bar_type = typed_actor<reacts_to<ok_atom>>;
auto foo_action = [](foo_type::pointer ptr) -> foo_type::behavior_type {
......
......@@ -71,25 +71,25 @@ namespace caf::io {
///
/// }
/// ~~~
using middleman_actor = typed_actor<
replies_to<publish_atom, uint16_t, strong_actor_ptr, std::set<std::string>,
std::string, bool>::with<uint16_t>,
using middleman_actor = typed_actor< //
result<uint16_t>(publish_atom, uint16_t, strong_actor_ptr,
std::set<std::string>, std::string, bool),
replies_to<open_atom, uint16_t, std::string, bool>::with<uint16_t>,
result<uint16_t>(open_atom, uint16_t, std::string, bool),
replies_to<connect_atom, std::string,
uint16_t>::with<node_id, strong_actor_ptr, std::set<std::string>>,
result<node_id, strong_actor_ptr, std::set<std::string>>(
connect_atom, std::string, uint16_t),
reacts_to<unpublish_atom, actor_addr, uint16_t>,
result<void>(unpublish_atom, actor_addr, uint16_t),
reacts_to<close_atom, uint16_t>,
result<void>(close_atom, uint16_t),
replies_to<spawn_atom, node_id, std::string, message,
std::set<std::string>>::with<strong_actor_ptr>,
result<strong_actor_ptr>(spawn_atom, node_id, std::string, message,
std::set<std::string>),
replies_to<get_atom, group_atom, node_id, std::string>::with<actor>,
result<actor>(get_atom, group_atom, node_id, std::string),
replies_to<get_atom, node_id>::with<node_id, std::string, uint16_t>>;
result<node_id, std::string, uint16_t>(get_atom, node_id)>;
/// Spawns the default implementation for the `middleman_actor` interface.
CAF_IO_EXPORT middleman_actor make_middleman_actor(actor_system& sys, actor db);
......
......@@ -41,16 +41,16 @@ namespace io {
/// Denotes a minimal "client" broker managing one or more connection
/// handles by reacting to `new_data_msg` and `connection_closed_msg`.
/// @relates typed_broker
using connection_handler = typed_actor<reacts_to<new_data_msg>,
reacts_to<connection_closed_msg>>;
using connection_handler = typed_actor<result<void>(new_data_msg),
result<void>(connection_closed_msg)>;
/// Denotes a minimal "server" broker managing one or more accept
/// handles by reacting to `new_connection_msg` and `acceptor_closed_msg`.
/// The accept handler usually calls `self->fork(...)` when receiving
/// a `new_connection_msg`.
/// @relates typed_broker
using accept_handler = typed_actor<reacts_to<new_connection_msg>,
reacts_to<acceptor_closed_msg>>;
using accept_handler = typed_actor<result<void>(new_connection_msg),
result<void>(acceptor_closed_msg)>;
/// A typed broker mediates between actor systems and other
/// components in the network.
......
#include "caf/test/bdd_dsl.hpp"
#include "caf/test/io_dsl.hpp"
using calculator = caf::typed_actor<
caf::replies_to<caf::add_atom, int32_t, int32_t>::with<int32_t>,
caf::replies_to<caf::sub_atom, int32_t, int32_t>::with<int32_t>>;
using calculator
= caf::typed_actor<caf::result<int32_t>(caf::add_atom, int32_t, int32_t),
caf::result<int32_t>(caf::sub_atom, int32_t, int32_t)>;
CAF_BEGIN_TYPE_ID_BLOCK(io_test, caf::first_custom_type_id)
......
......@@ -121,7 +121,7 @@ behavior peer_acceptor_fun(broker* self, const actor& buddy) {
};
}
using int_peer = connection_handler::extend<replies_to<int>::with<int>>;
using int_peer = connection_handler::extend<result<int>(int)>;
int_peer::behavior_type int_peer_fun(int_peer::broker_pointer) {
return {
......
......@@ -58,7 +58,7 @@ behavior pong(event_based_actor* self, suite_state_ptr ssp) {
};
}
using fragile_mirror_actor = typed_actor<replies_to<int>::with<int>>;
using fragile_mirror_actor = typed_actor<result<int>(int)>;
fragile_mirror_actor::behavior_type
fragile_mirror(fragile_mirror_actor::pointer self) {
......
......@@ -240,13 +240,14 @@ Statically typed actors require abstract messaging interfaces to allow the
compiler to type-check actor communication. Interfaces in CAF are defined using
the variadic template ``typed_actor<...>``, which defines the proper
actor handle at the same time. Each template parameter defines one
``input/output`` pair via
``replies_to<X1,...,Xn>::with<Y1,...,Yn>``. For inputs that do not
generate outputs, ``reacts_to<X1,...,Xn>`` can be used as shortcut for
``replies_to<X1,...,Xn>::with<void>``. In the same way functions cannot
be overloaded only by their return type, interfaces cannot accept one input
twice (possibly mapping it to different outputs). The example below defines a
messaging interface for a simple calculator.
``input/output`` pair via function signature syntax with the return type wrapped
in a ``result``. For example, ``typed_actor<result<string, string>(double)>``.
Also, the arguments must not use any cv-qualifiers.
In the same way functions cannot be overloaded only by their return type,
interfaces cannot accept one input twice (possibly mapping it to different
outputs). The example below defines a messaging interface for a simple
calculator.
.. literalinclude:: /examples/message_passing/calculator.cpp
:language: C++
......
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