Inherit maxscale::Filter from MXS_FILTER

All use of reinterpret_cast can be removed. No cast needed when
the C++ instances are returned, and static_cast is sufficient for
downcasting.
This commit is contained in:
Johan Wikman
2017-02-27 10:59:06 +02:00
parent 677e8aaabf
commit 870a72ae71

View File

@ -28,7 +28,7 @@ namespace maxscale
* are virtual. That is by design, as the class will be used in a context where * are virtual. That is by design, as the class will be used in a context where
* the concrete class is known. That is, there is no need for the virtual mechanism. * the concrete class is known. That is, there is no need for the virtual mechanism.
*/ */
class FilterSession class FilterSession : public MXS_FILTER_SESSION
{ {
public: public:
/** /**
@ -200,7 +200,7 @@ protected:
* @endcode * @endcode
*/ */
template<class FilterType, class FilterSessionType> template<class FilterType, class FilterSessionType>
class Filter class Filter : public MXS_FILTER
{ {
public: public:
static MXS_FILTER* createInstance(const char* zName, char** pzOptions, MXS_CONFIG_PARAMETER* ppParams) static MXS_FILTER* createInstance(const char* zName, char** pzOptions, MXS_CONFIG_PARAMETER* ppParams)
@ -209,36 +209,36 @@ public:
MXS_EXCEPTION_GUARD(pFilter = FilterType::create(zName, pzOptions, ppParams)); MXS_EXCEPTION_GUARD(pFilter = FilterType::create(zName, pzOptions, ppParams));
return reinterpret_cast<MXS_FILTER*>(pFilter); return pFilter;
} }
static MXS_FILTER_SESSION* newSession(MXS_FILTER* pInstance, MXS_SESSION* pSession) static MXS_FILTER_SESSION* newSession(MXS_FILTER* pInstance, MXS_SESSION* pSession)
{ {
FilterType* pFilter = reinterpret_cast<FilterType*>(pInstance); FilterType* pFilter = static_cast<FilterType*>(pInstance);
void* pFilterSession; FilterSessionType* pFilterSession;
MXS_EXCEPTION_GUARD(pFilterSession = pFilter->newSession(pSession)); MXS_EXCEPTION_GUARD(pFilterSession = pFilter->newSession(pSession));
return reinterpret_cast<MXS_FILTER_SESSION*>(pFilterSession); return pFilterSession;
} }
static void closeSession(MXS_FILTER*, MXS_FILTER_SESSION* pData) static void closeSession(MXS_FILTER*, MXS_FILTER_SESSION* 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(MXS_FILTER*, MXS_FILTER_SESSION* pData) static void freeSession(MXS_FILTER*, MXS_FILTER_SESSION* 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(MXS_FILTER*, MXS_FILTER_SESSION* pData, MXS_DOWNSTREAM* pDownstream) static void setDownstream(MXS_FILTER*, MXS_FILTER_SESSION* pData, MXS_DOWNSTREAM* pDownstream)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
typename FilterSessionType::Downstream down(*pDownstream); typename FilterSessionType::Downstream down(*pDownstream);
@ -247,7 +247,7 @@ public:
static void setUpstream(MXS_FILTER* pInstance, MXS_FILTER_SESSION* pData, MXS_UPSTREAM* pUpstream) static void setUpstream(MXS_FILTER* pInstance, MXS_FILTER_SESSION* pData, MXS_UPSTREAM* pUpstream)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
typename FilterSessionType::Upstream up(*pUpstream); typename FilterSessionType::Upstream up(*pUpstream);
@ -256,7 +256,7 @@ public:
static int routeQuery(MXS_FILTER* pInstance, MXS_FILTER_SESSION* pData, GWBUF* pPacket) static int routeQuery(MXS_FILTER* pInstance, MXS_FILTER_SESSION* 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));
@ -266,7 +266,7 @@ public:
static int clientReply(MXS_FILTER* pInstance, MXS_FILTER_SESSION* pData, GWBUF* pPacket) static int clientReply(MXS_FILTER* pInstance, MXS_FILTER_SESSION* 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));
@ -278,13 +278,13 @@ public:
{ {
if (pData) if (pData)
{ {
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData); FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
MXS_EXCEPTION_GUARD(pFilterSession->diagnostics(pDcb)); MXS_EXCEPTION_GUARD(pFilterSession->diagnostics(pDcb));
} }
else else
{ {
FilterType* pFilter = reinterpret_cast<FilterType*>(pInstance); FilterType* pFilter = static_cast<FilterType*>(pInstance);
MXS_EXCEPTION_GUARD(pFilter->diagnostics(pDcb)); MXS_EXCEPTION_GUARD(pFilter->diagnostics(pDcb));
} }
@ -294,7 +294,7 @@ public:
{ {
uint64_t rv = 0; uint64_t rv = 0;
FilterType* pFilter = reinterpret_cast<FilterType*>(pInstance); FilterType* pFilter = static_cast<FilterType*>(pInstance);
MXS_EXCEPTION_GUARD(rv = pFilter->getCapabilities()); MXS_EXCEPTION_GUARD(rv = pFilter->getCapabilities());
@ -303,7 +303,7 @@ public:
static void destroyInstance(MXS_FILTER* pInstance) static void destroyInstance(MXS_FILTER* pInstance)
{ {
FilterType* pFilter = reinterpret_cast<FilterType*>(pInstance); FilterType* pFilter = static_cast<FilterType*>(pInstance);
MXS_EXCEPTION_GUARD(delete pFilter); MXS_EXCEPTION_GUARD(delete pFilter);
} }