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
1b98e243
Commit
1b98e243
authored
Mar 07, 2018
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move add_..._path functions to stream mangers
parent
e730ad4a
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
175 additions
and
133 deletions
+175
-133
libcaf_core/caf/detail/invoke_result_visitor.hpp
libcaf_core/caf/detail/invoke_result_visitor.hpp
+1
-1
libcaf_core/caf/detail/stream_sink_driver_impl.hpp
libcaf_core/caf/detail/stream_sink_driver_impl.hpp
+4
-6
libcaf_core/caf/detail/stream_sink_impl.hpp
libcaf_core/caf/detail/stream_sink_impl.hpp
+6
-3
libcaf_core/caf/output_stream.hpp
libcaf_core/caf/output_stream.hpp
+0
-9
libcaf_core/caf/scheduled_actor.hpp
libcaf_core/caf/scheduled_actor.hpp
+15
-70
libcaf_core/caf/stream_manager.hpp
libcaf_core/caf/stream_manager.hpp
+45
-0
libcaf_core/caf/stream_result.hpp
libcaf_core/caf/stream_result.hpp
+17
-9
libcaf_core/caf/stream_sink.hpp
libcaf_core/caf/stream_sink.hpp
+17
-0
libcaf_core/caf/stream_sink_driver.hpp
libcaf_core/caf/stream_sink_driver.hpp
+12
-1
libcaf_core/caf/stream_source.hpp
libcaf_core/caf/stream_source.hpp
+16
-0
libcaf_core/caf/stream_stage.hpp
libcaf_core/caf/stream_stage.hpp
+1
-0
libcaf_core/src/scheduled_actor.cpp
libcaf_core/src/scheduled_actor.cpp
+13
-25
libcaf_core/src/stream_manager.cpp
libcaf_core/src/stream_manager.cpp
+19
-0
libcaf_core/test/continuous_streaming.cpp
libcaf_core/test/continuous_streaming.cpp
+2
-2
libcaf_core/test/fused_streaming.cpp
libcaf_core/test/fused_streaming.cpp
+4
-4
libcaf_core/test/native_streaming_classes.cpp
libcaf_core/test/native_streaming_classes.cpp
+1
-1
libcaf_core/test/selective_streaming.cpp
libcaf_core/test/selective_streaming.cpp
+2
-2
No files found.
libcaf_core/caf/detail/invoke_result_visitor.hpp
View file @
1b98e243
...
@@ -176,7 +176,7 @@ public:
...
@@ -176,7 +176,7 @@ public:
/// Calls `(*this)(x.ptr)`.
/// Calls `(*this)(x.ptr)`.
template
<
class
T
>
template
<
class
T
>
void
operator
()(
stream_result
<
T
>&
x
)
{
void
operator
()(
stream_result
<
T
>&
x
)
{
(
*
this
)(
x
.
slot
(),
0
,
x
.
ptr
());
(
*
this
)(
x
.
in
(),
0
,
x
.
ptr
());
}
}
// -- visit API: return true if T was visited, false if T was skipped --------
// -- visit API: return true if T was visited, false if T was skipped --------
...
...
libcaf_core/caf/detail/stream_sink_driver_impl.hpp
View file @
1b98e243
...
@@ -28,19 +28,17 @@ namespace caf {
...
@@ -28,19 +28,17 @@ namespace caf {
namespace
detail
{
namespace
detail
{
/// Identifies an unbound sequence of messages.
/// Identifies an unbound sequence of messages.
template
<
class
Input
,
class
Process
,
class
Finalize
>
template
<
class
Input
,
class
Result
,
class
Process
,
class
Finalize
>
class
stream_sink_driver_impl
final
:
public
stream_sink_driver
<
Input
>
{
class
stream_sink_driver_impl
final
:
public
stream_sink_driver
<
Input
,
Result
>
{
public:
public:
// -- member types -----------------------------------------------------------
// -- member types -----------------------------------------------------------
using
super
=
stream_sink_driver
<
Input
>
;
using
super
=
stream_sink_driver
<
Input
,
Result
>
;
using
input_type
=
typename
super
::
input_type
;
using
typename
super
::
input_type
;
using
trait
=
stream_sink_trait_t
<
Process
,
Finalize
>
;
using
trait
=
stream_sink_trait_t
<
Process
,
Finalize
>
;
using
output_type
=
typename
trait
::
output
;
using
state_type
=
typename
trait
::
state
;
using
state_type
=
typename
trait
::
state
;
template
<
class
Init
>
template
<
class
Init
>
...
...
libcaf_core/caf/detail/stream_sink_impl.hpp
View file @
1b98e243
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
#include "caf/message_id.hpp"
#include "caf/message_id.hpp"
#include "caf/sec.hpp"
#include "caf/sec.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_sink.hpp"
#include "caf/stream_sink_trait.hpp"
#include "caf/stream_sink_trait.hpp"
#include "caf/terminal_stream_scatterer.hpp"
#include "caf/terminal_stream_scatterer.hpp"
...
@@ -34,9 +35,9 @@ namespace caf {
...
@@ -34,9 +35,9 @@ namespace caf {
namespace
detail
{
namespace
detail
{
template
<
class
Driver
>
template
<
class
Driver
>
class
stream_sink_impl
:
public
stream_manager
{
class
stream_sink_impl
:
public
Driver
::
sink_type
{
public:
public:
using
super
=
stream_manager
;
using
super
=
typename
Driver
::
sink_type
;
using
driver_type
=
Driver
;
using
driver_type
=
Driver
;
...
@@ -45,6 +46,7 @@ public:
...
@@ -45,6 +46,7 @@ public:
template
<
class
...
Ts
>
template
<
class
...
Ts
>
stream_sink_impl
(
scheduled_actor
*
self
,
Ts
&&
...
xs
)
stream_sink_impl
(
scheduled_actor
*
self
,
Ts
&&
...
xs
)
:
stream_manager
(
self
),
:
stream_manager
(
self
),
super
(
self
),
driver_
(
std
::
forward
<
Ts
>
(
xs
)...),
driver_
(
std
::
forward
<
Ts
>
(
xs
)...),
out_
(
self
)
{
out_
(
self
)
{
// nop
// nop
...
@@ -84,7 +86,8 @@ private:
...
@@ -84,7 +86,8 @@ private:
};
};
template
<
class
Driver
,
class
...
Ts
>
template
<
class
Driver
,
class
...
Ts
>
stream_manager_ptr
make_stream_sink
(
scheduled_actor
*
self
,
Ts
&&
...
xs
)
{
typename
Driver
::
sink_ptr_type
make_stream_sink
(
scheduled_actor
*
self
,
Ts
&&
...
xs
)
{
using
impl
=
stream_sink_impl
<
Driver
>
;
using
impl
=
stream_sink_impl
<
Driver
>
;
return
make_counted
<
impl
>
(
self
,
std
::
forward
<
Ts
>
(
xs
)...);
return
make_counted
<
impl
>
(
self
,
std
::
forward
<
Ts
>
(
xs
)...);
}
}
...
...
libcaf_core/caf/output_stream.hpp
View file @
1b98e243
...
@@ -21,7 +21,6 @@
...
@@ -21,7 +21,6 @@
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
#include "caf/make_source_result.hpp"
#include "caf/make_source_result.hpp"
#include "caf/make_stage_result.hpp"
#include "caf/stream_slot.hpp"
#include "caf/stream_slot.hpp"
#include "caf/invalid_stream.hpp"
#include "caf/invalid_stream.hpp"
...
@@ -57,14 +56,6 @@ public:
...
@@ -57,14 +56,6 @@ public:
// nop
// nop
}
}
template
<
class
I
,
class
R
,
class
S
>
output_stream
(
make_stage_result
<
I
,
R
,
T
,
S
,
Ts
...
>
x
)
:
in_
(
x
.
in
()),
out_
(
x
.
out
()),
ptr_
(
std
::
move
(
x
.
ptr
()))
{
// nop
}
output_stream
(
stream_slot
in_slot
,
stream_slot
out_slot
,
output_stream
(
stream_slot
in_slot
,
stream_slot
out_slot
,
stream_manager_ptr
mgr
)
stream_manager_ptr
mgr
)
:
in_
(
in_slot
),
:
in_
(
in_slot
),
...
...
libcaf_core/caf/scheduled_actor.hpp
View file @
1b98e243
...
@@ -413,58 +413,6 @@ public:
...
@@ -413,58 +413,6 @@ public:
// -- stream management ------------------------------------------------------
// -- stream management ------------------------------------------------------
/// Creates an output path for given source.
template
<
class
Out
,
class
Scatterer
,
class
...
Ts
>
make_source_result
<
Out
,
Scatterer
,
Ts
...
>
add_outbound_path
(
stream_source_ptr
<
Out
,
Scatterer
,
Ts
...
>
mgr
)
{
auto
slot
=
assign_next_pending_slot
(
mgr
);
return
{
slot
,
std
::
move
(
mgr
)};
}
/// Creates an output path for given stage.
template
<
class
In
,
class
Result
,
class
Out
,
class
Scatterer
,
class
...
Ts
>
make_source_result
<
Out
,
Scatterer
,
Ts
...
>
add_outbound_path
(
stream_stage_ptr
<
In
,
Result
,
Out
,
Scatterer
,
Ts
...
>
mgr
)
{
auto
slot
=
assign_next_pending_slot
(
mgr
);
return
{
slot
,
std
::
move
(
mgr
)};
}
/// Creates an output path for the given stage without any type checking.
/// @private
template
<
class
Out
,
class
...
Ts
>
output_stream
<
Out
,
Ts
...
>
add_unsafe_outbound_path
(
stream_manager_ptr
mgr
)
{
auto
slot
=
assign_next_pending_slot
(
mgr
);
return
{
0
,
slot
,
std
::
move
(
mgr
)};
}
/// Creates an output path for the given stage without any type checking.
/// @pre `next != nullptr`
/// @pre `pending_stream_managers_[slot] == mgr`
/// @pre `mgr->out().terminal() == false`
/// @private
void
add_unsafe_outbound_path
(
stream_manager_ptr
mgr
,
strong_actor_ptr
next
,
stream_slot
slot
,
strong_actor_ptr
origin
,
mailbox_element
::
forwarding_stack
stages
,
message_id
mid
);
/// Creates an input path for given stage.
template
<
class
In
,
class
Result
,
class
Out
,
class
Scatterer
,
class
...
Ts
>
make_sink_result
<
In
,
Result
>
add_inbound_path
(
const
stream
<
In
>&
,
stream_stage_ptr
<
In
,
Result
,
Out
,
Scatterer
,
Ts
...
>
mgr
)
{
auto
slot
=
assign_next_slot
(
mgr
);
return
{
slot
,
std
::
move
(
mgr
)};
}
/// Creates an input path for given stage.
/// @private
template
<
class
Result
,
class
In
>
stream_result
<
Result
>
add_unsafe_inbound_path
(
const
stream
<
In
>&
,
stream_manager_ptr
mgr
)
{
auto
slot
=
assign_next_slot
(
mgr
);
return
{
slot
,
std
::
move
(
mgr
)};
}
/// Creates a new stream source from `Driver`.
/// Creates a new stream source from `Driver`.
/// @param dest Actor handle to the stream destination.
/// @param dest Actor handle to the stream destination.
/// @param xs User-defined handshake payload.
/// @param xs User-defined handshake payload.
...
@@ -478,8 +426,7 @@ public:
...
@@ -478,8 +426,7 @@ public:
typename
Driver
::
make_source_result_type
make_source
(
Ts
&&
...
xs
)
{
typename
Driver
::
make_source_result_type
make_source
(
Ts
&&
...
xs
)
{
using
detail
::
make_stream_source
;
using
detail
::
make_stream_source
;
auto
mgr
=
make_stream_source
<
Driver
>
(
this
,
std
::
forward
<
Ts
>
(
xs
)...);
auto
mgr
=
make_stream_source
<
Driver
>
(
this
,
std
::
forward
<
Ts
>
(
xs
)...);
auto
slot
=
assign_next_pending_slot
(
mgr
);
return
mgr
->
add_outbound_path
();
return
{
slot
,
std
::
move
(
mgr
)};
}
}
template
<
class
...
Ts
,
class
Init
,
class
Pull
,
class
Done
,
class
Finalize
,
template
<
class
...
Ts
,
class
Init
,
class
Pull
,
class
Done
,
class
Finalize
,
...
@@ -552,9 +499,9 @@ public:
...
@@ -552,9 +499,9 @@ public:
auto
result
=
make_source
(
std
::
move
(
xs
),
std
::
move
(
init
),
std
::
move
(
pull
),
auto
result
=
make_source
(
std
::
move
(
xs
),
std
::
move
(
init
),
std
::
move
(
pull
),
std
::
move
(
done
),
scatterer_arg
);
std
::
move
(
done
),
scatterer_arg
);
auto
mid
=
new_request_id
(
message_priority
::
normal
);
auto
mid
=
new_request_id
(
message_priority
::
normal
);
add_unsafe_outbound_path
(
result
.
ptr
(),
actor_cast
<
strong_actor_ptr
>
(
dest
),
result
.
ptr
()
->
add_unsafe_outbound_path
(
result
.
out
(),
actor_cast
<
strong_actor_ptr
>
(
this
),
actor_cast
<
strong_actor_ptr
>
(
dest
),
result
.
out
(
),
no_stages
,
mid
);
actor_cast
<
strong_actor_ptr
>
(
this
),
no_stages
,
mid
);
behavior
tmp
{
behavior
tmp
{
[
=
](
handle_res_result
&
x
)
mutable
{
handle_res
(
std
::
move
(
x
));
},
[
=
](
handle_res_result
&
x
)
mutable
{
handle_res
(
std
::
move
(
x
));
},
[
=
](
error
&
err
)
mutable
{
handle_res
(
std
::
move
(
err
));
}
[
=
](
error
&
err
)
mutable
{
handle_res
(
std
::
move
(
err
));
}
...
@@ -580,13 +527,10 @@ public:
...
@@ -580,13 +527,10 @@ public:
}
}
template
<
class
Driver
,
class
Input
,
class
...
Ts
>
template
<
class
Driver
,
class
Input
,
class
...
Ts
>
stream_result
<
typename
Driver
::
output_type
>
stream_result
<
typename
Driver
::
result_type
>
make_sink
(
const
stream
<
Input
>&
src
,
Ts
&&
...
xs
)
{
make_sink
(
const
stream
<
Input
>&
,
Ts
&&
...
xs
)
{
auto
mgr
=
detail
::
make_stream_sink
<
Driver
>
(
this
,
std
::
forward
<
Ts
>
(
xs
)...);
auto
mgr
=
detail
::
make_stream_sink
<
Driver
>
(
this
,
std
::
forward
<
Ts
>
(
xs
)...);
auto
slot
=
assign_next_slot
(
mgr
);
return
mgr
->
add_inbound_path
(
src
);
return
{
slot
,
std
::
move
(
mgr
)};
}
}
template
<
class
Input
,
class
Init
,
class
Fun
,
class
Finalize
,
template
<
class
Input
,
class
Init
,
class
Fun
,
class
Finalize
,
...
@@ -594,18 +538,19 @@ public:
...
@@ -594,18 +538,19 @@ public:
stream_result
<
typename
Trait
::
output
>
stream_result
<
typename
Trait
::
output
>
make_sink
(
const
stream
<
Input
>&
in
,
Init
init
,
Fun
fun
,
Finalize
fin
)
{
make_sink
(
const
stream
<
Input
>&
in
,
Init
init
,
Fun
fun
,
Finalize
fin
)
{
using
driver
=
detail
::
stream_sink_driver_impl
<
typename
Trait
::
input
,
using
driver
=
detail
::
stream_sink_driver_impl
<
typename
Trait
::
input
,
typename
Trait
::
output
,
Fun
,
Finalize
>
;
Fun
,
Finalize
>
;
return
make_sink
<
driver
>
(
in
,
std
::
move
(
init
),
std
::
move
(
fun
),
return
make_sink
<
driver
>
(
in
,
std
::
move
(
init
),
std
::
move
(
fun
),
std
::
move
(
fin
));
std
::
move
(
fin
));
}
}
template
<
class
Driver
,
class
In
,
class
...
Ts
>
template
<
class
Driver
,
class
In
,
class
...
Ts
>
typename
Driver
::
make_stage_result_type
make_stage
(
const
stream
<
In
>&
,
typename
Driver
::
make_stage_result_type
make_stage
(
const
stream
<
In
>&
src
,
Ts
&&
...
xs
)
{
Ts
&&
...
xs
)
{
using
detail
::
make_stream_stage
;
using
detail
::
make_stream_stage
;
auto
mgr
=
make_stream_stage
<
Driver
>
(
this
,
std
::
forward
<
Ts
>
(
xs
)...);
auto
mgr
=
make_stream_stage
<
Driver
>
(
this
,
std
::
forward
<
Ts
>
(
xs
)...);
auto
in
=
assign_next_slot
(
mgr
);
auto
in
=
mgr
->
add_inbound_path
(
src
).
in
(
);
auto
out
=
assign_next_pending_slot
(
mgr
);
auto
out
=
mgr
->
add_outbound_path
().
out
(
);
return
{
in
,
out
,
std
::
move
(
mgr
)};
return
{
in
,
out
,
std
::
move
(
mgr
)};
}
}
...
@@ -896,15 +841,15 @@ public:
...
@@ -896,15 +841,15 @@ public:
/// Assigns slot `x` to `mgr`, i.e., adds a new entry to `stream_managers_`.
/// Assigns slot `x` to `mgr`, i.e., adds a new entry to `stream_managers_`.
void
assign_slot
(
stream_slot
x
,
stream_manager_ptr
mgr
);
void
assign_slot
(
stream_slot
x
,
stream_manager_ptr
mgr
);
/// Convenience function for calling `assign_slot(next_slot(), mgr)`.
stream_slot
assign_next_slot
(
stream_manager_ptr
mgr
);
/// Assigns slot `x` to the pending manager `mgr`, i.e., adds a new entry to
/// Assigns slot `x` to the pending manager `mgr`, i.e., adds a new entry to
/// `pending_stream_managers_`.
/// `pending_stream_managers_`.
void
assign_pending_slot
(
stream_slot
x
,
stream_manager_ptr
mgr
);
void
assign_pending_slot
(
stream_slot
x
,
stream_manager_ptr
mgr
);
/// Convenience function for calling `assign_slot(next_slot(), mgr)`.
/// Convenience function for calling `assign_slot(next_slot(), mgr)`.
stream_slot
assign_next_pending_slot
(
stream_manager_ptr
mgr
);
stream_slot
assign_next_slot_to
(
stream_manager_ptr
mgr
);
/// Convenience function for calling `assign_slot(next_slot(), mgr)`.
stream_slot
assign_next_pending_slot_to
(
stream_manager_ptr
mgr
);
/// Adds a new stream manager to the actor and starts cycle management if
/// Adds a new stream manager to the actor and starts cycle management if
/// needed.
/// needed.
...
...
libcaf_core/caf/stream_manager.hpp
View file @
1b98e243
...
@@ -175,7 +175,33 @@ public:
...
@@ -175,7 +175,33 @@ public:
return
self_
;
return
self_
;
}
}
/// Creates an outbound path to the current sender without any type checking.
/// @pre `out().terminal() == false`
/// @private
template
<
class
Out
,
class
...
Ts
>
output_stream
<
Out
,
Ts
...
>
add_unsafe_outbound_path
();
/// Creates an outbound path to `next` without any type checking.
/// @pre `next != nullptr`
/// @pre `self()->pending_stream_managers_[slot] == this`
/// @pre `out().terminal() == false`
/// @private
void
add_unsafe_outbound_path
(
strong_actor_ptr
next
,
stream_slot
slot
,
strong_actor_ptr
origin
,
mailbox_element
::
forwarding_stack
stages
,
message_id
mid
);
/// Creates an inbound path to the current sender without any type checking.
template
<
class
Result
,
class
In
>
stream_result
<
Result
>
add_unsafe_inbound_path
(
const
stream
<
In
>&
in
);
protected:
protected:
// -- modifiers for self -----------------------------------------------------
stream_slot
assign_next_slot
();
stream_slot
assign_next_pending_slot
();
// -- implementation hooks ---------------------------------------------------
// -- implementation hooks ---------------------------------------------------
virtual
void
finalize
(
const
error
&
reason
);
virtual
void
finalize
(
const
error
&
reason
);
...
@@ -238,4 +264,23 @@ using stream_manager_ptr = intrusive_ptr<stream_manager>;
...
@@ -238,4 +264,23 @@ using stream_manager_ptr = intrusive_ptr<stream_manager>;
}
// namespace caf
}
// namespace caf
#include "caf/output_stream.hpp"
#include "caf/stream_result.hpp"
namespace
caf
{
template
<
class
Out
,
class
...
Ts
>
output_stream
<
Out
,
Ts
...
>
stream_manager
::
add_unsafe_outbound_path
()
{
return
{
0
,
this
->
assign_next_pending_slot
(),
this
};
}
template
<
class
Result
,
class
In
>
stream_result
<
Result
>
stream_manager
::
add_unsafe_inbound_path
(
const
stream
<
In
>&
)
{
return
{
this
->
assign_next_slot
(),
this
};
}
}
// namespace caf
#endif // CAF_STREAM_MANAGER_HPP
#endif // CAF_STREAM_MANAGER_HPP
libcaf_core/caf/stream_result.hpp
View file @
1b98e243
...
@@ -20,9 +20,10 @@
...
@@ -20,9 +20,10 @@
#define CAF_STREAM_RESULT_HPP
#define CAF_STREAM_RESULT_HPP
#include "caf/fwd.hpp"
#include "caf/fwd.hpp"
#include "caf/make_sink_result.hpp"
#include "caf/none.hpp"
#include "caf/none.hpp"
#include "caf/stream_slot.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_slot.hpp"
#include "caf/meta/type_name.hpp"
#include "caf/meta/type_name.hpp"
...
@@ -37,18 +38,18 @@ public:
...
@@ -37,18 +38,18 @@ public:
stream_result
&
operator
=
(
stream_result
&&
)
=
default
;
stream_result
&
operator
=
(
stream_result
&&
)
=
default
;
stream_result
&
operator
=
(
const
stream_result
&
)
=
default
;
stream_result
&
operator
=
(
const
stream_result
&
)
=
default
;
stream_result
(
none_t
=
none
)
:
slot
_
(
0
)
{
stream_result
(
none_t
=
none
)
:
in
_
(
0
)
{
// nop
// nop
}
}
stream_result
(
stream_slot
id
)
:
slot
_
(
id
)
{
stream_result
(
stream_slot
id
)
:
in
_
(
id
)
{
// nop
// nop
}
}
/// Convenience constructor for returning the result of `self->new_stream_result`
/// Convenience constructor for returning the result of `self->new_stream_result`
/// and similar functions.
/// and similar functions.
stream_result
(
stream_slot
id
,
stream_manager_ptr
sptr
)
stream_result
(
stream_slot
id
,
stream_manager_ptr
sptr
)
:
slot
_
(
id
),
:
in
_
(
id
),
ptr_
(
std
::
move
(
sptr
))
{
ptr_
(
std
::
move
(
sptr
))
{
// nop
// nop
}
}
...
@@ -56,14 +57,21 @@ public:
...
@@ -56,14 +57,21 @@ public:
/// Convenience constructor for returning the result of `self->new_stream_result`
/// Convenience constructor for returning the result of `self->new_stream_result`
/// and similar functions.
/// and similar functions.
stream_result
(
stream_result
other
,
stream_manager_ptr
sptr
)
stream_result
(
stream_result
other
,
stream_manager_ptr
sptr
)
:
slot_
(
other
.
slot
_
),
:
in_
(
other
.
in
_
),
ptr_
(
std
::
move
(
sptr
))
{
ptr_
(
std
::
move
(
sptr
))
{
// nop
// nop
}
}
template
<
class
In
>
stream_result
(
make_sink_result
<
In
,
T
>
other
)
:
in_
(
other
.
in
()),
ptr_
(
other
.
ptr
())
{
// nop
}
/// Returns the unique identifier for this stream_result.
/// Returns the unique identifier for this stream_result.
inline
stream_slot
slot
()
const
noexcept
{
inline
stream_slot
in
()
const
noexcept
{
return
slot
_
;
return
in
_
;
}
}
/// Returns the handler assigned to this stream on this actor.
/// Returns the handler assigned to this stream on this actor.
...
@@ -79,11 +87,11 @@ public:
...
@@ -79,11 +87,11 @@ public:
template
<
class
Inspector
>
template
<
class
Inspector
>
friend
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
friend
typename
Inspector
::
result_type
inspect
(
Inspector
&
f
,
stream_result
&
x
)
{
stream_result
&
x
)
{
return
f
(
meta
::
type_name
(
"stream_result"
),
x
.
slot
_
);
return
f
(
meta
::
type_name
(
"stream_result"
),
x
.
in
_
);
}
}
private:
private:
stream_slot
slot
_
;
stream_slot
in
_
;
stream_manager_ptr
ptr_
;
stream_manager_ptr
ptr_
;
};
};
...
...
libcaf_core/caf/stream_sink.hpp
View file @
1b98e243
...
@@ -40,6 +40,11 @@ public:
...
@@ -40,6 +40,11 @@ public:
stream_sink
(
scheduled_actor
*
self
)
:
stream_manager
(
self
)
{
stream_sink
(
scheduled_actor
*
self
)
:
stream_manager
(
self
)
{
// nop
// nop
}
}
// -- properties -------------------------------------------------------------
/// Creates a new input path to the current sender.
make_sink_result
<
In
,
Result
>
add_inbound_path
(
const
stream
<
In
>&
in
);
};
};
template
<
class
In
,
class
Result
>
template
<
class
In
,
class
Result
>
...
@@ -47,4 +52,16 @@ using stream_sink_ptr = intrusive_ptr<stream_sink<In, Result>>;
...
@@ -47,4 +52,16 @@ using stream_sink_ptr = intrusive_ptr<stream_sink<In, Result>>;
}
// namespace caf
}
// namespace caf
#include "caf/make_sink_result.hpp"
namespace
caf
{
template
<
class
In
,
class
Result
>
make_sink_result
<
In
,
Result
>
stream_sink
<
In
,
Result
>::
add_inbound_path
(
const
stream
<
In
>&
)
{
return
{
this
->
assign_next_slot
(),
this
};
}
}
// namespace caf
#endif // CAF_DETAIL_STREAM_SINK_HPP
#endif // CAF_DETAIL_STREAM_SINK_HPP
libcaf_core/caf/stream_sink_driver.hpp
View file @
1b98e243
...
@@ -30,13 +30,24 @@
...
@@ -30,13 +30,24 @@
namespace
caf
{
namespace
caf
{
/// Identifies an unbound sequence of messages.
/// Identifies an unbound sequence of messages.
template
<
class
Input
>
template
<
class
Input
,
class
Result
>
class
stream_sink_driver
{
class
stream_sink_driver
{
public:
public:
// -- member types -----------------------------------------------------------
// -- member types -----------------------------------------------------------
using
input_type
=
Input
;
using
input_type
=
Input
;
using
result_type
=
Result
;
/// Implemented `stream_sink` interface.
using
sink_type
=
stream_sink
<
input_type
,
result_type
>
;
/// Smart pointer to the interface type.
using
sink_ptr_type
=
intrusive_ptr
<
sink_type
>
;
/// Wrapper type holding a pointer to `sink_type`.
using
make_sink_result_type
=
make_sink_result
<
input_type
,
result_type
>
;
// -- constructors, destructors, and assignment operators --------------------
// -- constructors, destructors, and assignment operators --------------------
virtual
~
stream_sink_driver
()
{
virtual
~
stream_sink_driver
()
{
...
...
libcaf_core/caf/stream_source.hpp
View file @
1b98e243
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include <tuple>
#include <tuple>
#include "caf/fwd.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/stream_manager.hpp"
#include "caf/stream_manager.hpp"
...
@@ -45,6 +46,9 @@ public:
...
@@ -45,6 +46,9 @@ public:
return
out_
;
return
out_
;
}
}
/// Creates a new output path to the current sender.
make_source_result
<
Out
,
Scatterer
,
Ts
...
>
add_outbound_path
();
protected:
protected:
Scatterer
out_
;
Scatterer
out_
;
};
};
...
@@ -60,4 +64,16 @@ using stream_source_ptr_t =
...
@@ -60,4 +64,16 @@ using stream_source_ptr_t =
}
// namespace caf
}
// namespace caf
#include "caf/make_source_result.hpp"
namespace
caf
{
template
<
class
Out
,
class
Scatterer
,
class
...
Ts
>
make_source_result
<
Out
,
Scatterer
,
Ts
...
>
stream_source
<
Out
,
Scatterer
,
Ts
...
>::
add_outbound_path
()
{
return
{
this
->
assign_next_pending_slot
(),
this
};
}
}
// namespace caf
#endif // CAF_DETAIL_STREAM_SOURCE_HPP
#endif // CAF_DETAIL_STREAM_SOURCE_HPP
libcaf_core/caf/stream_stage.hpp
View file @
1b98e243
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
#include <tuple>
#include <tuple>
#include "caf/fwd.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/stream_sink.hpp"
#include "caf/stream_sink.hpp"
#include "caf/stream_source.hpp"
#include "caf/stream_source.hpp"
...
...
libcaf_core/src/scheduled_actor.cpp
View file @
1b98e243
...
@@ -402,19 +402,6 @@ void scheduled_actor::quit(error x) {
...
@@ -402,19 +402,6 @@ void scheduled_actor::quit(error x) {
// -- stream management --------------------------------------------------------
// -- stream management --------------------------------------------------------
void
scheduled_actor
::
add_unsafe_outbound_path
(
stream_manager_ptr
mgr
,
strong_actor_ptr
next
,
stream_slot
slot
,
strong_actor_ptr
origin
,
mailbox_element
::
forwarding_stack
stages
,
message_id
mid
)
{
CAF_ASSERT
(
next
!=
nullptr
);
CAF_ASSERT
(
mgr
->
out
().
terminal
()
==
false
);
CAF_ASSERT
(
pending_stream_managers_
[
slot
]
==
mgr
);
// Build pipeline by forwarding handshake along the path.
mgr
->
send_handshake
(
std
::
move
(
next
),
slot
,
std
::
move
(
origin
),
std
::
move
(
stages
),
mid
);
mgr
->
generate_messages
();
}
sec
scheduled_actor
::
build_pipeline
(
stream_slot
in
,
stream_slot
out
,
sec
scheduled_actor
::
build_pipeline
(
stream_slot
in
,
stream_slot
out
,
stream_manager_ptr
mgr
)
{
stream_manager_ptr
mgr
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
in
)
<<
CAF_ARG
(
out
)
<<
CAF_ARG
(
mgr
));
CAF_LOG_TRACE
(
CAF_ARG
(
in
)
<<
CAF_ARG
(
out
)
<<
CAF_ARG
(
mgr
));
...
@@ -444,7 +431,7 @@ sec scheduled_actor::build_pipeline(stream_slot in, stream_slot out,
...
@@ -444,7 +431,7 @@ sec scheduled_actor::build_pipeline(stream_slot in, stream_slot out,
if
(
out
!=
0
&&
mgr
->
out
().
path
(
out
)
==
nullptr
)
{
if
(
out
!=
0
&&
mgr
->
out
().
path
(
out
)
==
nullptr
)
{
if
(
next
==
nullptr
)
if
(
next
==
nullptr
)
return
fail
(
sec
::
no_downstream_stages_defined
);
return
fail
(
sec
::
no_downstream_stages_defined
);
add_unsafe_outbound_path
(
mgr
,
std
::
move
(
next
),
out
,
current_sender
(),
mgr
->
add_unsafe_outbound_path
(
std
::
move
(
next
),
out
,
current_sender
(),
take_current_forwarding_stack
(),
take_current_forwarding_stack
(),
current_message_id
());
current_message_id
());
}
}
...
@@ -940,20 +927,13 @@ stream_slot scheduled_actor::next_slot() {
...
@@ -940,20 +927,13 @@ stream_slot scheduled_actor::next_slot() {
}
}
void
scheduled_actor
::
assign_slot
(
stream_slot
x
,
stream_manager_ptr
mgr
)
{
void
scheduled_actor
::
assign_slot
(
stream_slot
x
,
stream_manager_ptr
mgr
)
{
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
CAF_ARG
(
x
)
);
if
(
stream_managers_
.
empty
())
if
(
stream_managers_
.
empty
())
stream_ticks_
.
start
(
clock
().
now
());
stream_ticks_
.
start
(
clock
().
now
());
CAF_ASSERT
(
stream_managers_
.
count
(
x
)
==
0
);
CAF_ASSERT
(
stream_managers_
.
count
(
x
)
==
0
);
stream_managers_
.
emplace
(
x
,
std
::
move
(
mgr
));
stream_managers_
.
emplace
(
x
,
std
::
move
(
mgr
));
}
}
stream_slot
scheduled_actor
::
assign_next_slot
(
stream_manager_ptr
mgr
)
{
CAF_LOG_TRACE
(
""
);
auto
x
=
next_slot
();
assign_slot
(
x
,
std
::
move
(
mgr
));
return
x
;
}
void
scheduled_actor
::
assign_pending_slot
(
stream_slot
x
,
void
scheduled_actor
::
assign_pending_slot
(
stream_slot
x
,
stream_manager_ptr
mgr
)
{
stream_manager_ptr
mgr
)
{
CAF_LOG_TRACE
(
CAF_ARG
(
x
));
CAF_LOG_TRACE
(
CAF_ARG
(
x
));
...
@@ -961,7 +941,15 @@ void scheduled_actor::assign_pending_slot(stream_slot x,
...
@@ -961,7 +941,15 @@ void scheduled_actor::assign_pending_slot(stream_slot x,
pending_stream_managers_
.
emplace
(
x
,
std
::
move
(
mgr
));
pending_stream_managers_
.
emplace
(
x
,
std
::
move
(
mgr
));
}
}
stream_slot
scheduled_actor
::
assign_next_pending_slot
(
stream_manager_ptr
mgr
)
{
stream_slot
scheduled_actor
::
assign_next_slot_to
(
stream_manager_ptr
mgr
)
{
CAF_LOG_TRACE
(
""
);
auto
x
=
next_slot
();
assign_slot
(
x
,
std
::
move
(
mgr
));
return
x
;
}
stream_slot
scheduled_actor
::
assign_next_pending_slot_to
(
stream_manager_ptr
mgr
)
{
CAF_LOG_TRACE
(
""
);
CAF_LOG_TRACE
(
""
);
auto
x
=
next_slot
();
auto
x
=
next_slot
();
assign_pending_slot
(
x
,
std
::
move
(
mgr
));
assign_pending_slot
(
x
,
std
::
move
(
mgr
));
...
...
libcaf_core/src/stream_manager.cpp
View file @
1b98e243
...
@@ -197,6 +197,25 @@ void stream_manager::deliver_promises(message x) {
...
@@ -197,6 +197,25 @@ void stream_manager::deliver_promises(message x) {
promises_
.
clear
();
promises_
.
clear
();
}
}
void
stream_manager
::
add_unsafe_outbound_path
(
strong_actor_ptr
next
,
stream_slot
slot
,
strong_actor_ptr
origin
,
mailbox_element
::
forwarding_stack
stages
,
message_id
mid
)
{
CAF_ASSERT
(
next
!=
nullptr
);
CAF_ASSERT
(
out
().
terminal
()
==
false
);
// Build pipeline by forwarding handshake along the path.
send_handshake
(
std
::
move
(
next
),
slot
,
std
::
move
(
origin
),
std
::
move
(
stages
),
mid
);
generate_messages
();
}
stream_slot
stream_manager
::
assign_next_slot
()
{
return
self_
->
assign_next_slot_to
(
this
);
}
stream_slot
stream_manager
::
assign_next_pending_slot
()
{
return
self_
->
assign_next_pending_slot_to
(
this
);
}
void
stream_manager
::
finalize
(
const
error
&
)
{
void
stream_manager
::
finalize
(
const
error
&
)
{
// nop
// nop
}
}
...
...
libcaf_core/test/continuous_streaming.cpp
View file @
1b98e243
...
@@ -127,11 +127,11 @@ TESTEE(stream_multiplexer) {
...
@@ -127,11 +127,11 @@ TESTEE(stream_multiplexer) {
return
{
return
{
[
=
](
join_atom
)
{
[
=
](
join_atom
)
{
CAF_MESSAGE
(
"received 'join' request"
);
CAF_MESSAGE
(
"received 'join' request"
);
return
self
->
add_outbound_path
(
self
->
state
.
stage
);
return
self
->
state
.
stage
->
add_outbound_path
(
);
},
},
[
=
](
const
stream
<
int
>&
in
,
std
::
string
&
fname
)
{
[
=
](
const
stream
<
int
>&
in
,
std
::
string
&
fname
)
{
CAF_CHECK_EQUAL
(
fname
,
"numbers.txt"
);
CAF_CHECK_EQUAL
(
fname
,
"numbers.txt"
);
return
self
->
add_inbound_path
(
in
,
self
->
state
.
stage
);
return
self
->
state
.
stage
->
add_inbound_path
(
in
);
},
},
};
};
}
}
...
...
libcaf_core/test/fused_streaming.cpp
View file @
1b98e243
...
@@ -225,24 +225,24 @@ TESTEE(stream_multiplexer) {
...
@@ -225,24 +225,24 @@ TESTEE(stream_multiplexer) {
[
=
](
join_atom
,
ints_atom
)
{
[
=
](
join_atom
,
ints_atom
)
{
auto
&
stg
=
self
->
state
.
stage
;
auto
&
stg
=
self
->
state
.
stage
;
CAF_MESSAGE
(
"received 'join' request for integers"
);
CAF_MESSAGE
(
"received 'join' request for integers"
);
auto
result
=
s
elf
->
add_unsafe_outbound_path
<
int
>
(
stg
);
auto
result
=
s
tg
->
add_unsafe_outbound_path
<
int
>
(
);
stg
->
out
().
assign
<
int_scatterer
>
(
result
.
out
());
stg
->
out
().
assign
<
int_scatterer
>
(
result
.
out
());
return
result
;
return
result
;
},
},
[
=
](
join_atom
,
strings_atom
)
{
[
=
](
join_atom
,
strings_atom
)
{
auto
&
stg
=
self
->
state
.
stage
;
auto
&
stg
=
self
->
state
.
stage
;
CAF_MESSAGE
(
"received 'join' request for integers"
);
CAF_MESSAGE
(
"received 'join' request for integers"
);
auto
result
=
s
elf
->
add_unsafe_outbound_path
<
string
>
(
stg
);
auto
result
=
s
tg
->
add_unsafe_outbound_path
<
string
>
(
);
stg
->
out
().
assign
<
string_scatterer
>
(
result
.
out
());
stg
->
out
().
assign
<
string_scatterer
>
(
result
.
out
());
return
result
;
return
result
;
},
},
[
=
](
const
stream
<
int
>&
in
)
{
[
=
](
const
stream
<
int
>&
in
)
{
CAF_MESSAGE
(
"received handshake for integers"
);
CAF_MESSAGE
(
"received handshake for integers"
);
return
self
->
add_unsafe_inbound_path
<
void
>
(
in
,
self
->
state
.
stage
);
return
self
->
state
.
stage
->
add_unsafe_inbound_path
<
void
>
(
in
);
},
},
[
=
](
const
stream
<
string
>&
in
)
{
[
=
](
const
stream
<
string
>&
in
)
{
CAF_MESSAGE
(
"received handshake for strings"
);
CAF_MESSAGE
(
"received handshake for strings"
);
return
self
->
add_unsafe_inbound_path
<
void
>
(
in
,
self
->
state
.
stage
);
return
self
->
state
.
stage
->
add_unsafe_inbound_path
<
void
>
(
in
);
}
}
};
};
}
}
...
...
libcaf_core/test/native_streaming_classes.cpp
View file @
1b98e243
...
@@ -319,7 +319,7 @@ public:
...
@@ -319,7 +319,7 @@ public:
// was called and we run as a stage.
// was called and we run as a stage.
auto
mgr
=
forwarder
;
auto
mgr
=
forwarder
;
if
(
mgr
==
nullptr
)
{
if
(
mgr
==
nullptr
)
{
struct
driver
final
:
public
stream_sink_driver
<
int
>
{
struct
driver
final
:
public
stream_sink_driver
<
int
,
void
>
{
public:
public:
driver
(
std
::
vector
<
int
>*
log
)
:
log_
(
log
)
{
driver
(
std
::
vector
<
int
>*
log
)
:
log_
(
log
)
{
// nop
// nop
...
...
libcaf_core/test/selective_streaming.cpp
View file @
1b98e243
...
@@ -132,12 +132,12 @@ TESTEE(log_dispatcher) {
...
@@ -132,12 +132,12 @@ TESTEE(log_dispatcher) {
[
=
](
join_atom
,
level
lvl
)
{
[
=
](
join_atom
,
level
lvl
)
{
auto
&
stg
=
self
->
state
.
stage
;
auto
&
stg
=
self
->
state
.
stage
;
CAF_MESSAGE
(
"received 'join' request"
);
CAF_MESSAGE
(
"received 'join' request"
);
auto
result
=
s
elf
->
add_outbound_path
(
stg
);
auto
result
=
s
tg
->
add_outbound_path
(
);
stg
->
out
().
set_filter
(
result
.
out
(),
lvl
);
stg
->
out
().
set_filter
(
result
.
out
(),
lvl
);
return
result
;
return
result
;
},
},
[
=
](
const
stream
<
value_type
>&
in
)
{
[
=
](
const
stream
<
value_type
>&
in
)
{
return
self
->
add_inbound_path
(
in
,
self
->
state
.
stage
);
return
self
->
state
.
stage
->
add_inbound_path
(
in
);
}
}
};
};
}
}
...
...
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