From 7ac5390042e0bc2c060bb29bceef0b0d8344f4b7 Mon Sep 17 00:00:00 2001 From: Arun Raghavan Date: Mon, 25 Apr 2016 18:12:39 +0530 Subject: client, protocol-native: Use macros for protocol version/flag access 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 69be5f497..c39cbe75a 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 9bbb903bc..01d2b6e4e 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 5619b9c20..594617ea5 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); -- cgit v1.2.3