Unverified Commit 99212ecc authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #1072

Fix several issues with typed actor views
parents 13d75ffe 90ce18a1
...@@ -89,6 +89,11 @@ is based on [Keep a Changelog](https://keepachangelog.com). ...@@ -89,6 +89,11 @@ is based on [Keep a Changelog](https://keepachangelog.com).
could monitor typed actors but not demonitoring it again. This member function 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` is now a template that accepts any actor handle in the same way `monitor`
already did. already did.
- The `typed_actor_view` decorator lacked several member functions such as
`link_to`, `send_exit`, etc. These are now available.
- Constructing a `typed_actor` handle from a pointer view failed du to a missing
constructor overload. This (explicit) overload now exists and the conversion
should work as expected.
## [0.17.5] - Unreleased ## [0.17.5] - Unreleased
......
...@@ -322,6 +322,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" ...@@ -322,6 +322,10 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
add_compile_options("-ftemplate-depth=512" add_compile_options("-ftemplate-depth=512"
"-ftemplate-backtrace-limit=0") "-ftemplate-backtrace-limit=0")
endif() endif()
# enable useful warnings by default
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wdocumentation)
endif()
# explicitly disable obnoxious GCC warnings # explicitly disable obnoxious GCC warnings
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU") if(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
build_string("EXTRA_FLAGS" "-Wno-missing-field-initializers") build_string("EXTRA_FLAGS" "-Wno-missing-field-initializers")
......
...@@ -44,7 +44,7 @@ public: ...@@ -44,7 +44,7 @@ public:
= 0; = 0;
/// Called before the actor system calls the destructor for `self`. /// Called before the actor system calls the destructor for `self`.
/// @param ptr Points to an actor that is about to get destroyed. /// @param self Points to an actor that is about to get destroyed.
/// @thread-safe /// @thread-safe
virtual void remove_actor(const local_actor& self) = 0; virtual void remove_actor(const local_actor& self) = 0;
......
...@@ -33,10 +33,7 @@ namespace caf { ...@@ -33,10 +33,7 @@ namespace caf {
/// implementation with `Driver`. The returned manager is not connected to any /// implementation with `Driver`. The returned manager is not connected to any
/// slot and thus not stored by the actor automatically. /// slot and thus not stored by the actor automatically.
/// @param self Points to the hosting actor. /// @param self Points to the hosting actor.
/// @param init Function object for initializing the state of the source. /// @param xs Parameter pack for constructing the driver.
/// @param pull Generator function object for producing downstream messages.
/// @param done Predicate returning `true` when generator is done.
/// @param fin Cleanup handler.
/// @returns The new `stream_manager`. /// @returns The new `stream_manager`.
template <class Driver, class... Ts> template <class Driver, class... Ts>
typename Driver::source_ptr_type typename Driver::source_ptr_type
......
...@@ -40,10 +40,7 @@ namespace caf { ...@@ -40,10 +40,7 @@ namespace caf {
/// manager with `Driver`. /// manager with `Driver`.
/// @param self Points to the hosting actor. /// @param self Points to the hosting actor.
/// @param xs User-defined arguments for the stream handshake. /// @param xs User-defined arguments for the stream handshake.
/// @param init Function object for initializing the state of the source. /// @param ctor_args Parameter pack for constructing the driver.
/// @param pull Function object for generating downstream messages.
/// @param done Predicate returning `true` when generator is done.
/// @param fin Optional cleanup handler.
/// @returns The allocated `stream_manager` and the output slot. /// @returns The allocated `stream_manager` and the output slot.
template <class Driver, class... Ts, class... CtorArgs> template <class Driver, class... Ts, class... CtorArgs>
make_source_result_t<typename Driver::downstream_manager_type, Ts...> make_source_result_t<typename Driver::downstream_manager_type, Ts...>
...@@ -104,10 +101,10 @@ template <class Init, class Pull, class Done, class Finalize = unit_t, ...@@ -104,10 +101,10 @@ template <class Init, class Pull, class Done, class Finalize = unit_t,
detail::enable_if_t<!is_actor_handle<Init>::value && Trait::valid, detail::enable_if_t<!is_actor_handle<Init>::value && Trait::valid,
make_source_result_t<DownstreamManager>> make_source_result_t<DownstreamManager>>
attach_stream_source(scheduled_actor* self, Init init, Pull pull, Done done, attach_stream_source(scheduled_actor* self, Init init, Pull pull, Done done,
Finalize finalize = {}, Finalize fin = {},
policy::arg<DownstreamManager> token = {}) { policy::arg<DownstreamManager> token = {}) {
return attach_stream_source(self, std::make_tuple(), init, pull, done, return attach_stream_source(self, std::make_tuple(), init, pull, done, fin,
finalize, token); token);
} }
/// Attaches a new stream source to `self` by creating a default stream source /// Attaches a new stream source to `self` by creating a default stream source
......
...@@ -167,16 +167,17 @@ public: ...@@ -167,16 +167,17 @@ public:
// -- sending asynchronous messages ------------------------------------------ // -- sending asynchronous messages ------------------------------------------
/// Sends an exit message to `dest`. /// Sends an exit message to `whom`.
void send_exit(const actor_addr& whom, error reason); void send_exit(const actor_addr& whom, error reason);
void send_exit(const strong_actor_ptr& dest, error reason); /// Sends an exit message to `whom`.
void send_exit(const strong_actor_ptr& whom, error reason);
/// Sends an exit message to `dest`. /// Sends an exit message to `whom`.
template <class ActorHandle> template <class ActorHandle>
void send_exit(const ActorHandle& dest, error reason) { void send_exit(const ActorHandle& whom, error reason) {
if (dest) if (whom)
dest->eq_impl(make_message_id(), ctrl(), context(), whom->eq_impl(make_message_id(), ctrl(), context(),
exit_msg{address(), std::move(reason)}); exit_msg{address(), std::move(reason)});
} }
...@@ -294,7 +295,7 @@ public: ...@@ -294,7 +295,7 @@ public:
/// Adds a unidirectional `monitor` to `whom`. /// Adds a unidirectional `monitor` to `whom`.
/// @note Each call to `monitor` creates a new, independent monitor. /// @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) { void monitor(const Handle& whom) {
monitor(actor_cast<abstract_actor*>(whom), P); monitor(actor_cast<abstract_actor*>(whom), P);
} }
......
This diff is collapsed.
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "caf/make_actor.hpp" #include "caf/make_actor.hpp"
#include "caf/replies_to.hpp" #include "caf/replies_to.hpp"
#include "caf/stateful_actor.hpp" #include "caf/stateful_actor.hpp"
#include "caf/typed_actor_view_base.hpp"
#include "caf/typed_behavior.hpp" #include "caf/typed_behavior.hpp"
#include "caf/typed_response_promise.hpp" #include "caf/typed_response_promise.hpp"
...@@ -148,6 +149,15 @@ public: ...@@ -148,6 +149,15 @@ public:
CAF_ASSERT(ptr != nullptr); CAF_ASSERT(ptr != nullptr);
} }
// Enable `handle_type{self}` for typed actor views.
template <class T, class = std::enable_if_t<
std::is_base_of<typed_actor_view_base, T>::value>>
explicit typed_actor(T ptr) : ptr_(ptr.internal_ptr()) {
static_assert(
detail::tl_subset_of<signatures, typename T::signatures>::value,
"Cannot assign T to incompatible handle type");
}
template <class... Ts> template <class... Ts>
typed_actor& operator=(const typed_actor<Ts...>& other) { typed_actor& operator=(const typed_actor<Ts...>& other) {
static_assert( static_assert(
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
namespace caf { namespace caf {
template <class... Sigs> template <class... Sigs>
class typed_actor_pointer { class typed_actor_pointer : public typed_actor_view_base {
public: public:
/// Stores the template parameter pack. /// Stores the template parameter pack.
using signatures = detail::type_list<Sigs...>; using signatures = detail::type_list<Sigs...>;
...@@ -45,6 +45,10 @@ public: ...@@ -45,6 +45,10 @@ public:
// nop // nop
} }
typed_actor_pointer(const typed_actor_pointer&) = default;
typed_actor_pointer& operator=(const typed_actor_pointer&) = default;
typed_actor_view<Sigs...>* operator->() { typed_actor_view<Sigs...>* operator->() {
return &view_; return &view_;
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#pragma once #pragma once
#include "caf/actor_traits.hpp" #include "caf/actor_traits.hpp"
#include "caf/config.hpp"
#include "caf/mixin/requester.hpp" #include "caf/mixin/requester.hpp"
#include "caf/mixin/sender.hpp" #include "caf/mixin/sender.hpp"
#include "caf/scheduled_actor.hpp" #include "caf/scheduled_actor.hpp"
...@@ -27,6 +28,8 @@ ...@@ -27,6 +28,8 @@
namespace caf { namespace caf {
/// Decorates a pointer to a @ref scheduled_actor with a statically typed actor
/// interface.
template <class... Sigs> template <class... Sigs>
class typed_actor_view : public extend<typed_actor_view_base, class typed_actor_view : public extend<typed_actor_view_base,
typed_actor_view<Sigs...>>::template typed_actor_view<Sigs...>>::template
...@@ -46,30 +49,129 @@ public: ...@@ -46,30 +49,129 @@ public:
return *this; return *this;
} }
/**************************************************************************** // -- spawn functions --------------------------------------------------------
* spawn actors *
****************************************************************************/
/// @copydoc local_actor::spawn
template <class T, spawn_options Os = no_spawn_options, class... Ts> template <class T, spawn_options Os = no_spawn_options, class... Ts>
typename infer_handle_from_class<T>::type typename infer_handle_from_class<T>::type
spawn(Ts&&... xs) { spawn(Ts&&... xs) {
return self_->spawn<T, Os>(std::forward<Ts>(xs)...); return self_->spawn<T, Os>(std::forward<Ts>(xs)...);
} }
/// @copydoc local_actor::spawn
template <class T, spawn_options Os = no_spawn_options> template <class T, spawn_options Os = no_spawn_options>
infer_handle_from_state_t<T> spawn() { infer_handle_from_state_t<T> spawn() {
return self_->spawn<T, Os>(); return self_->spawn<T, Os>();
} }
/// @copydoc local_actor::spawn
template <spawn_options Os = no_spawn_options, class F, class... Ts> template <spawn_options Os = no_spawn_options, class F, class... Ts>
typename infer_handle_from_fun<F>::type typename infer_handle_from_fun<F>::type
spawn(F fun, Ts&&... xs) { spawn(F fun, Ts&&... xs) {
return self_->spawn<Os>(std::move(fun), std::forward<Ts>(xs)...); return self_->spawn<Os>(std::move(fun), std::forward<Ts>(xs)...);
} }
/**************************************************************************** // -- state modifiers --------------------------------------------------------
* miscellaneous actor operations *
****************************************************************************/ /// @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 { execution_unit* context() const {
return self_->context(); return self_->context();
...@@ -93,16 +195,6 @@ public: ...@@ -93,16 +195,6 @@ public:
return self_->make_response_promise<Ts...>(); 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) { message_id new_request_id(message_priority mp) {
return self_->new_request_id(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