Browse Source

Tab2Space & Newlines

peercoin
Intel 12 years ago
parent
commit
57c65a4ba2
  1. 60
      src/server/poolserver/Main.cpp
  2. 12
      src/server/poolserver/Server/Server.cpp
  3. 20
      src/server/shared/Configuration/Config.h
  4. 16
      src/server/shared/Database/Database.h
  5. 10
      src/server/shared/Database/MySQL/DatabaseConnectionMySQL.h
  6. 14
      src/server/shared/Database/MySQL/DatabaseWorkerPoolMySQL.h
  7. 116
      src/server/shared/Logging/Log.cpp
  8. 38
      src/server/shared/Logging/Log.h
  9. 2
      src/server/shared/Util.h

60
src/server/poolserver/Main.cpp

@ -9,41 +9,41 @@ bool InitConfig(int argc, char *argv[]) @@ -9,41 +9,41 @@ bool InitConfig(int argc, char *argv[])
{
// Containers
boost::program_options::options_description descGeneric("Generic Options");
boost::program_options::options_description descServer("Server Configuration");
boost::program_options::options_description descStratum("Stratum Configuration");
boost::program_options::options_description descLogging("Logging Configuration");
boost::program_options::options_description descServer("Server Configuration");
boost::program_options::options_description descStratum("Stratum Configuration");
boost::program_options::options_description descLogging("Logging Configuration");
boost::program_options::options_description descDatabase("Database Configuration");
#ifdef WITH_MYSQL
boost::program_options::options_description descMySQL("MySQL Configuration");
#endif
boost::program_options::options_description cmdlineOptions;
boost::program_options::options_description fileOptions;
boost::program_options::options_description cmdlineOptions;
boost::program_options::options_description fileOptions;
// Generic
descGeneric.add_options()
("version,v", "print version string")
("help,h", "produce help message")
("config,c", boost::program_options::value<std::string>()->default_value("poolserver.cfg"),"name of a file of a configuration.")
("version,v", "print version string")
("help,h", "produce help message")
("config,c", boost::program_options::value<std::string>()->default_value("poolserver.cfg"),"name of a file of a configuration.")
;
// Server
// Server
descServer.add_options()
("MinDiffTime", boost::program_options::value<uint32_t>()->default_value(100), "Minimum server diff time")
;
// Stratum
// Stratum
descStratum.add_options()
("StratumHost,sh", boost::program_options::value<std::string>()->default_value("0.0.0.0"), "Stratum server host")
("StratumPort,sp", boost::program_options::value<uint16_t>()->default_value(3333), "Stratum server port")
("StratumPort,sp", boost::program_options::value<uint16_t>()->default_value(3333), "Stratum server port")
;
// Logging
descLogging.add_options()
// Logging
descLogging.add_options()
("LogConsoleLevel", boost::program_options::value<uint32_t>()->default_value(LOG_LEVEL_INFO), "Console log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)")
("LogConsoleDebugMask", boost::program_options::value<uint32_t>()->default_value(0), "Console log debug mask")
("LogFilePath", boost::program_options::value<std::string>()->default_value("."), "File log path")
("LogFileLevel", boost::program_options::value<uint32_t>()->default_value(LOG_LEVEL_WARN), "File log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)")
("LogFileDebugMask", boost::program_options::value<uint32_t>()->default_value(0), "File log debug mask")
("LogConsoleDebugMask", boost::program_options::value<uint32_t>()->default_value(0), "Console log debug mask")
("LogFilePath", boost::program_options::value<std::string>()->default_value("."), "File log path")
("LogFileLevel", boost::program_options::value<uint32_t>()->default_value(LOG_LEVEL_WARN), "File log level (0-None, 1-Error, 2-Warn, 3-Info, 4-Debug)")
("LogFileDebugMask", boost::program_options::value<uint32_t>()->default_value(0), "File log debug mask")
;
// Database
@ -69,31 +69,31 @@ bool InitConfig(int argc, char *argv[]) @@ -69,31 +69,31 @@ bool InitConfig(int argc, char *argv[])
store(boost::program_options::command_line_parser(argc, argv).options(cmdlineOptions).run(), sConfig.vm);
notify(sConfig.vm);
if (sConfig.vm.count("help")) {
std::cout << cmdlineOptions << std::endl;
return false;
}
if (sConfig.vm.count("help")) {
std::cout << cmdlineOptions << std::endl;
return false;
}
std::ifstream ifs(sConfig.Get<std::string>("config").c_str());
if (!ifs.is_open()) {
if (!ifs.is_open()) {
sLog.Error(LOG_GENERAL, "Failed opening config file: %s", sConfig.Get<std::string>("config").c_str());
return false;
}
return false;
}
store(parse_config_file(ifs, fileOptions), sConfig.vm);
notify(sConfig.vm);
store(parse_config_file(ifs, fileOptions), sConfig.vm);
notify(sConfig.vm);
return true;
}
int main(int argc, char *argv[])
{
if (!InitConfig(argc, argv))
return 0;
if (!InitConfig(argc, argv))
return 0;
sLog.OpenLogFile(sConfig.Get<std::string>("LogFilePath"));
sLog.Info(LOG_GENERAL, "LogFile Started: %s", sLog.logFileLoc.c_str());
sLog.OpenLogFile(sConfig.Get<std::string>("LogFilePath"));
sLog.Info(LOG_GENERAL, "LogFile Started: %s", sLog.logFileLoc.c_str());
Server* server = new Server();
int exitcode = server->Run();

12
src/server/poolserver/Server/Server.cpp

@ -19,7 +19,7 @@ Server::~Server() @@ -19,7 +19,7 @@ Server::~Server()
int Server::Run()
{
sLog.Info(LOG_SERVER, "Server is starting...");
sLog.Info(LOG_SERVER, "Server is starting...");
InitDatabase();
@ -27,7 +27,7 @@ int Server::Run() @@ -27,7 +27,7 @@ int Server::Run()
sDatabase.ExecuteAsync("INSERT INTO `test_table` VALUES ('999', 'sync', '1.1')");
// Start stratum server
sLog.Info(LOG_SERVER, "Starting stratum");
sLog.Info(LOG_SERVER, "Starting stratum");
//stratumServer = new Stratum::Server(Config::GetString("STRATUM_IP"), Config::GetInt("STRATUM_PORT"));
// Init loop vars
@ -36,10 +36,10 @@ int Server::Run() @@ -36,10 +36,10 @@ int Server::Run()
running = true;
// Init diff
uint32_t minDiffTime = sConfig.Get<uint32_t>("MinDiffTime");
uint32_t minDiffTime = sConfig.Get<uint32_t>("MinDiffTime");
diffStart = boost::chrono::steady_clock::now();
sLog.Info(LOG_SERVER, "Server is running!");
sLog.Info(LOG_SERVER, "Server is running!");
while (running)
{
@ -60,8 +60,8 @@ int Server::Run() @@ -60,8 +60,8 @@ int Server::Run()
++serverLoops;
if (serverLoops > 50)
running = false;
if (serverLoops > 50)
running = false;
//std::cout << "Diff: " << diff << ", Loop: " << serverLoops << std::endl;
}

20
src/server/shared/Configuration/Config.h

@ -9,18 +9,18 @@ @@ -9,18 +9,18 @@
class Config
{
public:
Config();
~Config();
Config();
~Config();
// Reading
template<class T>
T Get(std::string key)
{
return vm[key].as<T>();
}
// Reading
template<class T>
T Get(std::string key)
{
return vm[key].as<T>();
}
// Containers
boost::program_options::variables_map vm;
// Containers
boost::program_options::variables_map vm;
};
extern Config sConfig;

16
src/server/shared/Database/Database.h

@ -9,22 +9,22 @@ @@ -9,22 +9,22 @@
class Database
{
public:
// Queries
virtual bool Execute(const char* query) = 0;
virtual ResultSet* Query(const char* query) = 0;
// Queries
virtual bool Execute(const char* query) = 0;
virtual ResultSet* Query(const char* query) = 0;
// Stmt
virtual bool Execute(PreparedStatement* stmt) = 0;
virtual ResultSet* Query(PreparedStatement* stmt) = 0;
virtual ResultSet* Query(PreparedStatement* stmt) = 0;
// Async
virtual bool ExecuteAsync(const char* query) = 0;
virtual bool ExecuteAsync(PreparedStatement* stmt) = 0;
virtual bool QueryAsync(DatabaseCallback callback, const char* query) = 0;
virtual bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) = 0;
virtual bool QueryAsync(DatabaseCallback callback, const char* query) = 0;
virtual bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt) = 0;
// Prepared Statements
virtual PreparedStatement* GetPreparedStatement(uint32_t index) = 0;
// Prepared Statements
virtual PreparedStatement* GetPreparedStatement(uint32_t index) = 0;
};
#endif

