spa: save the old change_mask and restore when emitting full

When we add a new listener to an object, it will emit the full state
of the object. For this it temporarily sets the change_mask to all
changes. Restore the previous state after this or else we might not
emit the right change_mask for the next listener.

Consider the case where one there are two listeners on an object.
The object emits a change and the first listener wants to enumerate the
changed params. For this is adds a new listener and then triggers the
enumeration. If we set the change_mask to 0 after adding the listener,
the second listener would get a 0 change_mask and fail to update
its state.
This commit is contained in:
Wim Taymans 2021-05-25 15:22:13 +02:00
parent c8c0a152b7
commit 46ef88e520
42 changed files with 151 additions and 77 deletions

View file

@ -219,6 +219,7 @@ static int emit_info(struct impl *this, bool full)
const struct acp_dict_item *it;
struct acp_card *card = this->card;
char path[128];
uint64_t old = full ? this->info.change_mask : 0;
if (full)
this->info.change_mask = this->info_all;
@ -247,7 +248,7 @@ static int emit_info(struct impl *this, bool full)
}
}
spa_device_emit_info(&this->hooks, &this->info);
this->info.change_mask = 0;
this->info.change_mask = old;
}
return err;
}

View file

@ -273,6 +273,8 @@ static int impl_node_send_command(void *object, const struct spa_command *comman
static void emit_node_info(struct state *this, bool full)
{
uint64_t old = full ? this->info.change_mask : 0;
if (full)
this->info.change_mask = this->info_all;
if (this->info.change_mask) {
@ -290,18 +292,20 @@ static void emit_node_info(struct state *this, bool full)
this->info.props = &SPA_DICT_INIT(items, n_items);
spa_node_emit_info(&this->hooks, &this->info);
this->info.change_mask = 0;
this->info.change_mask = old;
}
}
static void emit_port_info(struct state *this, bool full)
{
uint64_t old = full ? this->port_info.change_mask : 0;
if (full)
this->port_info.change_mask = this->port_info_all;
if (this->port_info.change_mask) {
spa_node_emit_port_info(&this->hooks,
SPA_DIRECTION_INPUT, 0, &this->port_info);
this->port_info.change_mask = 0;
this->port_info.change_mask = old;
}
}

View file

@ -274,6 +274,7 @@ static int impl_node_send_command(void *object, const struct spa_command *comman
static void emit_node_info(struct state *this, bool full)
{
uint64_t old = full ? this->info.change_mask : 0;
if (full)
this->info.change_mask = this->info_all;
if (this->info.change_mask) {
@ -291,18 +292,19 @@ static void emit_node_info(struct state *this, bool full)
this->info.props = &SPA_DICT_INIT(items, n_items);
spa_node_emit_info(&this->hooks, &this->info);
this->info.change_mask = 0;
this->info.change_mask = old;
}
}
static void emit_port_info(struct state *this, bool full)
{
uint64_t old = full ? this->port_info.change_mask : 0;
if (full)
this->port_info.change_mask = this->port_info_all;
if (this->port_info.change_mask) {
spa_node_emit_port_info(&this->hooks,
SPA_DIRECTION_OUTPUT, 0, &this->port_info);
this->port_info.change_mask = 0;
this->port_info.change_mask = old;
}
}

View file

@ -214,12 +214,13 @@ static const struct spa_dict_item node_info_items[] = {
static void emit_node_info(struct seq_state *this, bool full)
{
uint64_t old = full ? this->info.change_mask : 0;
if (full)
this->info.change_mask = this->info_all;
if (this->info.change_mask) {
this->info.props = &SPA_DICT_INIT_ARRAY(node_info_items);
spa_node_emit_info(&this->hooks, &this->info);
this->info.change_mask = 0;
this->info.change_mask = old;
}
}
@ -234,6 +235,7 @@ static inline void clean_name(char *name)
static void emit_port_info(struct seq_state *this, struct seq_port *port, bool full)
{
uint64_t old = full ? port->info.change_mask : 0;
if (full)
port->info.change_mask = port->info_all;
if (port->info.change_mask) {
@ -286,7 +288,7 @@ static void emit_port_info(struct seq_state *this, struct seq_port *port, bool f
spa_node_emit_port_info(&this->hooks,
port->direction, port->id, &port->info);
port->info.change_mask = 0;
port->info.change_mask = old;
}
}

View file

@ -641,12 +641,13 @@ static const struct spa_dict_item device_info_items[] = {
static void emit_device_info(struct impl *this, bool full)
{
uint64_t old = full ? this->info.change_mask : 0;
if (full)
this->info.change_mask = this->info_all;
if (this->info.change_mask) {
this->info.props = &SPA_DICT_INIT_ARRAY(device_info_items);
spa_device_emit_info(&this->hooks, &this->info);
this->info.change_mask = 0;
this->info.change_mask = old;
}
}