Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Putting global objects with short names under a namespace #576

Merged
merged 4 commits into from
Feb 15, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions srtcore/api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ modified by
#endif

using namespace std;
using namespace logging;
extern LogConfig srt_logger_config;

extern logging::LogConfig srt_logger_config;

extern logging::Logger mglog;

CUDTSocket::CUDTSocket():
m_Status(SRTS_INIT),
Expand Down
3 changes: 1 addition & 2 deletions srtcore/buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ modified by
#include "logging.h"

using namespace std;

extern logging::Logger mglog, dlog, tslog;
using namespace logging;

CSndBuffer::CSndBuffer(int size, int mss):
m_BufLock(),
Expand Down
4 changes: 1 addition & 3 deletions srtcore/channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ modified by
#endif

using namespace std;


extern logging::Logger mglog;
using namespace logging;

CChannel::CChannel():
m_iIPversion(AF_INET),
Expand Down
37 changes: 26 additions & 11 deletions srtcore/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ modified by

using namespace std;

namespace logging
rndi marked this conversation as resolved.
Show resolved Hide resolved
{

struct AllFaOn
{
logging::LogConfig::fa_bitset_t allfa;

AllFaOn()
{
allfa.set(SRT_LOGFA_BSTATS, true);
// allfa.set(SRT_LOGFA_BSTATS, true);
allfa.set(SRT_LOGFA_CONTROL, true);
allfa.set(SRT_LOGFA_DATA, true);
allfa.set(SRT_LOGFA_TSBPD, true);
Expand All @@ -97,14 +100,26 @@ struct AllFaOn
}
} logger_fa_all;

SRT_API logging::LogConfig srt_logger_config (logger_fa_all.allfa);
}

// We need it outside the namespace to preserve the global name.
// It's a part of "hidden API" (used by applications)
SRT_API logging::LogConfig srt_logger_config (logging::logger_fa_all.allfa);

namespace logging
{

Logger glog(SRT_LOGFA_GENERAL, srt_logger_config, "SRT.g");
// Unused. If not found useful, maybe reuse for another FA.
//Logger blog(SRT_LOGFA_BSTATS, srt_logger_config, "SRT.b");
Logger mglog(SRT_LOGFA_CONTROL, srt_logger_config, "SRT.c");
Logger dlog(SRT_LOGFA_DATA, srt_logger_config, "SRT.d");
Logger tslog(SRT_LOGFA_TSBPD, srt_logger_config, "SRT.t");
Logger rxlog(SRT_LOGFA_REXMIT, srt_logger_config, "SRT.r");

}

logging::Logger glog(SRT_LOGFA_GENERAL, srt_logger_config, "SRT.g");
logging::Logger blog(SRT_LOGFA_BSTATS, srt_logger_config, "SRT.b");
logging::Logger mglog(SRT_LOGFA_CONTROL, srt_logger_config, "SRT.c");
logging::Logger dlog(SRT_LOGFA_DATA, srt_logger_config, "SRT.d");
logging::Logger tslog(SRT_LOGFA_TSBPD, srt_logger_config, "SRT.t");
logging::Logger rxlog(SRT_LOGFA_REXMIT, srt_logger_config, "SRT.r");
using namespace logging;

CUDTUnited CUDT::s_UDTUnited;

Expand Down Expand Up @@ -4231,7 +4246,7 @@ void* CUDT::tsbpd(void* param)
timediff = int64_t(tsbpdtime) - int64_t(CTimer::getTime());
#if ENABLE_HEAVY_LOGGING
HLOGC(tslog.Debug, log << self->CONID() << "tsbpd: DROPSEQ: up to seq=" << CSeqNo::decseq(skiptoseqno)
<< " (" << seqlen << " packets) playable at " << logging::FormatTime(tsbpdtime) << " delayed "
<< " (" << seqlen << " packets) playable at " << FormatTime(tsbpdtime) << " delayed "
<< (timediff/1000) << "." << (timediff%1000) << " ms");
#endif
LOGC(dlog.Debug, log << "RCV-DROPPED packet delay=" << (timediff/1000) << "ms");
Expand Down Expand Up @@ -4284,7 +4299,7 @@ void* CUDT::tsbpd(void* param)
self->m_bTsbPdAckWakeup = false;
THREAD_PAUSED();
HLOGC(tslog.Debug, log << self->CONID() << "tsbpd: FUTURE PACKET seq=" << current_pkt_seq
<< " T=" << logging::FormatTime(tsbpdtime) << " - waiting " << (timediff/1000.0) << "ms");
<< " T=" << FormatTime(tsbpdtime) << " - waiting " << (timediff/1000.0) << "ms");
CTimer::condTimedWaitUS(&self->m_RcvTsbPdCond, &self->m_RecvLock, timediff);
THREAD_RESUMED();
}
Expand Down Expand Up @@ -8387,7 +8402,7 @@ void CUDT::checkTimers()

// This is a very heavy log, unblock only for temporary debugging!
#if 0
HLOGC(mglog.Debug, log << CONID() << "checkTimers: nextacktime=" << logging::FormatTime(m_ullNextACKTime_tk)
HLOGC(mglog.Debug, log << CONID() << "checkTimers: nextacktime=" << FormatTime(m_ullNextACKTime_tk)
<< " AckInterval=" << m_iACKInterval
<< " pkt-count=" << m_iPktCount << " liteack-count=" << m_iLightACKCount);
#endif
Expand Down
9 changes: 7 additions & 2 deletions srtcore/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,19 @@ modified by

#include <haicrypt.h>

extern logging::Logger
namespace logging
{

extern Logger
glog,
blog,
// blog,
mglog,
dlog,
tslog,
rxlog;

}


// XXX Utility function - to be moved to utilities.h?
template <class T>
Expand Down
2 changes: 1 addition & 1 deletion srtcore/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ written by
#include "logging.h"
#include "core.h"

extern logging::Logger mglog, dlog;
using namespace logging;

#define SRT_MAX_KMRETRY 10

Expand Down
7 changes: 6 additions & 1 deletion srtcore/crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ written by

std::string KmStateStr(SRT_KM_STATE state);

extern logging::Logger mglog;
namespace logging
{
extern Logger mglog;
}

#endif

Expand Down Expand Up @@ -152,6 +155,8 @@ class CCryptoControl
/// during transmission (otherwise it's during the handshake)
void getKmMsg_markSent(size_t ki, bool runtime)
{
using logging::mglog;

m_SndKmLastTime = CTimer::getTime();
if (runtime)
{
Expand Down
37 changes: 25 additions & 12 deletions srtcore/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,21 +133,36 @@ struct SRT_API LogDispatcher
private:
int fa;
LogLevel::type level;
std::string prefix;
static const size_t MAX_PREFIX_SIZE = 32;
char prefix[MAX_PREFIX_SIZE+1];
LogConfig* src_config;
pthread_mutex_t mutex;

bool isset(int flg) { return (src_config->flags & flg) != 0; }

public:

LogDispatcher(int functional_area, LogLevel::type log_level, const std::string& pfx, LogConfig& config):
LogDispatcher(int functional_area, LogLevel::type log_level, const char* your_pfx,
const char* logger_pfx /*[[nullable]]*/, LogConfig& config):
fa(functional_area),
level(log_level),
prefix(pfx),
//enabled(false),
src_config(&config)
{
// XXX stpcpy desired, but not enough portable
// Composing the exact prefix is not critical, so simply
// cut the prefix, if the lenght is exceeded
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/lenght/length/


// See Logger::Logger; we know this has normally 2 characters,
// except !!FATAL!!, which has 9. Still less than 32.
strcpy(prefix, your_pfx);
rndi marked this conversation as resolved.
Show resolved Hide resolved

// If the size of the FA name together with severity exceeds the size,
// just skip the former.
if (logger_pfx && strlen(prefix) + strlen(logger_pfx) < MAX_PREFIX_SIZE)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for ":"

{
strcat(prefix, ":");
strcat(prefix, logger_pfx);
}
pthread_mutex_init(&mutex, 0);
}

Expand Down Expand Up @@ -346,7 +361,6 @@ struct LogDispatcher::Proxy

class Logger
{
std::string m_prefix;
int m_fa;
LogConfig& m_config;

Expand All @@ -358,15 +372,14 @@ class Logger
LogDispatcher Error;
LogDispatcher Fatal;

Logger(int functional_area, LogConfig& config, std::string globprefix = std::string()):
m_prefix( globprefix == "" ? globprefix : ": " + globprefix),
Logger(int functional_area, LogConfig& config, const char* logger_pfx = NULL):
m_fa(functional_area),
m_config(config),
Debug ( m_fa, LogLevel::debug, " D" + m_prefix, m_config ),
Note ( m_fa, LogLevel::note, ".N" + m_prefix, m_config ),
Warn ( m_fa, LogLevel::warning, "!W" + m_prefix, m_config ),
Error ( m_fa, LogLevel::error, "*E" + m_prefix, m_config ),
Fatal ( m_fa, LogLevel::fatal, "!!FATAL!!" + m_prefix, m_config )
Debug ( m_fa, LogLevel::debug, " D", logger_pfx, m_config ),
Note ( m_fa, LogLevel::note, ".N", logger_pfx, m_config ),
Warn ( m_fa, LogLevel::warning, "!W", logger_pfx, m_config ),
Error ( m_fa, LogLevel::error, "*E", logger_pfx, m_config ),
Fatal ( m_fa, LogLevel::fatal, "!!FATAL!!", logger_pfx, m_config )
{
}

Expand Down
6 changes: 5 additions & 1 deletion srtcore/packet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ modified by
#include "packet.h"
#include "logging.h"

extern logging::Logger mglog;
namespace logging
{
extern Logger mglog;
}
using namespace logging;

// Set up the aliases in the constructure
CPacket::CPacket():
Expand Down
1 change: 1 addition & 0 deletions srtcore/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ modified by
#include "queue.h"

using namespace std;
using namespace logging;

CUnitQueue::CUnitQueue():
m_pQEntry(NULL),
Expand Down
1 change: 1 addition & 0 deletions srtcore/smoother.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "logging.h"

using namespace std;
using namespace logging;

SmootherBase::SmootherBase(CUDT* parent)
{
Expand Down