Commit 196b8080 authored by neverlord's avatar neverlord

behavior typedef

parent f4912f83
......@@ -78,6 +78,7 @@ nobase_library_include_HEADERS = \
cppa/anything.hpp \
cppa/atom.hpp \
cppa/attachable.hpp \
cppa/behavior.hpp \
cppa/binary_deserializer.hpp \
cppa/binary_serializer.hpp \
cppa/channel.hpp \
......
......@@ -242,3 +242,4 @@ cppa/event_based_actor_mixin.hpp
cppa/fsm_actor.hpp
cppa/self.hpp
src/self.cpp
cppa/behavior.hpp
......@@ -27,7 +27,7 @@ class actor : public channel
{
bool m_is_proxy;
std::uint32_t m_id;
actor_id m_id;
process_information_ptr m_parent_process;
protected:
......@@ -163,14 +163,14 @@ class actor : public channel
* the process it's executed in.
* @returns The unique identifier of this actor.
*/
inline std::uint32_t id() const;
inline actor_id id() const;
/**
* @brief Get the actor that has the unique identifier @p actor_id.
* @brief Get the actor that has the unique identifier @p needle.
* @returns A pointer to the requestet actor or @c nullptr if no
* running actor with the ID @p actor_id was found in this process.
*/
static intrusive_ptr<actor> by_id(std::uint32_t actor_id);
static intrusive_ptr<actor> by_id(actor_id needle);
inline bool is_proxy() const;
......
#ifndef BEHAVIOR_HPP
#define BEHAVIOR_HPP
#include "cppa/util/either.hpp"
#include "cppa/invoke_rules.hpp"
namespace cppa {
typedef util::either<invoke_rules, timed_invoke_rules> behavior;
} // namespace cppa
#endif // BEHAVIOR_HPP
#ifndef EVENT_BASED_ACTOR_HPP
#define EVENT_BASED_ACTOR_HPP
#include "cppa/behavior.hpp"
#include "cppa/event_based_actor_mixin.hpp"
namespace cppa {
......@@ -13,8 +14,10 @@ class event_based_actor : public event_based_actor_mixin<event_based_actor>
typedef abstract_event_based_actor::stack_element stack_element;
void clear();
void do_become(invoke_rules* behavior, bool has_ownership);
void do_become(timed_invoke_rules* behavior, bool has_ownership);
// has_ownership == false
void do_become(behavior* bhvr);
void do_become(invoke_rules* bhvr, bool has_ownership);
void do_become(timed_invoke_rules* bhvr, bool has_ownership);
};
......
#ifndef EVENT_BASED_ACTOR_MIXIN_HPP
#define EVENT_BASED_ACTOR_MIXIN_HPP
#include "cppa/behavior.hpp"
#include "cppa/abstract_event_based_actor.hpp"
#include <iostream>
using std::cout;
using std::endl;
namespace cppa {
template<typename Derived>
......@@ -36,22 +33,27 @@ class event_based_actor_mixin : public abstract_event_based_actor
protected:
void become(invoke_rules* behavior)
inline void become(behavior* bhvr)
{
d_this()->do_become(bhvr);
}
inline void become(invoke_rules* behavior)
{
d_this()->do_become(behavior, false);
}
void become(timed_invoke_rules* behavior)
inline void become(timed_invoke_rules* behavior)
{
d_this()->do_become(behavior, false);
}
void become(invoke_rules&& behavior)
inline void become(invoke_rules&& behavior)
{
d_this()->do_become(new invoke_rules(std::move(behavior)), true);
}
void become(timed_invoke_rules&& behavior)
inline void become(timed_invoke_rules&& behavior)
{
d_this()->do_become(new timed_invoke_rules(std::move(behavior)), true);
}
......
......@@ -7,20 +7,30 @@ void event_based_actor::clear()
if (!m_loop_stack.empty()) m_loop_stack.pop();
}
void event_based_actor::do_become(invoke_rules* behavior,
bool has_ownership)
void event_based_actor::do_become(behavior* bhvr)
{
if (bhvr->is_left())
{
do_become(&(bhvr->left()), false);
}
else
{
do_become(&(bhvr->right()), false);
}
}
void event_based_actor::do_become(invoke_rules* bhvr, bool has_ownership)
{
clear();
reset_timeout();
m_loop_stack.push(stack_element(behavior, has_ownership));
m_loop_stack.push(stack_element(bhvr, has_ownership));
}
void event_based_actor::do_become(timed_invoke_rules* behavior,
bool has_ownership)
void event_based_actor::do_become(timed_invoke_rules* bhvr, bool has_ownership)
{
clear();
request_timeout(behavior->timeout());
m_loop_stack.push(stack_element(behavior, has_ownership));
request_timeout(bhvr->timeout());
m_loop_stack.push(stack_element(bhvr, has_ownership));
}
} // namespace cppa
......@@ -28,7 +28,7 @@ using namespace cppa;
struct event_testee : public fsm_actor<event_testee>
{
invoke_rules wait4string =
behavior wait4string =
(
on<std::string>() >> [this]()
{
......@@ -40,7 +40,7 @@ struct event_testee : public fsm_actor<event_testee>
}
);
invoke_rules wait4float =
behavior wait4float =
(
on<float>() >> [=]()
{
......@@ -52,7 +52,7 @@ struct event_testee : public fsm_actor<event_testee>
}
);
invoke_rules init_state =
behavior init_state =
(
on<int>() >> [=]()
{
......@@ -73,9 +73,9 @@ class event_testee : public fsm_actor<event_testee>
friend class fsm_actor<event_testee>;
invoke_rules wait4string;
invoke_rules wait4float;
invoke_rules init_state;
behavior wait4string;
behavior wait4float;
behavior init_state;
public:
......@@ -125,7 +125,12 @@ class event_testee : public fsm_actor<event_testee>
on<atom("GetState")>() >> [=]()
{
reply("init_state");
},
after(std::chrono::seconds(5)) >> [=]()
{
quit(exit_reason::user_defined);
}
);
}
......@@ -307,14 +312,14 @@ size_t test__spawn()
CPPA_CHECK_EQUAL(behavior_test<testee_actor>(), "init_state");
CPPA_CHECK_EQUAL(behavior_test<event_testee>(), "init_state");
// create one million actors linked to one single actor
// create 20,000 actors linked to one single actor
// and kill them all through killing the link
auto my_link = spawn(new event_testee);
for (int i = 0; i < 20000; ++i)
{
link(my_link, spawn(new event_testee));
}
send(my_link, atom(":Exit"), exit_reason::user_defined);
// auto my_link = spawn(new event_testee);
// for (int i = 0; i < 20000; ++i)
// {
// link(my_link, spawn(new event_testee));
// }
// send(my_link, atom(":Exit"), exit_reason::user_defined);
return CPPA_TEST_RESULT;
......
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