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
ad7506fc
Commit
ad7506fc
authored
Aug 01, 2019
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add wrapper for dispatching write_packet calls
parent
a61eaed8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
92 additions
and
0 deletions
+92
-0
libcaf_net/caf/net/dispatcher.hpp
libcaf_net/caf/net/dispatcher.hpp
+92
-0
No files found.
libcaf_net/caf/net/dispatcher.hpp
0 → 100644
View file @
ad7506fc
/******************************************************************************
* ____ _ _____ *
* / ___| / \ | ___| 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
namespace
caf
{
namespace
net
{
/// Implements the interface for transport and application policies and
/// dispatches member functions either to `decorator` or `fallback`.
template
<
class
Decorator
,
class
Fallback
>
class
dispatcher
{
public:
dispatcher
(
Decorator
&
decorator
,
Fallback
&
fallback
)
:
decorator_
(
decorator
),
fallback_
(
fallback
)
{
// nop
}
template
<
class
Header
>
void
write_packet
(
const
Header
&
header
,
span
<
const
byte
>
payload
)
{
decltype
(
write_packet_delegate_test
<
Decorator
>
(
nullptr
,
header
,
payload
))
x
;
write_packet_delegate
(
x
,
header
,
payload
);
}
actor_system
&
system
()
{
fallback_
.
system
();
}
void
cancel_timeout
(
atom_value
type
,
uint64_t
id
)
{
fallback_
.
cancel_timeout
(
type
,
id
);
}
void
set_timeout
(
timestamp
tout
,
atom_value
type
,
uint64_t
id
)
{
fallback_
.
set_timeout
(
tout
,
type
,
id
);
}
typename
Fallback
::
transport_type
&
transport
()
{
return
fallback_
.
transport_
;
}
typename
Fallback
::
application_type
&
application
()
{
return
fallback_
.
application_
;
}
private:
template
<
class
U
,
class
Header
>
static
auto
write_packet_delegate_test
(
U
*
x
,
const
Header
&
hdr
,
span
<
const
byte
>
payload
)
->
decltype
(
x
->
write_packet
(
hdr
,
payload
),
std
::
true_type
());
template
<
class
U
>
static
auto
write_packet_delegate_test
(...)
->
std
::
false_type
;
template
<
class
Header
>
void
write_packet_delegate
(
std
::
true_type
,
const
Header
&
header
,
span
<
const
byte
>
payload
)
{
decorator_
.
write_packet
(
header
,
payload
);
}
template
<
class
Header
>
void
write_packet_delegate
(
std
::
false_type
,
const
Header
&
header
,
span
<
const
byte
>
payload
)
{
fallback_
.
write_packet
(
header
,
payload
);
}
Object
&
decorator_
;
Fallback
&
fallback_
;
};
template
<
class
Decorator
,
class
Fallback
>
dispatcher
<
Decorator
,
Fallback
>
make_dispatcher
(
Decorator
&
decorator
,
Fallback
&
fallback
)
{
return
{
decorator
,
fallback
};
}
}
// namespace net
}
// namespace caf
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