pipewire/src/modules/module-protocol-native/protocol-footer.h

40 lines
1 KiB
C
Raw Normal View History

/* PipeWire */
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
/*
* Protocol footer.
*
* For passing around general state data that is not associated with
* messages sent to objects.
*/
enum {
FOOTER_CORE_OPCODE_GENERATION = 0,
FOOTER_CORE_OPCODE_LAST
};
enum {
FOOTER_CLIENT_OPCODE_GENERATION = 0,
FOOTER_CLIENT_OPCODE_LAST
};
struct footer_core_global_state {
impl-core/protocol-native: use generation counter for global registry Some client messages have bare ids (as opposed to proxies/resources), eg. as in pw_registry_bind/destroy. If the client is processing messages late, these may refer to an object that was already removed, and the id may now refers to a differnt objects. I.e. the following race condition needs to be resolved: server client Global 1 (gen. 1) Global 1 Global 1 remove Global 1 (gen. 2) Bind/destroy 1 Where the client would bind/destroy the wrong global, since it did not yet see the messages for the second one. To keep track of which object the client means, the server keeps track of the "generation number" of its global registry, and what generation the client is at. Each global remembers at what generation of registry they were registered. When processing the messages that use bare ids, check the registry generation of the client, to know whether the message refers to a stale global that was already removed. Messages where client sends bare ids to server are: pw_registry_bind, pw_registry_destroy, metadata_set_property In pw_registry_* do the staleness check directly. Also add staleness check in pw_impl_client_check_permissions, so that also the metadata case is handled. The generation numbers are passed around in message footers, but only if they have changed. When the generation number changes on server, we send the updated value to the client in a message footer. When client has received an update value, it will send the value back in the footer of the next message it sends to the server. Based on: Wim Taymans <wtaymans@redhat.com> "impl-core: check serial number"
2021-11-08 12:26:37 +01:00
uint64_t last_recv_generation;
};
struct footer_client_global_state {
};
struct footer_demarshal {
int (*demarshal)(void *object, struct spa_pod_parser *parser);
};
extern const struct footer_demarshal footer_core_demarshal[FOOTER_CORE_OPCODE_LAST];
extern const struct footer_demarshal footer_client_demarshal[FOOTER_CLIENT_OPCODE_LAST];
void marshal_core_footers(struct footer_core_global_state *state, struct pw_core *core,
struct spa_pod_builder *builder);
void marshal_client_footers(struct footer_client_global_state *state, struct pw_impl_client *client,
struct spa_pod_builder *builder);