Use signals to allow us to exit the application and do proper cleanup
This commit is contained in:
parent
89b4253d54
commit
4b181e30e3
1 changed files with 25 additions and 7 deletions
|
@ -1,7 +1,10 @@
|
|||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <telldus-core.h>
|
||||
|
||||
bool running;
|
||||
|
||||
class Events {
|
||||
public:
|
||||
Events();
|
||||
|
@ -43,15 +46,30 @@ void Events::deviceEventCallback(int deviceId, int method, const char *data, int
|
|||
}
|
||||
}
|
||||
|
||||
void signalHandler(int sig) {
|
||||
if (sig == SIGINT) {
|
||||
printf("Shutting down\n");
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
|
||||
void run() {
|
||||
Events ev;
|
||||
|
||||
running = true;
|
||||
|
||||
printf("Listening for events, press control-c to quit...\n");
|
||||
//Our own simple eventloop
|
||||
while(running) {
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
tdInit();
|
||||
|
||||
Events ev;
|
||||
|
||||
//Our own simple eventloop
|
||||
while(1) {
|
||||
sleep(100);
|
||||
}
|
||||
signal(SIGINT, signalHandler);
|
||||
run();
|
||||
|
||||
tdClose();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue