Commit 02b6648f authored by Dominik Charousset's avatar Dominik Charousset

Reorganize examples, add high prio example

parent c57e7e92
...@@ -11,7 +11,7 @@ else () ...@@ -11,7 +11,7 @@ else ()
set(WSLIB) set(WSLIB)
endif() endif()
macro(add name folder) macro(add folder name)
add_executable(${name} ${folder}/${name}.cpp ${ARGN}) add_executable(${name} ${folder}/${name}.cpp ${ARGN})
target_link_libraries(${name} target_link_libraries(${name}
${LD_FLAGS} ${LD_FLAGS}
...@@ -22,32 +22,46 @@ macro(add name folder) ...@@ -22,32 +22,46 @@ macro(add name folder)
add_dependencies(${name} all_examples) add_dependencies(${name} all_examples)
endmacro() endmacro()
add(custom_types_1 custom_types) # introductionary applications
add(custom_types_2 custom_types) add(. aout)
add(custom_types_3 custom_types) add(. hello_world)
add(dancing_kirby message_passing)
add(request message_passing) # basic message passing primitives
add(delegating message_passing) add(message_passing cell)
add(fixed_stack message_passing) add(message_passing divider)
add(cell message_passing) add(message_passing request)
add(divider message_passing) add(message_passing calculator)
add(hello_world .) add(message_passing delegating)
add(aout .) add(message_passing fixed_stack)
add(calculator message_passing) add(message_passing prioritizing)
add(distributed_calculator remote_actors) add(message_passing dancing_kirby)
add(group_server remote_actors)
add(group_chat remote_actors) # dynamic behavior changes using 'become'
add(simple_broker brokers) add(dynamic_behavior skip_messages)
add(simple_http_broker brokers) add(dynamic_behavior dining_philosophers)
add(dining_philosophers dynamic_behavior)
add(skip_messages dynamic_behavior) # composing actors using states or other actors
add(calculator_behavior composition) add(composition calculator_behavior)
add(dictionary_behavior composition) add(composition dictionary_behavior)
# adding custom message types
add(custom_type custom_types_1)
add(custom_type custom_types_2)
add(custom_type custom_types_3)
# basic remoting
add(remoting group_chat)
add(remoting group_server)
add(remoting distributed_calculator)
# basic I/O with brokers
add(broker simple_broker)
add(broker simple_http_broker)
if(NOT CAF_NO_PROTOBUF_EXAMPLES) if(NOT CAF_NO_PROTOBUF_EXAMPLES)
find_package(Protobuf) find_package(Protobuf)
if(PROTOBUF_FOUND AND PROTOBUF_PROTOC_EXECUTABLE) if(PROTOBUF_FOUND AND PROTOBUF_PROTOC_EXECUTABLE)
PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders "${CMAKE_CURRENT_SOURCE_DIR}/remote_actors/pingpong.proto") PROTOBUF_GENERATE_CPP(ProtoSources ProtoHeaders "${CMAKE_CURRENT_SOURCE_DIR}/remoting/pingpong.proto")
include_directories(${PROTOBUF_INCLUDE_DIR}) include_directories(${PROTOBUF_INCLUDE_DIR})
# add binary dir as include path as generated headers will be located there # add binary dir as include path as generated headers will be located there
include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR})
......
#include "caf/all.hpp"
using std::endl;
using namespace caf;
behavior foo(event_based_actor* self) {
self->send(self, "world");
self->send<message_priority::high>(self, "hello");
// when spawning `foo` with priority_aware flag, it will print "hello" first
return {
[=](const std::string& str) {
aout(self) << str << endl;
}
};
}
int main() {
actor_system system;
scoped_actor self{system};
aout(self) << "spawn foo" << endl;
self->spawn(foo);
self->await_all_other_actors_done();
aout(self) << "spawn foo again with priority_aware flag" << endl;
self->spawn<priority_aware>(foo);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment