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 3 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
8 changes: 4 additions & 4 deletions apps/logsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ map<string, int> srt_level_names



logging::LogLevel::type SrtParseLogLevel(string level)
srt_logging::LogLevel::type SrtParseLogLevel(string level)
{
using namespace logging;
using namespace srt_logging;

if ( level.empty() )
return LogLevel::fatal;
Expand Down Expand Up @@ -74,9 +74,9 @@ logging::LogLevel::type SrtParseLogLevel(string level)
return LogLevel::type(i->second);
}

set<logging::LogFA> SrtParseLogFA(string fa)
set<srt_logging::LogFA> SrtParseLogFA(string fa)
{
using namespace logging;
using namespace srt_logging;

set<LogFA> fas;

Expand Down
4 changes: 2 additions & 2 deletions apps/logsupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include "../srtcore/srt.h"
#include "../srtcore/logging_api.h"

logging::LogLevel::type SrtParseLogLevel(std::string level);
std::set<logging::LogFA> SrtParseLogFA(std::string fa);
srt_logging::LogLevel::type SrtParseLogLevel(std::string level);
std::set<srt_logging::LogFA> SrtParseLogFA(std::string fa);

SRT_API extern std::map<std::string, int> srt_level_names;

Expand Down
4 changes: 2 additions & 2 deletions apps/srt-file-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ written by
bool Upload(UriParser& srt, UriParser& file);
bool Download(UriParser& srt, UriParser& file);

const logging::LogFA SRT_LOGFA_APP = 10;
const srt_logging::LogFA SRT_LOGFA_APP = 10;

static size_t g_buffer_size = 1456;
static bool g_skip_flushing = false;
Expand Down Expand Up @@ -95,7 +95,7 @@ int main( int argc, char** argv )
}

string loglevel = Option<OutString>(params, "error", o_loglevel);
logging::LogLevel::type lev = SrtParseLogLevel(loglevel);
srt_logging::LogLevel::type lev = SrtParseLogLevel(loglevel);
UDT::setloglevel(lev);
UDT::addlogfa(SRT_LOGFA_APP);

Expand Down
4 changes: 2 additions & 2 deletions apps/srt-live-transmit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ int main( int argc, char** argv )
std::ofstream logfile_stream; // leave unused if not set

srt_setloglevel(SrtParseLogLevel(loglevel));
set<logging::LogFA> fas = SrtParseLogFA(logfa);
for (set<logging::LogFA>::iterator i = fas.begin(); i != fas.end(); ++i)
set<srt_logging::LogFA> fas = SrtParseLogFA(logfa);
for (set<srt_logging::LogFA>::iterator i = fas.begin(); i != fas.end(); ++i)
srt_addlogfa(*i);

char NAME[] = "SRTLIB";
Expand Down
6 changes: 3 additions & 3 deletions apps/srt-multiplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ using namespace std;
// So far, this function must be used and up to this length of payload.
const size_t DEFAULT_CHUNK = 1316;

const logging::LogFA SRT_LOGFA_APP = 10;
logging::Logger applog(SRT_LOGFA_APP, srt_logger_config, "srt-mplex");
const srt_logging::LogFA SRT_LOGFA_APP = 10;
srt_logging::Logger applog(SRT_LOGFA_APP, srt_logger_config, "srt-mplex");

volatile bool siplex_int_state = false;
void OnINT_SetIntState(int)
Expand Down Expand Up @@ -545,7 +545,7 @@ int main( int argc, char** argv )
}

string loglevel = Option<OutString>(params, "error", "ll", "loglevel");
logging::LogLevel::type lev = SrtParseLogLevel(loglevel);
srt_logging::LogLevel::type lev = SrtParseLogLevel(loglevel);
UDT::setloglevel(lev);
UDT::addlogfa(SRT_LOGFA_APP);

Expand Down
13 changes: 6 additions & 7 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 srt_logging;
extern LogConfig srt_logger_config;

extern logging::LogConfig srt_logger_config;

extern logging::Logger mglog;

CUDTSocket::CUDTSocket():
m_Status(SRTS_INIT),
Expand Down Expand Up @@ -3078,25 +3077,25 @@ SRT_SOCKSTATUS getsockstate(SRTSOCKET u)
return CUDT::getsockstate(u);
}

