[pulseaudio-discuss] [PATCH] client, protocol-native: Use macros for protocol version/flag access
arun at accosted.net
arun at accosted.net
Wed Apr 27 13:09:58 UTC 2016
From: Arun Raghavan <git at arunraghavan.net>
This makes it easier to read and cleaner in general.
---
src/pulse/context.c | 14 +++++++-------
src/pulse/internal.h | 6 ++++++
src/pulsecore/protocol-native.c | 10 +++++-----
3 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/src/pulse/context.c b/src/pulse/context.c
index 69be5f4..c39cbe7 100644
--- a/src/pulse/context.c
+++ b/src/pulse/context.c
@@ -504,17 +504,17 @@ static void setup_complete_callback(pa_pdispatch *pd, uint32_t command, uint32_t
/* Starting with protocol version 13 the MSB of the version
tag reflects if shm is available for this connection or
not. */
- if (c->version >= 13) {
- shm_on_remote = !!(c->version & 0x80000000U);
+ if ((c->version & PA_PROTOCOL_VERSION_MASK) >= 13) {
+ shm_on_remote = !!(c->version & PA_PROTOCOL_FLAG_SHM);
/* Starting with protocol version 31, the second MSB of the version
* tag reflects whether memfd is supported on the other PA end. */
- if (c->version >= 31)
- memfd_on_remote = !!(c->version & 0x40000000U);
+ if ((c->version & PA_PROTOCOL_VERSION_MASK) >= 31)
+ memfd_on_remote = !!(c->version & PA_PROTOCOL_FLAG_MEMFD);
/* Reserve the two most-significant _bytes_ of the version tag
* for flags. */
- c->version &= 0x0000FFFFU;
+ c->version &= PA_PROTOCOL_VERSION_MASK;
}
pa_log_debug("Protocol version: remote %u, local %u", c->version, PA_PROTOCOL_VERSION);
@@ -629,8 +629,8 @@ static void setup_context(pa_context *c, pa_iochannel *io) {
/* Starting with protocol version 13 we use the MSB of the version
* tag for informing the other side if we could do SHM or not.
* Starting from version 31, second MSB is used to flag memfd support. */
- pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION | (c->do_shm ? 0x80000000U : 0) |
- (c->memfd_on_local ? 0x40000000 : 0));
+ pa_tagstruct_putu32(t, PA_PROTOCOL_VERSION | (c->do_shm ? PA_PROTOCOL_FLAG_SHM : 0) |
+ (c->memfd_on_local ? PA_PROTOCOL_FLAG_MEMFD: 0));
pa_tagstruct_put_arbitrary(t, cookie, sizeof(cookie));
#ifdef HAVE_CREDS
diff --git a/src/pulse/internal.h b/src/pulse/internal.h
index 9bbb903..01d2b6e 100644
--- a/src/pulse/internal.h
+++ b/src/pulse/internal.h
@@ -49,6 +49,12 @@
#define DEFAULT_TIMEOUT (30)
+#define PA_PROTOCOL_FLAG_MASK 0xFFFF0000U
+#define PA_PROTOCOL_VERSION_MASK 0x0000FFFFU
+
+#define PA_PROTOCOL_FLAG_SHM 0x80000000U
+#define PA_PROTOCOL_FLAG_MEMFD 0x40000000U
+
struct pa_context {
PA_REFCNT_DECLARE;
diff --git a/src/pulsecore/protocol-native.c b/src/pulsecore/protocol-native.c
index 5619b9c..594617e 100644
--- a/src/pulsecore/protocol-native.c
+++ b/src/pulsecore/protocol-native.c
@@ -2718,17 +2718,17 @@ static void command_auth(pa_pdispatch *pd, uint32_t command, uint32_t tag, pa_ta
/* Starting with protocol version 13 the MSB of the version tag
reflects if shm is available for this pa_native_connection or
not. */
- if (c->version >= 13) {
- shm_on_remote = !!(c->version & 0x80000000U);
+ if ((c->version & PA_PROTOCOL_VERSION_MASK) >= 13) {
+ shm_on_remote = !!(c->version & PA_PROTOCOL_FLAG_SHM);
/* Starting with protocol version 31, the second MSB of the version
* tag reflects whether memfd is supported on the other PA end. */
- if (c->version >= 31)
- memfd_on_remote = !!(c->version & 0x40000000U);
+ if ((c->version & PA_PROTOCOL_VERSION_MASK) >= 31)
+ memfd_on_remote = !!(c->version & PA_PROTOCOL_FLAG_MEMFD);
/* Reserve the two most-significant _bytes_ of the version tag
* for flags. */
- c->version &= 0x0000FFFFU;
+ c->version &= PA_PROTOCOL_VERSION_MASK;
}
pa_log_debug("Protocol version: remote %u, local %u", c->version, PA_PROTOCOL_VERSION);
--
2.5.5
More information about the pulseaudio-discuss
mailing list