-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.cpp
65 lines (53 loc) · 1.26 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
//
// main.cpp - This file is part of the Grinder library
//
// Copyright (c) 2015 Matthew Brush <[email protected]>
// All rights reserved.
//
#include <Grinder/Grinder>
#include <iostream>
using namespace std;
using namespace Grinder;
int main()
{
EventLoop loop;
//loop.add_idle([&](EventSource&) {
// cout << ".";
// return true;
//});
loop.add_timeout(1000, [&](EventSource&) {
cout << "timer expired" << endl;
return true;
});
loop.add_file(0, FileEvents::INPUT, [&](EventSource&) {
string text;
cin >> text;
if (text.length() > 0)
cout << "file text:" << text << endl;
return true;
});
auto sig_source = new GenericSignalSource(true);
sig_source->add(SIGINT);
sig_source->add(SIGTERM);
loop.add_event_source(sig_source, [&](EventSource&) {
cout << "Recevied signal '" << sig_source->signo << "', quitting" << endl;
loop.quit();
return true;
});
#if 0
loop.add_event_source(new TimerFD(250), [&](EventSource&) {
cout << "TimerFD expired" << endl;
return true;
});
sigset_t ss;
::sigemptyset(&ss);
::sigaddset(&ss, SIGINT);
::sigaddset(&ss, SIGTERM);
loop.add_event_source(new SignalFD(&ss), [&](EventSource&) {
cout << "Received signal, quitting" << endl;
loop.quit();
return true;
});
#endif
return loop.run();
}