Add helper functions and default parameters

Added some helper functions into the MaxScale class and default parameters
into the connection creation functions. Also made the ip() function const
correct.
This commit is contained in:
Markus Mäkelä
2018-03-10 12:20:42 +02:00
parent 464d52453b
commit 36c960a141
5 changed files with 37 additions and 6 deletions

View File

@ -71,7 +71,7 @@ MYSQL* open_conn_db_timeout(int port, std::string ip, std::string db, std::strin
* @return MYSQL struct * @return MYSQL struct
*/ */
static MYSQL* open_conn_db(int port, std::string ip, std::string db, std::string user, std::string password, static MYSQL* open_conn_db(int port, std::string ip, std::string db, std::string user, std::string password,
bool ssl) bool ssl = false)
{ {
return open_conn_db_flags(port, ip, db, user, password, CLIENT_MULTI_STATEMENTS, ssl); return open_conn_db_flags(port, ip, db, user, password, CLIENT_MULTI_STATEMENTS, ssl);
} }
@ -87,7 +87,7 @@ static MYSQL* open_conn_db(int port, std::string ip, std::string db, std::string
* *
* @return MYSQL struct * @return MYSQL struct
*/ */
static MYSQL* open_conn(int port, std::string ip, std::string user, std::string password, bool ssl) static MYSQL* open_conn(int port, std::string ip, std::string user, std::string password, bool ssl = false)
{ {
return open_conn_db(port, ip.c_str(), "test", user.c_str(), password.c_str(), ssl); return open_conn_db(port, ip.c_str(), "test", user.c_str(), password.c_str(), ssl);
} }
@ -103,7 +103,7 @@ static MYSQL* open_conn(int port, std::string ip, std::string user, std::string
* *
* @return MYSQL struct * @return MYSQL struct
*/ */
static MYSQL* open_conn_no_db(int port, std::string ip, std::string user, std::string password, bool ssl) static MYSQL* open_conn_no_db(int port, std::string ip, std::string user, std::string password, bool ssl = false)
{ {
return open_conn_db_flags(port, ip, "", user, password, CLIENT_MULTI_STATEMENTS, ssl); return open_conn_db_flags(port, ip, "", user, password, CLIENT_MULTI_STATEMENTS, ssl);
} }

View File

@ -417,3 +417,17 @@ StringSet Maxscales::get_server_status(const char* name, int m)
return rval; return rval;
} }
int Maxscales::port(enum service type, int m) const
{
switch (type)
{
case RWSPLIT:
return rwsplit_port[m];
case READCONN_MASTER:
return readconn_master_port[m];
case READCONN_SLAVE:
return readconn_slave_port[m];
}
return -1;
}

View File

@ -8,6 +8,13 @@
class Maxscales: public Nodes class Maxscales: public Nodes
{ {
public: public:
enum service
{
RWSPLIT,
READCONN_MASTER,
READCONN_SLAVE
};
Maxscales(const char *pref, const char *test_cwd, bool verbose); Maxscales(const char *pref, const char *test_cwd, bool verbose);
int read_env(); int read_env();
@ -26,6 +33,16 @@ public:
*/ */
int readconn_slave_port[256]; int readconn_slave_port[256];
/**
* @brief Get port number of a MaxScale service
*
* @param type Type of service
* @param m MaxScale instance to use
*
* @return Port number of the service
*/
int port(enum service type = RWSPLIT, int m = 0) const;
/** /**
* @brief binlog_port binlog router service port * @brief binlog_port binlog router service port
*/ */

View File

@ -467,7 +467,7 @@ int Nodes::read_basic_env()
return 0; return 0;
} }
char* Nodes::ip(int i) const const char* Nodes::ip(int i) const
{ {
return use_ipv6 ? (char*)IP6[i] : (char*)IP[i]; return use_ipv6 ? IP6[i] : IP[i];
} }

View File

@ -93,7 +93,7 @@ public:
* *
* @return The current IP address * @return The current IP address
*/ */
char* ip(int i) const; const char* ip(int i = 0) const;
/** /**
* @brief Generate command line to execute command on the node via ssh * @brief Generate command line to execute command on the node via ssh