pulse-server: message: use union to store event data

Store subscription event data in a union instead of
just an array for better readability.
This commit is contained in:
Barnabás Pőcze 2024-05-14 16:32:19 +02:00 committed by Wim Taymans
parent d467f6fdc6
commit 46e4a33f27
3 changed files with 21 additions and 9 deletions

View file

@ -310,11 +310,11 @@ static bool client_prune_subscribe_events(struct client *client, uint32_t event,
/* NOTE: reverse iteration */ /* NOTE: reverse iteration */
spa_list_for_each_safe_reverse(m, t, &client->out_messages, link) { spa_list_for_each_safe_reverse(m, t, &client->out_messages, link) {
if (m->extra[0] != COMMAND_SUBSCRIBE_EVENT) if (m->type != MESSAGE_TYPE_SUBSCRIPTION_EVENT)
continue; continue;
if ((m->extra[1] ^ event) & SUBSCRIPTION_EVENT_FACILITY_MASK) if ((m->u.subscription_event.event ^ event) & SUBSCRIPTION_EVENT_FACILITY_MASK)
continue; continue;
if (m->extra[2] != index) if (m->u.subscription_event.index != index)
continue; continue;
if ((event & SUBSCRIPTION_EVENT_TYPE_MASK) == SUBSCRIPTION_EVENT_REMOVE) { if ((event & SUBSCRIPTION_EVENT_TYPE_MASK) == SUBSCRIPTION_EVENT_REMOVE) {
@ -322,7 +322,7 @@ static bool client_prune_subscribe_events(struct client *client, uint32_t event,
* point in keeping the old events regarding * point in keeping the old events regarding
* entry in the queue. */ * entry in the queue. */
bool is_new = (m->extra[1] & SUBSCRIPTION_EVENT_TYPE_MASK) == SUBSCRIPTION_EVENT_NEW; bool is_new = (m->u.subscription_event.event & SUBSCRIPTION_EVENT_TYPE_MASK) == SUBSCRIPTION_EVENT_NEW;
if (drop_from_out_queue(client, m)) { if (drop_from_out_queue(client, m)) {
pw_log_debug("client %p: dropped redundant event due to remove event for object %u", pw_log_debug("client %p: dropped redundant event due to remove event for object %u",
@ -371,9 +371,9 @@ int client_queue_subscribe_event(struct client *client, uint32_t mask, uint32_t
if (!reply) if (!reply)
return -errno; return -errno;
reply->extra[0] = COMMAND_SUBSCRIBE_EVENT; reply->type = MESSAGE_TYPE_SUBSCRIPTION_EVENT;
reply->extra[1] = event; reply->u.subscription_event.event = event;
reply->extra[2] = index; reply->u.subscription_event.index = index;
message_put(reply, message_put(reply,
TAG_U32, COMMAND_SUBSCRIBE_EVENT, TAG_U32, COMMAND_SUBSCRIBE_EVENT,

View file

@ -847,7 +847,7 @@ struct message *message_alloc(struct impl *impl, uint32_t channel, uint32_t size
return NULL; return NULL;
} }
spa_zero(msg->extra); msg->type = MESSAGE_TYPE_UNSPECIFIED;
msg->channel = channel; msg->channel = channel;
msg->offset = 0; msg->offset = 0;
msg->length = size; msg->length = size;

View file

@ -13,15 +13,27 @@
struct impl; struct impl;
enum message_type {
MESSAGE_TYPE_UNSPECIFIED,
MESSAGE_TYPE_SUBSCRIPTION_EVENT,
};
struct message { struct message {
struct spa_list link; struct spa_list link;
struct impl *impl; struct impl *impl;
uint32_t extra[4];
uint32_t channel; uint32_t channel;
uint32_t allocated; uint32_t allocated;
uint32_t length; uint32_t length;
uint32_t offset; uint32_t offset;
uint8_t *data; uint8_t *data;
enum message_type type;
union {
struct {
uint32_t event;
uint32_t index;
} subscription_event;
} u;
}; };
enum { enum {