forked from tralamazza/event_system
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
46 lines (38 loc) · 1.22 KB
/
main.cpp
File metadata and controls
46 lines (38 loc) · 1.22 KB
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
/*
* Copyright 2020 Alexander Dahmen
*/
#include <iostream>
#include "Observer.hpp"
#include "TestEvent.hpp"
#include <eventsystem/Dispatcher.hpp>
#include <eventsystem/Event.hpp>
using eventsystem::Dispatcher;
using eventsystem::Event;
/*
* Client Testprogram
*/
void hello_function(const Event &event) {
std::cout << "Hello from function" << std::endl;
}
int main(int argc, char *argv[]) {
Dispatcher dispatcher;
Observer observer;
TestEvent test_event;
BufferFullEvent buffer_full_event;
// callback object::method
std::uint8_t id_observer_test = dispatcher.registerCallback(
test_event.name(),
std::bind(&Observer::handleEvent, observer, std::placeholders::_1));
std::uint8_t id_observer_buffer = dispatcher.registerCallback(
buffer_full_event.name(),
std::bind(&Observer::handleEvent, observer, std::placeholders::_1));
// callback stand alone function
std::uint8_t id_hello_function =
dispatcher.registerCallback(test_event.name(), hello_function);
dispatcher.trigger(test_event);
dispatcher.trigger(buffer_full_event);
// unregister one of them
dispatcher.unregisterCallback(id_observer_test);
dispatcher.trigger(test_event);
dispatcher.trigger(buffer_full_event);
}