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
52110a9b
Commit
52110a9b
authored
Nov 30, 2020
by
Hauke Goldhammer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Port protobuf example to CAF 0.18 message types
parent
2e9ba05d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
22 deletions
+19
-22
examples/broker/protobuf_broker.cpp
examples/broker/protobuf_broker.cpp
+19
-22
No files found.
examples/broker/protobuf_broker.cpp
View file @
52110a9b
...
...
@@ -17,15 +17,18 @@ CAF_PUSH_WARNINGS
#include "pingpong.pb.h"
CAF_POP_WARNINGS
CAF_BEGIN_TYPE_ID_BLOCK
(
protobuf_example
,
first_custom_type_id
)
CAF_ADD_ATOM
(
protobuf_example
,
kickoff_atom
)
CAF_END_TYPE_ID_BLOCK
(
protobuf_example
)
namespace
{
using
namespace
std
;
using
namespace
caf
;
using
namespace
caf
::
io
;
using
ping_atom
=
atom_constant
<
atom
(
"ping"
)
>
;
using
pong_atom
=
atom_constant
<
atom
(
"pong"
)
>
;
using
kickoff_atom
=
atom_constant
<
atom
(
"kickoff"
)
>
;
// utility function to print an exit message with custom name
void
print_on_exit
(
scheduled_actor
*
self
,
const
std
::
string
&
name
)
{
...
...
@@ -40,26 +43,20 @@ struct ping_state {
behavior
ping
(
stateful_actor
<
ping_state
>*
self
,
size_t
num_pings
)
{
print_on_exit
(
self
,
"ping"
);
return
{
[
=
](
kickoff_atom
,
const
actor
&
pong
)
{
self
->
send
(
pong
,
ping_atom
::
value
,
1
);
self
->
become
(
[
=
](
pong_atom
,
int
value
)
->
message
{
return
{[
=
](
kickoff_atom
,
const
actor
&
pong
)
{
self
->
send
(
pong
,
ping_atom_v
,
1
);
self
->
become
([
=
](
pong_atom
,
int
value
)
->
message
{
if
(
++
(
self
->
state
.
count
)
>=
num_pings
)
self
->
quit
();
return
make_message
(
ping_atom
::
value
,
value
+
1
);
}
);
}
};
return
make_message
(
ping_atom_v
,
value
+
1
);
});
}};
}
behavior
pong
(
event_based_actor
*
self
)
{
print_on_exit
(
self
,
"pong"
);
return
{
[
=
](
ping_atom
,
int
value
)
{
return
make_message
(
pong_atom
::
value
,
value
);
}
[
=
](
ping_atom
,
int
value
)
{
return
make_message
(
pong_atom_v
,
value
);
},
};
}
...
...
@@ -105,10 +102,10 @@ void protobuf_io(broker* self, connection_handle hdl, const actor& buddy) {
org
::
libcppa
::
PingOrPong
p
;
p
.
ParseFromArray
(
msg
.
buf
.
data
(),
static_cast
<
int
>
(
msg
.
buf
.
size
()));
if
(
p
.
has_ping
())
{
self
->
send
(
buddy
,
ping_atom
::
value
,
p
.
ping
().
id
());
self
->
send
(
buddy
,
ping_atom
_v
,
p
.
ping
().
id
());
}
else
if
(
p
.
has_pong
())
{
self
->
send
(
buddy
,
pong_atom
::
value
,
p
.
pong
().
id
());
self
->
send
(
buddy
,
pong_atom
_v
,
p
.
pong
().
id
());
}
else
{
self
->
quit
(
exit_reason
::
user_shutdown
);
...
...
@@ -187,7 +184,7 @@ void run_client(actor_system& system, const config& cfg) {
<<
to_string
(
io_actor
.
error
())
<<
endl
;
return
;
}
send_as
(
*
io_actor
,
ping_actor
,
kickoff_atom
::
value
,
*
io_actor
);
send_as
(
*
io_actor
,
ping_actor
,
kickoff_atom
_v
,
*
io_actor
);
}
void
caf_main
(
actor_system
&
system
,
const
config
&
cfg
)
{
...
...
@@ -197,4 +194,4 @@ void caf_main(actor_system& system, const config& cfg) {
}
// namespace
CAF_MAIN
(
io
::
middleman
)
CAF_MAIN
(
i
d_block
::
protobuf_example
,
i
o
::
middleman
)
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