10
src/server/shared/Database/MySQL/DatabaseConnectionMySQL.h

@ -35,18 +35,18 @@ public: @@ -35,18 +35,18 @@ public:
void Close();
// Ping!
void Ping()
void Ping()
{
mysql_ping(_mysql);
}
// Queries
bool Execute(const char* query);
ResultSetMySQL* Query(const char* query);
// Queries
bool Execute(const char* query);
ResultSetMySQL* Query(const char* query);
// Stmt
bool Execute(PreparedStatement* stmt);
ResultSetMySQL* Query(PreparedStatement* stmt);
ResultSetMySQL* Query(PreparedStatement* stmt);
// Locking
bool LockIfReady()

14
src/server/shared/Database/MySQL/DatabaseWorkerPoolMySQL.h

@ -69,14 +69,14 @@ public: @@ -69,14 +69,14 @@ public:
}
// Queries
bool Execute(const char* query)
bool Execute(const char* query)
{
DatabaseConnectionMySQL* conn = GetSyncConnection();
bool result = conn->Execute(query);
conn->Unlock();
return result;
}
ResultSetMySQL* Query(const char* query)
ResultSetMySQL* Query(const char* query)
{
DatabaseConnectionMySQL* conn = GetSyncConnection();
ResultSetMySQL* result = conn->Query(query);
@ -92,7 +92,7 @@ public: @@ -92,7 +92,7 @@ public:
conn->Unlock();
return result;
}
ResultSetMySQL* Query(PreparedStatement* stmt)
ResultSetMySQL* Query(PreparedStatement* stmt)
{
DatabaseConnectionMySQL* conn = GetSyncConnection();
ResultSetMySQL* result = conn->Query(stmt);
@ -113,21 +113,21 @@ public: @@ -113,21 +113,21 @@ public:
_asyncQueue->Enqueue(op);
return true;
}
bool QueryAsync(DatabaseCallback callback, const char* query)
bool QueryAsync(DatabaseCallback callback, const char* query)
{
DatabaseQueryOperationMySQL* op = new DatabaseQueryOperationMySQL(query, callback);
_asyncQueue->Enqueue(op);
return true;
}
bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt)
bool QueryAsync(DatabaseCallback callback, PreparedStatement* stmt)
{
DatabasePreparedStatementOperationMySQL* op = new DatabasePreparedStatementOperationMySQL(stmt, callback);
_asyncQueue->Enqueue(op);
return true;
}
// Prepared Statements
PreparedStatement* GetPreparedStatement(uint32_t stmtid)
// Prepared Statements
PreparedStatement* GetPreparedStatement(uint32_t stmtid)
{
return NULL;//new PreparedStatement(stmtid);
}

