-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (57 loc) · 1.63 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include "actor/actor.hpp"
#include "engine/executor.hpp"
#include "engine/coordinator.hpp"
struct FooEvent { std::uint32_t counter{0}; };
struct BarEvent { std::uint32_t counter{0}; std::uint64_t data{0}; };
struct MyActor : public Actor<EventHandler<FooEvent>>
{
MyActor() = default;
MyActor(MyActor&&) = default;
MyActor(const MyActor&) = delete;
MyActor& operator=(const MyActor&) = delete;
template <typename TPublisher>
void onStart(TPublisher& bus)
{
bus.publish(BarEvent{0, 55});
}
template <typename TPublisher>
void onEvent(FooEvent e, TPublisher& bus)
{
std::cout << "foo " << (int)e.counter << std::endl;
bus.publish(BarEvent{e.counter+1, 55});
}
};
struct MyOtherActor : public Actor<EventHandler<BarEvent>>
{
template <typename TPublisher>
void onEvent(BarEvent e, TPublisher& bus)
{
std::cout << "bar " << (int)e.counter << " " << e.data << std::endl;
bus.publish(FooEvent{e.counter+1});
}
};
struct MyCombinedActor : public Actor<EventHandler<FooEvent, BarEvent>>
{
void onEvent(FooEvent e)
{
std::cout << "cfoo " << (int)e.counter << std::endl;
}
void onEvent(BarEvent e)
{
std::cout << "cbar " << (int)e.counter << " " << e.data << std::endl;
}
};
int main()
{
std::cout << "Hello, World!" << std::endl;
auto coordinator = Coordinator {
Executor{MyActor{}},
Executor{MyOtherActor{}, MyCombinedActor{}},
Executor{MyCombinedActor{}}
};
coordinator.mainloop();
std::cout << "Kthxbye!" << std::endl;
return 0;
}