Fix diagnostics on filter template

Diagnostics can be required on both instance and session level,
so both cases need to be handled explicitly.

In addition, some reinterpret_casts were changed into static_casts.
Reinterpret_cast needs to be used with the instance, which is a
void** but static_cast is sufficient for the session, which is void*.
This commit is contained in:
Johan Wikman
2016-12-13 12:26:00 +02:00
parent aa2de52054
commit 4239182aa0
3 changed files with 28 additions and 10 deletions

View File

@ -182,12 +182,13 @@ protected:
* *
* MyFilterSession* newSession(SESSION* pSession); * MyFilterSession* newSession(SESSION* pSession);
* *
* void diagnostics(DCB* pDcb);
* static uint64_t getCapabilities(); * static uint64_t getCapabilities();
* }; * };
* @endcode * @endcode
* *
* The concrete filter class must implement the methods @c create, @c newSession and * The concrete filter class must implement the methods @c create, @c newSession,
* @c getCapabilities, with the prototypes as shown above. * @c diagnostics and @c getCapabilities, with the prototypes as shown above.
* *
* The plugin function @c GetModuleObject is then implemented as follows: * The plugin function @c GetModuleObject is then implemented as follows:
* *
@ -223,21 +224,21 @@ public:
static void closeSession(FILTER*, void* pData) static void closeSession(FILTER*, void* pData)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
MXS_EXCEPTION_GUARD(pFilterSession->close()); MXS_EXCEPTION_GUARD(pFilterSession->close());
} }
static void freeSession(FILTER*, void* pData) static void freeSession(FILTER*, void* pData)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
MXS_EXCEPTION_GUARD(delete pFilterSession); MXS_EXCEPTION_GUARD(delete pFilterSession);
} }
static void setDownstream(FILTER*, void* pData, DOWNSTREAM* pDownstream) static void setDownstream(FILTER*, void* pData, DOWNSTREAM* pDownstream)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
typename FilterSessionType::Downstream down(*pDownstream); typename FilterSessionType::Downstream down(*pDownstream);
@ -246,7 +247,7 @@ public:
static void setUpstream(FILTER* pInstance, void* pData, UPSTREAM* pUpstream) static void setUpstream(FILTER* pInstance, void* pData, UPSTREAM* pUpstream)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
typename FilterSessionType::Upstream up(*pUpstream); typename FilterSessionType::Upstream up(*pUpstream);
@ -255,7 +256,7 @@ public:
static int routeQuery(FILTER* pInstance, void* pData, GWBUF* pPacket) static int routeQuery(FILTER* pInstance, void* pData, GWBUF* pPacket)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
int rv = 0; int rv = 0;
MXS_EXCEPTION_GUARD(rv = pFilterSession->routeQuery(pPacket)); MXS_EXCEPTION_GUARD(rv = pFilterSession->routeQuery(pPacket));
@ -265,7 +266,7 @@ public:
static int clientReply(FILTER* pInstance, void* pData, GWBUF* pPacket) static int clientReply(FILTER* pInstance, void* pData, GWBUF* pPacket)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
int rv = 0; int rv = 0;
MXS_EXCEPTION_GUARD(rv = pFilterSession->clientReply(pPacket)); MXS_EXCEPTION_GUARD(rv = pFilterSession->clientReply(pPacket));
@ -275,9 +276,18 @@ public:
static void diagnostics(FILTER* pInstance, void* pData, DCB* pDcb) static void diagnostics(FILTER* pInstance, void* pData, DCB* pDcb)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); if (pData)
{
FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
MXS_EXCEPTION_GUARD(pFilterSession->diagnostics(pDcb)); MXS_EXCEPTION_GUARD(pFilterSession->diagnostics(pDcb));
}
else
{
FilterType* pFilter = reinterpret_cast<FilterType*>(pInstance);
MXS_EXCEPTION_GUARD(pFilter->diagnostics(pDcb));
}
} }
static uint64_t getCapabilities(void) static uint64_t getCapabilities(void)

View File

@ -223,6 +223,12 @@ CacheFilterSession* CacheFilter::newSession(SESSION* pSession)
return CacheFilterSession::Create(m_sCache.get(), pSession); return CacheFilterSession::Create(m_sCache.get(), pSession);
} }
// static
void CacheFilter::diagnostics(DCB* pDcb)
{
m_sCache->show(pDcb);
}
// static // static
uint64_t CacheFilter::getCapabilities() uint64_t CacheFilter::getCapabilities()
{ {

View File

@ -29,6 +29,8 @@ public:
CacheFilterSession* newSession(SESSION* pSession); CacheFilterSession* newSession(SESSION* pSession);
void diagnostics(DCB* pDcb);
static uint64_t getCapabilities(); static uint64_t getCapabilities();
private: private: