-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
51 lines (40 loc) · 1.09 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
#include "Event.hpp"
#include "EventBus.hpp"
#include "IOContext.hpp"
#include "IOMultiplexer.hpp"
#include "Logger.hpp"
#include "ThreadPool.hpp"
#include "Timer.hpp"
#include "Buffer.hpp"
#include <mutex>
#include <csignal>
struct MyData
{
int foo;
};
std::atomic<bool> stopped{false};
void signalHandler(int signum)
{
stopped = true;
}
int main()
{
logger::LoggerConfigurator::getInstance().setLogLevel(logger::LogLevel::TRACE);
logger::LoggerConfigurator::getInstance().setLogTarget(logger::LogTarget::CONSOLE);
io_context::IOContext context;
signal(SIGINT, signalHandler);
event::Event<MyData> mMydataHandler(context);
mMydataHandler.addSubscriber([](MyData data) {
std::cout << "Got Event" << std::endl;
});
timer::Timer t2(context, 1000, timer::TimerType::PERIODIC, [&mMydataHandler]() {
std::cout << "Lambda Callback" << std::endl;
mMydataHandler.sendEvent(MyData{12});
});
t2.start();
while (!stopped.load()) {
context.run();
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
return 0;
}