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 <maxscale/cppdefs.hh>
#include <memory> #include <memory>
#include <string>
#include <maxscale/filter.h> #include <maxscale/filter.h>
#include "../filtermodule.hh" #include "../filtermodule.hh"
#include "dcb.hh" #include "dcb.hh"
@ -70,11 +71,25 @@ public:
/** /**
* Constructor * Constructor
* *
* @param zUser The client of the session,
* @param zHost The host of the client.
* @param pHandler Optional response handler. * @param pHandler Optional response handler.
*/ */
Client(Handler* pHandler = NULL); Client(const char* zUser,
const char* zHost,
Handler* pHandler = NULL);
~Client(); ~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 * Set a response handler
* *
@ -115,6 +130,8 @@ private:
private: private:
MXS_FILTER m_instance; MXS_FILTER m_instance;
std::string m_user;
std::string m_host;
Handler* m_pHandler; Handler* m_pHandler;
size_t m_n_responses; size_t m_n_responses;
}; };

View File

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

View File

@ -22,8 +22,12 @@ namespace mock
// //
// Client // Client
// //
Client::Client(Handler* pHandler) Client::Client(const char* zUser,
: m_pHandler(pHandler) const char* zHost,
Handler* pHandler)
: m_user(zUser)
, m_host(zHost)
, m_pHandler(pHandler)
, m_n_responses(0) , 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 size_t Client::n_responses() const
{ {
return m_n_responses; return m_n_responses;

View File

@ -19,10 +19,9 @@ namespace maxscale
namespace mock namespace mock
{ {
Session::Session(const char* zUser, Session::Session(Client* pClient)
const char* zHost, : m_client(*pClient)
Dcb::Handler* pHandler) , m_client_dcb(this, pClient->user(), pClient->host(), pClient)
: m_client_dcb(this, zUser, zHost, pHandler)
{ {
MXS_SESSION* pSession = this; 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) if (c.zStatement)
{ {
mock::Client client; mock::Client client(c.zUser, c.zHost);
mock::Session session(c.zUser, c.zHost, &client); mock::Session session(&client);
auto_ptr<FilterModule::Session> sFilter_session = filter_instance.newSession(&session); auto_ptr<FilterModule::Session> sFilter_session = filter_instance.newSession(&session);