Move C++ code out of C headers
The additions into the server.h header used C++ language which caused C programs to fail to compile. Moved the implementation of the EMAverage class into the private Server class in the server.hh header and exposed it via functions in the server.h header. Also temporarily moved almost_equal_server_scores into the public server.hh as there is no service.hh header.
This commit is contained in:
@ -20,7 +20,6 @@
|
||||
|
||||
#include <maxscale/cdefs.h>
|
||||
#include <maxbase/jansson.h>
|
||||
#include <maxbase/average.hh>
|
||||
#include <maxscale/config.h>
|
||||
#include <maxscale/dcb.h>
|
||||
|
||||
@ -166,9 +165,6 @@ typedef struct server
|
||||
* by rwsplit. TODO: Move to rwsplit */
|
||||
bool warn_ssl_not_enabled;/**< SSL not used for an SSL enabled server */
|
||||
MxsDiskSpaceThreshold* disk_space_threshold;/**< Disk space thresholds */
|
||||
// TODO, this is a plain ptr to a C++ class. Soonish, when the server is new/deleted
|
||||
// this will become a std::unique ptr. But not in this commit.
|
||||
maxbase::EMAverage* response_time; /**< for calculating average response time */
|
||||
} SERVER;
|
||||
|
||||
/**
|
||||
@ -528,4 +524,7 @@ extern void dprintServer(DCB*, const SERVER*);
|
||||
extern void dprintPersistentDCBs(DCB*, const SERVER*);
|
||||
extern void dListServers(DCB*);
|
||||
|
||||
int server_response_time_num_samples(const SERVER* server);
|
||||
double server_response_time_average(const SERVER* server);
|
||||
|
||||
MXS_END_DECLS
|
||||
|
||||
@ -15,10 +15,24 @@
|
||||
#include <maxscale/ccdefs.hh>
|
||||
|
||||
#include <string>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <maxscale/server.h>
|
||||
|
||||
namespace maxscale
|
||||
{
|
||||
bool server_set_status(SERVER* server, int bit, std::string* errmsg_out = NULL);
|
||||
bool server_clear_status(SERVER* server, int bit, std::string* errmsg_out = NULL);
|
||||
|
||||
/** Returns true if the two server "scores" are within 1/(see code) of each other.
|
||||
* The epsilon needs tweaking, and might even need to be in config. This
|
||||
* function is important for some compares, where one server might be only
|
||||
* marginally better than others, in which case historical data could determine
|
||||
* the outcome.
|
||||
*/
|
||||
inline bool almost_equal_server_scores(double lhs, double rhs)
|
||||
{
|
||||
constexpr double div = 100; // within 1% of each other.
|
||||
return std::abs((long)(lhs - rhs)) < std::abs((long)std::max(lhs, rhs)) * (1 / div);
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,18 +68,6 @@ typedef struct server_ref_t
|
||||
bool active; /**< Whether this reference is valid and in use*/
|
||||
} SERVER_REF;
|
||||
|
||||
/** Returns true if the two server "scores" are within 1/(see code) of each other.
|
||||
* The epsilon needs tweaking, and might even need to be in config. This
|
||||
* function is important for some compares, where one server might be only
|
||||
* marginally better than others, in which case historical data could determine
|
||||
* the outcome.
|
||||
*/
|
||||
inline bool almost_equal_server_scores(double lhs, double rhs)
|
||||
{
|
||||
constexpr double div = 100; // within 1% of each other.
|
||||
return std::abs(lhs - rhs) < std::abs(std::max(lhs, rhs)) * (1 / div);
|
||||
}
|
||||
|
||||
/** Macro to check whether a SERVER_REF is active */
|
||||
#define SERVER_REF_IS_ACTIVE(ref) (ref->active && server_is_active(ref->server))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user