Commit 156fd942 authored by ufownl's avatar ufownl Committed by Dominik Charousset

Deprecate `spawn_typed`

parent dd49a57d
...@@ -97,7 +97,7 @@ void test_calculators() { ...@@ -97,7 +97,7 @@ void test_calculators() {
self->spawn(tester<actor>, spawn(calculator), 3, 4); self->spawn(tester<actor>, spawn(calculator), 3, 4);
self->await_all_other_actors_done(); self->await_all_other_actors_done();
aout(self) << "typed actor:" << endl; aout(self) << "typed actor:" << endl;
self->spawn(tester<calculator_actor>, spawn_typed(typed_calculator), 5, 6); self->spawn(tester<calculator_actor>, spawn(typed_calculator), 5, 6);
self->await_all_other_actors_done(); self->await_all_other_actors_done();
} }
......
...@@ -189,7 +189,7 @@ void dining_philosophers() { ...@@ -189,7 +189,7 @@ void dining_philosophers() {
aout(self) << "chopstick ids are:"; aout(self) << "chopstick ids are:";
std::vector<chopstick> chopsticks; std::vector<chopstick> chopsticks;
for (size_t i = 0; i < 5; ++i) { for (size_t i = 0; i < 5; ++i) {
chopsticks.push_back(spawn_typed(available_chopstick)); chopsticks.push_back(spawn(available_chopstick));
aout(self) << " " << chopsticks.back()->id(); aout(self) << " " << chopsticks.back()->id();
} }
aout(self) << endl; aout(self) << endl;
......
...@@ -74,10 +74,10 @@ void tester(event_based_actor* self, const calculator_type& testee) { ...@@ -74,10 +74,10 @@ void tester(event_based_actor* self, const calculator_type& testee) {
int main() { int main() {
// test function-based impl // test function-based impl
spawn(tester, spawn_typed(typed_calculator)); spawn(tester, spawn(typed_calculator));
await_all_actors_done(); await_all_actors_done();
// test class-based impl // test class-based impl
spawn(tester, spawn_typed<typed_calculator_class>()); spawn(tester, spawn<typed_calculator_class>());
await_all_actors_done(); await_all_actors_done();
// done // done
shutdown(); shutdown();
......
...@@ -23,10 +23,23 @@ ...@@ -23,10 +23,23 @@
#include "caf/actor.hpp" #include "caf/actor.hpp"
#include "caf/actor_addr.hpp" #include "caf/actor_addr.hpp"
#include "caf/typed_behavior.hpp" #include "caf/typed_behavior.hpp"
#include "caf/typed_event_based_actor.hpp"
#include "caf/experimental/stateful_actor.hpp"
namespace caf { namespace caf {
template <class... Sigs>
class typed_event_based_actor;
namespace io {
namespace experimental {
template <class... Sigs>
class typed_broker;
} // namespace experimental
} // namespace io
enum class spawn_mode { enum class spawn_mode {
function, function,
function_with_selfptr, function_with_selfptr,
...@@ -88,6 +101,31 @@ struct infer_handle_from_fun_impl<Result, typed_event_based_actor<Sigs...>*, ...@@ -88,6 +101,31 @@ struct infer_handle_from_fun_impl<Result, typed_event_based_actor<Sigs...>*,
static constexpr spawn_mode mode = spawn_mode::function_with_selfptr; static constexpr spawn_mode mode = spawn_mode::function_with_selfptr;
}; };
// statically typed stateful actor with self pointer
template <class Result, class State, class... Sigs>
struct infer_handle_from_fun_impl<Result,
experimental::stateful_actor<
State, typed_event_based_actor<Sigs...>
>*,
true> {
using type = typed_actor<Sigs...>;
using impl =
experimental::stateful_actor<State, typed_event_based_actor<Sigs...>>;
using behavior_type = typed_behavior<Sigs...>;
static constexpr spawn_mode mode = spawn_mode::function_with_selfptr;
};
// statically typed broker with self pointer
template <class Result, class... Sigs>
struct infer_handle_from_fun_impl<Result,
io::experimental::typed_broker<Sigs...>*,
true> {
using type = typed_actor<Sigs...>;
using impl = io::experimental::typed_broker<Sigs...>;
using behavior_type = typed_behavior<Sigs...>;
static constexpr spawn_mode mode = spawn_mode::function_with_selfptr;
};
template <class F, class Trait = typename detail::get_callable_trait<F>::type> template <class F, class Trait = typename detail::get_callable_trait<F>::type>
struct infer_handle_from_fun { struct infer_handle_from_fun {
using result_type = typename Trait::result_type; using result_type = typename Trait::result_type;
......
...@@ -72,22 +72,24 @@ public: ...@@ -72,22 +72,24 @@ public:
~local_actor(); ~local_actor();
/**************************************************************************** /****************************************************************************
* spawn untyped actors * * spawn actors *
****************************************************************************/ ****************************************************************************/
template <class T, spawn_options Os = no_spawn_options, class... Ts> template <class T, spawn_options Os = no_spawn_options, class... Ts>
actor spawn(Ts&&... xs) { typename infer_handle_from_class<T>::type
spawn(Ts&&... xs) {
constexpr auto os = make_unbound(Os); constexpr auto os = make_unbound(Os);
auto res = spawn_class<T, os>(host(), empty_before_launch_callback{}, auto res = spawn_class<T, os>(host(), empty_before_launch_callback{},
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
return eval_opts(Os, std::move(res)); return eval_opts(Os, std::move(res));
} }
template <spawn_options Os = no_spawn_options, class... Ts> template <spawn_options Os = no_spawn_options, class F, class... Ts>
actor spawn(Ts&&... xs) { typename infer_handle_from_fun<F>::type
spawn(F fun, Ts&&... xs) {
constexpr auto os = make_unbound(Os); constexpr auto os = make_unbound(Os);
auto res = spawn_functor<os>(host(), empty_before_launch_callback{}, auto res = spawn_functor<os>(host(), empty_before_launch_callback{},
std::forward<Ts>(xs)...); std::move(fun), std::forward<Ts>(xs)...);
return eval_opts(Os, std::move(res)); return eval_opts(Os, std::move(res));
} }
...@@ -139,11 +141,11 @@ public: ...@@ -139,11 +141,11 @@ public:
} }
/**************************************************************************** /****************************************************************************
* spawn typed actors * * spawn typed actors (deprecated) *
****************************************************************************/ ****************************************************************************/
template <class T, spawn_options Os = no_spawn_options, class... Ts> template <class T, spawn_options Os = no_spawn_options, class... Ts>
typename actor_handle_from_signature_list< CAF_DEPRECATED typename actor_handle_from_signature_list<
typename T::signatures typename T::signatures
>::type >::type
spawn_typed(Ts&&... xs) { spawn_typed(Ts&&... xs) {
...@@ -154,7 +156,7 @@ public: ...@@ -154,7 +156,7 @@ public:
} }
template <spawn_options Os = no_spawn_options, typename F, class... Ts> template <spawn_options Os = no_spawn_options, typename F, class... Ts>
typename infer_typed_actor_handle< CAF_DEPRECATED typename infer_typed_actor_handle<
typename detail::get_callable_trait<F>::result_type, typename detail::get_callable_trait<F>::result_type,
typename detail::tl_head< typename detail::tl_head<
typename detail::get_callable_trait<F>::arg_types typename detail::get_callable_trait<F>::arg_types
......
...@@ -102,20 +102,9 @@ intrusive_ptr<C> spawn_functor_impl(execution_unit* eu, BeforeLaunch cb, ...@@ -102,20 +102,9 @@ intrusive_ptr<C> spawn_functor_impl(execution_unit* eu, BeforeLaunch cb,
/// should not be called by users of the library). This function /// should not be called by users of the library). This function
/// selects a proper implementation class and then delegates to `spawn_class`. /// selects a proper implementation class and then delegates to `spawn_class`.
template <spawn_options Os, typename BeforeLaunch, typename F, class... Ts> template <spawn_options Os, typename BeforeLaunch, typename F, class... Ts>
actor spawn_functor(execution_unit* eu, BeforeLaunch cb, F fun, Ts&&... xs) { typename infer_handle_from_fun<F>::type
using trait = typename detail::get_callable_trait<F>::type; spawn_functor(execution_unit* eu, BeforeLaunch cb, F fun, Ts&&... xs) {
using arg_types = typename trait::arg_types; using impl = typename infer_handle_from_fun<F>::impl;
using first_arg = typename detail::tl_head<arg_types>::type;
using impl =
typename std::conditional<
std::is_pointer<first_arg>::value,
typename std::remove_pointer<first_arg>::type,
typename std::conditional<
has_blocking_api_flag(Os),
blocking_actor,
event_based_actor
>::type
>::type;
return spawn_functor_impl<Os, impl>(eu, cb, std::move(fun), return spawn_functor_impl<Os, impl>(eu, cb, std::move(fun),
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
} }
...@@ -127,7 +116,8 @@ actor spawn_functor(execution_unit* eu, BeforeLaunch cb, F fun, Ts&&... xs) { ...@@ -127,7 +116,8 @@ actor spawn_functor(execution_unit* eu, BeforeLaunch cb, F fun, Ts&&... xs) {
/// arguments. The behavior of `spawn` can be modified by setting `Os`, e.g., /// arguments. The behavior of `spawn` can be modified by setting `Os`, e.g.,
/// to opt-out of the cooperative scheduling. /// to opt-out of the cooperative scheduling.
template <class C, spawn_options Os = no_spawn_options, class... Ts> template <class C, spawn_options Os = no_spawn_options, class... Ts>
actor spawn(Ts&&... xs) { typename infer_handle_from_class<C>::type
spawn(Ts&&... xs) {
return spawn_class<C, Os>(nullptr, empty_before_launch_callback{}, return spawn_class<C, Os>(nullptr, empty_before_launch_callback{},
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
} }
...@@ -136,11 +126,11 @@ actor spawn(Ts&&... xs) { ...@@ -136,11 +126,11 @@ actor spawn(Ts&&... xs) {
/// the remainder of `xs...` is used to invoke the functor. /// the remainder of `xs...` is used to invoke the functor.
/// The behavior of `spawn` can be modified by setting `Os`, e.g., /// The behavior of `spawn` can be modified by setting `Os`, e.g.,
/// to opt-out of the cooperative scheduling. /// to opt-out of the cooperative scheduling.
template <spawn_options Os = no_spawn_options, class... Ts> template <spawn_options Os = no_spawn_options, class F, class... Ts>
actor spawn(Ts&&... xs) { typename infer_handle_from_fun<F>::type
static_assert(sizeof...(Ts) > 0, "too few arguments provided"); spawn(F fun, Ts&&... xs) {
return spawn_functor<Os>(nullptr, empty_before_launch_callback{}, return spawn_functor<Os>(nullptr, empty_before_launch_callback{},
std::forward<Ts>(xs)...); std::move(fun), std::forward<Ts>(xs)...);
} }
/// Returns a new actor that immediately, i.e., before this function /// Returns a new actor that immediately, i.e., before this function
...@@ -206,30 +196,30 @@ template <class Result, ...@@ -206,30 +196,30 @@ template <class Result,
local_actor, local_actor,
typename std::remove_pointer<FirstArg>::type typename std::remove_pointer<FirstArg>::type
>::value> >::value>
struct infer_typed_actor_base; struct CAF_DEPRECATED infer_typed_actor_base;
template <class... Sigs, class FirstArg> template <class... Sigs, class FirstArg>
struct infer_typed_actor_base<typed_behavior<Sigs...>, FirstArg, false> { struct infer_typed_actor_base<typed_behavior<Sigs...>, FirstArg, false> {
using type = typed_event_based_actor<Sigs...>; using type = typed_event_based_actor<Sigs...>;
}; } CAF_DEPRECATED;
template <class Result, class T> template <class Result, class T>
struct infer_typed_actor_base<Result, T*, true> { struct infer_typed_actor_base<Result, T*, true> {
using type = T; using type = T;
}; } CAF_DEPRECATED;
/// Returns a new typed actor of type `C` using `xs...` as /// Returns a new typed actor of type `C` using `xs...` as
/// constructor arguments. /// constructor arguments.
template <class C, spawn_options Os = no_spawn_options, class... Ts> template <class C, spawn_options Os = no_spawn_options, class... Ts>
typename actor_handle_from_signature_list<typename C::signatures>::type CAF_DEPRECATED typename actor_handle_from_signature_list<typename C::signatures>::type
CAF_DEPRECATED spawn_typed(Ts&&... xs) { spawn_typed(Ts&&... xs) {
return spawn_class<C, Os>(nullptr, empty_before_launch_callback{}, return spawn_class<C, Os>(nullptr, empty_before_launch_callback{},
std::forward<Ts>(xs)...); std::forward<Ts>(xs)...);
} }
/// Spawns a typed actor from a functor . /// Spawns a typed actor from a functor .
template <spawn_options Os, typename BeforeLaunch, typename F, class... Ts> template <spawn_options Os, typename BeforeLaunch, typename F, class... Ts>
typename infer_typed_actor_handle< CAF_DEPRECATED typename infer_typed_actor_handle<
typename detail::get_callable_trait<F>::result_type, typename detail::get_callable_trait<F>::result_type,
typename detail::tl_head< typename detail::tl_head<
typename detail::get_callable_trait<F>::arg_types typename detail::get_callable_trait<F>::arg_types
...@@ -252,7 +242,7 @@ spawn_typed_functor(execution_unit* eu, BeforeLaunch cb, F fun, Ts&&... xs) { ...@@ -252,7 +242,7 @@ spawn_typed_functor(execution_unit* eu, BeforeLaunch cb, F fun, Ts&&... xs) {
/// invoke the functor. This function delegates its arguments to /// invoke the functor. This function delegates its arguments to
/// `spawn_typed_functor`. /// `spawn_typed_functor`.
template <spawn_options Os = no_spawn_options, typename F, class... Ts> template <spawn_options Os = no_spawn_options, typename F, class... Ts>
typename infer_typed_actor_handle< CAF_DEPRECATED typename infer_typed_actor_handle<
typename detail::get_callable_trait<F>::result_type, typename detail::get_callable_trait<F>::result_type,
typename detail::tl_head< typename detail::tl_head<
typename detail::get_callable_trait<F>::arg_types typename detail::get_callable_trait<F>::arg_types
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "caf/group.hpp" #include "caf/group.hpp"
#include "caf/typed_actor.hpp" #include "caf/typed_actor.hpp"
#include "caf/infer_handle.hpp"
#include "caf/spawn_options.hpp" #include "caf/spawn_options.hpp"
#include "caf/detail/type_list.hpp" #include "caf/detail/type_list.hpp"
...@@ -43,10 +44,11 @@ template <spawn_options Os = no_spawn_options, ...@@ -43,10 +44,11 @@ template <spawn_options Os = no_spawn_options,
class BeforeLaunch = void (*)(abstract_actor*), class BeforeLaunch = void (*)(abstract_actor*),
class F = behavior (*)(), class F = behavior (*)(),
class... Ts> class... Ts>
actor spawn_functor(execution_unit* host, typename infer_handle_from_fun<F>::type
BeforeLaunch before_launch_fun, spawn_functor(execution_unit* host,
F fun, BeforeLaunch before_launch_fun,
Ts&&... xs); F fun,
Ts&&... xs);
template <class InputIt> template <class InputIt>
class groups_subscriber { class groups_subscriber {
...@@ -77,23 +79,23 @@ struct empty_before_launch_callback { ...@@ -77,23 +79,23 @@ struct empty_before_launch_callback {
}; };
/****************************************************************************** /******************************************************************************
* typed actors * * typed actors (deprecated) *
******************************************************************************/ ******************************************************************************/
template <class TypedBehavior, class FirstArg> template <class TypedBehavior, class FirstArg>
struct infer_typed_actor_handle; struct CAF_DEPRECATED infer_typed_actor_handle;
// infer actor type from result type if possible // infer actor type from result type if possible
template <class... Sigs, class FirstArg> template <class... Sigs, class FirstArg>
struct infer_typed_actor_handle<typed_behavior<Sigs...>, FirstArg> { struct infer_typed_actor_handle<typed_behavior<Sigs...>, FirstArg> {
using type = typed_actor<Sigs...>; using type = typed_actor<Sigs...>;
}; } CAF_DEPRECATED;
// infer actor type from first argument if result type is void // infer actor type from first argument if result type is void
template <class... Sigs> template <class... Sigs>
struct infer_typed_actor_handle<void, typed_event_based_actor<Sigs...>*> { struct infer_typed_actor_handle<void, typed_event_based_actor<Sigs...>*> {
using type = typed_actor<Sigs...>; using type = typed_actor<Sigs...>;
}; } CAF_DEPRECATED;
template <class SignatureList> template <class SignatureList>
struct actor_handle_from_signature_list; struct actor_handle_from_signature_list;
...@@ -101,7 +103,7 @@ struct actor_handle_from_signature_list; ...@@ -101,7 +103,7 @@ struct actor_handle_from_signature_list;
template <class... Sigs> template <class... Sigs>
struct actor_handle_from_signature_list<detail::type_list<Sigs...>> { struct actor_handle_from_signature_list<detail::type_list<Sigs...>> {
using type = typed_actor<Sigs...>; using type = typed_actor<Sigs...>;
}; } CAF_DEPRECATED;
template <spawn_options Os, typename BeforeLaunch, typename F, class... Ts> template <spawn_options Os, typename BeforeLaunch, typename F, class... Ts>
typename infer_typed_actor_handle< typename infer_typed_actor_handle<
...@@ -110,7 +112,7 @@ typename infer_typed_actor_handle< ...@@ -110,7 +112,7 @@ typename infer_typed_actor_handle<
typename detail::get_callable_trait<F>::arg_types typename detail::get_callable_trait<F>::arg_types
>::type >::type
>::type >::type
spawn_typed_functor(execution_unit*, BeforeLaunch bl, F fun, Ts&&... xs); spawn_typed_functor(execution_unit*, BeforeLaunch bl, F fun, Ts&&... xs) CAF_DEPRECATED;
} // namespace caf } // namespace caf
......
...@@ -220,7 +220,25 @@ private: ...@@ -220,7 +220,25 @@ private:
// has local subscriptions and a "LEAVE" message to the original group // has local subscriptions and a "LEAVE" message to the original group
// if there's no subscription left. // if there's no subscription left.
class proxy_broker; class local_group_proxy;
using local_group_proxy_ptr = intrusive_ptr<local_group_proxy>;
class proxy_broker : public event_based_actor {
public:
explicit proxy_broker(local_group_proxy_ptr grp) : group_(std::move(grp)) {
// nop
}
behavior make_behavior();
void on_exit() {
group_.reset();
}
private:
local_group_proxy_ptr group_;
};
class local_group_proxy : public local_group { class local_group_proxy : public local_group {
public: public:
...@@ -294,30 +312,14 @@ private: ...@@ -294,30 +312,14 @@ private:
actor monitor_; actor monitor_;
}; };
using local_group_proxy_ptr = intrusive_ptr<local_group_proxy>; behavior proxy_broker::make_behavior() {
return {
class proxy_broker : public event_based_actor { others >> [=] {
public: group_->send_all_subscribers(current_sender(), current_message(),
explicit proxy_broker(local_group_proxy_ptr grp) : group_(std::move(grp)) { host());
// nop }
} };
}
behavior make_behavior() {
return {
others >> [=] {
group_->send_all_subscribers(current_sender(), current_message(),
host());
}
};
}
void on_exit() {
group_.reset();
}
private:
local_group_proxy_ptr group_;
};
class local_group_module : public abstract_group::module { class local_group_module : public abstract_group::module {
public: public:
......
...@@ -136,7 +136,7 @@ testee::behavior_type testee_impl(testee::pointer self) { ...@@ -136,7 +136,7 @@ testee::behavior_type testee_impl(testee::pointer self) {
CAF_TEST(sync_send_atom_constants) { CAF_TEST(sync_send_atom_constants) {
scoped_actor self; scoped_actor self;
auto tst = spawn_typed(testee_impl); auto tst = spawn(testee_impl);
self->sync_send(tst, abc_atom::value).await( self->sync_send(tst, abc_atom::value).await(
[](int i) { [](int i) {
CAF_CHECK_EQUAL(i, 42); CAF_CHECK_EQUAL(i, 42);
......
...@@ -771,7 +771,7 @@ typed_testee::behavior_type testee() { ...@@ -771,7 +771,7 @@ typed_testee::behavior_type testee() {
CAF_TEST(typed_await) { CAF_TEST(typed_await) {
scoped_actor self; scoped_actor self;
auto x = spawn_typed(testee); auto x = spawn(testee);
self->sync_send(x, abc_atom::value).await( self->sync_send(x, abc_atom::value).await(
[](const std::string& str) { [](const std::string& str) {
CAF_CHECK_EQUAL(str, "abc"); CAF_CHECK_EQUAL(str, "abc");
......
...@@ -76,7 +76,7 @@ CAF_TEST(basic_usage) { ...@@ -76,7 +76,7 @@ CAF_TEST(basic_usage) {
} }
CAF_TEST(either_in_typed_interfaces) { CAF_TEST(either_in_typed_interfaces) {
auto mf = spawn_typed(my_foo); auto mf = spawn(my_foo);
scoped_actor self; scoped_actor self;
self->sync_send(mf, 42).await( self->sync_send(mf, 42).await(
[](int val) { [](int val) {
......
...@@ -123,7 +123,7 @@ CAF_TEST(dynamic_stateful_actor) { ...@@ -123,7 +123,7 @@ CAF_TEST(dynamic_stateful_actor) {
} }
CAF_TEST(typed_stateful_actor) { CAF_TEST(typed_stateful_actor) {
test_adder(spawn_typed(typed_adder)); test_adder(spawn(typed_adder));
} }
CAF_TEST(dynamic_stateful_actor_class) { CAF_TEST(dynamic_stateful_actor_class) {
...@@ -131,7 +131,7 @@ CAF_TEST(dynamic_stateful_actor_class) { ...@@ -131,7 +131,7 @@ CAF_TEST(dynamic_stateful_actor_class) {
} }
CAF_TEST(typed_stateful_actor_class) { CAF_TEST(typed_stateful_actor_class) {
test_adder(spawn_typed<typed_adder_class>()); test_adder(spawn<typed_adder_class>());
} }
CAF_TEST(no_name) { CAF_TEST(no_name) {
......
...@@ -253,7 +253,7 @@ CAF_TEST_FIXTURE_SCOPE(atom_tests, fixture) ...@@ -253,7 +253,7 @@ CAF_TEST_FIXTURE_SCOPE(atom_tests, fixture)
CAF_TEST(test_void_res) { CAF_TEST(test_void_res) {
using testee_a = typed_actor<replies_to<int, int>::with<void>>; using testee_a = typed_actor<replies_to<int, int>::with<void>>;
auto buddy = spawn_typed([]() -> testee_a::behavior_type { auto buddy = spawn([]() -> testee_a::behavior_type {
return [](int, int) { return [](int, int) {
// nop // nop
}; };
......
...@@ -81,7 +81,7 @@ CAF_TEST_FIXTURE_SCOPE(typed_spawn_tests, fixture) ...@@ -81,7 +81,7 @@ CAF_TEST_FIXTURE_SCOPE(typed_spawn_tests, fixture)
CAF_TEST(typed_response_promise) { CAF_TEST(typed_response_promise) {
scoped_actor self; scoped_actor self;
auto foo = spawn_typed<foo_actor_impl>(); auto foo = spawn<foo_actor_impl>();
self->sync_send(foo, get_atom::value, 42).await( self->sync_send(foo, get_atom::value, 42).await(
[](int x) { [](int x) {
CAF_CHECK_EQUAL(x, 84); CAF_CHECK_EQUAL(x, 84);
......
...@@ -201,7 +201,7 @@ string_actor::behavior_type string_reverter() { ...@@ -201,7 +201,7 @@ string_actor::behavior_type string_reverter() {
// uses `return sync_send(...).then(...)` // uses `return sync_send(...).then(...)`
string_actor::behavior_type string_relay(string_actor::pointer self, string_actor::behavior_type string_relay(string_actor::pointer self,
string_actor master, bool leaf) { string_actor master, bool leaf) {
auto next = leaf ? spawn_typed(string_relay, master, false) : master; auto next = leaf ? spawn(string_relay, master, false) : master;
self->link_to(next); self->link_to(next);
return { return {
[=](const string& str) { [=](const string& str) {
...@@ -217,7 +217,7 @@ string_actor::behavior_type string_relay(string_actor::pointer self, ...@@ -217,7 +217,7 @@ string_actor::behavior_type string_relay(string_actor::pointer self,
// uses `return delegate(...)` // uses `return delegate(...)`
string_actor::behavior_type string_delegator(string_actor::pointer self, string_actor::behavior_type string_delegator(string_actor::pointer self,
string_actor master, bool leaf) { string_actor master, bool leaf) {
auto next = leaf ? spawn_typed(string_delegator, master, false) : master; auto next = leaf ? spawn(string_delegator, master, false) : master;
self->link_to(next); self->link_to(next);
return { return {
[=](string& str) -> delegated<string> { [=](string& str) -> delegated<string> {
...@@ -326,16 +326,16 @@ CAF_TEST_FIXTURE_SCOPE(typed_spawn_tests, fixture) ...@@ -326,16 +326,16 @@ CAF_TEST_FIXTURE_SCOPE(typed_spawn_tests, fixture)
CAF_TEST(typed_spawns) { CAF_TEST(typed_spawns) {
// run test series with typed_server(1|2) // run test series with typed_server(1|2)
test_typed_spawn(spawn_typed(typed_server1)); test_typed_spawn(spawn(typed_server1));
await_all_actors_done(); await_all_actors_done();
CAF_MESSAGE("finished test series with `typed_server1`"); CAF_MESSAGE("finished test series with `typed_server1`");
test_typed_spawn(spawn_typed(typed_server2)); test_typed_spawn(spawn(typed_server2));
await_all_actors_done(); await_all_actors_done();
CAF_MESSAGE("finished test series with `typed_server2`"); CAF_MESSAGE("finished test series with `typed_server2`");
{ {
scoped_actor self; scoped_actor self;
test_typed_spawn(spawn_typed<typed_server3>("hi there", self)); test_typed_spawn(spawn<typed_server3>("hi there", self));
self->receive(on("hi there") >> [] { self->receive(on("hi there") >> [] {
CAF_MESSAGE("received \"hi there\""); CAF_MESSAGE("received \"hi there\"");
}); });
...@@ -345,7 +345,7 @@ CAF_TEST(typed_spawns) { ...@@ -345,7 +345,7 @@ CAF_TEST(typed_spawns) {
CAF_TEST(test_event_testee) { CAF_TEST(test_event_testee) {
// run test series with event_testee // run test series with event_testee
scoped_actor self; scoped_actor self;
auto et = self->spawn_typed<event_testee>(); auto et = self->spawn<event_testee>();
string result; string result;
self->send(et, 1); self->send(et, 1);
self->send(et, 2); self->send(et, 2);
...@@ -385,8 +385,8 @@ CAF_TEST(reverter_relay_chain) { ...@@ -385,8 +385,8 @@ CAF_TEST(reverter_relay_chain) {
// run test series with string reverter // run test series with string reverter
scoped_actor self; scoped_actor self;
// actor-under-test // actor-under-test
auto aut = self->spawn_typed<monitored>(string_relay, auto aut = self->spawn<monitored>(string_relay,
spawn_typed(string_reverter), spawn(string_reverter),
true); true);
set<string> iface{"caf::replies_to<@str>::with<@str>"}; set<string> iface{"caf::replies_to<@str>::with<@str>"};
CAF_CHECK(aut->message_types() == iface); CAF_CHECK(aut->message_types() == iface);
...@@ -402,8 +402,8 @@ CAF_TEST(string_delegator_chain) { ...@@ -402,8 +402,8 @@ CAF_TEST(string_delegator_chain) {
// run test series with string reverter // run test series with string reverter
scoped_actor self; scoped_actor self;
// actor-under-test // actor-under-test
auto aut = self->spawn_typed<monitored>(string_delegator, auto aut = self->spawn<monitored>(string_delegator,
spawn_typed(string_reverter), spawn(string_reverter),
true); true);
set<string> iface{"caf::replies_to<@str>::with<@str>"}; set<string> iface{"caf::replies_to<@str>::with<@str>"};
CAF_CHECK(aut->message_types() == iface); CAF_CHECK(aut->message_types() == iface);
...@@ -417,8 +417,8 @@ CAF_TEST(string_delegator_chain) { ...@@ -417,8 +417,8 @@ CAF_TEST(string_delegator_chain) {
CAF_TEST(maybe_string_delegator_chain) { CAF_TEST(maybe_string_delegator_chain) {
scoped_actor self; scoped_actor self;
auto aut = spawn_typed(maybe_string_delegator, auto aut = spawn(maybe_string_delegator,
spawn_typed(maybe_string_reverter)); spawn(maybe_string_reverter));
self->sync_send(aut, "").await( self->sync_send(aut, "").await(
[](ok_atom, const string&) { [](ok_atom, const string&) {
throw std::logic_error("unexpected result!"); throw std::logic_error("unexpected result!");
...@@ -440,7 +440,7 @@ CAF_TEST(maybe_string_delegator_chain) { ...@@ -440,7 +440,7 @@ CAF_TEST(maybe_string_delegator_chain) {
CAF_TEST(test_sending_typed_actors) { CAF_TEST(test_sending_typed_actors) {
scoped_actor self; scoped_actor self;
auto aut = spawn_typed(int_fun); auto aut = spawn(int_fun);
self->send(spawn(foo), 10, aut); self->send(spawn(foo), 10, aut);
self->receive( self->receive(
[](int i) { CAF_CHECK_EQUAL(i, 100); } [](int i) { CAF_CHECK_EQUAL(i, 100); }
...@@ -450,7 +450,7 @@ CAF_TEST(test_sending_typed_actors) { ...@@ -450,7 +450,7 @@ CAF_TEST(test_sending_typed_actors) {
CAF_TEST(test_sending_typed_actors_and_down_msg) { CAF_TEST(test_sending_typed_actors_and_down_msg) {
scoped_actor self; scoped_actor self;
auto aut = spawn_typed(int_fun2); auto aut = spawn(int_fun2);
self->send(spawn(foo2), 10, aut); self->send(spawn(foo2), 10, aut);
self->receive([](int i) { CAF_CHECK_EQUAL(i, 100); }); self->receive([](int i) { CAF_CHECK_EQUAL(i, 100); });
} }
...@@ -469,7 +469,7 @@ CAF_TEST(check_signature) { ...@@ -469,7 +469,7 @@ CAF_TEST(check_signature) {
}; };
}; };
auto bar_action = [=](bar_type::pointer self) -> bar_type::behavior_type { auto bar_action = [=](bar_type::pointer self) -> bar_type::behavior_type {
auto foo = self->spawn_typed<linked>(foo_action); auto foo = self->spawn<linked>(foo_action);
self->send(foo, put_atom::value); self->send(foo, put_atom::value);
return { return {
[=](ok_atom) { [=](ok_atom) {
...@@ -481,7 +481,7 @@ CAF_TEST(check_signature) { ...@@ -481,7 +481,7 @@ CAF_TEST(check_signature) {
}; };
}; };
scoped_actor self; scoped_actor self;
self->spawn_typed<monitored>(bar_action); self->spawn<monitored>(bar_action);
self->receive( self->receive(
[](const down_msg& dm) { [](const down_msg& dm) {
CAF_CHECK_EQUAL(dm.reason, exit_reason::normal); CAF_CHECK_EQUAL(dm.reason, exit_reason::normal);
......
...@@ -58,17 +58,17 @@ class typed_broker; ...@@ -58,17 +58,17 @@ class typed_broker;
/// Infers the appropriate base class for a functor-based typed actor /// Infers the appropriate base class for a functor-based typed actor
/// from the result and the first argument of the functor. /// from the result and the first argument of the functor.
template <class Result, class FirstArg> template <class Result, class FirstArg>
struct infer_typed_broker_base; struct CAF_DEPRECATED infer_typed_broker_base;
template <class... Sigs, class FirstArg> template <class... Sigs, class FirstArg>
struct infer_typed_broker_base<typed_behavior<Sigs...>, FirstArg> { struct infer_typed_broker_base<typed_behavior<Sigs...>, FirstArg> {
using type = typed_broker<Sigs...>; using type = typed_broker<Sigs...>;
}; } CAF_DEPRECATED;
template <class... Sigs> template <class... Sigs>
struct infer_typed_broker_base<void, typed_event_based_actor<Sigs...>*> { struct infer_typed_broker_base<void, typed_broker<Sigs...>*> {
using type = typed_broker<Sigs...>; using type = typed_broker<Sigs...>;
}; } CAF_DEPRECATED;
/// A typed broker mediates between actor systems and other components in /// A typed broker mediates between actor systems and other components in
/// the network. /// the network.
...@@ -166,22 +166,11 @@ public: ...@@ -166,22 +166,11 @@ public:
} }
template <class F, class... Ts> template <class F, class... Ts>
typename infer_typed_actor_handle< typename infer_handle_from_fun<F>::type
typename detail::get_callable_trait<F>::result_type,
typename detail::tl_head<
typename detail::get_callable_trait<F>::arg_types
>::type
>::type
fork(F fun, connection_handle hdl, Ts&&... xs) { fork(F fun, connection_handle hdl, Ts&&... xs) {
auto sptr = this->take(hdl); auto sptr = this->take(hdl);
CAF_ASSERT(sptr->hdl() == hdl); CAF_ASSERT(sptr->hdl() == hdl);
using impl = using impl = typename infer_handle_from_fun<F>::impl;
typename infer_typed_broker_base<
typename detail::get_callable_trait<F>::result_type,
typename detail::tl_head<
typename detail::get_callable_trait<F>::arg_types
>::type
>::type;
static_assert(std::is_convertible<typename impl::actor_hdl, static_assert(std::is_convertible<typename impl::actor_hdl,
minimal_client>::value, minimal_client>::value,
"Cannot fork: new broker misses required handlers"); "Cannot fork: new broker misses required handlers");
......
...@@ -72,7 +72,8 @@ intrusive_ptr<Impl> spawn_io_server_impl(F fun, uint16_t port, Ts&&... xs) { ...@@ -72,7 +72,8 @@ intrusive_ptr<Impl> spawn_io_server_impl(F fun, uint16_t port, Ts&&... xs) {
/// Spawns a new functor-based broker. /// Spawns a new functor-based broker.
template <spawn_options Os = no_spawn_options, template <spawn_options Os = no_spawn_options,
class F = std::function<void(broker*)>, class... Ts> class F = std::function<void(broker*)>, class... Ts>
actor spawn_io(F fun, Ts&&... xs) { typename infer_handle_from_fun<F>::type
spawn_io(F fun, Ts&&... xs) {
return spawn_functor<Os>(nullptr, empty_before_launch_callback{}, return spawn_functor<Os>(nullptr, empty_before_launch_callback{},
std::move(fun), std::forward<Ts>(xs)...); std::move(fun), std::forward<Ts>(xs)...);
} }
...@@ -80,25 +81,29 @@ actor spawn_io(F fun, Ts&&... xs) { ...@@ -80,25 +81,29 @@ actor spawn_io(F fun, Ts&&... xs) {
/// Spawns a new functor-based broker connecting to `host:port`. /// Spawns a new functor-based broker connecting to `host:port`.
template <spawn_options Os = no_spawn_options, template <spawn_options Os = no_spawn_options,
class F = std::function<void(broker*)>, class... Ts> class F = std::function<void(broker*)>, class... Ts>
actor spawn_io_client(F fun, const std::string& host, typename infer_handle_from_fun<F>::type
spawn_io_client(F fun, const std::string& host,
uint16_t port, Ts&&... xs) { uint16_t port, Ts&&... xs) {
return spawn_io_client_impl<Os, broker>(std::move(fun), host, port, using impl = typename infer_handle_from_fun<F>::impl;
std::forward<Ts>(xs)...); return spawn_io_client_impl<Os, impl>(std::move(fun), host, port,
std::forward<Ts>(xs)...);
} }
/// Spawns a new broker as server running on given `port`. /// Spawns a new broker as server running on given `port`.
template <spawn_options Os = no_spawn_options, template <spawn_options Os = no_spawn_options,
class F = std::function<void(broker*)>, class... Ts> class F = std::function<void(broker*)>, class... Ts>
actor spawn_io_server(F fun, uint16_t port, Ts&&... xs) { typename infer_handle_from_fun<F>::type
return spawn_io_server_impl<Os, broker>(std::move(fun), port, spawn_io_server(F fun, uint16_t port, Ts&&... xs) {
std::forward<Ts>(xs)...); using impl = typename infer_handle_from_fun<F>::impl;
return spawn_io_server_impl<Os, impl>(std::move(fun), port,
std::forward<Ts>(xs)...);
} }
namespace experimental { namespace experimental {
/// Spawns a new functor-based typed-broker. /// Spawns a new functor-based typed-broker.
template <spawn_options Os = no_spawn_options, class F, class... Ts> template <spawn_options Os = no_spawn_options, class F, class... Ts>
typename infer_typed_actor_handle< CAF_DEPRECATED typename infer_typed_actor_handle<
typename detail::get_callable_trait<F>::result_type, typename detail::get_callable_trait<F>::result_type,
typename detail::tl_head< typename detail::tl_head<
typename detail::get_callable_trait<F>::arg_types typename detail::get_callable_trait<F>::arg_types
...@@ -119,7 +124,7 @@ spawn_io_typed(F fun, Ts&&... xs) { ...@@ -119,7 +124,7 @@ spawn_io_typed(F fun, Ts&&... xs) {
/// Spawns a new functor-based typed-broker connecting to `host:port`. /// Spawns a new functor-based typed-broker connecting to `host:port`.
template <spawn_options Os = no_spawn_options, class F, class... Ts> template <spawn_options Os = no_spawn_options, class F, class... Ts>
typename infer_typed_actor_handle< CAF_DEPRECATED typename infer_typed_actor_handle<
typename detail::get_callable_trait<F>::result_type, typename detail::get_callable_trait<F>::result_type,
typename detail::tl_head< typename detail::tl_head<
typename detail::get_callable_trait<F>::arg_types typename detail::get_callable_trait<F>::arg_types
...@@ -140,7 +145,7 @@ spawn_io_client_typed(F fun, const std::string& host, uint16_t port, ...@@ -140,7 +145,7 @@ spawn_io_client_typed(F fun, const std::string& host, uint16_t port,
/// Spawns a new typed-broker as server running on given `port`. /// Spawns a new typed-broker as server running on given `port`.
template <spawn_options Os = no_spawn_options, class F, class... Ts> template <spawn_options Os = no_spawn_options, class F, class... Ts>
typename infer_typed_actor_handle< CAF_DEPRECATED typename infer_typed_actor_handle<
typename detail::get_callable_trait<F>::result_type, typename detail::get_callable_trait<F>::result_type,
typename detail::tl_head< typename detail::tl_head<
typename detail::get_callable_trait<F>::arg_types typename detail::get_callable_trait<F>::arg_types
...@@ -160,7 +165,6 @@ spawn_io_server_typed(F fun, uint16_t port, Ts&&... xs) { ...@@ -160,7 +165,6 @@ spawn_io_server_typed(F fun, uint16_t port, Ts&&... xs) {
} // namespace experimental } // namespace experimental
} // namespace io } // namespace io
} // namespace caf } // namespace caf
......
...@@ -270,7 +270,7 @@ void middleman::initialize() { ...@@ -270,7 +270,7 @@ void middleman::initialize() {
do_announce<new_connection_msg>("caf::io::new_connection_msg"); do_announce<new_connection_msg>("caf::io::new_connection_msg");
do_announce<new_data_msg>("caf::io::new_data_msg"); do_announce<new_data_msg>("caf::io::new_data_msg");
actor mgr = get_named_broker<basp_broker>(atom("_BASP")); actor mgr = get_named_broker<basp_broker>(atom("_BASP"));
manager_ = spawn_typed<middleman_actor_impl, detached + hidden>(*this, mgr); manager_ = spawn<middleman_actor_impl, detached + hidden>(*this, mgr);
} }
void middleman::stop() { void middleman::stop() {
......
...@@ -186,7 +186,7 @@ acceptor::behavior_type acceptor_fun(acceptor::broker_pointer self, ...@@ -186,7 +186,7 @@ acceptor::behavior_type acceptor_fun(acceptor::broker_pointer self,
void run_server(bool spawn_client, const char* bin_path, bool use_asio) { void run_server(bool spawn_client, const char* bin_path, bool use_asio) {
scoped_actor self; scoped_actor self;
auto serv = spawn_io_typed(acceptor_fun, spawn(pong)); auto serv = spawn_io(acceptor_fun, spawn(pong));
self->sync_send(serv, publish_atom::value).await( self->sync_send(serv, publish_atom::value).await(
[&](uint16_t port) { [&](uint16_t port) {
CAF_MESSAGE("server is running on port " << port); CAF_MESSAGE("server is running on port " << port);
...@@ -233,7 +233,7 @@ CAF_TEST(test_typed_broker) { ...@@ -233,7 +233,7 @@ CAF_TEST(test_typed_broker) {
if (r.opts.count("client-port") > 0) { if (r.opts.count("client-port") > 0) {
auto p = spawn(ping, 10); auto p = spawn(ping, 10);
CAF_MESSAGE("spawn_io_client_typed..."); CAF_MESSAGE("spawn_io_client_typed...");
auto cl = spawn_io_client_typed(peer_fun, "localhost", port, p); auto cl = spawn_io_client(peer_fun, "localhost", port, p);
CAF_MESSAGE("spawn_io_client_typed finished"); CAF_MESSAGE("spawn_io_client_typed finished");
anon_send(p, kickoff_atom::value, cl); anon_send(p, kickoff_atom::value, cl);
CAF_MESSAGE("`kickoff_atom` has been send"); CAF_MESSAGE("`kickoff_atom` has been send");
......
...@@ -95,7 +95,7 @@ void run_client(const char* host, uint16_t port) { ...@@ -95,7 +95,7 @@ void run_client(const char* host, uint16_t port) {
} }
uint16_t run_server() { uint16_t run_server() {
auto port = io::typed_publish(spawn_typed(server), 0, "127.0.0.1"); auto port = io::typed_publish(spawn(server), 0, "127.0.0.1");
CAF_MESSAGE("running on port " << port); CAF_MESSAGE("running on port " << port);
return port; return port;
} }
......
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