examples: Add signal handler and clean up resources

pull/24/head
Andri Yngvason 2020-03-16 20:43:11 +00:00
parent 76e721c4cd
commit be085c9a79
2 changed files with 23 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include <stdlib.h>
#include <string.h>
#include <aml.h>
#include <signal.h>
#include <assert.h>
#include <pixman.h>
#include <libdrm/drm_fourcc.h>
@ -53,6 +54,11 @@ void on_pointer_event(struct nvnc_client* client, uint16_t x, uint16_t y,
pixman_region_fini(&region);
}
void on_sigint()
{
aml_exit(aml_get_default());
}
int main(int argc, char* argv[])
{
struct draw draw;
@ -76,7 +82,13 @@ int main(int argc, char* argv[])
nvnc_set_pointer_fn(server, on_pointer_event);
nvnc_set_userdata(server, &draw);
struct aml_signal* sig = aml_signal_new(SIGINT, on_sigint, NULL, NULL);
aml_start(aml_get_default(), sig);
aml_unref(sig);
aml_run(aml);
nvnc_close(server);
nvnc_fb_unref(draw.fb);
aml_unref(aml);
}

View File

@ -18,11 +18,17 @@
#include <stdio.h>
#include <aml.h>
#include <signal.h>
#include <assert.h>
#include <pixman.h>
struct nvnc_fb* read_png_file(const char* filename);
void on_sigint()
{
aml_exit(aml_get_default());
}
int main(int argc, char* argv[])
{
const char* file = argv[1];
@ -56,8 +62,13 @@ int main(int argc, char* argv[])
nvnc_feed_frame(server, fb, &region);
pixman_region_fini(&region);
struct aml_signal* sig = aml_signal_new(SIGINT, on_sigint, NULL, NULL);
aml_start(aml_get_default(), sig);
aml_unref(sig);
aml_run(aml);
nvnc_close(server);
nvnc_fb_unref(fb);
aml_unref(aml);
}