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
d8884198
Commit
d8884198
authored
Jul 27, 2016
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Accept behavior& in receive functions, close #494
parent
7ad680ec
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
70 additions
and
36 deletions
+70
-36
libcaf_core/caf/after.hpp
libcaf_core/caf/after.hpp
+3
-5
libcaf_core/caf/blocking_actor.hpp
libcaf_core/caf/blocking_actor.hpp
+6
-1
libcaf_core/caf/detail/blocking_behavior.hpp
libcaf_core/caf/detail/blocking_behavior.hpp
+20
-16
libcaf_core/src/abstract_coordinator.cpp
libcaf_core/src/abstract_coordinator.cpp
+14
-13
libcaf_core/src/blocking_actor.cpp
libcaf_core/src/blocking_actor.cpp
+16
-0
libcaf_core/src/blocking_behavior.cpp
libcaf_core/src/blocking_behavior.cpp
+1
-1
libcaf_core/test/blocking_actor.cpp
libcaf_core/test/blocking_actor.cpp
+10
-0
No files found.
libcaf_core/caf/after.hpp
View file @
d8884198
...
...
@@ -29,7 +29,7 @@ namespace caf {
class
timeout_definition_builder
{
public:
constexpr
timeout_definition_builder
(
const
duration
&
d
)
:
tout_
(
d
)
{
constexpr
timeout_definition_builder
(
duration
d
)
:
tout_
(
d
)
{
// nop
}
...
...
@@ -43,10 +43,8 @@ private:
};
/// Returns a generator for timeouts.
template
<
class
Rep
,
class
Period
>
constexpr
timeout_definition_builder
after
(
const
std
::
chrono
::
duration
<
Rep
,
Period
>&
d
)
{
return
{
duration
(
d
)};
constexpr
timeout_definition_builder
after
(
duration
d
)
{
return
{
d
};
}
}
// namespace caf
...
...
libcaf_core/caf/blocking_actor.hpp
View file @
d8884198
...
...
@@ -27,6 +27,7 @@
#include "caf/fwd.hpp"
#include "caf/send.hpp"
#include "caf/none.hpp"
#include "caf/after.hpp"
#include "caf/extend.hpp"
#include "caf/behavior.hpp"
#include "caf/local_actor.hpp"
...
...
@@ -336,10 +337,14 @@ public:
tl_size
<
filtered
>::
value
,
sizeof
...(
Ts
)
>::
type
;
make_blocking_behavior_t
factory
;
auto
fun
=
apply_moved_args_prefixed
(
factory
,
tail_indices
{},
tup
,
bhvr
);
auto
fun
=
apply_moved_args_prefixed
(
factory
,
tail_indices
{},
tup
,
&
bhvr
);
receive_impl
(
rcc
,
mid
,
fun
);
}
/// Receives messages until either a pre- or postcheck of `rcc` fails.
void
varargs_tup_receive
(
receive_cond
&
rcc
,
message_id
mid
,
std
::
tuple
<
behavior
&>&
tup
);
/// Receives messages until either a pre- or postcheck of `rcc` fails.
template
<
class
...
Ts
>
void
varargs_receive
(
receive_cond
&
rcc
,
message_id
mid
,
Ts
&&
...
xs
)
{
...
...
libcaf_core/caf/detail/blocking_behavior.hpp
View file @
d8884198
...
...
@@ -29,9 +29,9 @@ namespace detail {
class
blocking_behavior
{
public:
behavior
nested
;
behavior
&
nested
;
blocking_behavior
(
behavior
nested
);
blocking_behavior
(
behavior
&
nested
);
blocking_behavior
(
blocking_behavior
&&
)
=
default
;
virtual
~
blocking_behavior
();
...
...
@@ -48,8 +48,8 @@ class blocking_behavior_v2 : public blocking_behavior {
public:
catch_all
<
F
>
f
;
blocking_behavior_v2
(
behavior
x
,
catch_all
<
F
>
y
)
:
blocking_behavior
(
std
::
move
(
x
)
),
blocking_behavior_v2
(
behavior
&
x
,
catch_all
<
F
>
y
)
:
blocking_behavior
(
x
),
f
(
std
::
move
(
y
))
{
// nop
}
...
...
@@ -66,8 +66,8 @@ class blocking_behavior_v3 : public blocking_behavior {
public:
timeout_definition
<
F
>
f
;
blocking_behavior_v3
(
behavior
x
,
timeout_definition
<
F
>
y
)
:
blocking_behavior
(
std
::
move
(
x
)
),
blocking_behavior_v3
(
behavior
&
x
,
timeout_definition
<
F
>
y
)
:
blocking_behavior
(
x
),
f
(
std
::
move
(
y
))
{
// nop
}
...
...
@@ -89,8 +89,8 @@ public:
catch_all
<
F1
>
f1
;
timeout_definition
<
F2
>
f2
;
blocking_behavior_v4
(
behavior
x
,
catch_all
<
F1
>
y
,
timeout_definition
<
F2
>
z
)
:
blocking_behavior
(
std
::
move
(
x
)
),
blocking_behavior_v4
(
behavior
&
x
,
catch_all
<
F1
>
y
,
timeout_definition
<
F2
>
z
)
:
blocking_behavior
(
x
),
f1
(
std
::
move
(
y
)),
f2
(
std
::
move
(
z
))
{
// nop
...
...
@@ -116,25 +116,29 @@ struct make_blocking_behavior_t {
// nop
}
inline
blocking_behavior
operator
()(
behavior
x
)
const
{
return
{
std
::
move
(
x
)};
inline
blocking_behavior
operator
()(
behavior
*
x
)
const
{
CAF_ASSERT
(
x
!=
nullptr
);
return
{
*
x
};
}
template
<
class
F
>
blocking_behavior_v2
<
F
>
operator
()(
behavior
x
,
catch_all
<
F
>
y
)
const
{
return
{
std
::
move
(
x
),
std
::
move
(
y
)};
blocking_behavior_v2
<
F
>
operator
()(
behavior
*
x
,
catch_all
<
F
>
y
)
const
{
CAF_ASSERT
(
x
!=
nullptr
);
return
{
*
x
,
std
::
move
(
y
)};
}
template
<
class
F
>
blocking_behavior_v3
<
F
>
operator
()(
behavior
x
,
blocking_behavior_v3
<
F
>
operator
()(
behavior
*
x
,
timeout_definition
<
F
>
y
)
const
{
return
{
std
::
move
(
x
),
std
::
move
(
y
)};
CAF_ASSERT
(
x
!=
nullptr
);
return
{
*
x
,
std
::
move
(
y
)};
}
template
<
class
F1
,
class
F2
>
blocking_behavior_v4
<
F1
,
F2
>
operator
()(
behavior
x
,
catch_all
<
F1
>
y
,
blocking_behavior_v4
<
F1
,
F2
>
operator
()(
behavior
*
x
,
catch_all
<
F1
>
y
,
timeout_definition
<
F2
>
z
)
const
{
return
{
std
::
move
(
x
),
std
::
move
(
y
),
std
::
move
(
z
)};
CAF_ASSERT
(
x
!=
nullptr
);
return
{
*
x
,
std
::
move
(
y
),
std
::
move
(
z
)};
}
};
...
...
libcaf_core/src/abstract_coordinator.cpp
View file @
d8884198
...
...
@@ -87,8 +87,7 @@ public:
bool
running
=
true
;
std
::
multimap
<
hrc
::
time_point
,
delayed_msg
>
messages
;
// our message handler
auto
bhvr
=
detail
::
make_blocking_behavior
(
behavior
{
behavior
nested
{
[
&
](
const
duration
&
d
,
strong_actor_ptr
&
from
,
strong_actor_ptr
&
to
,
message_id
mid
,
message
&
msg
)
{
insert_dmsg
(
messages
,
d
,
std
::
move
(
from
),
...
...
@@ -100,7 +99,9 @@ public:
running
=
false
;
}
}
},
};
auto
bhvr
=
detail
::
make_blocking_behavior
(
&
nested
,
others
>>
[
&
](
message_view
&
x
)
->
result
<
message
>
{
std
::
cerr
<<
"*** unexpected message in timer_actor: "
<<
to_string
(
x
.
content
())
<<
std
::
endl
;
...
...
libcaf_core/src/blocking_actor.cpp
View file @
d8884198
...
...
@@ -396,6 +396,22 @@ mailbox_element_ptr blocking_actor::dequeue() {
return
next_message
();
}
void
blocking_actor
::
varargs_tup_receive
(
receive_cond
&
rcc
,
message_id
mid
,
std
::
tuple
<
behavior
&>&
tup
)
{
using
namespace
detail
;
auto
&
bhvr
=
std
::
get
<
0
>
(
tup
);
if
(
bhvr
.
timeout
().
valid
())
{
auto
tmp
=
after
(
bhvr
.
timeout
())
>>
[
&
]
{
bhvr
.
handle_timeout
();
};
auto
fun
=
make_blocking_behavior
(
&
bhvr
,
std
::
move
(
tmp
));
receive_impl
(
rcc
,
mid
,
fun
);
}
else
{
auto
fun
=
make_blocking_behavior
(
&
bhvr
);
receive_impl
(
rcc
,
mid
,
fun
);
}
}
size_t
blocking_actor
::
attach_functor
(
const
actor
&
x
)
{
return
attach_functor
(
actor_cast
<
strong_actor_ptr
>
(
x
));
}
...
...
libcaf_core/src/blocking_behavior.cpp
View file @
d8884198
...
...
@@ -26,7 +26,7 @@ blocking_behavior::~blocking_behavior() {
// nop
}
blocking_behavior
::
blocking_behavior
(
behavior
x
)
:
nested
(
std
::
move
(
x
)
)
{
blocking_behavior
::
blocking_behavior
(
behavior
&
x
)
:
nested
(
x
)
{
// nop
}
...
...
libcaf_core/test/blocking_actor.cpp
View file @
d8884198
...
...
@@ -60,4 +60,14 @@ CAF_TEST(catch_all) {
);
}
CAF_TEST
(
behavior_ref
)
{
behavior
bhvr
{
[](
int
i
)
{
CAF_CHECK_EQUAL
(
i
,
42
);
}
};
self
->
send
(
self
,
42
);
self
->
receive
(
bhvr
);
}
CAF_TEST_FIXTURE_SCOPE_END
()
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