116
src/server/shared/Logging/Log.cpp

@ -10,109 +10,109 @@ Log::Log(): logfile(NULL) @@ -10,109 +10,109 @@ Log::Log(): logfile(NULL)
Log::~Log()
{
if (logfile)
logfile.close();
if (logfile)
logfile.close();
}
void Log::Error(LogType type, const char * str, ...)
{
va_list ap;
va_start(ap, str);
va_list ap;
va_start(ap, str);
char text[MAX_MSG_LEN];
char text[MAX_MSG_LEN];
vsnprintf(text, MAX_MSG_LEN, str, ap);
Write(LOG_LEVEL_ERROR, type, std::string(text));
va_end(ap);
va_end(ap);
}
void Log::Warn(LogType type, const char * str, ...)
{
va_list ap;
va_start(ap, str);
va_list ap;
va_start(ap, str);
char text[MAX_MSG_LEN];
char text[MAX_MSG_LEN];
vsnprintf(text, MAX_MSG_LEN, str, ap);
Write(LOG_LEVEL_WARN, type, std::string(text));
va_end(ap);
va_end(ap);
}
void Log::Info(LogType type, const char * str, ...)
{
va_list ap;
va_start(ap, str);
va_list ap;
va_start(ap, str);
char text[MAX_MSG_LEN];
char text[MAX_MSG_LEN];
vsnprintf(text, MAX_MSG_LEN, str, ap);
Write(LOG_LEVEL_INFO, type, std::string(text));
va_end(ap);
va_end(ap);
}
void Log::Debug(LogType type, const char * str, ...)
{
va_list ap;
va_start(ap, str);
va_list ap;
va_start(ap, str);
char text[MAX_MSG_LEN];
char text[MAX_MSG_LEN];
vsnprintf(text, MAX_MSG_LEN, str, ap);
Write(LOG_LEVEL_DEBUG, type, std::string(text));
va_end(ap);
va_end(ap);
}
void Log::OpenLogFile(std::string path)
{
if (!logfile) {
logFileLoc = path + "/server-" + Util::Date("%Y%m%d-%H%M%S") + ".log";
logfile.open(logFileLoc.c_str());
}
if (!logfile) {
logFileLoc = path + "/server-" + Util::Date("%Y%m%d-%H%M%S") + ".log";
logfile.open(logFileLoc.c_str());
}
}
void Log::Write(LogLevel level, LogType type, std::string msg)
{
boost::lock_guard<boost::mutex> lock(_mutex);
switch(level)
{
case LOG_LEVEL_ERROR:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[ERROR] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[ERROR] " + msg);
break;
case LOG_LEVEL_WARN:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[WARN] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[WARN] " + msg);
break;
case LOG_LEVEL_INFO:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[INFO] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[INFO] " + msg);
break;
case LOG_LEVEL_DEBUG:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) {
uint32_t debugmask = sConfig.Get<uint32_t>("LogConsoleDebugMask");
if (debugmask & uint32_t(pow(2, type)))
std::cout << "[DEBUG] " << msg << std::endl;
}
if (sConfig.Get<uint32_t>("LogFileLevel") >= level) {
uint32_t debugmask = sConfig.Get<uint32_t>("LogFileDebugMask");
if (debugmask & uint32_t(pow(2, type)))
AppendFile("[DEBUG] " + msg);
}
break;
}
switch(level)
{
case LOG_LEVEL_ERROR:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[ERROR] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[ERROR] " + msg);
break;
case LOG_LEVEL_WARN:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[WARN] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[WARN] " + msg);
break;
case LOG_LEVEL_INFO:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level)
std::cout << "[INFO] " << msg << std::endl;
if (sConfig.Get<uint32_t>("LogFileLevel") >= level)
AppendFile("[INFO] " + msg);
break;
case LOG_LEVEL_DEBUG:
if (sConfig.Get<uint32_t>("LogConsoleLevel") >= level) {
uint32_t debugmask = sConfig.Get<uint32_t>("LogConsoleDebugMask");
if (debugmask & uint32_t(pow(2, type)))
std::cout << "[DEBUG] " << msg << std::endl;
}
if (sConfig.Get<uint32_t>("LogFileLevel") >= level) {
uint32_t debugmask = sConfig.Get<uint32_t>("LogFileDebugMask");
if (debugmask & uint32_t(pow(2, type)))
AppendFile("[DEBUG] " + msg);
}
break;
}
}
void Log::AppendFile(std::string msg)
{
if (!logfile)
return;
if (!logfile)
return;
logfile << msg << std::endl;
logfile << msg << std::endl;
}

38
src/server/shared/Logging/Log.h

@ -14,40 +14,40 @@ @@ -14,40 +14,40 @@
enum LogType
{
LOG_GENERAL = 0,
LOG_SERVER = 1,
LOG_GENERAL = 0,
LOG_SERVER = 1,
LOG_DATABASE = 2
};
enum LogLevel
{
LOG_LEVEL_NONE = 0,
LOG_LEVEL_ERROR = 1,
LOG_LEVEL_WARN = 2,
LOG_LEVEL_INFO = 3,
LOG_LEVEL_DEBUG = 4
LOG_LEVEL_NONE = 0,
LOG_LEVEL_ERROR = 1,
LOG_LEVEL_WARN = 2,
LOG_LEVEL_INFO = 3,
LOG_LEVEL_DEBUG = 4
};
class Log
{
public:
Log();
~Log();
Log();
~Log();
void Error(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Warn(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Info(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Debug(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Error(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Warn(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Info(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void Debug(LogType type, const char * str, ...) ATTR_PRINTF(3, 4);
void OpenLogFile(std::string filename);
std::string logFileLoc;
void OpenLogFile(std::string filename);
std::string logFileLoc;
private:
void Write(LogLevel level, LogType type, std::string msg);
void AppendFile(std::string);
void Write(LogLevel level, LogType type, std::string msg);
void AppendFile(std::string);
std::string logfileloc;
std::ofstream logfile;
std::string logfileloc;
std::ofstream logfile;
boost::mutex _mutex;
};

2
src/server/shared/Util.h

@ -10,7 +10,7 @@ @@ -10,7 +10,7 @@
namespace Util
{
std::string Date(const char* format, bool utc = false);
std::string Date(const char* format, bool utc = false);
template <typename T>
class SynchronisedQueue

Loading…
Cancel
Save