From 7ddcc91461a707a8f79d6de6cc49d43f5d138f05 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 17 Feb 2022 16:56:21 +0100 Subject: [PATCH] pulse-server: add operation with custom callback Add an operation with a custom callback when the roundtrip completed. --- src/modules/module-protocol-pulse/operation.c | 16 ++++++++++++++-- src/modules/module-protocol-pulse/operation.h | 5 +++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/modules/module-protocol-pulse/operation.c b/src/modules/module-protocol-pulse/operation.c index 3c9f29c49..e0e67b374 100644 --- a/src/modules/module-protocol-pulse/operation.c +++ b/src/modules/module-protocol-pulse/operation.c @@ -33,7 +33,9 @@ #include "operation.h" #include "reply.h" -int operation_new(struct client *client, uint32_t tag) +int operation_new_cb(struct client *client, uint32_t tag, + void (*callback)(void *data, struct client *client, uint32_t tag), + void *data) { struct operation *o; @@ -42,6 +44,8 @@ int operation_new(struct client *client, uint32_t tag) o->client = client; o->tag = tag; + o->callback = callback; + o->data = data; spa_list_append(&client->operations, &o->link); pw_manager_sync(client->manager); @@ -51,6 +55,11 @@ int operation_new(struct client *client, uint32_t tag) return 0; } +int operation_new(struct client *client, uint32_t tag) +{ + return operation_new_cb(client, tag, NULL, NULL); +} + void operation_free(struct operation *o) { spa_list_remove(&o->link); @@ -63,6 +72,9 @@ void operation_complete(struct operation *o) pw_log_info("[%s]: tag:%u complete", client->name, o->tag); - reply_simple_ack(client, o->tag); + if (o->callback) + o->callback(o->data, client, o->tag); + else + reply_simple_ack(client, o->tag); operation_free(o); } diff --git a/src/modules/module-protocol-pulse/operation.h b/src/modules/module-protocol-pulse/operation.h index c509487ef..d282ee5e5 100644 --- a/src/modules/module-protocol-pulse/operation.h +++ b/src/modules/module-protocol-pulse/operation.h @@ -35,9 +35,14 @@ struct operation { struct spa_list link; struct client *client; uint32_t tag; + void (*callback) (void *data, struct client *client, uint32_t tag); + void *data; }; int operation_new(struct client *client, uint32_t tag); +int operation_new_cb(struct client *client, uint32_t tag, + void (*callback) (void *data, struct client *client, uint32_t tag), + void *data); void operation_free(struct operation *o); void operation_complete(struct operation *o);