Add a cleanup callback to nvnc_set_userdata
parent
41c9ebe960
commit
1b7b51af44
|
@ -57,6 +57,7 @@ struct nvnc_display;
|
|||
|
||||
struct nvnc_common {
|
||||
void* userdata;
|
||||
nvnc_cleanup_fn cleanup_fn;
|
||||
};
|
||||
|
||||
struct cut_text {
|
||||
|
|
|
@ -51,6 +51,7 @@ typedef bool (*nvnc_auth_fn)(const char* username, const char* password,
|
|||
void* userdata);
|
||||
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_cleanup_fn)(void* userdata);
|
||||
|
||||
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_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);
|
||||
|
||||
struct nvnc* nvnc_client_get_server(const struct nvnc_client* client);
|
||||
|
|
4
src/fb.c
4
src/fb.c
|
@ -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)
|
||||
{
|
||||
nvnc_cleanup_fn cleanup = fb->common.cleanup_fn;
|
||||
if (cleanup)
|
||||
cleanup(fb->common.userdata);
|
||||
|
||||
free(fb->addr);
|
||||
free(fb);
|
||||
}
|
||||
|
|
11
src/server.c
11
src/server.c
|
@ -99,6 +99,10 @@ static void client_close(struct nvnc_client* client)
|
|||
{
|
||||
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;
|
||||
if (fn)
|
||||
fn(client);
|
||||
|
@ -1177,6 +1181,10 @@ void nvnc_close(struct nvnc* self)
|
|||
{
|
||||
struct nvnc_client* client;
|
||||
|
||||
nvnc_cleanup_fn cleanup = self->common.cleanup_fn;
|
||||
if (cleanup)
|
||||
cleanup(self->common.userdata);
|
||||
|
||||
if (self->display)
|
||||
nvnc_display_unref(self->display);
|
||||
|
||||
|
@ -1441,10 +1449,11 @@ void nvnc__damage_region(struct nvnc* self, const struct pixman_region16* damage
|
|||
}
|
||||
|
||||
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;
|
||||
common->userdata = userdata;
|
||||
common->cleanup_fn = cleanup_fn;
|
||||
}
|
||||
|
||||
EXPORT
|
||||
|
|
Loading…
Reference in New Issue