Introduce opaque type for filter session data

This commit is contained in:
Johan Wikman
2017-01-13 10:52:55 +02:00
parent d0cc246b79
commit ce182e3788
14 changed files with 220 additions and 209 deletions

View File

@ -33,11 +33,24 @@
MXS_BEGIN_DECLS
/**
* The FILTER handle points to module specific data, so the best we can do
* is to make it a void * externally.
* MXS_FILTER is an opaque type representing a particular filter instance.
*
* MaxScale itself does not do anything with it, except for receiving it
* from the @c createInstance function of a filter module and subsequently
* passing it back to the API functions of the filter.
*/
typedef void *MXS_FILTER;
/**
* MXS_FILTER_SESSION is an opaque type representing the session related
* data of a particular filter instance.
*
* MaxScale itself does not do anything with it, except for receiving it
* from the @c newSession function of a filter module and subsequently
* passing it back to the API functions of the filter.
*/
typedef void *MXS_FILTER_SESSION;
/**
* @verbatim
* The "module object" structure for a query router module
@ -63,17 +76,15 @@ typedef void *MXS_FILTER;
*/
typedef struct mxs_filter_object
{
MXS_FILTER *(*createInstance)(const char *name,
char **options,
CONFIG_PARAMETER *params);
void *(*newSession)(MXS_FILTER *instance, SESSION *session);
void (*closeSession)(MXS_FILTER *instance, void *fsession);
void (*freeSession)(MXS_FILTER *instance, void *fsession);
void (*setDownstream)(MXS_FILTER *instance, void *fsession, DOWNSTREAM *downstream);
void (*setUpstream)(MXS_FILTER *instance, void *fsession, UPSTREAM *downstream);
int32_t (*routeQuery)(MXS_FILTER *instance, void *fsession, GWBUF *queue);
int32_t (*clientReply)(MXS_FILTER *instance, void *fsession, GWBUF *queue);
void (*diagnostics)(MXS_FILTER *instance, void *fsession, DCB *dcb);
MXS_FILTER *(*createInstance)(const char *name, char **options, CONFIG_PARAMETER *params);
MXS_FILTER_SESSION *(*newSession)(MXS_FILTER *instance, SESSION *session);
void (*closeSession)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
void (*freeSession)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession);
void (*setDownstream)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DOWNSTREAM *downstream);
void (*setUpstream)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, UPSTREAM *downstream);
int32_t (*routeQuery)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
int32_t (*clientReply)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, GWBUF *queue);
void (*diagnostics)(MXS_FILTER *instance, MXS_FILTER_SESSION *fsession, DCB *dcb);
uint64_t (*getCapabilities)(void);
void (*destroyInstance)(MXS_FILTER *instance);
} MXS_FILTER_OBJECT;

View File

@ -212,51 +212,51 @@ public:
return reinterpret_cast<MXS_FILTER*>(pFilter);
}
static void* newSession(MXS_FILTER* pInstance, SESSION* pSession)
static MXS_FILTER_SESSION* newSession(MXS_FILTER* pInstance, SESSION* pSession)
{
FilterType* pFilter = reinterpret_cast<FilterType*>(pInstance);
void* pFilterSession;
MXS_EXCEPTION_GUARD(pFilterSession = pFilter->newSession(pSession));
return pFilterSession;
return reinterpret_cast<MXS_FILTER_SESSION*>(pFilterSession);
}
static void closeSession(MXS_FILTER*, void* pData)
static void closeSession(MXS_FILTER*, MXS_FILTER_SESSION* pData)
{
FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData);
MXS_EXCEPTION_GUARD(pFilterSession->close());
}
static void freeSession(MXS_FILTER*, void* pData)
static void freeSession(MXS_FILTER*, MXS_FILTER_SESSION* pData)
{
FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData);
MXS_EXCEPTION_GUARD(delete pFilterSession);
}
static void setDownstream(MXS_FILTER*, void* pData, DOWNSTREAM* pDownstream)
static void setDownstream(MXS_FILTER*, MXS_FILTER_SESSION* pData, DOWNSTREAM* pDownstream)
{
FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData);
typename FilterSessionType::Downstream down(*pDownstream);
MXS_EXCEPTION_GUARD(pFilterSession->setDownstream(down));
}
static void setUpstream(MXS_FILTER* pInstance, void* pData, UPSTREAM* pUpstream)
static void setUpstream(MXS_FILTER* pInstance, MXS_FILTER_SESSION* pData, UPSTREAM* pUpstream)
{
FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData);
typename FilterSessionType::Upstream up(*pUpstream);
MXS_EXCEPTION_GUARD(pFilterSession->setUpstream(up));
}
static int routeQuery(MXS_FILTER* pInstance, void* pData, GWBUF* pPacket)
static int routeQuery(MXS_FILTER* pInstance, MXS_FILTER_SESSION* pData, GWBUF* pPacket)
{
FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData);
int rv = 0;
MXS_EXCEPTION_GUARD(rv = pFilterSession->routeQuery(pPacket));
@ -264,9 +264,9 @@ public:
return rv;
}
static int clientReply(MXS_FILTER* pInstance, void* pData, GWBUF* pPacket)
static int clientReply(MXS_FILTER* pInstance, MXS_FILTER_SESSION* pData, GWBUF* pPacket)
{
FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData);
int rv = 0;
MXS_EXCEPTION_GUARD(rv = pFilterSession->clientReply(pPacket));
@ -274,11 +274,11 @@ public:
return rv;
}
static void diagnostics(MXS_FILTER* pInstance, void* pData, DCB* pDcb)
static void diagnostics(MXS_FILTER* pInstance, MXS_FILTER_SESSION* pData, DCB* pDcb)
{
if (pData)
{
FilterSessionType* pFilterSession = static_cast<FilterSessionType*>(pData);
FilterSessionType* pFilterSession = reinterpret_cast<FilterSessionType*>(pData);
MXS_EXCEPTION_GUARD(pFilterSession->diagnostics(pDcb));
}