Replace STRTARGET macro

The macro was extremely unwieldly to update and made the addition of debug
assertions harder. Rewriting it as an inline function makes this possible.
This commit is contained in:
Markus Mäkelä 2019-01-24 16:22:54 +02:00
parent 9f1619f4da
commit 2c95119a3b
No known key found for this signature in database
GPG Key ID: 72D48FCE664F7B19
2 changed files with 33 additions and 21 deletions

View File

@ -344,8 +344,7 @@ bool RWSplitSession::route_single_stmt(GWBUF* querybuf)
else
{
MXS_ERROR("Could not find valid server for target type %s, closing "
"connection.",
STRTARGET(route_target));
"connection.", route_target_to_string(route_target));
}
}

View File

@ -322,22 +322,35 @@ private:
*/
uint32_t get_internal_ps_id(RWSplitSession* rses, GWBUF* buffer);
#define STRTARGET(t) \
(t == TARGET_ALL ? "TARGET_ALL" \
: (t == TARGET_MASTER ? "TARGET_MASTER" \
: (t == TARGET_SLAVE ? "TARGET_SLAVE" \
: (t \
== TARGET_NAMED_SERVER \
? "TARGET_NAMED_SERVER" \
: (t \
== \
TARGET_RLAG_MAX \
? "TARGET_RLAG_MAX" \
: ( \
t \
== \
TARGET_UNDEFINED \
? \
"TARGET_UNDEFINED" \
: \
"Unknown target value"))))))
static inline const char* route_target_to_string(route_target_t target)
{
if (TARGET_IS_MASTER(target))
{
return "TARGET_MASTER";
}
else if (TARGET_IS_SLAVE(target))
{
return "TARGET_SLAVE";
}
else if (TARGET_IS_NAMED_SERVER(target))
{
return "TARGET_NAMED_SERVER";
}
else if (TARGET_IS_ALL(target))
{
return "TARGET_ALL";
}
else if (TARGET_IS_RLAG_MAX(target))
{
return "TARGET_RLAG_MAX";
}
else if (TARGET_IS_LAST_USED(target))
{
return "TARGET_LAST_USED";
}
else
{
mxb_assert(!true);
return "Unknown target value";
}
}