MXS-1461 Move client data to Client

The user and host are now in Client.
This commit is contained in:
Johan Wikman 2017-11-15 16:21:01 +02:00
parent 083c3bcad7
commit a596e1a77c
5 changed files with 54 additions and 19 deletions

View File

@ -14,6 +14,7 @@
#include <maxscale/cppdefs.hh>
#include <memory>
#include <string>
#include <maxscale/filter.h>
#include "../filtermodule.hh"
#include "dcb.hh"
@ -70,11 +71,25 @@ public:
/**
* Constructor
*
* @param zUser The client of the session,
* @param zHost The host of the client.
* @param pHandler Optional response handler.
*/
Client(Handler* pHandler = NULL);
Client(const char* zUser,
const char* zHost,
Handler* pHandler = NULL);
~Client();
/**
* @return The name of the client.
*/
const char* user() const;
/**
* @return The name of the host.
*/
const char* host() const;
/**
* Set a response handler
*
@ -114,9 +129,11 @@ private:
int32_t write(GWBUF* pBuffer);
private:
MXS_FILTER m_instance;
Handler* m_pHandler;
size_t m_n_responses;
MXS_FILTER m_instance;
std::string m_user;
std::string m_host;
Handler* m_pHandler;
size_t m_n_responses;
};
}

View File

@ -15,7 +15,7 @@
#include "mock.hh"
#include <maxscale/session.h>
#include <maxscale/protocol/mysql.h>
#include "dcb.hh"
#include "client.hh"
namespace maxscale
{
@ -36,16 +36,16 @@ public:
/**
* Constructor
*
* @param zUser The client of the session,
* @param zHost The host of the client.
* @param pHandler Handler for the client Dcb.
* @param pClient The client of the session. Must remain valid for
* the lifetime of the Session.
*/
Session(const char* zUser,
const char* zHost,
Dcb::Handler* pHandler = NULL);
Session(Client* pClient);
~Session();
Client& client() const;
private:
Client& m_client;
Dcb m_client_dcb;
MYSQL_session m_mysql_session;
};

View File

@ -22,8 +22,12 @@ namespace mock
//
// Client
//
Client::Client(Handler* pHandler)
: m_pHandler(pHandler)
Client::Client(const char* zUser,
const char* zHost,
Handler* pHandler)
: m_user(zUser)
, m_host(zHost)
, m_pHandler(pHandler)
, m_n_responses(0)
{
}
@ -32,6 +36,16 @@ Client::~Client()
{
}
const char* Client::user() const
{
return m_user.c_str();
}
const char* Client::host() const
{
return m_host.c_str();
}
size_t Client::n_responses() const
{
return m_n_responses;

View File

@ -19,10 +19,9 @@ namespace maxscale
namespace mock
{
Session::Session(const char* zUser,
const char* zHost,
Dcb::Handler* pHandler)
: m_client_dcb(this, zUser, zHost, pHandler)
Session::Session(Client* pClient)
: m_client(*pClient)
, m_client_dcb(this, pClient->user(), pClient->host(), pClient)
{
MXS_SESSION* pSession = this;
@ -45,6 +44,11 @@ Session::~Session()
{
}
Client& Session::client() const
{
return m_client;
}
}
}

View File

@ -177,8 +177,8 @@ int test(FilterModule::Instance& filter_instance, const FW_TEST& t)
if (c.zStatement)
{
mock::Client client;
mock::Session session(c.zUser, c.zHost, &client);
mock::Client client(c.zUser, c.zHost);
mock::Session session(&client);
auto_ptr<FilterModule::Session> sFilter_session = filter_instance.newSession(&session);