Commit 6b0cb27c authored by Dominik Charousset's avatar Dominik Charousset

Add missing member functions to typed_actor_view

parent 1d2b18e4
......@@ -89,6 +89,8 @@ is based on [Keep a Changelog](https://keepachangelog.com).
could monitor typed actors but not demonitoring it again. This member function
is now a template that accepts any actor handle in the same way `monitor`
already did.
- The `typed_actor_view` decorator lacked several member functions such as
`link_to`, `send_exit`, etc. These are now available.
## [0.17.5] - Unreleased
......
......@@ -170,13 +170,14 @@ public:
/// Sends an exit message to `dest`.
void send_exit(const actor_addr& whom, error reason);
void send_exit(const strong_actor_ptr& dest, error reason);
/// Sends an exit message to `dest`.
void send_exit(const strong_actor_ptr& whom, error reason);
/// Sends an exit message to `dest`.
template <class ActorHandle>
void send_exit(const ActorHandle& dest, error reason) {
if (dest)
dest->eq_impl(make_message_id(), ctrl(), context(),
void send_exit(const ActorHandle& whom, error reason) {
if (whom)
whom->eq_impl(make_message_id(), ctrl(), context(),
exit_msg{address(), std::move(reason)});
}
......@@ -294,7 +295,7 @@ public:
/// Adds a unidirectional `monitor` to `whom`.
/// @note Each call to `monitor` creates a new, independent monitor.
template <message_priority P = message_priority::normal, class Handle = actor>
template <message_priority P = message_priority::normal, class Handle>
void monitor(const Handle& whom) {
monitor(actor_cast<abstract_actor*>(whom), P);
}
......
......@@ -300,23 +300,16 @@ public:
// -- state modifiers --------------------------------------------------------
/// Finishes execution of this actor after any currently running
/// message handler is done.
/// This member function clears the behavior stack of the running actor
/// and invokes `on_exit()`. The actors does not finish execution
/// if the implementation of `on_exit()` sets a new behavior.
/// When setting a new behavior in `on_exit()`, one has to make sure
/// to not produce an infinite recursion.
/// Finishes execution of this actor after any currently running message
/// handler is done. This member function clears the behavior stack of the
/// running actor and invokes `on_exit()`. The actors does not finish
/// execution if the implementation of `on_exit()` sets a new behavior. When
/// setting a new behavior in `on_exit()`, one has to make sure to not produce
/// an infinite recursion.
///
/// If `on_exit()` did not set a new behavior, the actor sends an
/// exit message to all of its linked actors, sets its state to exited
/// and finishes execution.
///
/// In case this actor uses the blocking API, this member function unwinds
/// the stack by throwing an `actor_exited` exception.
/// @warning This member function throws immediately in thread-based actors
/// that do not use the behavior stack, i.e., actors that use
/// blocking API calls such as {@link receive()}.
/// If `on_exit()` did not set a new behavior, the actor sends an exit message
/// to all of its linked actors, sets its state to exited and finishes
/// execution.
void quit(error x = error{});
// -- properties -------------------------------------------------------------
......
......@@ -19,6 +19,7 @@
#pragma once
#include "caf/actor_traits.hpp"
#include "caf/config.hpp"
#include "caf/mixin/requester.hpp"
#include "caf/mixin/sender.hpp"
#include "caf/scheduled_actor.hpp"
......@@ -27,6 +28,8 @@
namespace caf {
/// Decorates a pointer to a @ref scheduled_actor with a statically typed actor
/// interface.
template <class... Sigs>
class typed_actor_view : public extend<typed_actor_view_base,
typed_actor_view<Sigs...>>::template
......@@ -46,30 +49,129 @@ public:
return *this;
}
/****************************************************************************
* spawn actors *
****************************************************************************/
// -- spawn functions --------------------------------------------------------
/// @copydoc local_actor::spawn
template <class T, spawn_options Os = no_spawn_options, class... Ts>
typename infer_handle_from_class<T>::type
spawn(Ts&&... xs) {
return self_->spawn<T, Os>(std::forward<Ts>(xs)...);
}
/// @copydoc local_actor::spawn
template <class T, spawn_options Os = no_spawn_options>
infer_handle_from_state_t<T> spawn() {
return self_->spawn<T, Os>();
}
/// @copydoc local_actor::spawn
template <spawn_options Os = no_spawn_options, class F, class... Ts>
typename infer_handle_from_fun<F>::type
spawn(F fun, Ts&&... xs) {
return self_->spawn<Os>(std::move(fun), std::forward<Ts>(xs)...);
}
/****************************************************************************
* miscellaneous actor operations *
****************************************************************************/
// -- state modifiers --------------------------------------------------------
/// @copydoc scheduled_actor::quit
void quit(error x = error{}) {
self_->quit(std::move(x));
}
// -- properties -------------------------------------------------------------
/// @copydoc scheduled_actor::mailbox
auto& mailbox() noexcept {
return self_->mailbox();
}
// -- event handlers ---------------------------------------------------------
/// @copydoc scheduled_actor::set_default_handler
template <class Fun>
void set_default_handler(Fun&& fun) {
self_->set_default_handler(std::forward<Fun>(fun));
}
/// @copydoc scheduled_actor::set_error_handler
template <class Fun>
void set_error_handler(Fun&& fun) {
self_->set_error_handler(std::forward<Fun>(fun));
}
/// @copydoc scheduled_actor::set_down_handler
template <class Fun>
void set_down_handler(Fun&& fun) {
self_->set_down_handler(std::forward<Fun>(fun));
}
/// @copydoc scheduled_actor::set_node_down_handler
template <class Fun>
void set_node_down_handler(Fun&& fun) {
self_->set_node_down_handler(std::forward<Fun>(fun));
}
/// @copydoc scheduled_actor::set_exit_handler
template <class Fun>
void set_exit_handler(Fun&& fun) {
self_->set_exit_handler(std::forward<Fun>(fun));
}
#ifndef CAF_NO_EXCEPTIONS
/// @copydoc scheduled_actor::set_exception_handler
template <class Fun>
void set_exception_handler(Fun&& fun) {
self_->set_exception_handler(std::forward<Fun>(fun));
}
#endif // CAF_NO_EXCEPTIONS
// -- linking and monitoring -------------------------------------------------
/// @copydoc monitorable_actor::link_to
template <class ActorHandle>
void link_to(const ActorHandle& x) {
self_->link_to(x);
}
/// @copydoc monitorable_actor::unlink_from
template <class ActorHandle>
void unlink_from(const ActorHandle& x) {
self_->unlink_from(x);
}
/// @copydoc local_actor::monitor
void monitor(const node_id& node) {
self_->monitor(node);
}
/// @copydoc local_actor::monitor
template <message_priority P = message_priority::normal, class Handle>
void monitor(const Handle& whom) {
self_->monitor(whom);
}
/// @copydoc local_actor::demonitor
void demonitor(const node_id& node) {
self_->demonitor(node);
}
/// @copydoc local_actor::demonitor
template <class Handle>
void demonitor(const Handle& whom) {
self_->demonitor(whom);
}
// -- sending asynchronous messages ------------------------------------------
/// @copydoc local_actor::send_exit
template <class ActorHandle>
void send_exit(const ActorHandle& whom, error reason) {
self_->send_exit(whom, std::move(reason));
}
// -- miscellaneous actor operations -----------------------------------------
execution_unit* context() const {
return self_->context();
......@@ -93,16 +195,6 @@ public:
return self_->make_response_promise<Ts...>();
}
template <message_priority P = message_priority::normal, class Handle = actor>
void monitor(const Handle& x) {
self_->monitor<P>(x);
}
template <class T>
void demonitor(const T& x) {
self_->demonitor(x);
}
message_id new_request_id(message_priority mp) {
return self_->new_request_id(mp);
}
......
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