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
38490411
Commit
38490411
authored
Dec 10, 2011
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixed math_actor_example makefile
parent
4f73fcf5
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
172 additions
and
24 deletions
+172
-24
cppa/detail/network_manager.hpp
cppa/detail/network_manager.hpp
+0
-1
cppa/invoke_rules.hpp
cppa/invoke_rules.hpp
+2
-0
cppa/receive.hpp
cppa/receive.hpp
+15
-15
cppa/serializer.hpp
cppa/serializer.hpp
+1
-1
examples/Makefile.am
examples/Makefile.am
+3
-3
examples/math_actor_example.cpp
examples/math_actor_example.cpp
+2
-0
src/invoke_rules.cpp
src/invoke_rules.cpp
+7
-0
unit_testing/test__atom.cpp
unit_testing/test__atom.cpp
+2
-2
unit_testing/test__local_group.cpp
unit_testing/test__local_group.cpp
+2
-1
unit_testing/test__spawn.cpp
unit_testing/test__spawn.cpp
+138
-1
No files found.
cppa/detail/network_manager.hpp
View file @
38490411
...
...
@@ -6,7 +6,6 @@
namespace
cppa
{
namespace
detail
{
// note: implemented in post_office.cpp
class
network_manager
{
...
...
cppa/invoke_rules.hpp
View file @
38490411
...
...
@@ -159,6 +159,8 @@ class invoke_rules : public invoke_rules_base
timed_invoke_rules
operator
,(
timed_invoke_rules
&&
other
);
invoke_rules
&
operator
=
(
invoke_rules
&&
other
);
private:
invoke_rules
(
invokable_list
&&
ll
);
...
...
cppa/receive.hpp
View file @
38490411
...
...
@@ -5,13 +5,13 @@
namespace
cppa
{
/*
*
/*
* @brief Dequeues the next message from the mailbox.
*/
inline
const
any_tuple
&
receive
()
{
return
self
()
->
mailbox
().
dequeue
();
}
//
inline const any_tuple& receive()
//
{
//
return self()->mailbox().dequeue();
//
}
/**
* @brief Dequeues the next message from the mailbox that's matched
...
...
@@ -54,25 +54,25 @@ void receive(invoke_rules& rules, Head&& head, Tail&&... tail)
std
::
forward
<
Tail
>
(
tail
)...);
}
/*
*
/*
* @brief Tries to dequeue the next message from the mailbox.
* @returns @p true if a messages was dequeued;
* @p false if the mailbox is empty
*/
inline
bool
try_receive
(
any_tuple
&
msg
)
{
return
self
()
->
mailbox
().
try_dequeue
(
msg
);
}
//
inline bool try_receive(any_tuple& msg)
//
{
//
return self()->mailbox().try_dequeue(msg);
//
}
/*
*
/*
* @brief Tries to dequeue the next message from the mailbox.
* @returns @p true if a messages was dequeued;
* @p false if the mailbox is empty
*/
inline
bool
try_receive
(
invoke_rules
&
rules
)
{
return
self
()
->
mailbox
().
try_dequeue
(
rules
);
}
//
inline bool try_receive(invoke_rules& rules)
//
{
//
return self()->mailbox().try_dequeue(rules);
//
}
}
// namespace cppa
...
...
cppa/serializer.hpp
View file @
38490411
...
...
@@ -72,7 +72,7 @@ serializer& operator<<(serializer& s, const T& what)
if
(
mtype
==
nullptr
)
{
throw
std
::
logic_error
(
"no uniform type info found for "
+
cppa
::
detail
::
to_uniform_name
(
typeid
(
T
)));
+
cppa
::
detail
::
to_uniform_name
(
typeid
(
T
)));
}
mtype
->
serialize
(
&
what
,
&
s
);
return
s
;
...
...
examples/Makefile.am
View file @
38490411
...
...
@@ -9,7 +9,7 @@ noinst_PROGRAMS = announce_example_1 \
announce_example_4
\
announce_example_5
\
hello_world_example
\
math_example
math_
actor_
example
announce_example_1_SOURCES
=
announce_example_1.cpp
announce_example_2_SOURCES
=
announce_example_2.cpp
...
...
@@ -17,7 +17,7 @@ announce_example_3_SOURCES = announce_example_3.cpp
announce_example_4_SOURCES
=
announce_example_4.cpp
announce_example_5_SOURCES
=
announce_example_5.cpp
hello_world_example_SOURCES
=
hello_world_example.cpp
math_
example_SOURCES
=
math
_example.cpp
math_
actor_example_SOURCES
=
math_actor
_example.cpp
EXAMPLES_LIBS
=
$(BOOST_LDFLAGS)
$(BOOST_THREAD_LIB)
-L
../.libs/
-lcppa
...
...
@@ -27,5 +27,5 @@ announce_example_3_LDADD = $(EXAMPLES_LIBS)
announce_example_4_LDADD
=
$(EXAMPLES_LIBS)
announce_example_5_LDADD
=
$(EXAMPLES_LIBS)
hello_world_example_LDADD
=
$(EXAMPLES_LIBS)
math_example_LDADD
=
$(EXAMPLES_LIBS)
math_
actor_
example_LDADD
=
$(EXAMPLES_LIBS)
examples/math_actor_example.cpp
View file @
38490411
...
...
@@ -2,6 +2,8 @@
#include <iostream>
#include "cppa/cppa.hpp"
using
std
::
cout
;
using
std
::
endl
;
using
namespace
cppa
;
void
math_actor
()
...
...
src/invoke_rules.cpp
View file @
38490411
...
...
@@ -137,4 +137,11 @@ invoke_rules invoke_rules::operator,(invoke_rules&& other)
return
std
::
move
(
m_list
);
}
invoke_rules
&
invoke_rules
::
operator
=
(
invoke_rules
&&
other
)
{
m_list
=
std
::
move
(
other
.
m_list
);
other
.
m_list
.
clear
();
return
*
this
;
}
}
// namespace cppa
unit_testing/test__atom.cpp
View file @
38490411
...
...
@@ -56,7 +56,7 @@ size_t test__atom()
}
);
CPPA_CHECK
(
matched_pattern
[
0
]
&&
matched_pattern
[
1
]
&&
matched_pattern
[
2
]);
any_tuple
msg
=
receiv
e
();
CPPA_CHECK
(
try_receiv
e
(
msg
)
==
false
);
any_tuple
msg
=
self
()
->
mailbox
().
dequeu
e
();
CPPA_CHECK
(
self
()
->
mailbox
().
try_dequeu
e
(
msg
)
==
false
);
return
CPPA_TEST_RESULT
;
}
unit_testing/test__local_group.cpp
View file @
38490411
...
...
@@ -19,6 +19,7 @@
using
std
::
cout
;
using
std
::
endl
;
using
std
::
string
;
using
namespace
cppa
;
size_t
test__local_group
()
...
...
@@ -56,6 +57,6 @@ size_t test__local_group()
.
until
([
&
result
]()
{
return
result
==
10
;
});
await_all_others_done
();
any_tuple
tmp
;
CPPA_CHECK_EQUAL
(
try_receiv
e
(
tmp
),
false
);
CPPA_CHECK_EQUAL
(
self
()
->
mailbox
().
try_dequeu
e
(
tmp
),
false
);
return
CPPA_TEST_RESULT
;
}
unit_testing/test__spawn.cpp
View file @
38490411
#include <stack>
#include <chrono>
#include <iostream>
#include <functional>
...
...
@@ -18,6 +19,130 @@ using std::endl;
using
namespace
cppa
;
namespace
{
const
any_tuple
*
s_lm
=
nullptr
;
}
class
event_actor
{
std
::
stack
<
invoke_rules
>
m_behavior
;
invoke_rules
m_next_behavior
;
invoke_rules
*
m_behavior_ptr
;
public:
event_actor
(
invoke_rules
&&
behavior
)
{
m_behavior
.
push
(
std
::
move
(
behavior
));
m_behavior_ptr
=
&
(
m_behavior
.
top
());
}
void
become
(
invoke_rules
&&
behavior
)
{
m_behavior
.
push
(
std
::
move
(
behavior
));
m_behavior_ptr
=
&
(
m_behavior
.
top
());
}
void
set_next_behavior
(
invoke_rules
&&
behavior
)
{
m_next_behavior
=
std
::
move
(
behavior
);
m_behavior_ptr
=
&
m_next_behavior
;
}
void
unbecome
()
{
if
(
!
m_behavior
.
empty
())
{
if
(
m_behavior_ptr
==
&
(
m_behavior
.
top
()))
{
m_behavior
.
pop
();
m_behavior_ptr
=
m_behavior
.
empty
()
?
nullptr
:
&
(
m_behavior
.
top
());
}
else
{
m_behavior
.
pop
();
}
}
}
void
operator
()(
const
any_tuple
&
msg
)
{
if
(
m_behavior_ptr
!=
nullptr
)
{
s_lm
=
&
msg
;
auto
ptr
=
m_behavior_ptr
;
(
*
ptr
)(
msg
);
// execute m_next_behavior at most once
if
(
ptr
==
m_behavior_ptr
&&
ptr
==
&
m_next_behavior
)
{
m_behavior_ptr
=
m_behavior
.
empty
()
?
nullptr
:
&
m_behavior
.
top
();
}
}
}
};
namespace
{
event_actor
*
s_event_actor_self
=
nullptr
;
}
void
set_next_behavior
(
invoke_rules
&&
behavior
)
{
s_event_actor_self
->
set_next_behavior
(
std
::
move
(
behavior
));
}
void
become
(
invoke_rules
&&
behavior
)
{
s_event_actor_self
->
become
(
std
::
move
(
behavior
));
}
void
unbecome
()
{
s_event_actor_self
->
unbecome
();
}
event_actor
*
event_testee
()
{
return
new
event_actor
{(
on
<
int
>
()
>>
[](
int
i
)
{
// do NOT call receive() here!
// this would hijack the worker thread
set_next_behavior
((
on
<
int
>
()
>>
[
=
](
int
i2
)
{
cout
<<
"event testee: ("
<<
i
<<
", "
<<
i2
<<
")"
<<
endl
;
},
on
<
float
>
()
>>
[
=
](
float
f
)
{
cout
<<
"event testee: ("
<<
i
<<
", "
<<
f
<<
")"
<<
endl
;
become
((
on
<
float
>
()
>>
[]()
{
unbecome
();
},
others
()
>>
[]()
{
cout
<<
"event testee[line "
<<
__LINE__
<<
"]: "
<<
to_string
(
*
s_lm
)
<<
endl
;
}
));
}
));
},
others
()
>>
[]()
{
cout
<<
"event testee[line "
<<
__LINE__
<<
"]: "
<<
to_string
(
*
s_lm
)
<<
endl
;
}
)};
}
void
testee1
()
{
receive_loop
...
...
@@ -69,6 +194,18 @@ size_t test__spawn()
spawn
(
testee1
);
await_all_others_done
();
auto
et
=
event_testee
();
s_event_actor_self
=
et
;
(
*
et
)(
make_tuple
(
42
));
(
*
et
)(
make_tuple
(
24
));
(
*
et
)(
make_tuple
(
42
));
(
*
et
)(
make_tuple
(
.24
f
));
(
*
et
)(
make_tuple
(
"hello event actor"
));
(
*
et
)(
make_tuple
(
42
));
(
*
et
)(
make_tuple
(
.24
f
));
(
*
et
)(
make_tuple
(
"hello event actor"
));
delete
et
;
return
CPPA_TEST_RESULT
;
...
...
@@ -128,7 +265,7 @@ size_t test__spawn()
CPPA_CHECK_EQUAL
(
flags
,
0x07
);
// mailbox has to be empty
any_tuple
msg
;
while
(
try_receiv
e
(
msg
))
while
(
self
()
->
mailbox
().
try_dequeu
e
(
msg
))
{
report_unexpected
();
}
...
...
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