neatvnc/examples/png-server.c

67 lines
1.6 KiB
C
Raw Normal View History

2019-09-07 16:51:07 +00:00
/*
* Copyright (c) 2019 Andri Yngvason
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
* REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
* AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
* LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
* OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#include <neatvnc.h>
2019-08-29 22:07:04 +00:00
#include <stdio.h>
2020-03-16 20:09:22 +00:00
#include <aml.h>
#include <signal.h>
2019-08-29 22:07:04 +00:00
#include <assert.h>
#include <pixman.h>
2019-10-20 22:13:51 +00:00
struct nvnc_fb* read_png_file(const char* filename);
2019-08-29 22:07:04 +00:00
void on_sigint()
{
aml_exit(aml_get_default());
}
2019-10-20 22:13:51 +00:00
int main(int argc, char* argv[])
2019-08-29 22:07:04 +00:00
{
2019-10-20 22:13:51 +00:00
const char* file = argv[1];
2019-08-29 22:07:04 +00:00
if (!file) {
printf("Missing argument\n");
return 1;
}
2019-10-07 17:39:54 +00:00
struct nvnc_fb* fb = read_png_file(file);
if (!fb) {
2019-08-29 22:07:04 +00:00
printf("Failed to read png file\n");
return 1;
}
2020-03-16 20:09:22 +00:00
struct aml* aml = aml_new(NULL, 0);
aml_set_default(aml);
2019-10-20 22:13:51 +00:00
struct nvnc* server = nvnc_open("127.0.0.1", 5900);
2019-08-29 22:07:04 +00:00
nvnc_set_buffer(server, fb);
2019-08-29 22:07:04 +00:00
nvnc_set_name(server, file);
nvnc_damage_whole(server);
2019-08-29 22:07:04 +00:00
struct aml_signal* sig = aml_signal_new(SIGINT, on_sigint, NULL, NULL);
aml_start(aml_get_default(), sig);
aml_unref(sig);
2020-03-16 20:09:22 +00:00
aml_run(aml);
2019-08-29 22:07:04 +00:00
nvnc_close(server);
2019-10-07 17:39:54 +00:00
nvnc_fb_unref(fb);
aml_unref(aml);
2019-08-29 22:07:04 +00:00
}