void setloglevel(logging::LogLevel::type ll)
void setloglevel(LogLevel::type ll)
{
CGuard gg(srt_logger_config.mutex);
srt_logger_config.max_level = ll;
}

void addlogfa(logging::LogFA fa)
void addlogfa(LogFA fa)
{
CGuard gg(srt_logger_config.mutex);
srt_logger_config.enabled_fa.set(fa, true);
}

void dellogfa(logging::LogFA fa)
void dellogfa(LogFA fa)
{
CGuard gg(srt_logger_config.mutex);
srt_logger_config.enabled_fa.set(fa, false);
}

void resetlogfa(set<logging::LogFA> fas)
void resetlogfa(set<LogFA> fas)
{
CGuard gg(srt_logger_config.mutex);
for (int i = 0; i <= SRT_LOGFA_LASTNONE; ++i)
Expand Down
5 changes: 2 additions & 3 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 srt_logging;

CSndBuffer::CSndBuffer(int size, int mss):
m_BufLock(),
Expand Down Expand Up @@ -1629,7 +1628,7 @@ int CRcvBuffer::readMsg(char* data, int len, ref_t<SRT_MSGCTRL> r_msgctl)
int64_t nowdiff = prev_now ? (nowtime - prev_now) : 0;
uint64_t srctimediff = prev_srctime ? (srctime - prev_srctime) : 0;

HLOGC(dlog.Debug, log << CONID() << "readMsg: DELIVERED seq=" << seq << " T=" << logging::FormatTime(srctime) << " in " << (timediff/1000.0) << "ms - "
HLOGC(dlog.Debug, log << CONID() << "readMsg: DELIVERED seq=" << seq << " T=" << FormatTime(srctime) << " in " << (timediff/1000.0) << "ms - "
"TIME-PREVIOUS: PKT: " << (srctimediff/1000.0) << " LOCAL: " << (nowdiff/1000.0));

prev_now = nowtime;
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 srt_logging;

CChannel::CChannel():
m_iIPversion(AF_INET),
Expand Down
16 changes: 11 additions & 5 deletions srtcore/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -839,7 +839,10 @@ std::string TransmissionEventStr(ETransmissionEvent ev)
return vals[ev];
}

std::string logging::FormatTime(uint64_t time)
namespace srt_logging
{

std::string FormatTime(uint64_t time)
{
using namespace std;

Expand All @@ -862,7 +865,7 @@ std::string logging::FormatTime(uint64_t time)
// Some logging imps
#if ENABLE_LOGGING

logging::LogDispatcher::Proxy::Proxy(LogDispatcher& guy) : that(guy), that_enabled(that.CheckEnabled())
LogDispatcher::Proxy::Proxy(LogDispatcher& guy) : that(guy), that_enabled(that.CheckEnabled())
{
if (that_enabled)
{
Expand All @@ -874,12 +877,12 @@ logging::LogDispatcher::Proxy::Proxy(LogDispatcher& guy) : that(guy), that_enabl
}
}

logging::LogDispatcher::Proxy logging::LogDispatcher::operator()()
LogDispatcher::Proxy LogDispatcher::operator()()
{
return Proxy(*this);
}

void logging::LogDispatcher::CreateLogLinePrefix(std::ostringstream& serr)
void LogDispatcher::CreateLogLinePrefix(std::ostringstream& serr)
{
using namespace std;

Expand Down Expand Up @@ -925,7 +928,7 @@ void logging::LogDispatcher::CreateLogLinePrefix(std::ostringstream& serr)
}
}

std::string logging::LogDispatcher::Proxy::ExtractName(std::string pretty_function)
std::string LogDispatcher::Proxy::ExtractName(std::string pretty_function)
{
if ( pretty_function == "" )
return "";
Expand Down Expand Up @@ -987,4 +990,7 @@ std::string logging::LogDispatcher::Proxy::ExtractName(std::string pretty_functi

return pretty_function.substr(pos+2);
}

} // (end namespace srt_logging)

#endif
39 changes: 27 additions & 12 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 srt_logging
{

struct AllFaOn
{
logging::LogConfig::fa_bitset_t allfa;
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 srt_logging::LogConfig srt_logger_config (srt_logging::logger_fa_all.allfa);

namespace srt_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 srt_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 srt_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 srt_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 srt_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 srt_logging::mglog;

m_SndKmLastTime = CTimer::getTime();
if (runtime)
{
Expand Down
Loading