Add a cleanup callback to nvnc_set_userdata

fb-api-v3
Andri Yngvason 2021-09-04 17:05:30 +00:00
parent 41c9ebe960
commit 1b7b51af44
4 changed files with 17 additions and 2 deletions

View File

@ -57,6 +57,7 @@ struct nvnc_display;
struct nvnc_common { struct nvnc_common {
void* userdata; void* userdata;
nvnc_cleanup_fn cleanup_fn;
}; };
struct cut_text { struct cut_text {

View File

@ -51,6 +51,7 @@ typedef bool (*nvnc_auth_fn)(const char* username, const char* password,
void* userdata); void* userdata);
typedef void (*nvnc_cut_text_fn)(struct nvnc*, const char* text, uint32_t len); typedef void (*nvnc_cut_text_fn)(struct nvnc*, const char* text, uint32_t len);
typedef void (*nvnc_fb_release_fn)(struct nvnc_fb*, void* context); typedef void (*nvnc_fb_release_fn)(struct nvnc_fb*, void* context);
typedef void (*nvnc_cleanup_fn)(void* userdata);
extern const char nvnc_version[]; extern const char nvnc_version[];
@ -61,7 +62,7 @@ void nvnc_close(struct nvnc* self);
void nvnc_add_display(struct nvnc*, struct nvnc_display*); void nvnc_add_display(struct nvnc*, struct nvnc_display*);
void nvnc_remove_display(struct nvnc*, struct nvnc_display*); void nvnc_remove_display(struct nvnc*, struct nvnc_display*);
void nvnc_set_userdata(void* self, void* userdata); void nvnc_set_userdata(void* self, void* userdata, nvnc_cleanup_fn);
void* nvnc_get_userdata(const void* self); void* nvnc_get_userdata(const void* self);
struct nvnc* nvnc_client_get_server(const struct nvnc_client* client); struct nvnc* nvnc_client_get_server(const struct nvnc_client* client);

View File

@ -94,6 +94,10 @@ uint32_t nvnc_fb_get_fourcc_format(const struct nvnc_fb* fb)
static void nvnc__fb_free(struct nvnc_fb* fb) static void nvnc__fb_free(struct nvnc_fb* fb)
{ {
nvnc_cleanup_fn cleanup = fb->common.cleanup_fn;
if (cleanup)
cleanup(fb->common.userdata);
free(fb->addr); free(fb->addr);
free(fb); free(fb);
} }

View File

@ -99,6 +99,10 @@ static void client_close(struct nvnc_client* client)
{ {
log_debug("client_close(%p): ref %d\n", client, client->ref); log_debug("client_close(%p): ref %d\n", client, client->ref);
nvnc_cleanup_fn cleanup = client->common.cleanup_fn;
if (cleanup)
cleanup(client->common.userdata);
nvnc_client_fn fn = client->cleanup_fn; nvnc_client_fn fn = client->cleanup_fn;
if (fn) if (fn)
fn(client); fn(client);
@ -1177,6 +1181,10 @@ void nvnc_close(struct nvnc* self)
{ {
struct nvnc_client* client; struct nvnc_client* client;
nvnc_cleanup_fn cleanup = self->common.cleanup_fn;
if (cleanup)
cleanup(self->common.userdata);
if (self->display) if (self->display)
nvnc_display_unref(self->display); nvnc_display_unref(self->display);
@ -1441,10 +1449,11 @@ void nvnc__damage_region(struct nvnc* self, const struct pixman_region16* damage
} }
EXPORT EXPORT
void nvnc_set_userdata(void* self, void* userdata) void nvnc_set_userdata(void* self, void* userdata, nvnc_cleanup_fn cleanup_fn)
{ {
struct nvnc_common* common = self; struct nvnc_common* common = self;
common->userdata = userdata; common->userdata = userdata;
common->cleanup_fn = cleanup_fn;
} }
EXPORT EXPORT