pulse-server: calculate event mask from facility and type

Make `client_queue_subscribe_event()` take the facility and type
separately, and calculate the mask itself, so that the caller
does not need to be concerned with that.
This commit is contained in:
Barnabás Pőcze 2024-06-28 01:39:25 +02:00
parent e3a7035e8f
commit 27b76ae686
6 changed files with 115 additions and 65 deletions

View file

@ -301,23 +301,23 @@ static bool drop_from_out_queue(struct client *client, struct message *m)
}
/* returns true if an event with the (mask, event, index) triplet should be dropped because it is redundant */
static bool client_prune_subscribe_events(struct client *client, uint32_t event, uint32_t index)
static bool client_prune_subscribe_events(struct client *client, uint32_t facility, uint32_t type, uint32_t index)
{
struct message *m, *t;
if ((event & SUBSCRIPTION_EVENT_TYPE_MASK) == SUBSCRIPTION_EVENT_NEW)
if (type == SUBSCRIPTION_EVENT_NEW)
return false;
/* NOTE: reverse iteration */
spa_list_for_each_safe_reverse(m, t, &client->out_messages, link) {
if (m->type != MESSAGE_TYPE_SUBSCRIPTION_EVENT)
continue;
if ((m->u.subscription_event.event ^ event) & SUBSCRIPTION_EVENT_FACILITY_MASK)
if ((m->u.subscription_event.event & SUBSCRIPTION_EVENT_FACILITY_MASK) != facility)
continue;
if (m->u.subscription_event.index != index)
continue;
if ((event & SUBSCRIPTION_EVENT_TYPE_MASK) == SUBSCRIPTION_EVENT_REMOVE) {
if (type == SUBSCRIPTION_EVENT_REMOVE) {
/* This object is being removed, hence there is
* point in keeping the old events regarding
* entry in the queue. */
@ -338,8 +338,7 @@ static bool client_prune_subscribe_events(struct client *client, uint32_t event,
if (is_new)
break;
}
if ((event & SUBSCRIPTION_EVENT_TYPE_MASK) == SUBSCRIPTION_EVENT_CHANGE) {
else if (type == SUBSCRIPTION_EVENT_CHANGE) {
/* This object has changed. If a "new" or "change" event for
* this object is still in the queue we can exit. */
goto drop;
@ -349,28 +348,46 @@ static bool client_prune_subscribe_events(struct client *client, uint32_t event,
return false;
drop:
pw_log_debug("client %p: dropped redundant event for object %u", client, index);
pw_log_debug("client %p: dropped redundant event '%s' on %s #%u",
client,
subscription_event_type_to_string(type), subscription_event_facility_to_string(facility),
index);
return true;
}
int client_queue_subscribe_event(struct client *client, uint32_t mask, uint32_t event, uint32_t index)
int client_queue_subscribe_event(struct client *client, uint32_t facility, uint32_t type, uint32_t index)
{
spa_assert(
type == SUBSCRIPTION_EVENT_NEW ||
type == SUBSCRIPTION_EVENT_CHANGE ||
type == SUBSCRIPTION_EVENT_REMOVE
);
const uint32_t mask = 1u << facility;
spa_assert(SUBSCRIPTION_MASK_ALL & mask);
if (client->disconnect)
return -ENOTCONN;
if (!(client->subscribed & mask))
return 0;
pw_log_debug("client %p: SUBSCRIBE event:%08x index:%u", client, event, index);
pw_log_debug("client %p: SUBSCRIBE facility:%s (%u) type:%s (0x%02x) index:%u",
client,
subscription_event_facility_to_string(facility), facility,
subscription_event_type_to_string(type), type,
index);
if (client_prune_subscribe_events(client, event, index))
if (client_prune_subscribe_events(client, facility, type, index))
return 0;
struct message *reply = message_alloc(client->impl, -1, 0);
if (!reply)
return -errno;
const uint32_t event = facility | type;
reply->type = MESSAGE_TYPE_SUBSCRIPTION_EVENT;
reply->u.subscription_event.event = event;
reply->u.subscription_event.index = index;