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
9fdea6a4
Commit
9fdea6a4
authored
Apr 03, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove match_result
parent
be8c3f34
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
53 additions
and
146 deletions
+53
-146
libcaf_core/CMakeLists.txt
libcaf_core/CMakeLists.txt
+0
-3
libcaf_core/caf/behavior.hpp
libcaf_core/caf/behavior.hpp
+2
-2
libcaf_core/caf/detail/behavior_impl.hpp
libcaf_core/caf/detail/behavior_impl.hpp
+6
-10
libcaf_core/caf/match_result.hpp
libcaf_core/caf/match_result.hpp
+0
-36
libcaf_core/caf/message_handler.hpp
libcaf_core/caf/message_handler.hpp
+2
-2
libcaf_core/src/blocking_actor.cpp
libcaf_core/src/blocking_actor.cpp
+22
-28
libcaf_core/src/detail/behavior_impl.cpp
libcaf_core/src/detail/behavior_impl.cpp
+8
-16
libcaf_core/src/match_result_strings.cpp
libcaf_core/src/match_result_strings.cpp
+0
-21
libcaf_core/src/raw_event_based_actor.cpp
libcaf_core/src/raw_event_based_actor.cpp
+1
-1
libcaf_core/src/scheduled_actor.cpp
libcaf_core/src/scheduled_actor.cpp
+12
-27
No files found.
libcaf_core/CMakeLists.txt
View file @
9fdea6a4
...
...
@@ -6,8 +6,6 @@ file(GLOB_RECURSE CAF_CORE_HEADERS "caf/*.hpp")
add_enum_consistency_check
(
"caf/sec.hpp"
"src/sec_strings.cpp"
)
add_enum_consistency_check
(
"caf/pec.hpp"
"src/pec_strings.cpp"
)
add_enum_consistency_check
(
"caf/match_result.hpp"
"src/match_result_strings.cpp"
)
add_enum_consistency_check
(
"caf/stream_priority.hpp"
"src/stream_priority_strings.cpp"
)
add_enum_consistency_check
(
"caf/exit_reason.hpp"
...
...
@@ -111,7 +109,6 @@ set(CAF_CORE_SOURCES
src/logger.cpp
src/mailbox_element.cpp
src/make_config_option.cpp
src/match_result_strings.cpp
src/memory_managed.cpp
src/message.cpp
src/message_builder.cpp
...
...
libcaf_core/caf/behavior.hpp
View file @
9fdea6a4
...
...
@@ -99,8 +99,8 @@ public:
}
/// Runs this handler with callback.
match_result
operator
()(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
{
return
impl_
?
impl_
->
invoke
(
f
,
xs
)
:
match_result
::
no_match
;
bool
operator
()(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
{
return
impl_
?
impl_
->
invoke
(
f
,
xs
)
:
false
;
}
/// Checks whether this behavior is not empty.
...
...
libcaf_core/caf/detail/behavior_impl.hpp
View file @
9fdea6a4
...
...
@@ -31,7 +31,6 @@
#include "caf/detail/type_traits.hpp"
#include "caf/intrusive_ptr.hpp"
#include "caf/make_counted.hpp"
#include "caf/match_result.hpp"
#include "caf/message.hpp"
#include "caf/none.hpp"
#include "caf/optional.hpp"
...
...
@@ -62,10 +61,9 @@ public:
explicit
behavior_impl
(
timespan
tout
);
match_result
invoke_empty
(
detail
::
invoke_result_visitor
&
f
);
bool
invoke_empty
(
detail
::
invoke_result_visitor
&
f
);
virtual
match_result
invoke
(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
=
0
;
virtual
bool
invoke
(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
=
0
;
optional
<
message
>
invoke
(
message
&
);
...
...
@@ -123,14 +121,13 @@ public:
// nop
}
virtual
match_result
invoke
(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
override
{
virtual
bool
invoke
(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
override
{
return
invoke_impl
(
f
,
xs
,
std
::
make_index_sequence
<
sizeof
...(
Ts
)
>
{});
}
template
<
size_t
...
Is
>
match_result
invoke_impl
(
detail
::
invoke_result_visitor
&
f
,
message
&
msg
,
std
::
index_sequence
<
Is
...
>
)
{
bool
invoke_impl
(
detail
::
invoke_result_visitor
&
f
,
message
&
msg
,
std
::
index_sequence
<
Is
...
>
)
{
auto
dispatch
=
[
&
](
auto
&
fun
)
{
using
fun_type
=
std
::
decay_t
<
decltype
(
fun
)
>
;
using
trait
=
get_callable_trait_t
<
fun_type
>
;
...
...
@@ -149,8 +146,7 @@ public:
}
return
false
;
};
bool
dispatched
=
(
dispatch
(
std
::
get
<
Is
>
(
cases_
))
||
...);
return
dispatched
?
match_result
::
match
:
match_result
::
no_match
;
return
(
dispatch
(
std
::
get
<
Is
>
(
cases_
))
||
...);
}
void
handle_timeout
()
override
{
...
...
libcaf_core/caf/match_result.hpp
deleted
100644 → 0
View file @
be8c3f34
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| C++ *
* | | / _ \ | |_ Actor *
* | |___ / ___ \| _| Framework *
* \____/_/ \_|_| *
* *
* Copyright 2011-2020 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 <string>
#include "caf/detail/core_export.hpp"
namespace
caf
{
/// Denotes the invoke result of a ::behavior or ::message_handler.
enum
class
match_result
{
match
,
no_match
,
};
/// @relates match_result
CAF_CORE_EXPORT
std
::
string
to_string
(
match_result
);
}
// namespace caf
libcaf_core/caf/message_handler.hpp
View file @
9fdea6a4
...
...
@@ -91,8 +91,8 @@ public:
}
/// Runs this handler with callback.
match_result
operator
()(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
{
return
impl_
?
impl_
->
invoke
(
f
,
xs
)
:
match_result
::
no_match
;
bool
operator
()(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
{
return
impl_
?
impl_
->
invoke
(
f
,
xs
)
:
false
;
}
/// Returns a new handler that concatenates this handler
...
...
libcaf_core/src/blocking_actor.cpp
View file @
9fdea6a4
...
...
@@ -190,35 +190,29 @@ blocking_actor::mailbox_visitor::operator()(mailbox_element& x) {
[
&
]
{
self
->
current_element_
=
prev_element
;
});
// Dispatch on x.
detail
::
default_invoke_result_visitor
<
blocking_actor
>
visitor
{
self
};
switch
(
bhvr
.
nested
(
visitor
,
x
.
content
()))
{
default:
if
(
bhvr
.
nested
(
visitor
,
x
.
content
()))
return
check_if_done
();
// Blocking actors can have fallback handlers for catch-all rules.
auto
sres
=
bhvr
.
fallback
(
self
->
current_element_
->
payload
);
auto
f
=
detail
::
make_overload
(
[
&
](
skip_t
&
)
{
// Response handlers must get re-invoked with an error when
// receiving an unexpected message.
if
(
mid
.
is_response
())
{
auto
err
=
make_error
(
sec
::
unexpected_response
,
std
::
move
(
x
.
payload
));
mailbox_element
tmp
{
std
::
move
(
x
.
sender
),
x
.
mid
,
std
::
move
(
x
.
stages
),
make_message
(
std
::
move
(
err
))};
self
->
current_element_
=
&
tmp
;
bhvr
.
nested
(
tmp
.
content
());
return
check_if_done
();
}
return
intrusive
::
task_result
::
skip
;
},
[
&
](
auto
&
res
)
{
visitor
(
res
);
return
check_if_done
();
case
match_result
:
:
no_match
:
{
// Blocking actors can have fallback
// handlers for catch-all rules.
auto
sres
=
bhvr
.
fallback
(
self
->
current_element_
->
payload
);
auto
f
=
detail
::
make_overload
(
[
&
](
skip_t
&
)
{
// Response handlers must get re-invoked with an error when
// receiving an unexpected message.
if
(
mid
.
is_response
())
{
auto
err
=
make_error
(
sec
::
unexpected_response
,
std
::
move
(
x
.
payload
));
mailbox_element
tmp
{
std
::
move
(
x
.
sender
),
x
.
mid
,
std
::
move
(
x
.
stages
),
make_message
(
std
::
move
(
err
))};
self
->
current_element_
=
&
tmp
;
bhvr
.
nested
(
tmp
.
content
());
return
check_if_done
();
}
return
intrusive
::
task_result
::
skip
;
},
[
&
](
auto
&
res
)
{
visitor
(
res
);
return
check_if_done
();
});
return
visit
(
f
,
sres
);
}
}
});
return
visit
(
f
,
sres
);
};
// Post-process the returned value from the function body.
auto
result
=
body
();
...
...
libcaf_core/src/detail/behavior_impl.cpp
View file @
9fdea6a4
...
...
@@ -28,9 +28,8 @@ namespace {
class
combinator
final
:
public
behavior_impl
{
public:
match_result
invoke
(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
override
{
auto
x
=
first
->
invoke
(
f
,
xs
);
return
x
==
match_result
::
no_match
?
second
->
invoke
(
f
,
xs
)
:
x
;
bool
invoke
(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
override
{
return
first
->
invoke
(
f
,
xs
)
||
second
->
invoke
(
f
,
xs
);
}
void
handle_timeout
()
override
{
...
...
@@ -76,27 +75,20 @@ behavior_impl::behavior_impl(timespan tout) : timeout_(tout) {
// nop
}
match_result
behavior_impl
::
invoke_empty
(
detail
::
invoke_result_visitor
&
f
)
{
bool
behavior_impl
::
invoke_empty
(
detail
::
invoke_result_visitor
&
f
)
{
message
xs
;
return
invoke
(
f
,
xs
);
}
optional
<
message
>
behavior_impl
::
invoke
(
message
&
xs
)
{
maybe_message_visitor
f
;
// the following const-cast is safe, because invoke() is aware of
// copy-on-write and does not modify x if it's shared
if
(
!
xs
.
empty
())
invoke
(
f
,
xs
);
else
invoke_empty
(
f
);
return
std
::
move
(
f
.
value
);
if
(
invoke
(
f
,
xs
))
return
std
::
move
(
f
.
value
);
return
none
;
}
match_result
behavior_impl
::
invoke
(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
{
if
(
!
xs
.
empty
())
return
invoke
(
f
,
xs
);
return
invoke_empty
(
f
);
bool
behavior_impl
::
invoke
(
detail
::
invoke_result_visitor
&
f
,
message
&
xs
)
{
return
invoke
(
f
,
xs
);
}
void
behavior_impl
::
handle_timeout
()
{
...
...
libcaf_core/src/match_result_strings.cpp
deleted
100644 → 0
View file @
be8c3f34
// clang-format off
// DO NOT EDIT: this file is auto-generated by caf-generate-enum-strings.
// Run the target update-enum-strings if this file is out of sync.
#include "caf/match_result.hpp"
#include <string>
namespace
caf
{
std
::
string
to_string
(
match_result
x
)
{
switch
(
x
)
{
default:
return
"???"
;
case
match_result
:
:
match
:
return
"match"
;
case
match_result
:
:
no_match
:
return
"no_match"
;
};
}
}
// namespace caf
libcaf_core/src/raw_event_based_actor.cpp
View file @
9fdea6a4
...
...
@@ -87,7 +87,7 @@ invoke_message_result raw_event_based_actor::consume(mailbox_element& x) {
unsetf
(
has_timeout_flag
);
if
(
!
bhvr_stack_
.
empty
())
{
auto
&
bhvr
=
bhvr_stack_
.
back
();
if
(
bhvr
(
visitor
,
x
.
content
())
==
match_result
::
match
)
if
(
bhvr
(
visitor
,
x
.
content
()))
return
invoke_message_result
::
consumed
;
}
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
.
payload
);
...
...
libcaf_core/src/scheduled_actor.cpp
View file @
9fdea6a4
...
...
@@ -696,7 +696,7 @@ invoke_message_result scheduled_actor::consume(mailbox_element& x) {
unsetf
(
has_timeout_flag
);
if
(
!
bhvr_stack_
.
empty
())
{
auto
&
bhvr
=
bhvr_stack_
.
back
();
if
(
bhvr
(
visitor
,
x
.
content
())
==
match_result
::
match
)
if
(
bhvr
(
visitor
,
x
.
content
()))
return
invoke_message_result
::
consumed
;
}
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
.
payload
);
...
...
@@ -1108,34 +1108,19 @@ scheduled_actor::handle_open_stream_msg(mailbox_element& x) {
auto
rp
=
make_response_promise
();
rp
.
deliver
(
sec
::
stream_init_failed
);
};
// Utility for invoking the default handler.
auto
fallback
=
[
&
]
{
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
.
payload
);
if
(
holds_alternative
<
skip_t
>
(
sres
))
{
CAF_LOG_DEBUG
(
"default handler skipped open_stream_msg:"
<<
osm
.
msg
);
return
invoke_message_result
::
skipped
;
}
else
{
CAF_LOG_DEBUG
(
"default handler was called for open_stream_msg:"
<<
osm
.
msg
);
fail
(
sec
::
stream_init_failed
,
"dropped open_stream_msg (no match)"
);
return
invoke_message_result
::
dropped
;
}
};
// Invoke behavior and dispatch on the result.
auto
&
bs
=
bhvr_stack
();
if
(
bs
.
empty
())
return
fallback
();
auto
res
=
(
bs
.
back
())(
f
,
osm
.
msg
);
switch
(
res
)
{
case
match_result
:
:
no_match
:
CAF_LOG_DEBUG
(
"no match in behavior, fall back to default handler"
);
return
fallback
();
case
match_result
:
:
match
:
{
return
invoke_message_result
::
consumed
;
}
default:
CAF_LOG_DEBUG
(
"behavior skipped open_stream_msg:"
<<
osm
.
msg
);
return
invoke_message_result
::
skipped
;
// nop
if
(
!
bs
.
empty
()
&&
bs
.
back
()(
f
,
osm
.
msg
))
return
invoke_message_result
::
consumed
;
CAF_LOG_DEBUG
(
"no match in behavior, fall back to default handler"
);
auto
sres
=
call_handler
(
default_handler_
,
this
,
x
.
payload
);
if
(
holds_alternative
<
skip_t
>
(
sres
))
{
CAF_LOG_DEBUG
(
"default handler skipped open_stream_msg:"
<<
osm
.
msg
);
return
invoke_message_result
::
skipped
;
}
else
{
CAF_LOG_DEBUG
(
"default handler was called for open_stream_msg:"
<<
osm
.
msg
);
fail
(
sec
::
stream_init_failed
,
"dropped open_stream_msg (no match)"
);
return
invoke_message_result
::
dropped
;
}
}
...
...
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