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:
Markus Mäkelä
2018-09-08 17:32:59 +03:00
parent 4f6990f90d
commit c81173e320
10 changed files with 85 additions and 52 deletions

View File

@ -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);
}
}