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
8181610d
Commit
8181610d
authored
Feb 22, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow composable states to modify handler inputs
parent
a78b7351
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
3 deletions
+44
-3
examples/hello_world.cpp
examples/hello_world.cpp
+1
-0
libcaf_core/caf/abstract_composable_state.hpp
libcaf_core/caf/abstract_composable_state.hpp
+30
-0
libcaf_core/caf/composable_state.hpp
libcaf_core/caf/composable_state.hpp
+0
-1
libcaf_core/caf/sec.hpp
libcaf_core/caf/sec.hpp
+2
-0
libcaf_core/caf/typed_actor_view.hpp
libcaf_core/caf/typed_actor_view.hpp
+4
-0
libcaf_core/test/composable_states.cpp
libcaf_core/test/composable_states.cpp
+7
-2
No files found.
examples/hello_world.cpp
View file @
8181610d
...
@@ -36,6 +36,7 @@ void hello_world(event_based_actor* self, const actor& buddy) {
...
@@ -36,6 +36,7 @@ void hello_world(event_based_actor* self, const actor& buddy) {
}
}
int
main
()
{
int
main
()
{
// our CAF environment
actor_system
system
;
actor_system
system
;
// create a new actor that calls 'mirror()'
// create a new actor that calls 'mirror()'
auto
mirror_actor
=
system
.
spawn
(
mirror
);
auto
mirror_actor
=
system
.
spawn
(
mirror
);
...
...
libcaf_core/caf/abstract_composable_state.hpp
View file @
8181610d
...
@@ -20,7 +20,15 @@
...
@@ -20,7 +20,15 @@
#ifndef CAF_ABSTRACT_COMPOSABLE_STATE_HPP
#ifndef CAF_ABSTRACT_COMPOSABLE_STATE_HPP
#define CAF_ABSTRACT_COMPOSABLE_STATE_HPP
#define CAF_ABSTRACT_COMPOSABLE_STATE_HPP
#include <utility>
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
#include "caf/sec.hpp"
#include "caf/message.hpp"
#include "caf/detail/int_list.hpp"
#include "caf/detail/apply_args.hpp"
#include "caf/detail/pseudo_tuple.hpp"
namespace
caf
{
namespace
caf
{
...
@@ -30,6 +38,28 @@ public:
...
@@ -30,6 +38,28 @@ public:
virtual
~
abstract_composable_state
();
virtual
~
abstract_composable_state
();
virtual
void
init_behavior
(
behavior
&
x
)
=
0
;
virtual
void
init_behavior
(
behavior
&
x
)
=
0
;
template
<
class
Derived
,
class
...
Ts
>
auto
invoke_mutable
(
Derived
*
thisptr
,
const
Ts
&
...)
->
decltype
(
std
::
declval
<
Derived
>
()(
std
::
declval
<
Ts
>
()...))
{
// re-dispatch on current message via lambda expression
auto
f
=
[
thisptr
](
Ts
&
...
xs
)
{
return
(
*
thisptr
)(
xs
...);
};
// reference to the current message
auto
&
msg
=
thisptr
->
self
->
current_message
();
if
(
!
msg
.
template
match_elements
<
Ts
...>())
return
sec
::
invalid_invoke_mutable
;
// make sure no other actor accesses the same data
msg
.
force_unshare
();
// fill a pseudo tuple with values and invoke f
detail
::
pseudo_tuple
<
Ts
...
>
buf
;
// msg is guaranteed to be detached, hence we don't need to
// check this condition over and over again via mutable_at
for
(
size_t
i
=
0
;
i
<
msg
.
size
();
++
i
)
buf
[
i
]
=
const_cast
<
void
*>
(
msg
.
at
(
i
));
return
detail
::
apply_args
(
f
,
detail
::
get_indices
(
buf
),
buf
);
}
};
};
}
// namespace caf
}
// namespace caf
...
...
libcaf_core/caf/composable_state.hpp
View file @
8181610d
...
@@ -116,7 +116,6 @@ public:
...
@@ -116,7 +116,6 @@ public:
init_behavior_impl
(
this
,
token
,
x
);
init_behavior_impl
(
this
,
token
,
x
);
}
}
protected:
typed_actor_pointer
<
Clauses
...
>
self
;
typed_actor_pointer
<
Clauses
...
>
self
;
};
};
...
...
libcaf_core/caf/sec.hpp
View file @
8181610d
...
@@ -29,6 +29,8 @@ namespace caf {
...
@@ -29,6 +29,8 @@ namespace caf {
enum
class
sec
:
uint8_t
{
enum
class
sec
:
uint8_t
{
/// Indicates that a dynamically typed actor dropped an unexpected message.
/// Indicates that a dynamically typed actor dropped an unexpected message.
unexpected_message
=
1
,
unexpected_message
=
1
,
/// Indicates that a call to `invoke_mutable` failed in a composable state.
invalid_invoke_mutable
,
/// Indicates that a response message did not match the provided handler.
/// Indicates that a response message did not match the provided handler.
unexpected_response
,
unexpected_response
,
/// Indicates that the receiver of a request is no longer alive.
/// Indicates that the receiver of a request is no longer alive.
...
...
libcaf_core/caf/typed_actor_view.hpp
View file @
8181610d
...
@@ -135,6 +135,10 @@ public:
...
@@ -135,6 +135,10 @@ public:
* miscellaneous actor operations *
* miscellaneous actor operations *
****************************************************************************/
****************************************************************************/
message
&
current_message
()
{
return
self_
->
current_message
();
}
actor_system
&
system
()
const
{
actor_system
&
system
()
const
{
return
self_
->
system
();
return
self_
->
system
();
}
}
...
...
libcaf_core/test/composable_states.cpp
View file @
8181610d
...
@@ -99,8 +99,13 @@ public:
...
@@ -99,8 +99,13 @@ public:
return
i
->
second
;
return
i
->
second
;
}
}
result
<
void
>
operator
()(
put_atom
,
const
std
::
string
&
key
,
const
std
::
string
&
value
)
override
{
result
<
void
>
operator
()(
put_atom
put
,
const
std
::
string
&
key
,
values_
[
key
]
=
value
;
const
std
::
string
&
value
)
override
{
return
invoke_mutable
(
this
,
put
,
key
,
value
);
}
result
<
void
>
operator
()(
put_atom
,
std
::
string
&
key
,
std
::
string
&
value
)
{
values_
.
emplace
(
std
::
move
(
key
),
std
::
move
(
value
));
return
unit
;
return
unit
;
}
}
...
...
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