Add callbacks for new clients and when clients go away
parent
ed5dadd203
commit
20139f617d
|
@ -30,6 +30,7 @@ typedef void (*nvnc_pointer_fn)(struct nvnc_client*, uint16_t x, uint16_t y,
|
||||||
typedef void (*nvnc_fb_req_fn)(struct nvnc_client*, bool is_incremental,
|
typedef void (*nvnc_fb_req_fn)(struct nvnc_client*, bool is_incremental,
|
||||||
uint16_t x, uint16_t y,
|
uint16_t x, uint16_t y,
|
||||||
uint16_t width, uint16_t height);
|
uint16_t width, uint16_t height);
|
||||||
|
typedef void (*nvnc_client_fn)(struct nvnc_client*);
|
||||||
|
|
||||||
struct nvnc *nvnc_open(const char *addr, uint16_t port);
|
struct nvnc *nvnc_open(const char *addr, uint16_t port);
|
||||||
void nvnc_close(struct nvnc *self);
|
void nvnc_close(struct nvnc *self);
|
||||||
|
@ -47,6 +48,8 @@ void nvnc_set_name(struct nvnc *self, const char *name);
|
||||||
void nvnc_set_key_fn(struct nvnc *self, nvnc_key_fn);
|
void nvnc_set_key_fn(struct nvnc *self, nvnc_key_fn);
|
||||||
void nvnc_set_pointer_fn(struct nvnc *self, nvnc_pointer_fn);
|
void nvnc_set_pointer_fn(struct nvnc *self, nvnc_pointer_fn);
|
||||||
void nvnc_set_fb_req_fn(struct nvnc *self, nvnc_fb_req_fn);
|
void nvnc_set_fb_req_fn(struct nvnc *self, nvnc_fb_req_fn);
|
||||||
|
void nvnc_set_new_client_fn(struct nvnc *self, nvnc_client_fn);
|
||||||
|
void nvnc_set_client_cleanup_fn(struct nvnc_client *self, nvnc_client_fn fn);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send an updated framebuffer to all clients with pending update requests.
|
* Send an updated framebuffer to all clients with pending update requests.
|
||||||
|
|
22
src/server.c
22
src/server.c
|
@ -54,6 +54,7 @@ struct nvnc_client {
|
||||||
enum vnc_encodings encodings;
|
enum vnc_encodings encodings;
|
||||||
LIST_ENTRY(nvnc_client) link;
|
LIST_ENTRY(nvnc_client) link;
|
||||||
struct pixman_region16 requested_region;
|
struct pixman_region16 requested_region;
|
||||||
|
nvnc_client_fn cleanup_fn;
|
||||||
size_t buffer_index;
|
size_t buffer_index;
|
||||||
size_t buffer_len;
|
size_t buffer_len;
|
||||||
uint8_t msg_buffer[MSG_BUFFER_SIZE];
|
uint8_t msg_buffer[MSG_BUFFER_SIZE];
|
||||||
|
@ -77,6 +78,7 @@ struct nvnc {
|
||||||
nvnc_key_fn key_fn;
|
nvnc_key_fn key_fn;
|
||||||
nvnc_pointer_fn pointer_fn;
|
nvnc_pointer_fn pointer_fn;
|
||||||
nvnc_fb_req_fn fb_req_fn;
|
nvnc_fb_req_fn fb_req_fn;
|
||||||
|
nvnc_client_fn new_client_fn;
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* fourcc_to_string(uint32_t fourcc)
|
static const char* fourcc_to_string(uint32_t fourcc)
|
||||||
|
@ -107,6 +109,10 @@ static void cleanup_client(uv_handle_t* handle)
|
||||||
container_of((uv_tcp_t*)handle, struct nvnc_client,
|
container_of((uv_tcp_t*)handle, struct nvnc_client,
|
||||||
stream_handle);
|
stream_handle);
|
||||||
|
|
||||||
|
nvnc_client_fn fn = client->cleanup_fn;
|
||||||
|
if (fn)
|
||||||
|
fn(client);
|
||||||
|
|
||||||
LIST_REMOVE(client, link);
|
LIST_REMOVE(client, link);
|
||||||
pixman_region_fini(&client->requested_region);
|
pixman_region_fini(&client->requested_region);
|
||||||
free(client);
|
free(client);
|
||||||
|
@ -409,6 +415,10 @@ static int on_init_message(struct nvnc_client *client)
|
||||||
|
|
||||||
send_server_init_message(client);
|
send_server_init_message(client);
|
||||||
|
|
||||||
|
nvnc_client_fn fn = client->server->new_client_fn;
|
||||||
|
if (fn)
|
||||||
|
fn(client);
|
||||||
|
|
||||||
client->state = VNC_CLIENT_STATE_READY;
|
client->state = VNC_CLIENT_STATE_READY;
|
||||||
return sizeof(shared_flag);
|
return sizeof(shared_flag);
|
||||||
}
|
}
|
||||||
|
@ -808,6 +818,18 @@ void nvnc_set_fb_req_fn(struct nvnc *self, nvnc_fb_req_fn fn)
|
||||||
self->fb_req_fn = fn;
|
self->fb_req_fn = fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
EXPORT
|
||||||
|
void nvnc_set_new_client_fn(struct nvnc *self, nvnc_client_fn fn)
|
||||||
|
{
|
||||||
|
self->new_client_fn = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPORT
|
||||||
|
void nvnc_set_client_cleanup_fn(struct nvnc_client *self, nvnc_client_fn fn)
|
||||||
|
{
|
||||||
|
self->cleanup_fn = fn;
|
||||||
|
}
|
||||||
|
|
||||||
EXPORT
|
EXPORT
|
||||||
void nvnc_set_dimensions(struct nvnc *self, uint16_t width, uint16_t height,
|
void nvnc_set_dimensions(struct nvnc *self, uint16_t width, uint16_t height,
|
||||||
uint32_t fourcc_format)
|
uint32_t fourcc_format)
|
||||||
|
|
Loading…
Reference in New Issue