Commit 51494159 authored by Dominik Charousset's avatar Dominik Charousset

re-renamed untyped_actor -> event_based_actor

with this patch, untyped_actor is called event_based_actor once more
and blocking_untyped_actor has been renamed to blocking_actor;
reason to this is, that untyped_actor is too general, as there
are several other classes that are indeed untyped actors but do not
inherit from event_based_actor (e.g. io::broker, actor_proxy)
parent e94c2c79
......@@ -147,7 +147,7 @@ set(LIBCPPA_SRC
src/binary_serializer.cpp
src/broker.cpp
src/buffer.cpp
src/blocking_untyped_actor.cpp
src/blocking_actor.cpp
src/channel.cpp
src/context_switching_resume.cpp
src/continuable.cpp
......@@ -159,6 +159,7 @@ set(LIBCPPA_SRC
src/deserializer.cpp
src/duration.cpp
src/empty_tuple.cpp
src/event_based_actor.cpp
src/exception.cpp
src/exit_reason.cpp
src/fd_util.cpp
......@@ -206,7 +207,6 @@ set(LIBCPPA_SRC
src/uniform_type_info.cpp
src/uniform_type_info_map.cpp
src/untyped_actor_handle.cpp
src/untyped_actor.cpp
src/weak_ptr_anchor.cpp
src/yield_interface.cpp)
......
......@@ -13,7 +13,7 @@ cppa/attachable.hpp
cppa/behavior.hpp
cppa/binary_deserializer.hpp
cppa/binary_serializer.hpp
cppa/blocking_untyped_actor.hpp
cppa/blocking_actor.hpp
cppa/channel.hpp
cppa/untyped_actor_handle.hpp
cppa/config.hpp
......@@ -155,7 +155,7 @@ cppa/typed_actor_ptr.hpp
cppa/typed_behavior.hpp
cppa/uniform_type_info.hpp
cppa/unit.hpp
cppa/untyped_actor.hpp
cppa/event_based_actor.hpp
cppa/util/abstract_uniform_type_info.hpp
cppa/util/algorithm.hpp
cppa/util/arg_match_t.hpp
......@@ -332,9 +332,9 @@ cppa/behavior_stack_based.hpp
cppa/resumable.hpp
src/resumable.cpp
cppa/policy/middleman_scheduling.hpp
src/untyped_actor.cpp
src/event_based_actor.cpp
src/functor_based_blocking_actor.cpp
src/blocking_untyped_actor.cpp
src/blocking_actor.cpp
cppa/policy/policies.hpp
cppa/detail/response_future_util.hpp
cppa/system_messages.hpp
......
......@@ -60,6 +60,7 @@ class deserializer;
*/
typedef std::uint32_t actor_id;
class actor;
class abstract_actor;
typedef intrusive_ptr<abstract_actor> abstract_actor_ptr;
......@@ -101,6 +102,9 @@ class abstract_actor : public abstract_channel {
*/
virtual void link_to(const actor_addr& other);
void link_to(const actor& whom);
/**
* @brief Unlinks this actor from @p other.
* @param other Linked Actor.
......
......@@ -33,6 +33,7 @@
#include <cstddef>
#include <cstdint>
#include <utility>
#include <type_traits>
#include "cppa/intrusive_ptr.hpp"
......@@ -44,9 +45,12 @@
namespace cppa {
class actor_addr;
class actor_proxy;
class untyped_actor;
class blocking_untyped_actor;
class blocking_actor;
class event_based_actor;
struct invalid_actor_addr_t;
namespace io {
class broker;
......@@ -58,20 +62,36 @@ class raw_access;
struct invalid_actor_t { constexpr invalid_actor_t() { } };
/**
* @brief Identifies an invalid {@link actor}.
* @relates actor
*/
constexpr invalid_actor_t invalid_actor = invalid_actor_t{};
/**
* @brief Identifies an untyped actor.
*
* Can be used with derived types of {@link event_based_actor},
* {@link blocking_actor}, {@link actor_proxy}, or
* {@link io::broker}.
*/
class actor : util::comparable<actor> {
class actor : util::comparable<actor>
, util::comparable<actor, actor_addr>
, util::comparable<actor, invalid_actor_t>
, util::comparable<actor, invalid_actor_addr_t> {
friend class detail::raw_access;
public:
/**
* @brief Extends {@link untyped_actor_handle} to grant
* access to the enqueue member function.
*/
class handle : public untyped_actor_handle {
// untyped_actor_handle does not provide a virtual destructor
// -> no new members
class handle : public untyped_actor_handle {
friend class actor;
......@@ -81,6 +101,9 @@ class actor : util::comparable<actor> {
handle() = default;
/**
* @brief Enqueues @p msg to the receiver specified in @p hdr.
*/
void enqueue(const message_header& hdr, any_tuple msg) const;
private:
......@@ -91,55 +114,114 @@ class actor : util::comparable<actor> {
actor() = default;
actor(actor&&) = default;
actor(const actor&) = default;
template<typename T>
actor(intrusive_ptr<T> ptr,
typename std::enable_if<
std::is_base_of<io::broker, T>::value
|| std::is_base_of<actor_proxy, T>::value
|| std::is_base_of<untyped_actor, T>::value
|| std::is_base_of<blocking_untyped_actor, T>::value
|| std::is_base_of<blocking_actor, T>::value
|| std::is_base_of<event_based_actor, T>::value
>::type* = 0)
: m_ops(std::move(ptr)) { }
template<typename T>
actor(T* ptr,
typename std::enable_if<
std::is_base_of<io::broker, T>::value
|| std::is_base_of<actor_proxy, T>::value
|| std::is_base_of<event_based_actor, T>::value
|| std::is_base_of<blocking_actor, T>::value
>::type* = 0)
: m_ops(ptr) { }
actor(const std::nullptr_t&);
actor(const invalid_actor_t&);
actor(actor_proxy*);
actor& operator=(actor&&) = default;
actor(untyped_actor*);
actor& operator=(const actor&) = default;
actor(blocking_untyped_actor*);
template<typename T>
typename std::enable_if<
std::is_base_of<io::broker, T>::value
|| std::is_base_of<actor_proxy, T>::value
|| std::is_base_of<event_based_actor, T>::value
|| std::is_base_of<blocking_actor, T>::value,
actor&
>::type
operator=(intrusive_ptr<T> ptr) {
actor tmp{std::move(ptr)};
swap(tmp);
return *this;
}
actor(const invalid_actor_t&);
template<typename T>
typename std::enable_if<
std::is_base_of<io::broker, T>::value
|| std::is_base_of<actor_proxy, T>::value
|| std::is_base_of<event_based_actor, T>::value
|| std::is_base_of<blocking_actor, T>::value,
actor&
>::type
operator=(T* ptr) {
actor tmp{ptr};
swap(tmp);
return *this;
}
actor& operator=(const invalid_actor_t&);
inline operator bool() const {
return static_cast<bool>(m_ops.m_ptr);
}
explicit inline operator bool() const;
inline bool operator!() const {
return !static_cast<bool>(m_ops.m_ptr);
}
inline bool operator!() const;
/**
* @brief Queries whether this handle is valid, i.e., points
* to an instance of an untyped actor.
*/
inline bool valid() const {
return static_cast<bool>(m_ops.m_ptr);
}
/**
* @brief Returns a handle that grants access to
* actor operations such as enqueue.
*/
inline const handle* operator->() const {
// this const cast is safe, because untyped_actor_handle cannot be
// modified anyways and the offered operations are intended to
// be called on const elements
return &m_ops;
}
inline const handle& operator*() const {
return m_ops;
}
intptr_t compare(const actor& other) const;
intptr_t compare(const invalid_actor_t&) const;
intptr_t compare(const actor_addr&) const;
inline intptr_t compare(const invalid_actor_addr_t&) const {
return compare(invalid_actor);
}
private:
void swap(actor& other);
actor(abstract_actor*);
handle m_ops;
};
inline actor::operator bool() const {
return static_cast<bool>(m_ops.m_ptr);
}
inline bool actor::operator!() const {
return !static_cast<bool>(*this);
}
} // namespace cppa
#endif // CPPA_ACTOR_HPP
......@@ -43,18 +43,23 @@
namespace cppa {
class actor;
class local_actor;
class actor_namespace;
namespace detail { class raw_access; }
/**
* @brief Identifies an invalid {@link actor_addr}.
* @relates actor_addr
*/
struct invalid_actor_addr_t { constexpr invalid_actor_addr_t() { } };
constexpr invalid_actor_addr_t invalid_actor_addr = invalid_actor_addr_t{};
/**
* @brief Stores the address of typed as well as untyped actors.
*/
class actor_addr : util::comparable<actor_addr>
, util::comparable<actor_addr, actor>
, util::comparable<actor_addr, abstract_actor*>
, util::comparable<actor_addr, abstract_actor_ptr> {
......@@ -64,37 +69,45 @@ class actor_addr : util::comparable<actor_addr>
public:
actor_addr() = default;
actor_addr(actor_addr&&) = default;
actor_addr(const actor_addr&) = default;
actor_addr& operator=(actor_addr&&) = default;
actor_addr& operator=(const actor_addr&) = default;
actor_addr(const actor&);
actor_addr& operator=(const actor&);
actor_addr& operator=(const actor_addr&) = default;
actor_addr(const invalid_actor_addr_t&);
actor_addr operator=(const invalid_actor_addr_t&);
explicit operator bool() const;
bool operator!() const;
inline explicit operator bool() const {
return valid();
}
inline bool operator!() const {
return !valid();
}
inline bool valid() const {
return static_cast<bool>(*this);
return m_ops.valid();
}
intptr_t compare(const actor& other) const;
intptr_t compare(const actor_addr& other) const;
intptr_t compare(const abstract_actor* other) const;
inline intptr_t compare(const abstract_actor_ptr& other) const {
return compare(other.get());
}
inline untyped_actor_handle* operator->() const {
// this const cast is safe, because untyped_actor_handle cannot be
// modified anyways and the offered operations are intended to
// be called on const elements
return const_cast<untyped_actor_handle*>(&m_ops);
inline const untyped_actor_handle* operator->() const {
return &m_ops;
}
inline const untyped_actor_handle& operator*() const {
return m_ops;
}
private:
......
......@@ -41,14 +41,14 @@ namespace cppa {
#ifdef CPPA_DOCUMENTATION
/**
* @brief Policy tag that causes {@link untyped_actor::become} to
* @brief Policy tag that causes {@link event_based_actor::become} to
* discard the current behavior.
* @relates local_actor
*/
constexpr auto discard_behavior;
/**
* @brief Policy tag that causes {@link untyped_actor::become} to
* @brief Policy tag that causes {@link event_based_actor::become} to
* keep the current behavior available.
* @relates local_actor
*/
......
......@@ -45,7 +45,7 @@ namespace cppa {
/**
* @extends local_actor
*/
class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
class blocking_actor : public extend<local_actor>::with<mailbox_based> {
public:
......@@ -89,14 +89,13 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
response_future(const response_future&) = default;
response_future& operator=(const response_future&) = default;
inline response_future(const message_id& from,
blocking_untyped_actor* self)
inline response_future(const message_id& from, blocking_actor* self)
: m_mid(from), m_self(self) { }
private:
message_id m_mid;
blocking_untyped_actor* m_self;
blocking_actor* m_self;
};
......@@ -153,7 +152,8 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
const util::duration& rtime,
Ts&&... what) {
static_assert(sizeof...(Ts) > 0, "no message to send");
return timed_sync_send_tuple(rtime, dest, make_any_tuple(std::forward<Ts>(what)...));
return timed_sync_send_tuple(rtime, dest,
make_any_tuple(std::forward<Ts>(what)...));
}
typedef std::chrono::high_resolution_clock::time_point timeout_type;
......@@ -207,7 +207,7 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
*/
template<typename... Ts>
void receive(Ts&&... args) {
static_assert(sizeof...(Ts), "receive() requires at least one argument");
static_assert(sizeof...(Ts), "at least one argument required");
dequeue(match_expr_convert(std::forward<Ts>(args)...));
}
......@@ -282,7 +282,8 @@ class blocking_untyped_actor : public extend<local_actor>::with<mailbox_based> {
/**
* @brief Receives messages until @p stmt returns true.
*
* Semantically equal to: <tt>do { receive(...); } while (stmt() == false);</tt>
* Semantically equal to:
* <tt>do { receive(...); } while (stmt() == false);</tt>
*
* <b>Usage example:</b>
* @code
......
......@@ -47,10 +47,7 @@ struct invalid_actor_t;
namespace detail { class raw_access; }
/**
* @brief Interface for all message receivers.
*
* This interface describes an entity that can receive messages
* and is implemented by {@link actor} and {@link group}.
* @brief A handle to instances of {@link abstract_channel}.
*/
class channel : util::comparable<channel>
, util::comparable<channel, actor>
......@@ -64,12 +61,14 @@ class channel : util::comparable<channel>
channel(const actor&);
channel(const std::nullptr_t&);
channel(const invalid_actor_t&);
template<typename T>
channel(intrusive_ptr<T> ptr, typename std::enable_if<std::is_base_of<abstract_channel, T>::value>::type* = 0) : m_ptr(ptr) { }
channel(intrusive_ptr<T> ptr,
typename std::enable_if<
std::is_base_of<abstract_channel, T>::value
>::type* = 0)
: m_ptr(ptr) { }
channel(abstract_channel* ptr);
......@@ -85,7 +84,8 @@ class channel : util::comparable<channel>
intptr_t compare(const abstract_channel* other) const;
static intptr_t compare(const abstract_channel* lhs, const abstract_channel* rhs);
static intptr_t compare(const abstract_channel* lhs,
const abstract_channel* rhs);
private:
......
......@@ -58,11 +58,11 @@
#include "cppa/scoped_actor.hpp"
#include "cppa/spawn_options.hpp"
#include "cppa/actor_ostream.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/abstract_actor.hpp"
#include "cppa/blocking_actor.hpp"
#include "cppa/system_messages.hpp"
#include "cppa/response_promise.hpp"
#include "cppa/blocking_untyped_actor.hpp"
#include "cppa/event_based_actor.hpp"
#include "cppa/util/type_traits.hpp"
......@@ -459,10 +459,15 @@ inline void anon_send(const channel& receiver, Ts&&... args) {
anon_send_tuple(receiver, make_any_tuple(std::forward<Ts>(args)...));
}
inline void anon_send_exit(const actor_addr&, std::uint32_t) {
// implemented in local_actor.cpp
void anon_send_exit(const actor_addr& whom, std::uint32_t reason);
inline void anon_send_exit(const actor& whom, std::uint32_t reason) {
whom->enqueue({invalid_actor_addr, whom, message_id{}.with_high_priority()},
make_any_tuple(exit_msg{invalid_actor_addr, reason}));
}
/**
* @brief Blocks execution of this actor until all
* other actors finished execution.
......
......@@ -45,13 +45,13 @@ class any_tuple;
class actor_addr;
class actor_proxy;
class scoped_actor;
class untyped_actor;
class abstract_actor;
class blocking_actor;
class message_header;
class partial_function;
class uniform_type_info;
class event_based_actor;
class primitive_variant;
class blocking_untyped_actor;
// structs
struct anything;
......
......@@ -33,21 +33,21 @@
#include <type_traits>
#include "cppa/untyped_actor.hpp"
#include "cppa/event_based_actor.hpp"
namespace cppa { namespace detail {
class functor_based_actor : public untyped_actor {
class functor_based_actor : public event_based_actor {
public:
typedef std::function<behavior(untyped_actor*)> make_behavior_fun;
typedef std::function<behavior(event_based_actor*)> make_behavior_fun;
typedef std::function<void(untyped_actor*)> void_fun;
typedef std::function<void(event_based_actor*)> void_fun;
template<typename F, typename... Ts>
functor_based_actor(F f, Ts&&... vs) {
untyped_actor* dummy = nullptr;
event_based_actor* dummy = nullptr;
create(dummy, f, std::forward<Ts>(vs)...);
}
......@@ -55,7 +55,7 @@ class functor_based_actor : public untyped_actor {
private:
void create(untyped_actor*, void_fun);
void create(event_based_actor*, void_fun);
template<class Actor, typename F, typename... Ts>
auto create(Actor*, F f, Ts&&... vs) ->
......
......@@ -31,20 +31,20 @@
#ifndef FUNCTOR_BASED_BLOCKING_ACTOR_HPP
#define FUNCTOR_BASED_BLOCKING_ACTOR_HPP
#include "cppa/blocking_untyped_actor.hpp"
#include "cppa/blocking_actor.hpp"
namespace cppa {
namespace detail {
class functor_based_blocking_actor : public blocking_untyped_actor {
class functor_based_blocking_actor : public blocking_actor {
public:
typedef std::function<void (blocking_untyped_actor*)> act_fun;
typedef std::function<void (blocking_actor*)> act_fun;
template<typename F, typename... Ts>
functor_based_blocking_actor(F f, Ts&&... vs) {
blocking_untyped_actor* dummy = nullptr;
blocking_actor* dummy = nullptr;
create(dummy, f, std::forward<Ts>(vs)...);
}
......@@ -54,7 +54,7 @@ class functor_based_blocking_actor : public blocking_untyped_actor {
private:
void create(blocking_untyped_actor*, act_fun);
void create(blocking_actor*, act_fun);
template<class Actor, typename F, typename T0, typename... Ts>
auto create(Actor* dummy, F f, T0&& v0, Ts&&... vs) ->
......
......@@ -5,8 +5,8 @@
#include "cppa/logging.hpp"
#include "cppa/resumable.hpp"
#include "cppa/blocking_actor.hpp"
#include "cppa/mailbox_element.hpp"
#include "cppa/blocking_untyped_actor.hpp"
#include "cppa/policy/scheduling_policy.hpp"
......@@ -152,7 +152,7 @@ class proper_actor_base : public Policies::resume_policy::template mixin<Base, D
template<class Base,
class Policies,
bool OverrideDequeue = std::is_base_of<blocking_untyped_actor, Base>::value>
bool OverrideDequeue = std::is_base_of<blocking_actor, Base>::value>
class proper_actor : public proper_actor_base<Base,
proper_actor<Base,
Policies,
......@@ -201,10 +201,10 @@ class proper_actor : public proper_actor_base<Base,
CPPA_LOG_DEBUG(std::distance(this->cache_begin(), e)
<< " elements in cache");
for (auto i = this->cache_begin(); i != e; ++i) {
auto res = this->invoke_policy().invoke_message(this, *i, bhvr, mid);
if (res || !*i) {
auto im = this->invoke_policy().invoke_message(this, *i, bhvr, mid);
if (im || !*i) {
this->cache_erase(i);
if (res) return true;
if (im) return true;
// start anew, because we have invalidated our iterators now
return invoke_message_from_cache();
}
......@@ -244,7 +244,7 @@ class proper_actor<Base, Policies,true> : public proper_actor_base<Base,
this->scheduling_policy().launch(this, is_hidden);
}
// implement blocking_untyped_actor::dequeue_response
// implement blocking_actor::dequeue_response
void dequeue_response(behavior& bhvr, message_id mid) override {
// try to dequeue from cache first
......
......@@ -65,12 +65,6 @@ class raw_access {
};
// utility function to get raw access + cast to a related type in one call
template<typename T>
T* actor_addr_cast(const actor_addr& hdl) {
return static_cast<T*>(raw_access::get(hdl));
}
} } // namespace cppa::detail
#endif // CPPA_RAW_ACCESS_HPP
......@@ -42,7 +42,7 @@
namespace cppa {
class untyped_actor;
class event_based_actor;
class continue_helper {
......@@ -50,7 +50,7 @@ class continue_helper {
typedef int message_id_wrapper_tag;
inline continue_helper(message_id mid, untyped_actor* self)
inline continue_helper(message_id mid, event_based_actor* self)
: m_mid(mid), m_self(self) { }
template<typename F>
......@@ -69,15 +69,15 @@ class continue_helper {
private:
message_id m_mid;
untyped_actor* m_self;
event_based_actor* m_self;
};
/**
* @extends local_actor
*/
class untyped_actor : public extend<local_actor>::with<mailbox_based,
behavior_stack_based> {
class event_based_actor : public extend<local_actor>::
with<mailbox_based, behavior_stack_based> {
protected:
......@@ -124,13 +124,13 @@ class untyped_actor : public extend<local_actor>::with<mailbox_based,
response_future& operator=(const response_future&) = default;
inline response_future(const message_id& from, untyped_actor* self)
inline response_future(const message_id& from, event_based_actor* self)
: m_mid(from), m_self(self) { }
private:
message_id m_mid;
untyped_actor* m_self;
event_based_actor* m_self;
inline void check_consistency() { }
......@@ -173,7 +173,8 @@ class untyped_actor : public extend<local_actor>::with<mailbox_based,
const util::duration& rtime,
Ts&&... what) {
static_assert(sizeof...(Ts) > 0, "no message to send");
return timed_sync_send_tuple(rtime, dest, make_any_tuple(std::forward<Ts>(what)...));
return timed_sync_send_tuple(rtime, dest,
make_any_tuple(std::forward<Ts>(what)...));
}
};
......
......@@ -162,7 +162,8 @@ class middleman {
* to the event loop of the middleman.
* @note This member function is thread-safe.
*/
virtual void register_acceptor(const actor_addr& pa, peer_acceptor* ptr) = 0;
virtual void register_acceptor(const actor_addr& pa,
peer_acceptor* ptr) = 0;
/**
* @brief Returns the namespace that contains all remote actors
......
......@@ -170,6 +170,10 @@ class local_actor : public extend<abstract_actor>::with<memory_cached> {
void send_exit(const actor_addr& whom, std::uint32_t reason);
inline void send_exit(const actor& whom, std::uint32_t reason) {
send_exit(whom->address(), reason);
}
/**
* @brief Sends a message to @p whom that is delayed by @p rel_time.
* @param whom Receiver of the message.
......
......@@ -67,7 +67,7 @@ class context_switching_resume {
mixin(Ts&&... args)
: Base(std::forward<Ts>(args)...)
, m_fiber(context_switching_resume::trampoline,
static_cast<blocking_untyped_actor*>(this)) { }
static_cast<blocking_actor*>(this)) { }
resumable::resume_result resume(util::fiber* from) override {
CPPA_REQUIRE(from != nullptr);
......
......@@ -35,7 +35,7 @@
#include <type_traits>
#include "cppa/util/dptr.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/event_based_actor.hpp"
namespace cppa {
......@@ -45,11 +45,11 @@ namespace cppa {
* to initialize the derived actor with its @p init_state member.
* @tparam Derived Direct subclass of @p sb_actor.
*/
template<class Derived, class Base = untyped_actor>
template<class Derived, class Base = event_based_actor>
class sb_actor : public Base {
static_assert(std::is_base_of<untyped_actor, Base>::value,
"Base must be untyped_actor or a derived type");
static_assert(std::is_base_of<event_based_actor, Base>::value,
"Base must be event_based_actor or a derived type");
protected:
......@@ -58,7 +58,7 @@ class sb_actor : public Base {
public:
/**
* @brief Overrides {@link untyped_actor::make_behavior()} and sets
* @brief Overrides {@link event_based_actor::make_behavior()} and sets
* the initial actor behavior to <tt>Derived::init_state</tt>.
*/
behavior make_behavior() override {
......
......@@ -51,7 +51,7 @@
namespace cppa {
class untyped_actor;
class event_based_actor;
class scheduled_actor;
class scheduler_helper;
typedef intrusive_ptr<scheduled_actor> scheduled_actor_ptr;
......
......@@ -32,10 +32,13 @@
#define CPPA_SCOPED_ACTOR_HPP
#include "cppa/behavior.hpp"
#include "cppa/blocking_untyped_actor.hpp"
#include "cppa/blocking_actor.hpp"
namespace cppa {
/**
* @brief A scoped handle to a blocking actor.
*/
class scoped_actor {
public:
......@@ -48,15 +51,15 @@ class scoped_actor {
~scoped_actor();
inline blocking_untyped_actor* operator->() const {
inline blocking_actor* operator->() const {
return m_self.get();
}
inline blocking_untyped_actor& operator*() const {
inline blocking_actor& operator*() const {
return *m_self;
}
inline blocking_untyped_actor* get() const {
inline blocking_actor* get() const {
return m_self.get();
}
......@@ -82,7 +85,7 @@ class scoped_actor {
bool m_hidden;
actor_id m_prev; // used for logging/debugging purposes only
intrusive_ptr<blocking_untyped_actor> m_self;
intrusive_ptr<blocking_actor> m_self;
};
......
......@@ -51,50 +51,50 @@ namespace cppa {
namespace detail {
template<class Impl, spawn_options Options, typename BeforeLaunch, typename... Ts>
template<class Impl, spawn_options Opts, typename BeforeLaunch, typename... Ts>
actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) {
static_assert(std::is_base_of<untyped_actor, Impl>::value ||
(std::is_base_of<blocking_untyped_actor, Impl>::value &&
has_blocking_api_flag(Options)),
"Impl is not a derived type of untyped_actor or "
"is a derived type of blocking_untyped_actor but "
static_assert(std::is_base_of<event_based_actor, Impl>::value ||
(std::is_base_of<blocking_actor, Impl>::value &&
has_blocking_api_flag(Opts)),
"Impl is not a derived type of event_based_actor or "
"is a derived type of blocking_actor but "
"blocking_api_flag is missing");
static_assert(is_unbound(Options),
static_assert(is_unbound(Opts),
"top-level spawns cannot have monitor or link flag");
CPPA_LOGF_TRACE("spawn " << detail::demangle<Impl>());
// runtime check wheter context_switching_resume can be used,
// i.e., add the detached flag if libcppa compiled without fiber support
// when using the blocking API
if (has_blocking_api_flag(Options)
&& !has_detach_flag(Options)
if (has_blocking_api_flag(Opts)
&& !has_detach_flag(Opts)
&& util::fiber::is_disabled_feature()) {
return spawn_impl<Impl, Options + detached>(before_launch_fun,
return spawn_impl<Impl, Opts + detached>(before_launch_fun,
std::forward<Ts>(args)...);
}
/*
using scheduling_policy = typename std::conditional<
has_detach_flag(Options),
has_detach_flag(Opts),
policy::no_scheduling,
policy::cooperative_scheduling
>::type;
*/
using scheduling_policy = policy::no_scheduling;
using priority_policy = typename std::conditional<
has_priority_aware_flag(Options),
has_priority_aware_flag(Opts),
policy::prioritizing,
policy::not_prioritizing
>::type;
using resume_policy = typename std::conditional<
has_blocking_api_flag(Options),
has_blocking_api_flag(Opts),
typename std::conditional<
has_detach_flag(Options),
has_detach_flag(Opts),
policy::no_resume,
policy::context_switching_resume
>::type,
policy::event_based_resume
>::type;
using invoke_policy = typename std::conditional<
has_blocking_api_flag(Options),
has_blocking_api_flag(Opts),
policy::nestable_invoke,
policy::sequential_invoke
>::type;
......@@ -106,7 +106,7 @@ actor spawn_impl(BeforeLaunch before_launch_fun, Ts&&... args) {
auto ptr = make_counted<proper_impl>(std::forward<Ts>(args)...);
CPPA_PUSH_AID(ptr->id());
before_launch_fun(ptr.get());
ptr->launch(has_hide_flag(Options));
ptr->launch(has_hide_flag(Opts));
return ptr;
}
......@@ -131,9 +131,9 @@ struct spawn_fwd<scoped_actor> {
// forwards the arguments to spawn_impl, replacing pointers
// to actors with instances of 'actor'
template<class Impl, spawn_options Options, typename BeforeLaunch, typename... Ts>
template<class Impl, spawn_options Opts, typename BeforeLaunch, typename... Ts>
actor spawn_fwd_args(BeforeLaunch before_launch_fun, Ts&&... args) {
return spawn_impl<Impl, Options>(
return spawn_impl<Impl, Opts>(
before_launch_fun,
spawn_fwd<typename util::rm_const_and_ref<Ts>::type>::fwd(
std::forward<Ts>(args))...);
......@@ -149,13 +149,13 @@ actor spawn_fwd_args(BeforeLaunch before_launch_fun, Ts&&... args) {
/**
* @brief Spawns an actor of type @p Impl.
* @param args Constructor arguments.
* @tparam Impl Subtype of {@link untyped_actor} or {@link sb_actor}.
* @tparam Options Optional flags to modify <tt>spawn</tt>'s behavior.
* @tparam Impl Subtype of {@link event_based_actor} or {@link sb_actor}.
* @tparam Opts Optional flags to modify <tt>spawn</tt>'s behavior.
* @returns An {@link actor} to the spawned {@link actor}.
*/
template<class Impl, spawn_options Options, typename... Ts>
template<class Impl, spawn_options Opts, typename... Ts>
actor spawn(Ts&&... args) {
return detail::spawn_fwd_args<Impl, Options>(
return detail::spawn_fwd_args<Impl, Opts>(
[](local_actor*) { /* no-op as BeforeLaunch callback */ },
std::forward<Ts>(args)...);
}
......@@ -163,38 +163,38 @@ actor spawn(Ts&&... args) {
/**
* @brief Spawns a new {@link actor} that evaluates given arguments.
* @param args A functor followed by its arguments.
* @tparam Options Optional flags to modify <tt>spawn</tt>'s behavior.
* @tparam Opts Optional flags to modify <tt>spawn</tt>'s behavior.
* @returns An {@link actor} to the spawned {@link actor}.
*/
//template<spawn_options Options = no_spawn_options, typename... Ts>
template<spawn_options Options, typename... Ts>
//template<spawn_options Opts = no_spawn_options, typename... Ts>
template<spawn_options Opts, typename... Ts>
actor spawn(Ts&&... args) {
static_assert(sizeof...(Ts) > 0, "too few arguments provided");
using base_class = typename std::conditional<
has_blocking_api_flag(Options),
has_blocking_api_flag(Opts),
detail::functor_based_blocking_actor,
detail::functor_based_actor
>::type;
return spawn<base_class, Options>(std::forward<Ts>(args)...);
return spawn<base_class, Opts>(std::forward<Ts>(args)...);
}
/**
* @brief Spawns a new actor that evaluates given arguments and
* immediately joins @p grp.
* @param args A functor followed by its arguments.
* @tparam Options Optional flags to modify <tt>spawn</tt>'s behavior.
* @tparam Opts Optional flags to modify <tt>spawn</tt>'s behavior.
* @returns An {@link actor} to the spawned {@link actor}.
* @note The spawned has joined the group before this function returns.
*/
template<spawn_options Options, typename... Ts>
template<spawn_options Opts, typename... Ts>
actor spawn_in_group(const group_ptr& grp, Ts&&... args) {
static_assert(sizeof...(Ts) > 0, "too few arguments provided");
using base_class = typename std::conditional<
has_blocking_api_flag(Options),
has_blocking_api_flag(Opts),
detail::functor_based_blocking_actor,
detail::functor_based_actor
>::type;
return detail::spawn_fwd_args<base_class, Options>(
return detail::spawn_fwd_args<base_class, Opts>(
[&](local_actor* ptr) { ptr->join(grp); },
std::forward<Ts>(args)...);
}
......@@ -202,20 +202,20 @@ actor spawn_in_group(const group_ptr& grp, Ts&&... args) {
/**
* @brief Spawns an actor of type @p Impl that immediately joins @p grp.
* @param args Constructor arguments.
* @tparam Impl Subtype of {@link untyped_actor} or {@link sb_actor}.
* @tparam Options Optional flags to modify <tt>spawn</tt>'s behavior.
* @tparam Impl Subtype of {@link event_based_actor} or {@link sb_actor}.
* @tparam Opts Optional flags to modify <tt>spawn</tt>'s behavior.
* @returns An {@link actor} to the spawned {@link actor}.
* @note The spawned has joined the group before this function returns.
*/
template<class Impl, spawn_options Options, typename... Ts>
template<class Impl, spawn_options Opts, typename... Ts>
actor spawn_in_group(const group_ptr& grp, Ts&&... args) {
return detail::spawn_fwd_args<Impl, Options>(
return detail::spawn_fwd_args<Impl, Opts>(
[&](local_actor* ptr) { ptr->join(grp); },
std::forward<Ts>(args)...);
}
/*
template<class Impl, spawn_options Options = no_spawn_options, typename... Ts>
template<class Impl, spawn_options Opts = no_spawn_options, typename... Ts>
typename Impl::typed_pointer_type spawn_typed(Ts&&... args) {
static_assert(util::tl_is_distinct<typename Impl::signatures>::value,
"typed actors are not allowed to define "
......@@ -223,13 +223,13 @@ typename Impl::typed_pointer_type spawn_typed(Ts&&... args) {
auto p = make_counted<Impl>(std::forward<Ts>(args)...);
using result_type = typename Impl::typed_pointer_type;
return result_type::cast_from(
eval_sopts(Options, get_scheduler()->exec(Options, std::move(p)))
eval_sopts(Opts, get_scheduler()->exec(Opts, std::move(p)))
);
}
*/
/*TODO:
template<spawn_options Options, typename... Ts>
template<spawn_options Opts, typename... Ts>
typed_actor<typename detail::deduce_signature<Ts>::type...>
spawn_typed(const match_expr<Ts...>& me) {
static_assert(util::conjunction<
......@@ -246,7 +246,7 @@ spawn_typed(const match_expr<Ts...>& me) {
using impl = detail::default_typed_actor<
typename detail::deduce_signature<Ts>::type...
>;
return spawn_typed<impl, Options>(me);
return spawn_typed<impl, Opts>(me);
}
template<typename... Ts>
......
......@@ -33,7 +33,7 @@
#include "cppa/replies_to.hpp"
#include "cppa/typed_behavior.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/event_based_actor.hpp"
#include "cppa/detail/typed_actor_util.hpp"
......@@ -43,7 +43,7 @@ template<typename... Signatures>
class typed_actor_ptr;
template<typename... Signatures>
class typed_actor : public untyped_actor {
class typed_actor : public event_based_actor {
public:
......
......@@ -33,6 +33,8 @@
#include "cppa/abstract_actor.hpp"
#include "cppa/util/comparable.hpp"
namespace cppa {
class actor;
......@@ -41,9 +43,9 @@ namespace detail { class raw_access; }
/**
* @brief Encapsulates actor operations that are valid for both {@link actor}
* and {@link actor_addr} handles.
* and {@link actor_addr}.
*/
class untyped_actor_handle {
class untyped_actor_handle : util::comparable<untyped_actor_handle> {
friend class actor;
friend class actor_addr;
......@@ -53,7 +55,7 @@ class untyped_actor_handle {
untyped_actor_handle() = default;
inline bool attach(attachable_ptr ptr);
inline bool attach(attachable_ptr ptr) const;
/**
* @brief Convenience function that attaches the functor
......@@ -67,7 +69,7 @@ class untyped_actor_handle {
* otherwise (actor already exited) @p false.
*/
template<typename F>
bool attach_functor(F&& f);
bool attach_functor(F&& f) const;
inline actor_id id() const;
......@@ -81,6 +83,12 @@ class untyped_actor_handle {
*/
bool is_remote() const;
inline bool valid() const {
return static_cast<bool>(m_ptr);
}
intptr_t compare(const untyped_actor_handle& other) const;
protected:
inline untyped_actor_handle(abstract_actor_ptr ptr) : m_ptr(std::move(ptr)) { }
......@@ -104,7 +112,7 @@ struct functor_attachable : attachable {
};
template<typename F>
bool untyped_actor_handle::attach_functor(F&& f) {
bool untyped_actor_handle::attach_functor(F&& f) const {
typedef typename util::rm_const_and_ref<F>::type f_type;
typedef functor_attachable<f_type> impl;
return attach(attachable_ptr{new impl(std::forward<F>(f))});
......@@ -114,7 +122,7 @@ inline actor_id untyped_actor_handle::id() const {
return (m_ptr) ? m_ptr->id() : 0;
}
inline bool untyped_actor_handle::attach(attachable_ptr ptr) {
inline bool untyped_actor_handle::attach(attachable_ptr ptr) const {
return m_ptr ? m_ptr->attach(std::move(ptr)) : false;
}
......
......@@ -112,7 +112,7 @@ constexpr int max_req_interval = 300;
} // namespace <anonymous>
// provides print utility and each base_actor has a parent
class base_actor : public untyped_actor {
class base_actor : public event_based_actor {
protected:
......@@ -308,7 +308,7 @@ class curl_master : public base_actor {
public:
curl_master() : base_actor(nullptr, "curl_master", color::magenta) { }
curl_master() : base_actor(invalid_actor, "curl_master", color::magenta) { }
protected:
......
......@@ -5,7 +5,7 @@
using namespace std;
using namespace cppa;
behavior mirror(untyped_actor* self) {
behavior mirror(event_based_actor* self) {
// wait for messages
return (
// invoke this lambda expression if we receive a string
......@@ -20,7 +20,7 @@ behavior mirror(untyped_actor* self) {
);
}
void hello_world(untyped_actor* self, const actor& buddy) {
void hello_world(event_based_actor* self, const actor& buddy) {
// send "Hello World!" to our buddy ...
self->sync_send(buddy, "Hello World!").then(
// ... and wait for a response
......
......@@ -13,7 +13,7 @@ using std::endl;
using namespace cppa;
// implementation using the blocking API
void blocking_math_fun(blocking_untyped_actor* self) {
void blocking_math_fun(blocking_actor* self) {
bool done = false;
self->do_receive (
// "arg_match" matches the parameter types of given lambda expression
......@@ -34,7 +34,7 @@ void blocking_math_fun(blocking_untyped_actor* self) {
).until(gref(done));
}
void calculator(untyped_actor* self) {
void calculator(event_based_actor* self) {
// execute this behavior until actor terminates
self->become (
on(atom("plus"), arg_match) >> [](int a, int b) {
......@@ -50,7 +50,7 @@ void calculator(untyped_actor* self) {
);
}
void tester(untyped_actor* self, const actor& testee) {
void tester(event_based_actor* self, const actor& testee) {
self->link_to(testee);
// will be invoked if we receive an unexpected response message
self->on_sync_failure([=] {
......
......@@ -53,7 +53,7 @@ void draw_kirby(const animation_step& animation) {
}
// uses a message-based loop to iterate over all animation steps
void dancing_kirby(untyped_actor* self) {
void dancing_kirby(event_based_actor* self) {
// let's get it started
self->send(self, atom("Step"), size_t{0});
self->become (
......
......@@ -17,7 +17,7 @@ using namespace std;
using namespace cppa;
// either taken by a philosopher or available
void chopstick(untyped_actor* self) {
void chopstick(event_based_actor* self) {
self->become(
on(atom("take"), arg_match) >> [=](const actor& philos) {
// tell philosopher it took this chopstick
......@@ -71,7 +71,7 @@ void chopstick(untyped_actor* self) {
* [ X = right => Y = left ]
*/
struct philosopher : untyped_actor {
struct philosopher : event_based_actor {
std::string name; // the name of this philosopher
actor left; // left chopstick
......
......@@ -26,7 +26,7 @@ using namespace cppa;
using namespace cppa::placeholders;
// our "service"
void calculator(untyped_actor* self) {
void calculator(event_based_actor* self) {
self->become (
on(atom("plus"), arg_match) >> [](int a, int b) -> any_tuple {
return make_any_tuple(atom("result"), a + b);
......@@ -49,13 +49,13 @@ inline string trim(std::string s) {
return s;
}
void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const actor& server) {
void client_bhvr(event_based_actor* self, const string& host, uint16_t port, const actor& server) {
// recover from sync failures by trying to reconnect to server
if (!self->has_sync_failure_handler()) {
self->on_sync_failure([=] {
aout(self) << "*** lost connection to " << host
<< ":" << port << endl;
client_bhvr(self, host, port, nullptr);
client_bhvr(self, host, port, invalid_actor);
});
}
// connect to server if needed
......@@ -74,7 +74,7 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a
}
}
self->become (
on_arg_match.when(_x1.in({atom("plus"), atom("minus")}) && gval(server) != nullptr) >> [=](atom_value op, int lhs, int rhs) {
on_arg_match.when(_x1.in({atom("plus"), atom("minus")}) && gval(server) != invalid_actor) >> [=](atom_value op, int lhs, int rhs) {
self->sync_send_tuple(server, self->last_dequeued()).then(
on(atom("result"), arg_match) >> [=](int result) {
aout(self) << lhs << " "
......@@ -86,15 +86,15 @@ void client_bhvr(untyped_actor* self, const string& host, uint16_t port, const a
},
on_arg_match >> [=](const down_msg&) {
aout(self) << "*** server down, try to reconnect ..." << endl;
client_bhvr(self, host, port, nullptr);
client_bhvr(self, host, port, invalid_actor);
},
on(atom("rebind"), arg_match) >> [=](const string& host, uint16_t port) {
aout(self) << "*** rebind to new server: "
<< host << ":" << port << endl;
client_bhvr(self, host, port, nullptr);
client_bhvr(self, host, port, invalid_actor);
},
on(atom("reconnect")) >> [=] {
client_bhvr(self, host, port, nullptr);
client_bhvr(self, host, port, invalid_actor);
}
);
}
......@@ -108,7 +108,7 @@ void client_repl(const string& host, uint16_t port) {
"connect <host> <port> Reconfigure server"
<< endl << endl;
string line;
auto client = spawn(client_bhvr, host, port, nullptr);
auto client = spawn(client_bhvr, host, port, invalid_actor);
const char connect[] = "connect ";
while (getline(cin, line)) {
line = trim(std::move(line)); // ignore leading and trailing whitespaces
......
......@@ -42,7 +42,7 @@ any_tuple split_line(const line& l) {
return any_tuple::view(std::move(result));
}
void client(untyped_actor* self, const string& name) {
void client(event_based_actor* self, const string& name) {
self->become (
on(atom("broadcast"), arg_match) >> [=](const string& message) {
for(auto& dest : self->joined_groups()) {
......
......@@ -42,7 +42,7 @@ bool operator==( const foo2& lhs, const foo2& rhs ) {
}
// receives `remaining` messages
void testee(untyped_actor* self, size_t remaining) {
void testee(event_based_actor* self, size_t remaining) {
auto set_next_behavior = [=] {
if (remaining > 1) testee(self, remaining - 1);
else self->quit();
......
......@@ -39,7 +39,7 @@ bool operator==(const foo& lhs, const foo& rhs) {
&& lhs.b() == rhs.b();
}
void testee(untyped_actor* self) {
void testee(event_based_actor* self) {
self->become (
on<foo>() >> [=](const foo& val) {
aout(self) << "foo("
......
......@@ -46,7 +46,7 @@ typedef int (foo::*foo_getter)() const;
// a member function pointer to set an attribute of foo
typedef void (foo::*foo_setter)(int);
void testee(untyped_actor* self) {
void testee(event_based_actor* self) {
self->become (
on<foo>() >> [=](const foo& val) {
aout(self) << "foo("
......
......@@ -79,7 +79,7 @@ bool operator==(const baz& lhs, const baz& rhs) {
}
// receives `remaining` messages
void testee(untyped_actor* self, size_t remaining) {
void testee(event_based_actor* self, size_t remaining) {
auto set_next_behavior = [=] {
if (remaining > 1) testee(self, remaining - 1);
else self->quit();
......
......@@ -131,7 +131,7 @@ class tree_type_info : public util::abstract_uniform_type_info<tree> {
typedef std::vector<tree> tree_vector;
// receives `remaining` messages
void testee(untyped_actor* self, size_t remaining) {
void testee(event_based_actor* self, size_t remaining) {
auto set_next_behavior = [=] {
if (remaining > 1) testee(self, remaining - 1);
else self->quit();
......
......@@ -66,10 +66,14 @@ abstract_actor::abstract_actor()
: m_id(get_actor_registry()->next_id()), m_is_proxy(false)
, m_exit_reason(exit_reason::not_exited) { }
void abstract_actor::link_to(const actor& whom) {
link_to(whom->address());
}
bool abstract_actor::link_to_impl(const actor_addr& other) {
if (other && other != this) {
guard_type guard{m_mtx};
auto ptr = detail::actor_addr_cast<abstract_actor>(other);
auto ptr = detail::raw_access::get(other);
// send exit message if already exited
if (exited()) {
ptr->enqueue({address(), ptr},
......@@ -147,7 +151,7 @@ bool abstract_actor::establish_backlink(const actor_addr& other) {
if (reason == exit_reason::not_exited) {
auto i = std::find(m_links.begin(), m_links.end(), other);
if (i == m_links.end()) {
m_links.push_back(detail::actor_addr_cast<abstract_actor>(other));
m_links.push_back(detail::raw_access::get(other));
return true;
}
}
......@@ -165,7 +169,7 @@ bool abstract_actor::unlink_from_impl(const actor_addr& other) {
if (!other) return false;
guard_type guard{m_mtx};
// remove_backlink returns true if this actor is linked to other
auto ptr = detail::actor_addr_cast<abstract_actor>(other);
auto ptr = detail::raw_access::get(other);
if (!exited() && ptr->remove_backlink(address())) {
auto i = std::find(m_links.begin(), m_links.end(), ptr);
CPPA_REQUIRE(i != m_links.end());
......
......@@ -35,22 +35,19 @@
#include "cppa/actor_addr.hpp"
#include "cppa/actor_proxy.hpp"
#include "cppa/local_actor.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/blocking_untyped_actor.hpp"
#include "cppa/event_based_actor.hpp"
#include "cppa/blocking_actor.hpp"
namespace cppa {
actor::actor(const std::nullptr_t&) : m_ops(nullptr) { }
actor::actor(actor_proxy* ptr) : m_ops(ptr) { }
actor::actor(untyped_actor* ptr) : m_ops(ptr) { }
actor::actor(blocking_untyped_actor* ptr) : m_ops(ptr) { }
actor::actor(const invalid_actor_t&) : m_ops(nullptr) { }
actor::actor(abstract_actor* ptr) : m_ops(ptr) { }
actor::actor(const invalid_actor_t&) : m_ops(nullptr) { }
actor& actor::operator=(const invalid_actor_t&) {
m_ops.m_ptr.reset();
return *this;
}
void actor::handle::enqueue(const message_header& hdr, any_tuple msg) const {
if (m_ptr) m_ptr->enqueue(hdr, std::move(msg));
......@@ -60,4 +57,16 @@ intptr_t actor::compare(const actor& other) const {
return channel::compare(m_ops.m_ptr.get(), other.m_ops.m_ptr.get());
}
intptr_t actor::compare(const invalid_actor_t&) const {
return valid() ? 1 : 0;
}
intptr_t actor::compare(const actor_addr& other) const {
return m_ops.compare(*other);
}
void actor::swap(actor& other) {
m_ops.m_ptr.swap(other.m_ops.m_ptr);
}
} // namespace cppa
......@@ -42,24 +42,10 @@ intptr_t compare_impl(const abstract_actor* lhs, const abstract_actor* rhs) {
}
} // namespace <anonymous>
actor_addr::actor_addr(const actor& other) : m_ops(detail::raw_access::get(other)) { }
actor_addr::actor_addr(const invalid_actor_addr_t&) : m_ops(nullptr) { }
actor_addr::actor_addr(abstract_actor* ptr) : m_ops(ptr) { }
actor_addr::operator bool() const {
return static_cast<bool>(m_ops.m_ptr);
}
bool actor_addr::operator!() const {
return !(m_ops.m_ptr);
}
intptr_t actor_addr::compare(const actor& other) const {
return compare_impl(m_ops.m_ptr.get(), detail::raw_access::get(other));
}
intptr_t actor_addr::compare(const actor_addr& other) const {
return compare_impl(m_ops.m_ptr.get(), other.m_ops.m_ptr.get());
}
......@@ -68,11 +54,6 @@ intptr_t actor_addr::compare(const abstract_actor* other) const {
return compare_impl(m_ops.m_ptr.get(), other);
}
actor_addr& actor_addr::operator=(const actor& other) {
m_ops.m_ptr = detail::raw_access::get(other);
return *this;
}
actor_addr actor_addr::operator=(const invalid_actor_addr_t&) {
m_ops.m_ptr.reset();
return *this;
......
......@@ -57,7 +57,7 @@ void actor_namespace::write(serializer* sink, const actor_addr& ptr) {
else {
// register locally running actors to be able to deserialize them later
if (!ptr->is_remote()) {
get_actor_registry()->put(ptr->id(), detail::actor_addr_cast<abstract_actor>(ptr));
get_actor_registry()->put(ptr->id(), detail::raw_access::get(ptr));
}
auto& pinf = ptr->node();
sink->write_value(ptr->id()); // actor id
......
......@@ -31,30 +31,30 @@
#include "cppa/logging.hpp"
#include "cppa/scheduler.hpp"
#include "cppa/singletons.hpp"
#include "cppa/blocking_untyped_actor.hpp"
#include "cppa/blocking_actor.hpp"
#include "cppa/detail/actor_registry.hpp"
namespace cppa {
void blocking_untyped_actor::response_future::await(behavior& bhvr) {
void blocking_actor::response_future::await(behavior& bhvr) {
m_self->dequeue_response(bhvr, m_mid);
}
void blocking_untyped_actor::await_all_other_actors_done() {
void blocking_actor::await_all_other_actors_done() {
get_actor_registry()->await_running_count_equal(1);
}
blocking_untyped_actor::response_future
blocking_untyped_actor::sync_send_tuple(const actor& dest, any_tuple what) {
blocking_actor::response_future
blocking_actor::sync_send_tuple(const actor& dest, any_tuple what) {
auto nri = new_request_id();
dest->enqueue({address(), dest, nri}, std::move(what));
return {nri.response_id(), this};
}
blocking_untyped_actor::response_future
blocking_untyped_actor::timed_sync_send_tuple(const util::duration& rtime,
blocking_actor::response_future
blocking_actor::timed_sync_send_tuple(const util::duration& rtime,
const actor& dest,
any_tuple what) {
return {timed_sync_send_tuple_impl(message_priority::normal, dest, rtime,
......@@ -62,7 +62,7 @@ blocking_untyped_actor::timed_sync_send_tuple(const util::duration& rtime,
this};
}
void blocking_untyped_actor::quit(std::uint32_t reason) {
void blocking_actor::quit(std::uint32_t reason) {
planned_exit_reason(reason);
throw actor_exited(reason);
}
......
......@@ -36,8 +36,6 @@
namespace cppa {
channel::channel(const std::nullptr_t&) : m_ptr(nullptr) { }
channel::channel(const invalid_actor_t&) : m_ptr(nullptr) { }
channel::channel(const actor& other) : m_ptr(detail::raw_access::get(other)) { }
......
......@@ -40,16 +40,16 @@ namespace cppa {
namespace policy {
void context_switching_resume::trampoline(void* this_ptr) {
auto _this = reinterpret_cast<blocking_untyped_actor*>(this_ptr);
auto shut_actor_down = [_this](std::uint32_t reason) {
if (_this->planned_exit_reason() == exit_reason::not_exited) {
_this->planned_exit_reason(reason);
auto self = reinterpret_cast<blocking_actor*>(this_ptr);
auto shut_actor_down = [self](std::uint32_t reason) {
if (self->planned_exit_reason() == exit_reason::not_exited) {
self->planned_exit_reason(reason);
}
_this->on_exit();
_this->cleanup(_this->planned_exit_reason());
self->on_exit();
self->cleanup(self->planned_exit_reason());
};
try {
_this->act();
self->act();
shut_actor_down(exit_reason::normal);
}
catch (actor_exited& e) {
......@@ -77,6 +77,4 @@ void context_switching_resume::trampoline(void*) {
} // namespace policy
} // namespace cppa
namespace cppa { int keep_compiler_happy_function() { return 42; } }
#endif // ifdef CPPA_DISABLE_CONTEXT_SWITCHING
......@@ -31,11 +31,12 @@
#include "cppa/scheduler.hpp"
#include "cppa/singletons.hpp"
#include "cppa/message_id.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/event_based_actor.hpp"
namespace cppa {
continue_helper& continue_helper::continue_with(behavior::continuation_fun fun) {
continue_helper&
continue_helper::continue_with(behavior::continuation_fun fun) {
auto ref_opt = m_self->bhvr_stack().sync_handler(m_mid);
if (ref_opt) {
behavior cpy = *ref_opt;
......@@ -45,19 +46,19 @@ continue_helper& continue_helper::continue_with(behavior::continuation_fun fun)
return *this;
}
void untyped_actor::forward_to(const actor& whom) {
void event_based_actor::forward_to(const actor& whom) {
forward_message(whom, message_priority::normal);
}
untyped_actor::response_future untyped_actor::sync_send_tuple(const actor& dest,
any_tuple what) {
event_based_actor::response_future
event_based_actor::sync_send_tuple(const actor& dest, any_tuple what) {
auto nri = new_request_id();
dest->enqueue({address(), dest, nri}, std::move(what));
return {nri.response_id(), this};
}
untyped_actor::response_future
untyped_actor::timed_sync_send_tuple(const util::duration& rtime,
event_based_actor::response_future
event_based_actor::timed_sync_send_tuple(const util::duration& rtime,
const actor& dest,
any_tuple what) {
return {timed_sync_send_tuple_impl(message_priority::normal, dest, rtime,
......
......@@ -33,8 +33,8 @@
namespace cppa {
namespace detail {
void functor_based_actor::create(untyped_actor*, void_fun fun) {
m_make_behavior = [=](untyped_actor* self) -> behavior {
void functor_based_actor::create(event_based_actor*, void_fun fun) {
m_make_behavior = [=](event_based_actor* self) -> behavior {
fun(self);
return behavior{};
};
......
......@@ -34,7 +34,7 @@
namespace cppa {
namespace detail {
void functor_based_blocking_actor::create(blocking_untyped_actor*, act_fun fun) {
void functor_based_blocking_actor::create(blocking_actor*, act_fun fun) {
m_act = fun;
}
......
......@@ -87,7 +87,7 @@ const std::string& group::module_name() const {
return get_module()->name();
}
struct group_nameserver : untyped_actor {
struct group_nameserver : event_based_actor {
behavior make_behavior() override {
return (
on(atom("GET_GROUP"), arg_match) >> [](const std::string& name) {
......
......@@ -40,8 +40,8 @@
#include "cppa/any_tuple.hpp"
#include "cppa/serializer.hpp"
#include "cppa/deserializer.hpp"
#include "cppa/untyped_actor.hpp"
#include "cppa/message_header.hpp"
#include "cppa/event_based_actor.hpp"
#include "cppa/io/middleman.hpp"
......@@ -132,7 +132,7 @@ class local_group : public group {
typedef intrusive_ptr<local_group> local_group_ptr;
class local_broker : public untyped_actor {
class local_broker : public event_based_actor {
public:
......@@ -218,8 +218,8 @@ class local_group_proxy : public local_group {
template<typename... Ts>
local_group_proxy(actor remote_broker, Ts&&... args)
: super(false, forward<Ts>(args)...) {
CPPA_REQUIRE(m_broker == nullptr);
CPPA_REQUIRE(remote_broker != nullptr);
CPPA_REQUIRE(m_broker == invalid_actor);
CPPA_REQUIRE(remote_broker != invalid_actor);
m_broker = move(remote_broker);
m_proxy_broker = spawn<proxy_broker, hidden>(this);
}
......@@ -230,7 +230,7 @@ class local_group_proxy : public local_group {
if (res.first) {
if (res.second == 1) {
// join the remote source
send_as(nullptr, m_broker, atom("JOIN"), m_proxy_broker);
anon_send(m_broker, atom("JOIN"), m_proxy_broker);
}
return {who, this};
}
......@@ -244,7 +244,7 @@ class local_group_proxy : public local_group {
if (res.first && res.second == 0) {
// leave the remote source,
// because there's no more subscriber on this node
send_as(nullptr, m_broker, atom("LEAVE"), m_proxy_broker);
anon_send(m_broker, atom("LEAVE"), m_proxy_broker);
}
}
......@@ -261,7 +261,7 @@ class local_group_proxy : public local_group {
typedef intrusive_ptr<local_group_proxy> local_group_proxy_ptr;
class proxy_broker : public untyped_actor {
class proxy_broker : public event_based_actor {
public:
......@@ -339,7 +339,7 @@ class local_group_module : public group::module {
void serialize(local_group* ptr, serializer* sink) {
// serialize identifier & broker
sink->write_value(ptr->identifier());
CPPA_REQUIRE(ptr->broker() != nullptr);
CPPA_REQUIRE(ptr->broker() != invalid_actor);
m_actor_utype->serialize(&ptr->broker(), sink);
}
......@@ -411,7 +411,7 @@ class shared_map : public ref_counted {
lock_type guard(m_mtx);
auto i = m_instances.find(key);
if (i == m_instances.end()) {
send_as(nullptr, m_worker, atom("FETCH"), key);
anon_send(m_worker, atom("FETCH"), key);
do {
m_cond.wait(guard);
} while ((i = m_instances.find(key)) == m_instances.end());
......@@ -462,7 +462,7 @@ class remote_group_module : public group::module {
auto sm = make_counted<shared_map>();
group::module_ptr _this = this;
m_map = sm;
m_map->m_worker = spawn<hidden>([=](untyped_actor* self) -> behavior {
m_map->m_worker = spawn<hidden>([=](event_based_actor* self) -> behavior {
CPPA_LOGC_TRACE(detail::demangle(typeid(*_this)),
"remote_group_module$worker",
"");
......
......@@ -55,12 +55,10 @@ class down_observer : public attachable {
}
void actor_exited(std::uint32_t reason) {
if (m_observer) {
auto ptr = detail::actor_addr_cast<abstract_actor>(m_observer);
auto ptr = detail::raw_access::get(m_observer);
message_header hdr{m_observed, ptr, message_id{}.with_high_priority()};
hdr.deliver(make_any_tuple(down_msg{m_observed, reason}));
}
}
bool matches(const attachable::token& match_token) {
if (match_token.subtype == typeid(down_observer)) {
......@@ -72,15 +70,13 @@ class down_observer : public attachable {
};
constexpr const char* s_default_debug_name = "actor";
} // namespace <anonymous>
local_actor::local_actor()
: m_trap_exit(false)
, m_dummy_node(), m_current_node(&m_dummy_node)
, m_planned_exit_reason(exit_reason::not_exited)
, m_state(actor_state::ready) {
: m_trap_exit(false)
, m_dummy_node(), m_current_node(&m_dummy_node)
, m_planned_exit_reason(exit_reason::not_exited)
, m_state(actor_state::ready) {
m_node = node_id::get();
}
......@@ -88,13 +84,13 @@ local_actor::~local_actor() { }
void local_actor::monitor(const actor_addr& whom) {
if (!whom) return;
auto ptr = detail::actor_addr_cast<abstract_actor>(whom);
auto ptr = detail::raw_access::get(whom);
ptr->attach(attachable_ptr{new down_observer(address(), whom)});
}
void local_actor::demonitor(const actor_addr& whom) {
if (!whom) return;
auto ptr = detail::actor_addr_cast<abstract_actor>(whom);
auto ptr = detail::raw_access::get(whom);
attachable::token mtoken{typeid(down_observer), this};
ptr->detach(mtoken);
}
......@@ -124,10 +120,10 @@ void local_actor::reply_message(any_tuple&& what) {
if (!whom) return;
auto& id = m_current_node->mid;
if (id.valid() == false || id.is_response()) {
send_tuple(detail::actor_addr_cast<abstract_actor>(whom), std::move(what));
send_tuple(detail::raw_access::get(whom), std::move(what));
}
else if (!id.is_answered()) {
auto ptr = detail::actor_addr_cast<abstract_actor>(whom);
auto ptr = detail::raw_access::get(whom);
ptr->enqueue({address(), ptr, id.response_id()}, std::move(what));
id.mark_as_answered();
}
......@@ -207,4 +203,10 @@ message_id local_actor::timed_sync_send_tuple_impl(message_priority mp,
return rri;
}
void anon_send_exit(const actor_addr& whom, std::uint32_t reason) {
auto ptr = detail::raw_access::get(whom);
ptr->enqueue({invalid_actor_addr, ptr, message_id{}.with_high_priority()},
make_any_tuple(exit_msg{invalid_actor_addr, reason}));
}
} // namespace cppa
......@@ -267,58 +267,65 @@ void peer::kill_proxy(const actor_addr& sender,
void peer::deliver(const message_header& hdr, any_tuple msg) {
CPPA_LOG_TRACE("");
if (hdr.sender && hdr.sender->is_remote()) {
auto ptr = detail::actor_addr_cast<actor_proxy>(hdr.sender);
// is_remote() is guaranteed to return true if and only if
// the actor is derived from actor_proxy, hence we do not
// need to use a dynamic_cast here
auto ptr = static_cast<actor_proxy*>(detail::raw_access::get(hdr.sender));
ptr->deliver(hdr, std::move(msg));
}
else hdr.deliver(std::move(msg));
}
void peer::link(const actor_addr& sender, const actor_addr& receiver) {
void peer::link(const actor_addr& lhs, const actor_addr& rhs) {
// this message is sent from default_actor_proxy in link_to and
// establish_backling to cause the original actor (sender) to establish
// a link to ptr as well
CPPA_LOG_TRACE(CPPA_TARG(sender, to_string) << ", "
<< CPPA_TARG(receiver, to_string));
CPPA_LOG_ERROR_IF(!sender, "received 'LINK' from invalid sender");
CPPA_LOG_ERROR_IF(!receiver, "received 'LINK' with invalid receiver");
if (!sender || !receiver) return;
auto locally_link_proxy = [](const actor_addr& lhs, const actor_addr& rhs) {
detail::actor_addr_cast<actor_proxy>(lhs)->local_link_to(rhs);
CPPA_LOG_TRACE(CPPA_TARG(lhs, to_string) << ", "
<< CPPA_TARG(rhs, to_string));
CPPA_LOG_ERROR_IF(!lhs, "received 'LINK' from invalid sender");
CPPA_LOG_ERROR_IF(!rhs, "received 'LINK' with invalid receiver");
if (!lhs || !rhs) return;
auto locally_link_proxy = [](const actor_addr& proxy, const actor_addr& addr) {
// again, no need to to use a dynamic_cast here
auto ptr = static_cast<actor_proxy*>(detail::raw_access::get(proxy));
ptr->local_link_to(addr);
};
switch ((sender->is_remote() ? 0x10 : 0x00) | (receiver->is_remote() ? 0x01 : 0x00)) {
switch ((lhs->is_remote() ? 0x10 : 0x00) | (rhs->is_remote() ? 0x01 : 0x00)) {
case 0x00: // both local
case 0x11: // both remote
detail::actor_addr_cast<abstract_actor>(sender)->link_to(receiver);
detail::raw_access::get(lhs)->link_to(rhs);
break;
case 0x10: // sender is remote
locally_link_proxy(sender, receiver);
locally_link_proxy(lhs, rhs);
break;
case 0x01: // receiver is remote
locally_link_proxy(receiver, sender);
locally_link_proxy(rhs, lhs);
break;
default: CPPA_LOG_ERROR("logic error");
}
}
void peer::unlink(const actor_addr& sender, const actor_addr& receiver) {
CPPA_LOG_TRACE(CPPA_TARG(sender, to_string) << ", "
<< CPPA_TARG(receiver, to_string));
CPPA_LOG_ERROR_IF(!sender, "received 'UNLINK' from invalid sender");
CPPA_LOG_ERROR_IF(!receiver, "received 'UNLINK' with invalid target");
if (!sender || !receiver) return;
auto locally_unlink_proxy = [](const actor_addr& lhs, const actor_addr& rhs) {
detail::actor_addr_cast<actor_proxy>(lhs)->local_unlink_from(rhs);
void peer::unlink(const actor_addr& lhs, const actor_addr& rhs) {
CPPA_LOG_TRACE(CPPA_TARG(lhs, to_string) << ", "
<< CPPA_TARG(rhs, to_string));
CPPA_LOG_ERROR_IF(!lhs, "received 'UNLINK' from invalid sender");
CPPA_LOG_ERROR_IF(!rhs, "received 'UNLINK' with invalid target");
if (!lhs || !rhs) return;
auto locally_unlink_proxy = [](const actor_addr& proxy, const actor_addr& addr) {
// again, no need to to use a dynamic_cast here
auto ptr = static_cast<actor_proxy*>(detail::raw_access::get(proxy));
ptr->local_unlink_from(addr);
};
switch ((sender->is_remote() ? 0x10 : 0x00) | (receiver->is_remote() ? 0x01 : 0x00)) {
switch ((lhs->is_remote() ? 0x10 : 0x00) | (rhs->is_remote() ? 0x01 : 0x00)) {
case 0x00: // both local
case 0x11: // both remote
detail::actor_addr_cast<abstract_actor>(sender)->unlink_from(receiver);
detail::raw_access::get(lhs)->unlink_from(rhs);
break;
case 0x10: // sender is remote
locally_unlink_proxy(sender, receiver);
locally_unlink_proxy(lhs, rhs);
break;
case 0x01: // receiver is remote
locally_unlink_proxy(receiver, sender);
locally_unlink_proxy(rhs, lhs);
break;
default: CPPA_LOG_ERROR("logic error");
}
......
......@@ -52,7 +52,7 @@ response_promise::operator bool() const {
void response_promise::deliver(any_tuple msg) {
if (m_to) {
auto ptr = detail::actor_addr_cast<abstract_actor>(m_to);
auto ptr = detail::raw_access::get(m_to);
ptr->enqueue({m_from, ptr, m_id}, move(msg));
m_to = invalid_actor_addr;
}
......
......@@ -95,7 +95,7 @@ inline void insert_dmsg(Map& storage, const util::duration& d,
storage.insert(std::make_pair(std::move(tout), std::move(dmsg)));
}
class timer_actor final : public detail::proper_actor<blocking_untyped_actor,
class timer_actor final : public detail::proper_actor<blocking_actor,
timer_actor_policies> {
public:
......@@ -194,7 +194,7 @@ class scheduler_helper {
static void timer_loop(timer_actor* self);
static void printer_loop(blocking_untyped_actor* self);
static void printer_loop(blocking_actor* self);
};
......@@ -202,7 +202,7 @@ void scheduler_helper::timer_loop(timer_actor* self) {
self->act();
}
void scheduler_helper::printer_loop(blocking_untyped_actor* self) {
void scheduler_helper::printer_loop(blocking_actor* self) {
std::map<actor_addr, std::string> out;
auto flush_output = [&out](const actor_addr& s) {
auto i = out.find(s);
......
......@@ -39,11 +39,11 @@ namespace cppa {
namespace {
struct impl : blocking_untyped_actor {
struct impl : blocking_actor {
void act() override { }
};
blocking_untyped_actor* alloc() {
blocking_actor* alloc() {
using namespace policy;
return new detail::proper_actor<impl,
policies<no_scheduling,
......
......@@ -42,10 +42,11 @@ namespace cppa { namespace detail {
sync_request_bouncer::sync_request_bouncer(std::uint32_t r)
: rsn(r == exit_reason::not_exited ? exit_reason::normal : r) { }
void sync_request_bouncer::operator()(const actor_addr& sender, const message_id& mid) const {
void sync_request_bouncer::operator()(const actor_addr& sender,
const message_id& mid) const {
CPPA_REQUIRE(rsn != exit_reason::not_exited);
if (sender && mid.is_request()) {
auto ptr = detail::actor_addr_cast<abstract_actor>(sender);
auto ptr = detail::raw_access::get(sender);
ptr->enqueue({invalid_actor_addr, ptr, mid.response_id()},
make_any_tuple(atom("EXITED"), rsn));
}
......
......@@ -68,9 +68,10 @@ using namespace io;
void publish(actor whom, std::unique_ptr<acceptor> aptr) {
CPPA_LOGF_TRACE(CPPA_TARG(whom, to_string) << ", " << CPPA_MARG(aptr, get));
if (!whom) return;
get_actor_registry()->put(whom->id(), detail::actor_addr_cast<abstract_actor>(whom));
get_actor_registry()->put(whom->id(), detail::raw_access::get(whom));
auto mm = get_middleman();
mm->register_acceptor(whom, new peer_acceptor(mm, move(aptr), whom));
auto addr = whom->address();
mm->register_acceptor(addr, new peer_acceptor(mm, move(aptr), addr));
}
void publish(actor whom, std::uint16_t port, const char* addr) {
......
......@@ -190,7 +190,7 @@ void serialize_impl(const actor& ptr, serializer* sink) {
void deserialize_impl(actor& ptr, deserializer* source) {
actor_addr addr;
deserialize_impl(addr, source);
ptr = detail::raw_access::unsafe_cast(detail::actor_addr_cast<abstract_actor>(addr));
ptr = detail::raw_access::unsafe_cast(addr);
}
void serialize_impl(const group_ptr& ptr, serializer* sink) {
......@@ -255,7 +255,7 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
case 1: {
actor tmp;
deserialize_impl(tmp, source);
ptrref = detail::actor_addr_cast<abstract_actor>(tmp);
ptrref = detail::raw_access::get(tmp);
break;
}
case 2: {
......@@ -273,7 +273,10 @@ void deserialize_impl(channel& ptrref, deserializer* source) {
void serialize_impl(const any_tuple& tup, serializer* sink) {
auto tname = tup.tuple_type_names();
auto uti = get_uniform_type_info_map()->by_uniform_name(tname ? *tname : detail::get_tuple_type_names(*tup.vals()));
auto uti = get_uniform_type_info_map()
->by_uniform_name(tname
? *tname
: detail::get_tuple_type_names(*tup.vals()));
if (uti == nullptr) {
std::string err = "could not get uniform type info for \"";
err += tname ? *tname : detail::get_tuple_type_names(*tup.vals());
......@@ -520,7 +523,8 @@ class int_tinfo : public abstract_int_tinfo {
bool equals(const std::type_info& ti) const {
auto tptr = &ti;
return std::any_of(m_natives.begin(), m_natives.end(), [tptr](const std::type_info* ptr) {
return std::any_of(m_natives.begin(), m_natives.end(),
[tptr](const std::type_info* ptr) {
return types_equal(ptr, tptr);
});
}
......@@ -787,21 +791,21 @@ class utim_impl : public uniform_type_info_map {
auto cmp = [](pointer lhs, pointer rhs) {
return strcmp(lhs->name(), rhs->name()) < 0;
};
if (!std::is_sorted(m_builtin_types.begin(), m_builtin_types.end(), cmp)) {
std::cerr << "FATAL: uniform type map not sorted" << std::endl;
std::cerr << "order is:" << std::endl;
for (auto ptr : m_builtin_types) std::cerr << ptr->name() << std::endl;
std::sort(m_builtin_types.begin(), m_builtin_types.end(), cmp);
std::cerr << "\norder should be:" << std::endl;
for (auto ptr : m_builtin_types) std::cerr << ptr->name() << std::endl;
auto& arr = m_builtin_types;
if (!std::is_sorted(arr.begin(), arr.end(), cmp)) {
std::cerr << "FATAL: uniform type map not sorted" << std::endl
<< "order is:" << std::endl;
for (auto ptr : arr) std::cerr << ptr->name() << std::endl;
std::sort(arr.begin(), arr.end(), cmp);
std::cerr << std::endl << "order should be:" << std::endl;
for (auto ptr : arr) std::cerr << ptr->name() << std::endl;
abort();
}
auto cmp2 = [](const char** lhs, const char** rhs) {
return strcmp(lhs[0], rhs[0]) < 0;
};
if (!std::is_sorted(std::begin(mapped_type_names), std::end(mapped_type_names), cmp2)) {
if (!std::is_sorted(std::begin(mapped_type_names),
std::end(mapped_type_names), cmp2)) {
std::cerr << "FATAL: mapped_type_names not sorted" << std::endl;
abort();
}
......@@ -847,7 +851,8 @@ class utim_impl : public uniform_type_info_map {
pointer insert(std::unique_ptr<uniform_type_info> uti) {
std::unique_lock<util::shared_spinlock> guard(m_lock);
auto e = m_user_types.end();
auto i = std::lower_bound(m_user_types.begin(), e, uti.get(), [](uniform_type_info* lhs, pointer rhs) {
auto i = std::lower_bound(m_user_types.begin(), e, uti.get(),
[](uniform_type_info* lhs, pointer rhs) {
return strcmp(lhs->name(), rhs->name()) < 0;
});
if (i == e) {
......@@ -934,7 +939,8 @@ class utim_impl : public uniform_type_info_map {
pointer find_name(const Container& c, const std::string& name) const {
auto e = c.end();
// both containers are sorted
auto i = std::lower_bound(c.begin(), e, name, [](pointer p, const std::string& n) {
auto i = std::lower_bound(c.begin(), e, name,
[](pointer p, const std::string& n) {
return p->name() < n;
});
return (i != e && (*i)->name() == name) ? *i : nullptr;
......
......@@ -28,6 +28,7 @@
\******************************************************************************/
#include "cppa/channel.hpp"
#include "cppa/actor_addr.hpp"
#include "cppa/untyped_actor_handle.hpp"
......@@ -45,4 +46,9 @@ bool untyped_actor_handle::is_remote() const {
return m_ptr ? m_ptr->is_proxy() : false;
}
intptr_t untyped_actor_handle::compare(const untyped_actor_handle& other) const {
return channel::compare(m_ptr.get(), other.m_ptr.get());
}
} // namespace cppa
......@@ -57,27 +57,27 @@ size_t pongs() {
return s_pongs;
}
void ping(blocking_untyped_actor* self, size_t num_pings) {
void ping(blocking_actor* self, size_t num_pings) {
CPPA_LOGF_TRACE("num_pings = " << num_pings);
s_pongs = 0;
self->receive_loop(ping_behavior(self, num_pings));
}
void event_based_ping(untyped_actor* self, size_t num_pings) {
void event_based_ping(event_based_actor* self, size_t num_pings) {
CPPA_LOGF_TRACE("num_pings = " << num_pings);
s_pongs = 0;
self->become(ping_behavior(self, num_pings));
}
void pong(blocking_untyped_actor* self, actor ping_actor) {
void pong(blocking_actor* self, actor ping_actor) {
CPPA_LOGF_TRACE("ping_actor = " << to_string(ping_actor));
self->send(ping_actor, atom("pong"), 0); // kickoff
self->receive_loop(pong_behavior(self));
}
void event_based_pong(untyped_actor* self, actor ping_actor) {
void event_based_pong(event_based_actor* self, actor ping_actor) {
CPPA_LOGF_TRACE("ping_actor = " << to_string(ping_actor));
CPPA_REQUIRE(ping_actor != nullptr);
CPPA_REQUIRE(ping_actor != invalid_actor);
self->send(ping_actor, atom("pong"), 0); // kickoff
self->become(pong_behavior(self));
}
......@@ -6,13 +6,13 @@
#include <cstddef>
#include "cppa/cppa_fwd.hpp"
void ping(cppa::blocking_untyped_actor*, size_t num_pings);
void ping(cppa::blocking_actor*, size_t num_pings);
void event_based_ping(cppa::untyped_actor*, size_t num_pings);
void event_based_ping(cppa::event_based_actor*, size_t num_pings);
void pong(cppa::blocking_untyped_actor*, cppa::actor ping_actor);
void pong(cppa::blocking_actor*, cppa::actor ping_actor);
void event_based_pong(cppa::untyped_actor*, cppa::actor ping_actor);
void event_based_pong(cppa::event_based_actor*, cppa::actor ping_actor);
// returns the number of messages ping received
size_t pongs();
......
......@@ -29,12 +29,12 @@ void foo() {
}
struct mirror {
mirror(blocking_untyped_actor* self) : m_self(self) { }
mirror(blocking_actor* self) : m_self(self) { }
template<typename... Ts>
void operator()(Ts&&... args) {
m_self->send(m_self, std::forward<Ts>(args)...);
}
blocking_untyped_actor* m_self;
blocking_actor* m_self;
};
int main() {
......
......@@ -39,7 +39,7 @@ using namespace cppa;
namespace { constexpr size_t message_size = sizeof(atom_value) + sizeof(int); }
void ping(cppa::untyped_actor* self, size_t num_pings) {
void ping(cppa::event_based_actor* self, size_t num_pings) {
CPPA_CHECKPOINT();
auto count = std::make_shared<size_t>(0);
self->become (
......@@ -59,7 +59,7 @@ void ping(cppa::untyped_actor* self, size_t num_pings) {
);
}
void pong(cppa::untyped_actor* self) {
void pong(cppa::event_based_actor* self) {
CPPA_CHECKPOINT();
self->become (
on(atom("ping"), arg_match)
......@@ -85,9 +85,11 @@ void pong(cppa::untyped_actor* self) {
void peer(io::broker* self, io::connection_handle hdl, const actor& buddy) {
CPPA_CHECKPOINT();
CPPA_CHECK(self != nullptr);
CPPA_CHECK(buddy != invalid_actor);
self->monitor(buddy);
if (self->num_connections() == 0) {
cout << "num_connections() != 1" << endl;
cerr << "num_connections() != 1" << endl;
throw std::logic_error("num_connections() != 1");
}
auto write = [=](atom_value type, int value) {
......@@ -145,7 +147,7 @@ int main(int argc, char** argv) {
CPPA_CHECKPOINT();
auto cl = spawn_io(peer, "localhost", port, p);
CPPA_CHECKPOINT();
send_as(nullptr, p, atom("kickoff"), cl);
anon_send(p, atom("kickoff"), cl);
CPPA_CHECKPOINT();
});
CPPA_CHECKPOINT();
......
......@@ -21,7 +21,7 @@ using std::endl;
using std::string;
using namespace cppa;
void testee(untyped_actor* self, int current_value, int final_result) {
void testee(event_based_actor* self, int current_value, int final_result) {
self->become(
on_arg_match >> [=](int result) {
auto next = result + current_value;
......
......@@ -22,7 +22,7 @@ typedef std::pair<std::string, std::string> string_pair;
typedef vector<actor> actor_vector;
void reflector(untyped_actor* self) {
void reflector(event_based_actor* self) {
self->become (
others() >> [=] {
CPPA_LOGF_INFO("reflect and quit");
......@@ -32,7 +32,7 @@ void reflector(untyped_actor* self) {
);
}
void spawn5_server_impl(untyped_actor* self, actor client, group_ptr grp) {
void spawn5_server_impl(event_based_actor* self, actor client, group_ptr grp) {
CPPA_LOGF_TRACE(CPPA_TARG(client, to_string)
<< ", " << CPPA_TARG(grp, to_string));
self->spawn_in_group(grp, reflector);
......@@ -103,7 +103,7 @@ void spawn5_server_impl(untyped_actor* self, actor client, group_ptr grp) {
}
// receive seven reply messages (2 local, 5 remote)
void spawn5_server(untyped_actor* self, actor client, bool inverted) {
void spawn5_server(event_based_actor* self, actor client, bool inverted) {
if (!inverted) spawn5_server_impl(self, client, group::get("local", "foobar"));
else {
CPPA_LOGF_INFO("request group");
......@@ -115,7 +115,7 @@ void spawn5_server(untyped_actor* self, actor client, bool inverted) {
}
}
void spawn5_client(untyped_actor* self) {
void spawn5_client(event_based_actor* self) {
self->become (
on(atom("GetGroup")) >> []() -> group_ptr {
CPPA_LOGF_INFO("received {'GetGroup'}");
......@@ -139,7 +139,7 @@ void spawn5_client(untyped_actor* self) {
} // namespace <anonymous>
template<typename F>
void await_down(untyped_actor* self, actor ptr, F continuation) {
void await_down(event_based_actor* self, actor ptr, F continuation) {
self->become (
on_arg_match >> [=](const down_msg& dm) -> bool {
if (dm.source == ptr) {
......@@ -153,7 +153,7 @@ void await_down(untyped_actor* self, actor ptr, F continuation) {
static constexpr size_t num_pings = 10;
class client : public untyped_actor {
class client : public event_based_actor {
public:
......@@ -233,7 +233,7 @@ class client : public untyped_actor {
};
class server : public untyped_actor {
class server : public event_based_actor {
public:
......
......@@ -56,7 +56,7 @@ class event_testee : public sb_actor<event_testee> {
// quits after 5 timeouts
actor spawn_event_testee2(actor parent) {
struct impl : untyped_actor {
struct impl : event_based_actor {
actor parent;
impl(actor parent) : parent(parent) { }
behavior wait4timeout(int remaining) {
......@@ -114,7 +114,7 @@ struct chopstick : public sb_actor<chopstick> {
class testee_actor {
void wait4string(blocking_untyped_actor* self) {
void wait4string(blocking_actor* self) {
bool string_received = false;
self->do_receive (
on<string>() >> [&] {
......@@ -127,7 +127,7 @@ class testee_actor {
.until(gref(string_received));
}
void wait4float(blocking_untyped_actor* self) {
void wait4float(blocking_actor* self) {
bool float_received = false;
self->do_receive (
on<float>() >> [&] {
......@@ -143,7 +143,7 @@ class testee_actor {
public:
void operator()(blocking_untyped_actor* self) {
void operator()(blocking_actor* self) {
self->receive_loop (
on<int>() >> [&] {
wait4float(self);
......@@ -157,7 +157,7 @@ class testee_actor {
};
// self->receives one timeout and quits
void testee1(untyped_actor* self) {
void testee1(event_based_actor* self) {
CPPA_LOGF_TRACE("");
self->become(after(chrono::milliseconds(10)) >> [=] {
CPPA_LOGF_TRACE("");
......@@ -165,7 +165,7 @@ void testee1(untyped_actor* self) {
});
}
void testee2(untyped_actor* self, actor other) {
void testee2(event_based_actor* self, actor other) {
self->link_to(other);
self->send(other, uint32_t(1));
self->become (
......@@ -262,7 +262,7 @@ class fixed_stack : public sb_actor<fixed_stack> {
};
behavior echo_actor(untyped_actor* self) {
behavior echo_actor(event_based_actor* self) {
return (
others() >> [=]() -> any_tuple {
self->quit(exit_reason::normal);
......@@ -282,7 +282,7 @@ struct simple_mirror : sb_actor<simple_mirror> {
};
behavior high_priority_testee(untyped_actor* self) {
behavior high_priority_testee(event_based_actor* self) {
self->send(self, atom("b"));
self->send(message_priority::high, self, atom("a"));
// 'a' must be self->received before 'b'
......@@ -305,13 +305,13 @@ behavior high_priority_testee(untyped_actor* self) {
);
}
struct high_priority_testee_class : untyped_actor {
struct high_priority_testee_class : event_based_actor {
behavior make_behavior() override {
return high_priority_testee(this);
}
};
struct master : untyped_actor {
struct master : event_based_actor {
behavior make_behavior() override {
return (
on(atom("done")) >> [=] {
......@@ -321,7 +321,7 @@ struct master : untyped_actor {
}
};
struct slave : untyped_actor {
struct slave : event_based_actor {
slave(actor master) : master{master} { }
......@@ -337,13 +337,13 @@ struct slave : untyped_actor {
};
void test_serial_reply() {
auto mirror_behavior = [=](untyped_actor* self) {
auto mirror_behavior = [=](event_based_actor* self) {
self->become(others() >> [=]() -> any_tuple {
CPPA_LOGF_INFO("return self->last_dequeued()");
return self->last_dequeued();
});
};
auto master = spawn([=](untyped_actor* self) {
auto master = spawn([=](event_based_actor* self) {
cout << "ID of master: " << self->id() << endl;
// spawn 5 mirror actors
auto c0 = self->spawn<linked>(mirror_behavior);
......@@ -450,7 +450,7 @@ void test_or_else() {
void test_continuation() {
auto mirror = spawn<simple_mirror>();
spawn([=](untyped_actor* self) {
spawn([=](event_based_actor* self) {
self->sync_send(mirror, 42).then(
on(42) >> [] {
return "fourty-two";
......@@ -473,7 +473,7 @@ void test_continuation() {
void test_simple_reply_response() {
scoped_actor self;
auto s = spawn([](untyped_actor* self) -> behavior {
auto s = spawn([](event_based_actor* self) -> behavior {
return (
others() >> [=]() -> any_tuple {
CPPA_CHECK(self->last_dequeued() == make_any_tuple(atom("hello")));
......@@ -655,7 +655,7 @@ void test_spawn() {
self->await_all_other_actors_done();
CPPA_CHECKPOINT();
auto sync_testee1 = spawn<blocking_api>([](blocking_untyped_actor* self) {
auto sync_testee1 = spawn<blocking_api>([](blocking_actor* self) {
self->receive (
on(atom("get")) >> [] {
return make_cow_tuple(42, 2);
......@@ -696,7 +696,7 @@ void test_spawn() {
CPPA_PRINT("test sync send");
CPPA_CHECKPOINT();
auto sync_testee = spawn<blocking_api>([](blocking_untyped_actor* self) {
auto sync_testee = spawn<blocking_api>([](blocking_actor* self) {
self->receive (
on("hi", arg_match) >> [&](actor from) {
self->sync_send(from, "whassup?", self).await(
......@@ -745,7 +745,7 @@ void test_spawn() {
CPPA_CHECKPOINT();
auto inflater = [](untyped_actor* self, const string& name, actor buddy) {
auto inflater = [](event_based_actor* self, const string& name, actor buddy) {
CPPA_LOGF_TRACE(CPPA_ARG(self) << ", " << CPPA_ARG(name)
<< ", " << CPPA_TARG(buddy, to_string));
self->become(
......@@ -776,7 +776,7 @@ void test_spawn() {
// - the lambda is always executed in the current actor's thread
// but using spawn_next in a message handler could
// still cause undefined behavior!
auto kr34t0r = [&spawn_next](untyped_actor* self, const string& name, actor pal) {
auto kr34t0r = [&spawn_next](event_based_actor* self, const string& name, actor pal) {
if (name == "Joe" && !pal) {
pal = spawn_next("Bob", self);
}
......@@ -827,7 +827,7 @@ void test_spawn() {
// create some actors linked to one single actor
// and kill them all through killing the link
auto legion = spawn([](untyped_actor* self) {
auto legion = spawn([](event_based_actor* self) {
CPPA_LOGF_INFO("spawn 1, 000 actors");
for (int i = 0; i < 1000; ++i) {
self->spawn<event_testee, linked>();
......
......@@ -19,7 +19,7 @@ struct float_or_int : sb_actor<float_or_int> {
);
};
struct popular_actor : untyped_actor { // popular actors have a buddy
struct popular_actor : event_based_actor { // popular actors have a buddy
actor m_buddy;
popular_actor(const actor& buddy) : m_buddy(buddy) { }
inline const actor& buddy() const { return m_buddy; }
......@@ -137,7 +137,7 @@ struct D : popular_actor {
* X *
\******************************************************************************/
struct server : untyped_actor {
struct server : event_based_actor {
behavior make_behavior() override {
auto die = [=] { quit(exit_reason::user_shutdown); };
......@@ -165,7 +165,7 @@ void test_sync_send() {
self->on_sync_failure([&] {
CPPA_FAILURE("received: " << to_string(self->last_dequeued()));
});
self->spawn<monitored + blocking_api>([](blocking_untyped_actor* self) {
self->spawn<monitored + blocking_api>([](blocking_actor* self) {
CPPA_LOGC_TRACE("NONE", "main$sync_failure_test", "id = " << self->id());
int invocations = 0;
auto foi = self->spawn<float_or_int, linked>();
......@@ -280,9 +280,9 @@ void test_sync_send() {
CPPA_CHECKPOINT();
// test use case 3
self->spawn<monitored + blocking_api>([](blocking_untyped_actor* self) { // client
self->spawn<monitored + blocking_api>([](blocking_actor* self) { // client
auto s = self->spawn<server, linked>(); // server
auto w = self->spawn<linked>([](untyped_actor* self) { // worker
auto w = self->spawn<linked>([](event_based_actor* self) { // worker
self->become(on(atom("request")) >> []{ return atom("response"); });
});
// first 'idle', then 'request'
......
......@@ -87,7 +87,7 @@ optional<int> str2int(const std::string& str) {
CPPA_FAILURE(#FunName " erroneously invoked"); \
} else { CPPA_CHECKPOINT(); } static_cast<void>(42)
struct dummy_receiver : untyped_actor {
struct dummy_receiver : event_based_actor {
behavior make_behavior() override {
return (
on_arg_match >> [=](expensive_copy_struct& ecs) -> expensive_copy_struct {
......
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