Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
bd235b6b
Commit
bd235b6b
authored
Aug 17, 2012
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added 'then' & 'await' member functions to message_future
parent
0c5a0c34
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
138 additions
and
32 deletions
+138
-32
cppa.files
cppa.files
+1
-0
cppa/cppa.hpp
cppa/cppa.hpp
+3
-6
cppa/detail/scheduled_actor_dummy.hpp
cppa/detail/scheduled_actor_dummy.hpp
+1
-1
cppa/detail/stacked_actor_mixin.hpp
cppa/detail/stacked_actor_mixin.hpp
+1
-1
cppa/event_based_actor.hpp
cppa/event_based_actor.hpp
+1
-1
cppa/local_actor.hpp
cppa/local_actor.hpp
+13
-20
cppa/message_future.hpp
cppa/message_future.hpp
+106
-0
src/event_based_actor.cpp
src/event_based_actor.cpp
+1
-1
src/local_actor.cpp
src/local_actor.cpp
+9
-0
src/scheduled_actor_dummy.cpp
src/scheduled_actor_dummy.cpp
+1
-1
unit_testing/test__sync_send.cpp
unit_testing/test__sync_send.cpp
+1
-1
No files found.
cppa.files
View file @
bd235b6b
...
@@ -262,3 +262,4 @@ src/ipv4_acceptor.cpp
...
@@ -262,3 +262,4 @@ src/ipv4_acceptor.cpp
cppa/detail/middleman.hpp
cppa/detail/middleman.hpp
src/middleman.cpp
src/middleman.cpp
src/buffer.cpp
src/buffer.cpp
cppa/message_future.hpp
cppa/cppa.hpp
View file @
bd235b6b
...
@@ -54,6 +54,7 @@
...
@@ -54,6 +54,7 @@
#include "cppa/tuple_cast.hpp"
#include "cppa/tuple_cast.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/exit_reason.hpp"
#include "cppa/local_actor.hpp"
#include "cppa/local_actor.hpp"
#include "cppa/message_future.hpp"
#include "cppa/scheduled_actor.hpp"
#include "cppa/scheduled_actor.hpp"
#include "cppa/scheduling_hint.hpp"
#include "cppa/scheduling_hint.hpp"
#include "cppa/event_based_actor.hpp"
#include "cppa/event_based_actor.hpp"
...
@@ -466,10 +467,6 @@ operator<<(const intrusive_ptr<C>& whom, any_tuple what) {
...
@@ -466,10 +467,6 @@ operator<<(const intrusive_ptr<C>& whom, any_tuple what) {
return
whom
;
return
whom
;
}
}
#ifndef CPPA_DOCUMENTATION
typedef
message_id_t
message_future
;
#endif // CPPA_DOCUMENTATION
/**
/**
* @brief Sends @p what as a synchronous message to @p whom.
* @brief Sends @p what as a synchronous message to @p whom.
* @param whom Receiver of the message.
* @param whom Receiver of the message.
...
@@ -508,8 +505,8 @@ inline message_future sync_send(const actor_ptr& whom, Args&&... what) {
...
@@ -508,8 +505,8 @@ inline message_future sync_send(const actor_ptr& whom, Args&&... what) {
* @throws std::logic_error if @p handle is not valid or if the actor
* @throws std::logic_error if @p handle is not valid or if the actor
* already received the response for @p handle
* already received the response for @p handle
*/
*/
inline
sync_recv_helper
receive_response
(
message_future
handle
)
{
inline
sync_recv_helper
receive_response
(
const
message_future
&
handle
)
{
return
{
handle
,
[](
behavior
&
bhvr
,
message_future
mf
)
{
return
{
handle
.
id
(),
[](
behavior
&
bhvr
,
message_id_t
mf
)
{
if
(
!
self
->
awaits
(
mf
))
{
if
(
!
self
->
awaits
(
mf
))
{
throw
std
::
logic_error
(
"response already received"
);
throw
std
::
logic_error
(
"response already received"
);
}
}
...
...
cppa/detail/scheduled_actor_dummy.hpp
View file @
bd235b6b
...
@@ -49,7 +49,7 @@ struct scheduled_actor_dummy : abstract_scheduled_actor {
...
@@ -49,7 +49,7 @@ struct scheduled_actor_dummy : abstract_scheduled_actor {
bool
attach
(
attachable
*
);
bool
attach
(
attachable
*
);
void
unbecome
();
void
unbecome
();
void
do_become
(
behavior
&&
,
bool
);
void
do_become
(
behavior
&&
,
bool
);
void
become_waiting_for
(
behavior
&&
,
message_
future
);
void
become_waiting_for
(
behavior
&&
,
message_
id_t
);
bool
has_behavior
();
bool
has_behavior
();
scheduled_actor_type
impl_type
();
scheduled_actor_type
impl_type
();
};
};
...
...
cppa/detail/stacked_actor_mixin.hpp
View file @
bd235b6b
...
@@ -88,7 +88,7 @@ class stacked_actor_mixin : public Base {
...
@@ -88,7 +88,7 @@ class stacked_actor_mixin : public Base {
become_impl
(
std
::
move
(
bhvr
),
discard_old
,
message_id_t
());
become_impl
(
std
::
move
(
bhvr
),
discard_old
,
message_id_t
());
}
}
virtual
void
become_waiting_for
(
behavior
&&
bhvr
,
message_
future
mid
)
{
virtual
void
become_waiting_for
(
behavior
&&
bhvr
,
message_
id_t
mid
)
{
become_impl
(
std
::
move
(
bhvr
),
false
,
mid
);
become_impl
(
std
::
move
(
bhvr
),
false
,
mid
);
}
}
...
...
cppa/event_based_actor.hpp
View file @
bd235b6b
...
@@ -134,7 +134,7 @@ class event_based_actor : public detail::abstract_scheduled_actor {
...
@@ -134,7 +134,7 @@ class event_based_actor : public detail::abstract_scheduled_actor {
void
do_become
(
behavior
&&
bhvr
,
bool
discard_old
);
void
do_become
(
behavior
&&
bhvr
,
bool
discard_old
);
void
become_waiting_for
(
behavior
&&
bhvr
,
message_
future
mf
);
void
become_waiting_for
(
behavior
&&
bhvr
,
message_
id_t
mf
);
private:
private:
...
...
cppa/local_actor.hpp
View file @
bd235b6b
...
@@ -46,12 +46,9 @@
...
@@ -46,12 +46,9 @@
namespace
cppa
{
namespace
cppa
{
#ifndef CPPA_DOCUMENTATION
typedef
message_id_t
message_future
;
#endif // CPPA_DOCUMENTATION
// forward declarations
// forward declarations
class
scheduler
;
class
scheduler
;
class
message_future
;
class
local_scheduler
;
class
local_scheduler
;
template
<
bool
DiscardOld
>
template
<
bool
DiscardOld
>
...
@@ -84,10 +81,10 @@ constexpr keep_behavior_t keep_behavior = keep_behavior_t();
...
@@ -84,10 +81,10 @@ constexpr keep_behavior_t keep_behavior = keep_behavior_t();
#endif // CPPA_DOCUMENTATION
#endif // CPPA_DOCUMENTATION
struct
sync_recv_helper
{
struct
sync_recv_helper
{
typedef
void
(
*
callback_type
)(
behavior
&
,
message_
future
);
typedef
void
(
*
callback_type
)(
behavior
&
,
message_
id_t
);
message_
future
m_handle
;
message_
id_t
m_handle
;
callback_type
m_fun
;
callback_type
m_fun
;
inline
sync_recv_helper
(
message_
future
handle
,
callback_type
fun
)
inline
sync_recv_helper
(
message_
id_t
handle
,
callback_type
fun
)
:
m_handle
(
handle
),
m_fun
(
fun
)
{
}
:
m_handle
(
handle
),
m_fun
(
fun
)
{
}
template
<
typename
...
Expression
>
template
<
typename
...
Expression
>
inline
void
operator
()(
Expression
&&
...
mexpr
)
const
{
inline
void
operator
()(
Expression
&&
...
mexpr
)
const
{
...
@@ -104,7 +101,9 @@ struct sync_recv_helper {
...
@@ -104,7 +101,9 @@ struct sync_recv_helper {
}
}
};
};
inline
sync_recv_helper
receive_response
(
message_future
);
class
message_future
;
//inline sync_recv_helper receive_response(message_future);
/**
/**
* @brief Base class for local running Actors.
* @brief Base class for local running Actors.
...
@@ -112,7 +111,7 @@ inline sync_recv_helper receive_response(message_future);
...
@@ -112,7 +111,7 @@ inline sync_recv_helper receive_response(message_future);
class
local_actor
:
public
actor
{
class
local_actor
:
public
actor
{
friend
class
scheduler
;
friend
class
scheduler
;
friend
inline
sync_recv_helper
receive_response
(
message_future
);
//
friend inline sync_recv_helper receive_response(message_future);
public:
public:
...
@@ -303,14 +302,7 @@ class local_actor : public actor {
...
@@ -303,14 +302,7 @@ class local_actor : public actor {
* @throws std::logic_error if @p handle is not valid or if the actor
* @throws std::logic_error if @p handle is not valid or if the actor
* already received the response for @p handle
* already received the response for @p handle
*/
*/
inline
sync_recv_helper
handle_response
(
message_future
handle
)
{
sync_recv_helper
handle_response
(
const
message_future
&
handle
);
return
{
handle
,
[](
behavior
&
bhvr
,
message_future
mf
)
{
if
(
!
self
->
awaits
(
mf
))
{
throw
std
::
logic_error
(
"response already received"
);
}
self
->
become_waiting_for
(
std
::
move
(
bhvr
),
mf
);
}};
}
/**
/**
* @brief Returns to a previous behavior if available.
* @brief Returns to a previous behavior if available.
...
@@ -409,6 +401,10 @@ class local_actor : public actor {
...
@@ -409,6 +401,10 @@ class local_actor : public actor {
if
(
i
!=
last
)
m_pending_responses
.
erase
(
i
);
if
(
i
!=
last
)
m_pending_responses
.
erase
(
i
);
}
}
virtual
void
dequeue_response
(
behavior
&
,
message_id_t
)
=
0
;
virtual
void
become_waiting_for
(
behavior
&&
,
message_id_t
)
=
0
;
protected:
protected:
// true if this actor uses the chained_send optimization
// true if this actor uses the chained_send optimization
...
@@ -452,9 +448,6 @@ class local_actor : public actor {
...
@@ -452,9 +448,6 @@ class local_actor : public actor {
* Use always the {@link cppa::receive_response receive_response}
* Use always the {@link cppa::receive_response receive_response}
* function.
* function.
*/
*/
virtual
void
dequeue_response
(
behavior
&
,
message_future
)
=
0
;
virtual
void
become_waiting_for
(
behavior
&&
,
message_future
)
=
0
;
};
};
...
...
cppa/message_future.hpp
0 → 100644
View file @
bd235b6b
/******************************************************************************\
* ___ __ *
* /\_ \ __/\ \ *
* \//\ \ /\_\ \ \____ ___ _____ _____ __ *
* \ \ \ \/\ \ \ '__`\ /'___\/\ '__`\/\ '__`\ /'__`\ *
* \_\ \_\ \ \ \ \L\ \/\ \__/\ \ \L\ \ \ \L\ \/\ \L\.\_ *
* /\____\\ \_\ \_,__/\ \____\\ \ ,__/\ \ ,__/\ \__/.\_\ *
* \/____/ \/_/\/___/ \/____/ \ \ \/ \ \ \/ \/__/\/_/ *
* \ \_\ \ \_\ *
* \/_/ \/_/ *
* *
* Copyright (C) 2011, 2012 *
* Dominik Charousset <dominik.charousset@haw-hamburg.de> *
* *
* This file is part of libcppa. *
* libcppa is free software: you can redistribute it and/or modify it under *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License *
* or (at your option) any later version. *
* *
* libcppa is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public License *
* along with libcppa. If not, see <http://www.gnu.org/licenses/>. *
\******************************************************************************/
#ifndef MESSAGE_FUTURE_HPP
#define MESSAGE_FUTURE_HPP
#include "cppa/behavior.hpp"
#include "cppa/match_expr.hpp"
#include "cppa/message_id.hpp"
#include "cppa/local_actor.hpp"
namespace
cppa
{
/**
* @brief Represents the result of a synchronous send.
*/
class
message_future
{
public:
/**
* @brief Sets @p mexpr as event-handler for the response message.
*/
template
<
typename
...
Expression
>
void
then
(
Expression
&&
...
mexpr
)
{
auto
f
=
[](
behavior
&
bhvr
,
message_id_t
mid
)
{
self
->
become_waiting_for
(
std
::
move
(
bhvr
),
mid
);
};
apply
(
f
,
std
::
forward
<
Expression
>
(
mexpr
)...);
}
/**
* @brief Blocks until the response arrives and then executes @p mexpr.
*/
template
<
typename
...
Expression
>
void
await
(
Expression
&&
...
mexpr
)
{
auto
f
=
[](
behavior
&
bhvr
,
message_id_t
mid
)
{
self
->
dequeue_response
(
bhvr
,
mid
);
};
apply
(
f
,
std
::
forward
<
Expression
>
(
mexpr
)...);
}
message_future
(
const
message_future
&
)
=
default
;
message_future
&
operator
=
(
const
message_future
&
)
=
default
;
# ifndef CPPA_DOCUMENTATION
inline
message_future
(
const
message_id_t
&
from
)
:
m_id
(
from
)
{
}
inline
const
message_id_t
&
id
()
const
{
return
m_id
;
}
# endif
private:
message_id_t
m_id
;
template
<
typename
Fun
,
typename
...
Args
>
void
apply
(
Fun
&
fun
,
Args
&&
...
args
)
{
auto
bhvr
=
match_expr_convert
(
std
::
forward
<
Args
>
(
args
)...);
static_assert
(
std
::
is_same
<
decltype
(
bhvr
),
behavior
>::
value
,
"no timeout specified"
);
if
(
bhvr
.
timeout
().
valid
()
==
false
||
bhvr
.
timeout
().
is_zero
())
{
throw
std
::
invalid_argument
(
"specified timeout is invalid or zero"
);
}
else
if
(
!
m_id
.
valid
()
||
!
m_id
.
is_response
())
{
throw
std
::
logic_error
(
"handle does not point to a response"
);
}
else
if
(
!
self
->
awaits
(
m_id
))
{
throw
std
::
logic_error
(
"response already received"
);
}
fun
(
bhvr
,
m_id
);
}
};
}
// namespace cppa
#endif // MESSAGE_FUTURE_HPP
src/event_based_actor.cpp
View file @
bd235b6b
...
@@ -103,7 +103,7 @@ void event_based_actor::do_become(behavior&& bhvr, bool discard_old) {
...
@@ -103,7 +103,7 @@ void event_based_actor::do_become(behavior&& bhvr, bool discard_old) {
m_bhvr_stack
.
push_back
(
std
::
move
(
bhvr
));
m_bhvr_stack
.
push_back
(
std
::
move
(
bhvr
));
}
}
void
event_based_actor
::
become_waiting_for
(
behavior
&&
bhvr
,
message_
future
mf
)
{
void
event_based_actor
::
become_waiting_for
(
behavior
&&
bhvr
,
message_
id_t
mf
)
{
CPPA_REQUIRE
(
bhvr
.
timeout
().
valid
());
CPPA_REQUIRE
(
bhvr
.
timeout
().
valid
());
reset_timeout
();
reset_timeout
();
request_timeout
(
bhvr
.
timeout
());
request_timeout
(
bhvr
.
timeout
());
...
...
src/local_actor.cpp
View file @
bd235b6b
...
@@ -140,4 +140,13 @@ void local_actor::forward_message(const actor_ptr& new_receiver) {
...
@@ -140,4 +140,13 @@ void local_actor::forward_message(const actor_ptr& new_receiver) {
}
}
}
}
sync_recv_helper
local_actor
::
handle_response
(
const
message_future
&
handle
)
{
return
{
handle
.
id
(),
[](
behavior
&
bhvr
,
message_id_t
mf
)
{
if
(
!
self
->
awaits
(
mf
))
{
throw
std
::
logic_error
(
"response already received"
);
}
self
->
become_waiting_for
(
std
::
move
(
bhvr
),
mf
);
}};
}
}
// namespace cppa
}
// namespace cppa
src/scheduled_actor_dummy.cpp
View file @
bd235b6b
...
@@ -42,7 +42,7 @@ void scheduled_actor_dummy::detach(const attachable::token&) { }
...
@@ -42,7 +42,7 @@ void scheduled_actor_dummy::detach(const attachable::token&) { }
bool
scheduled_actor_dummy
::
attach
(
attachable
*
)
{
return
false
;
}
bool
scheduled_actor_dummy
::
attach
(
attachable
*
)
{
return
false
;
}
void
scheduled_actor_dummy
::
unbecome
()
{
}
void
scheduled_actor_dummy
::
unbecome
()
{
}
void
scheduled_actor_dummy
::
do_become
(
behavior
&&
,
bool
)
{
}
void
scheduled_actor_dummy
::
do_become
(
behavior
&&
,
bool
)
{
}
void
scheduled_actor_dummy
::
become_waiting_for
(
behavior
&&
,
message_
future
)
{
}
void
scheduled_actor_dummy
::
become_waiting_for
(
behavior
&&
,
message_
id_t
)
{
}
bool
scheduled_actor_dummy
::
has_behavior
()
{
return
false
;
}
bool
scheduled_actor_dummy
::
has_behavior
()
{
return
false
;
}
resume_result
scheduled_actor_dummy
::
resume
(
util
::
fiber
*
)
{
resume_result
scheduled_actor_dummy
::
resume
(
util
::
fiber
*
)
{
...
...
unit_testing/test__sync_send.cpp
View file @
bd235b6b
...
@@ -27,7 +27,7 @@ struct A : event_based_actor {
...
@@ -27,7 +27,7 @@ struct A : event_based_actor {
};
};
become
(
become
(
on
(
atom
(
"go"
),
arg_match
)
>>
[
=
](
const
actor_ptr
&
next
)
{
on
(
atom
(
"go"
),
arg_match
)
>>
[
=
](
const
actor_ptr
&
next
)
{
handle_response
(
sync_send
(
next
,
atom
(
"gogo"
)))
(
sync_send
(
next
,
atom
(
"gogo"
)).
then
(
on
(
atom
(
"gogogo"
))
>>
[
=
]
{
on
(
atom
(
"gogogo"
))
>>
[
=
]
{
send
(
m_parent
,
atom
(
"success"
));
send
(
m_parent
,
atom
(
"success"
));
quit
();
quit
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment