mirror of
https://github.com/ShaYmez/NXDNClients.git
synced 2025-08-03 05:22:24 -04:00
Merge branch 'master' into IPv6
This commit is contained in:
commit
a3eb137659
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -22,6 +22,7 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -36,6 +37,7 @@ static std::string m_filePath;
|
|||||||
static std::string m_fileRoot;
|
static std::string m_fileRoot;
|
||||||
|
|
||||||
static FILE* m_fpLog = NULL;
|
static FILE* m_fpLog = NULL;
|
||||||
|
static bool m_daemon = false;
|
||||||
|
|
||||||
static unsigned int m_displayLevel = 2U;
|
static unsigned int m_displayLevel = 2U;
|
||||||
|
|
||||||
@ -45,6 +47,8 @@ static char LEVELS[] = " DMIWEF";
|
|||||||
|
|
||||||
static bool LogOpen()
|
static bool LogOpen()
|
||||||
{
|
{
|
||||||
|
bool status = false;
|
||||||
|
|
||||||
if (m_fileLevel == 0U)
|
if (m_fileLevel == 0U)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -61,25 +65,38 @@ static bool LogOpen()
|
|||||||
::fclose(m_fpLog);
|
::fclose(m_fpLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
char filename[100U];
|
char filename[200U];
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
||||||
#else
|
#else
|
||||||
::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_fpLog = ::fopen(filename, "a+t");
|
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
|
||||||
m_tm = *tm;
|
status = true;
|
||||||
|
|
||||||
return m_fpLog != NULL;
|
#if !defined(_WIN32) && !defined(_WIN64)
|
||||||
|
if (m_daemon)
|
||||||
|
dup2(fileno(m_fpLog), fileno(stderr));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LogInitialise(const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel)
|
m_tm = *tm;
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel)
|
||||||
{
|
{
|
||||||
m_filePath = filePath;
|
m_filePath = filePath;
|
||||||
m_fileRoot = fileRoot;
|
m_fileRoot = fileRoot;
|
||||||
m_fileLevel = fileLevel;
|
m_fileLevel = fileLevel;
|
||||||
m_displayLevel = displayLevel;
|
m_displayLevel = displayLevel;
|
||||||
|
m_daemon = daemon;
|
||||||
|
|
||||||
|
if (m_daemon)
|
||||||
|
m_displayLevel = 0U;
|
||||||
|
|
||||||
return ::LogOpen();
|
return ::LogOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +110,7 @@ void Log(unsigned int level, const char* fmt, ...)
|
|||||||
{
|
{
|
||||||
assert(fmt != NULL);
|
assert(fmt != NULL);
|
||||||
|
|
||||||
char buffer[300U];
|
char buffer[501U];
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
::GetSystemTime(&st);
|
::GetSystemTime(&st);
|
||||||
@ -105,13 +122,13 @@ void Log(unsigned int level, const char* fmt, ...)
|
|||||||
|
|
||||||
struct tm* tm = ::gmtime(&now.tv_sec);
|
struct tm* tm = ::gmtime(&now.tv_sec);
|
||||||
|
|
||||||
::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03lu ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000U);
|
::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03ld ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000L);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
va_list vl;
|
va_list vl;
|
||||||
va_start(vl, fmt);
|
va_start(vl, fmt);
|
||||||
|
|
||||||
::vsprintf(buffer + ::strlen(buffer), fmt, vl);
|
::vsnprintf(buffer + ::strlen(buffer), 500, fmt, vl);
|
||||||
|
|
||||||
va_end(vl);
|
va_end(vl);
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
extern void Log(unsigned int level, const char* fmt, ...);
|
extern void Log(unsigned int level, const char* fmt, ...);
|
||||||
|
|
||||||
extern bool LogInitialise(const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel);
|
extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel);
|
||||||
extern void LogFinalise();
|
extern void LogFinalise();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -166,7 +166,11 @@ void CNXDNGateway::run()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
#if !defined(_WIN32) && !defined(_WIN64)
|
||||||
|
ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
||||||
|
#else
|
||||||
|
ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
||||||
|
#endif
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
::fprintf(stderr, "NXDNGateway: unable to open the log file\n");
|
::fprintf(stderr, "NXDNGateway: unable to open the log file\n");
|
||||||
return;
|
return;
|
||||||
|
@ -127,7 +127,7 @@
|
|||||||
22200 nxdn.hblink.it 41400
|
22200 nxdn.hblink.it 41400
|
||||||
|
|
||||||
# 22202 IT SARDINIA
|
# 22202 IT SARDINIA
|
||||||
22202 nxdn.is0hha.hblink.it 41400
|
22202 nxdn.sardinia.hblink.it 41400
|
||||||
|
|
||||||
# 22221 HBLINK IT-DMR REGIONALE LOMBARDIA
|
# 22221 HBLINK IT-DMR REGIONALE LOMBARDIA
|
||||||
22221 dagobah.hblink.it 41400
|
22221 dagobah.hblink.it 41400
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -95,7 +95,13 @@ void* CThread::helper(void* arg)
|
|||||||
|
|
||||||
void CThread::sleep(unsigned int ms)
|
void CThread::sleep(unsigned int ms)
|
||||||
{
|
{
|
||||||
::usleep(ms * 1000);
|
struct timespec ts;
|
||||||
|
|
||||||
|
ts.tv_sec = ms / 1000U;
|
||||||
|
ts.tv_nsec = (ms % 1000U) * 1000000U;
|
||||||
|
|
||||||
|
::nanosleep(&ts, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -22,6 +22,7 @@
|
|||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@ -36,6 +37,7 @@ static std::string m_filePath;
|
|||||||
static std::string m_fileRoot;
|
static std::string m_fileRoot;
|
||||||
|
|
||||||
static FILE* m_fpLog = NULL;
|
static FILE* m_fpLog = NULL;
|
||||||
|
static bool m_daemon = false;
|
||||||
|
|
||||||
static unsigned int m_displayLevel = 2U;
|
static unsigned int m_displayLevel = 2U;
|
||||||
|
|
||||||
@ -45,6 +47,8 @@ static char LEVELS[] = " DMIWEF";
|
|||||||
|
|
||||||
static bool LogOpen()
|
static bool LogOpen()
|
||||||
{
|
{
|
||||||
|
bool status = false;
|
||||||
|
|
||||||
if (m_fileLevel == 0U)
|
if (m_fileLevel == 0U)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@ -61,25 +65,38 @@ static bool LogOpen()
|
|||||||
::fclose(m_fpLog);
|
::fclose(m_fpLog);
|
||||||
}
|
}
|
||||||
|
|
||||||
char filename[100U];
|
char filename[200U];
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
::sprintf(filename, "%s\\%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
||||||
#else
|
#else
|
||||||
::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
::sprintf(filename, "%s/%s-%04d-%02d-%02d.log", m_filePath.c_str(), m_fileRoot.c_str(), tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_fpLog = ::fopen(filename, "a+t");
|
if ((m_fpLog = ::fopen(filename, "a+t")) != NULL) {
|
||||||
m_tm = *tm;
|
status = true;
|
||||||
|
|
||||||
return m_fpLog != NULL;
|
#if !defined(_WIN32) && !defined(_WIN64)
|
||||||
|
if (m_daemon)
|
||||||
|
dup2(fileno(m_fpLog), fileno(stderr));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LogInitialise(const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel)
|
m_tm = *tm;
|
||||||
|
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel)
|
||||||
{
|
{
|
||||||
m_filePath = filePath;
|
m_filePath = filePath;
|
||||||
m_fileRoot = fileRoot;
|
m_fileRoot = fileRoot;
|
||||||
m_fileLevel = fileLevel;
|
m_fileLevel = fileLevel;
|
||||||
m_displayLevel = displayLevel;
|
m_displayLevel = displayLevel;
|
||||||
|
m_daemon = daemon;
|
||||||
|
|
||||||
|
if (m_daemon)
|
||||||
|
m_displayLevel = 0U;
|
||||||
|
|
||||||
return ::LogOpen();
|
return ::LogOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,7 +110,7 @@ void Log(unsigned int level, const char* fmt, ...)
|
|||||||
{
|
{
|
||||||
assert(fmt != NULL);
|
assert(fmt != NULL);
|
||||||
|
|
||||||
char buffer[300U];
|
char buffer[501U];
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
SYSTEMTIME st;
|
SYSTEMTIME st;
|
||||||
::GetSystemTime(&st);
|
::GetSystemTime(&st);
|
||||||
@ -105,13 +122,13 @@ void Log(unsigned int level, const char* fmt, ...)
|
|||||||
|
|
||||||
struct tm* tm = ::gmtime(&now.tv_sec);
|
struct tm* tm = ::gmtime(&now.tv_sec);
|
||||||
|
|
||||||
::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03lu ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000U);
|
::sprintf(buffer, "%c: %04d-%02d-%02d %02d:%02d:%02d.%03ld ", LEVELS[level], tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, now.tv_usec / 1000L);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
va_list vl;
|
va_list vl;
|
||||||
va_start(vl, fmt);
|
va_start(vl, fmt);
|
||||||
|
|
||||||
::vsprintf(buffer + ::strlen(buffer), fmt, vl);
|
::vsnprintf(buffer + ::strlen(buffer), 500, fmt, vl);
|
||||||
|
|
||||||
va_end(vl);
|
va_end(vl);
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
extern void Log(unsigned int level, const char* fmt, ...);
|
extern void Log(unsigned int level, const char* fmt, ...);
|
||||||
|
|
||||||
extern bool LogInitialise(const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel);
|
extern bool LogInitialise(bool daemon, const std::string& filePath, const std::string& fileRoot, unsigned int fileLevel, unsigned int displayLevel);
|
||||||
extern void LogFinalise();
|
extern void LogFinalise();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -154,7 +154,11 @@ void CNXDNReflector::run()
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
ret = ::LogInitialise(m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
#if !defined(_WIN32) && !defined(_WIN64)
|
||||||
|
ret = ::LogInitialise(m_daemon, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
||||||
|
#else
|
||||||
|
ret = ::LogInitialise(false, m_conf.getLogFilePath(), m_conf.getLogFileRoot(), m_conf.getLogFileLevel(), m_conf.getLogDisplayLevel());
|
||||||
|
#endif
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
::fprintf(stderr, "NXDNReflector: unable to open the log file\n");
|
::fprintf(stderr, "NXDNReflector: unable to open the log file\n");
|
||||||
return;
|
return;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2015,2016 by Jonathan Naylor G4KLX
|
* Copyright (C) 2015,2016,2020 by Jonathan Naylor G4KLX
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -95,7 +95,13 @@ void* CThread::helper(void* arg)
|
|||||||
|
|
||||||
void CThread::sleep(unsigned int ms)
|
void CThread::sleep(unsigned int ms)
|
||||||
{
|
{
|
||||||
::usleep(ms * 1000);
|
struct timespec ts;
|
||||||
|
|
||||||
|
ts.tv_sec = ms / 1000U;
|
||||||
|
ts.tv_nsec = (ms % 1000U) * 1000000U;
|
||||||
|
|
||||||
|
::nanosleep(&ts, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user