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
f78f6c9c
Commit
f78f6c9c
authored
Sep 03, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add attach_stream_stage to replace make_stage
parent
690fa47b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
123 additions
and
7 deletions
+123
-7
doc/tex/Streaming.tex
doc/tex/Streaming.tex
+3
-3
examples/streaming/integer_stream.cpp
examples/streaming/integer_stream.cpp
+3
-2
libcaf_core/caf/all.hpp
libcaf_core/caf/all.hpp
+1
-0
libcaf_core/caf/attach_stream_stage.hpp
libcaf_core/caf/attach_stream_stage.hpp
+108
-0
libcaf_core/caf/scheduled_actor.hpp
libcaf_core/caf/scheduled_actor.hpp
+3
-0
libcaf_core/test/pipeline_streaming.cpp
libcaf_core/test/pipeline_streaming.cpp
+5
-2
No files found.
doc/tex/Streaming.tex
View file @
f78f6c9c
...
@@ -67,7 +67,7 @@ producing values, and \emph{predicate} for signaling the end of the stream.
...
@@ -67,7 +67,7 @@ producing values, and \emph{predicate} for signaling the end of the stream.
\subsection
{
Defining Stages
}
\subsection
{
Defining Stages
}
\cppexample
[4
3-72
]
{
streaming/integer
_
stream
}
\cppexample
[4
8-78
]
{
streaming/integer
_
stream
}
The function
\lstinline
^
make
_
stage
^
also takes three lambdas but additionally
The function
\lstinline
^
make
_
stage
^
also takes three lambdas but additionally
the received input stream handshake as first argument. Instead of a predicate,
the received input stream handshake as first argument. Instead of a predicate,
...
@@ -78,7 +78,7 @@ data on its own and a stream terminates if no more sources exist.
...
@@ -78,7 +78,7 @@ data on its own and a stream terminates if no more sources exist.
\subsection
{
Defining Sinks
}
\subsection
{
Defining Sinks
}
\cppexample
[
73-100
]
{
streaming/integer
_
stream
}
\cppexample
[
80-106
]
{
streaming/integer
_
stream
}
The function
\lstinline
^
make
_
sink
^
is similar to
\lstinline
^
make
_
stage
^
, except
The function
\lstinline
^
make
_
sink
^
is similar to
\lstinline
^
make
_
stage
^
, except
that is does not produce outputs.
that is does not produce outputs.
...
@@ -87,7 +87,7 @@ that is does not produce outputs.
...
@@ -87,7 +87,7 @@ that is does not produce outputs.
\subsection
{
Initiating Streams
}
\subsection
{
Initiating Streams
}
\cppexample
[1
19-123
]
{
streaming/integer
_
stream
}
\cppexample
[1
20-124
]
{
streaming/integer
_
stream
}
In our example, we always have a source
\lstinline
^
int
_
source
^
and a sink
In our example, we always have a source
\lstinline
^
int
_
source
^
and a sink
\lstinline
^
int
_
sink
^
with an optional stage
\lstinline
^
int
_
selector
^
. Sending
\lstinline
^
int
_
sink
^
with an optional stage
\lstinline
^
int
_
selector
^
. Sending
...
...
examples/streaming/integer_stream.cpp
View file @
f78f6c9c
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
* Basic, non-interactive streaming example for processing integers. *
* Basic, non-interactive streaming example for processing integers. *
******************************************************************************/
******************************************************************************/
// Manual refs: lines 17-46, 4
3-72, 73-100, 119-123
(Streaming)
// Manual refs: lines 17-46, 4
8-78, 80-106, 120-124
(Streaming)
#include <iostream>
#include <iostream>
#include <vector>
#include <vector>
...
@@ -51,7 +51,8 @@ behavior int_selector(event_based_actor* self) {
...
@@ -51,7 +51,8 @@ behavior int_selector(event_based_actor* self) {
// Create a stream manager for implementing a stream stage. Similar to
// Create a stream manager for implementing a stream stage. Similar to
// `make_source`, we need three functions: initialzer, processor, and
// `make_source`, we need three functions: initialzer, processor, and
// finalizer.
// finalizer.
return
self
->
make_stage
(
return
attach_stream_stage
(
self
,
// Our input source.
// Our input source.
in
,
in
,
// Initializer. Here, we don't need any state and simply use unit_t.
// Initializer. Here, we don't need any state and simply use unit_t.
...
...
libcaf_core/caf/all.hpp
View file @
f78f6c9c
...
@@ -36,6 +36,7 @@
...
@@ -36,6 +36,7 @@
#include "caf/atom.hpp"
#include "caf/atom.hpp"
#include "caf/attach_continuous_stream_source.hpp"
#include "caf/attach_continuous_stream_source.hpp"
#include "caf/attach_stream_source.hpp"
#include "caf/attach_stream_source.hpp"
#include "caf/attach_stream_stage.hpp"
#include "caf/attachable.hpp"
#include "caf/attachable.hpp"
#include "caf/behavior.hpp"
#include "caf/behavior.hpp"
#include "caf/behavior_policy.hpp"
#include "caf/behavior_policy.hpp"
...
...
libcaf_core/caf/attach_stream_stage.hpp
0 → 100644
View file @
f78f6c9c
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2019 Dominik Charousset *
* *
* Distributed under the terms and conditions of the BSD 3-Clause License or *
* (at your option) under the terms and conditions of the Boost Software *
* License 1.0. See accompanying files LICENSE and LICENSE_ALTERNATIVE. *
* *
* If you did not receive a copy of the license files, see *
* http://opensource.org/licenses/BSD-3-Clause and *
* http://www.boost.org/LICENSE_1_0.txt. *
******************************************************************************/
#pragma once
#include "caf/default_downstream_manager.hpp"
#include "caf/detail/stream_stage_driver_impl.hpp"
#include "caf/detail/stream_stage_impl.hpp"
#include "caf/downstream_manager.hpp"
#include "caf/fwd.hpp"
#include "caf/make_stage_result.hpp"
#include "caf/policy/arg.hpp"
#include "caf/stream.hpp"
#include "caf/stream_source.hpp"
namespace
caf
{
/// Attaches a new stream stage to `self` by creating a default stream stage
/// manager with `Driver`.
/// @param self Points to the hosting actor.
/// @param in Stream handshake from upstream path.
/// @param xs User-defined arguments for the downstream handshake.
/// @param ys Additional constructor arguments for `Driver`.
/// @returns The new `stream_manager`, an inbound slot, and an outbound slot.
template
<
class
Driver
,
class
In
,
class
...
Ts
,
class
...
Us
>
make_stage_result_t
<
In
,
typename
Driver
::
downstream_manager_type
,
Ts
...
>
attach_stream_stage
(
scheduled_actor
*
self
,
const
stream
<
In
>&
in
,
std
::
tuple
<
Ts
...
>
xs
,
Us
&&
...
ys
)
{
using
detail
::
make_stream_stage
;
auto
mgr
=
make_stream_stage
<
Driver
>
(
self
,
std
::
forward
<
Us
>
(
ys
)...);
auto
islot
=
mgr
->
add_inbound_path
(
in
);
auto
oslot
=
mgr
->
add_outbound_path
(
std
::
move
(
xs
));
return
{
islot
,
oslot
,
std
::
move
(
mgr
)};
}
/// Attaches a new stream stage to `self` by creating a default stream stage
/// manager from given callbacks.
/// @param self Points to the hosting actor.
/// @param in Stream handshake from upstream path.
/// @param xs User-defined arguments for the downstream handshake.
/// @param init Function object for initializing the state of the stage.
/// @param fun Processing function.
/// @param fin Optional cleanup handler.
/// @param token Policy token for selecting a downstream manager
/// implementation.
/// @returns The new `stream_manager`, an inbound slot, and an outbound slot.
template
<
class
In
,
class
...
Ts
,
class
Init
,
class
Fun
,
class
Finalize
=
unit_t
,
class
DownstreamManager
=
default_downstream_manager_t
<
Fun
>,
class
Trait
=
stream_stage_trait_t
<
Fun
>>
make_stage_result_t
<
In
,
DownstreamManager
,
Ts
...
>
attach_stream_stage
(
scheduled_actor
*
self
,
const
stream
<
In
>&
in
,
std
::
tuple
<
Ts
...
>
xs
,
Init
init
,
Fun
fun
,
Finalize
fin
=
{},
policy
::
arg
<
DownstreamManager
>
token
=
{})
{
CAF_IGNORE_UNUSED
(
token
);
using
output_type
=
typename
stream_stage_trait_t
<
Fun
>::
output
;
using
state_type
=
typename
stream_stage_trait_t
<
Fun
>::
state
;
static_assert
(
std
::
is_same
<
void
(
state_type
&
),
typename
detail
::
get_callable_trait
<
Init
>::
fun_sig
>::
value
,
"Expected signature `void (State&)` for init function"
);
static_assert
(
std
::
is_same
<
void
(
state_type
&
,
downstream
<
output_type
>&
,
In
),
typename
detail
::
get_callable_trait
<
Fun
>::
fun_sig
>::
value
,
"Expected signature `void (State&, downstream<Out>&, In)` "
"for consume function"
);
using
driver
=
detail
::
stream_stage_driver_impl
<
typename
Trait
::
input
,
DownstreamManager
,
Fun
,
Finalize
>
;
return
attach_stream_stage
<
driver
>
(
self
,
in
,
std
::
move
(
xs
),
std
::
move
(
init
),
std
::
move
(
fun
),
std
::
move
(
fin
));
}
/// Attaches a new stream stage to `self` by creating a default stream stage
/// manager from given callbacks.
/// @param self Points to the hosting actor.
/// @param in Stream handshake from upstream path.
/// @param init Function object for initializing the state of the stage.
/// @param fun Processing function.
/// @param fin Optional cleanup handler.
/// @param token Policy token for selecting a downstream manager
/// implementation.
/// @returns The new `stream_manager`, an inbound slot, and an outbound slot.
template
<
class
In
,
class
Init
,
class
Fun
,
class
Finalize
=
unit_t
,
class
DownstreamManager
=
default_downstream_manager_t
<
Fun
>,
class
Trait
=
stream_stage_trait_t
<
Fun
>>
make_stage_result_t
<
In
,
DownstreamManager
>
attach_stream_stage
(
scheduled_actor
*
self
,
const
stream
<
In
>&
in
,
Init
init
,
Fun
fun
,
Finalize
fin
=
{},
policy
::
arg
<
DownstreamManager
>
token
=
{})
{
return
attach_stream_stage
(
self
,
in
,
std
::
make_tuple
(),
std
::
move
(
init
),
std
::
move
(
fun
),
std
::
move
(
fin
),
token
);
}
}
// namespace caf
libcaf_core/caf/scheduled_actor.hpp
View file @
f78f6c9c
...
@@ -538,6 +538,7 @@ public:
...
@@ -538,6 +538,7 @@ public:
std
::
move
(
fin
));
std
::
move
(
fin
));
}
}
/// @deprecated Please use `attach_stream_stage` instead.
template
<
class
Driver
,
class
In
,
class
...
Ts
,
class
...
Us
>
template
<
class
Driver
,
class
In
,
class
...
Ts
,
class
...
Us
>
make_stage_result_t
<
In
,
typename
Driver
::
downstream_manager_type
,
Ts
...
>
make_stage_result_t
<
In
,
typename
Driver
::
downstream_manager_type
,
Ts
...
>
make_stage
(
const
stream
<
In
>&
src
,
std
::
tuple
<
Ts
...
>
xs
,
Us
&&
...
ys
)
{
make_stage
(
const
stream
<
In
>&
src
,
std
::
tuple
<
Ts
...
>
xs
,
Us
&&
...
ys
)
{
...
@@ -548,6 +549,7 @@ public:
...
@@ -548,6 +549,7 @@ public:
return
{
in
,
out
,
std
::
move
(
mgr
)};
return
{
in
,
out
,
std
::
move
(
mgr
)};
}
}
/// @deprecated Please use `attach_stream_stage` instead.
template
<
class
In
,
class
...
Ts
,
class
Init
,
class
Fun
,
template
<
class
In
,
class
...
Ts
,
class
Init
,
class
Fun
,
class
Finalize
=
unit_t
,
class
Finalize
=
unit_t
,
class
DownstreamManager
=
default_downstream_manager_t
<
Fun
>,
class
DownstreamManager
=
default_downstream_manager_t
<
Fun
>,
...
@@ -579,6 +581,7 @@ public:
...
@@ -579,6 +581,7 @@ public:
std
::
move
(
fun
),
std
::
move
(
fin
));
std
::
move
(
fun
),
std
::
move
(
fin
));
}
}
/// @deprecated Please use `attach_stream_stage` instead.
template
<
class
In
,
class
Init
,
class
Fun
,
class
Finalize
=
unit_t
,
template
<
class
In
,
class
Init
,
class
Fun
,
class
Finalize
=
unit_t
,
class
DownstreamManager
=
default_downstream_manager_t
<
Fun
>,
class
DownstreamManager
=
default_downstream_manager_t
<
Fun
>,
class
Trait
=
stream_stage_trait_t
<
Fun
>>
class
Trait
=
stream_stage_trait_t
<
Fun
>>
...
...
libcaf_core/test/pipeline_streaming.cpp
View file @
f78f6c9c
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#include "caf/actor_system.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/attach_stream_stage.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/event_based_actor.hpp"
#include "caf/stateful_actor.hpp"
#include "caf/stateful_actor.hpp"
...
@@ -153,7 +154,8 @@ TESTEE(broken_sink) {
...
@@ -153,7 +154,8 @@ TESTEE(broken_sink) {
TESTEE
(
filter
)
{
TESTEE
(
filter
)
{
CAF_IGNORE_UNUSED
(
self
);
CAF_IGNORE_UNUSED
(
self
);
return
{[
=
](
stream
<
int
>&
in
)
{
return
{[
=
](
stream
<
int
>&
in
)
{
return
self
->
make_stage
(
return
attach_stream_stage
(
self
,
// input stream
// input stream
in
,
in
,
// initialize state
// initialize state
...
@@ -173,7 +175,8 @@ TESTEE(filter) {
...
@@ -173,7 +175,8 @@ TESTEE(filter) {
TESTEE
(
doubler
)
{
TESTEE
(
doubler
)
{
CAF_IGNORE_UNUSED
(
self
);
CAF_IGNORE_UNUSED
(
self
);
return
{[
=
](
stream
<
int
>&
in
)
{
return
{[
=
](
stream
<
int
>&
in
)
{
return
self
->
make_stage
(
return
attach_stream_stage
(
self
,
// input stream
// input stream
in
,
in
,
// initialize state
// initialize state
...
...
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