From 45b3166729a1158289bc121a76eff0b81155cbd6 Mon Sep 17 00:00:00 2001 From: Rolf Ahrenberg Date: Sun, 7 Dec 2014 16:09:56 +0200 Subject: [PATCH] Simplified the logging interface. --- config.c | 4 ++-- config.h | 39 ++++++++++++++++----------------------- discover.c | 2 +- log.h | 16 ++++++++-------- rtsp.c | 2 +- satip.c | 6 +++--- 6 files changed, 31 insertions(+), 38 deletions(-) diff --git a/config.c b/config.c index 01e03fc..eeaccff 100644 --- a/config.c +++ b/config.c @@ -14,9 +14,9 @@ cSatipConfig SatipConfig; cSatipConfig::cSatipConfig(void) : operatingModeM(eOperatingModeLow), #ifdef DEBUG - loggingM(eLoggingDebug1 & eLoggingDebug2), + loggingModeM(eLoggingModeDebug1 & eLoggingModeDebug2), #else - loggingM(eLoggingNormal), + loggingModeM(eLoggingModeNormal), #endif eitScanM(1), useBytesM(1) diff --git a/config.h b/config.h index 99737ff..84b2efc 100644 --- a/config.h +++ b/config.h @@ -15,7 +15,7 @@ class cSatipConfig { private: unsigned int operatingModeM; - unsigned int loggingM; + unsigned int loggingModeM; unsigned int eitScanM; unsigned int useBytesM; int disabledSourcesM[MAX_DISABLED_SOURCES_COUNT]; @@ -23,24 +23,24 @@ private: char configDirectoryM[PATH_MAX]; public: - enum { + enum eOperatingMode { eOperatingModeOff = 0, eOperatingModeLow, eOperatingModeNormal, eOperatingModeHigh, eOperatingModeCount }; - enum { - eLoggingNormal = 0x00, - eLoggingDebug1 = 0x01, - eLoggingDebug2 = 0x02, - eLoggingDebug3 = 0x04, - eLoggingDebug4 = 0x08, - eLoggingDebug5 = 0x10, - eLoggingDebug6 = 0x20, - eLoggingDebug7 = 0x40, - eLoggingDebug8 = 0x80, - eLoggingMask = 0xFF + enum eLoggingMode { + eLoggingModeNormal = 0x00, + eLoggingModeDebug1 = 0x01, + eLoggingModeDebug2 = 0x02, + eLoggingModeDebug3 = 0x04, + eLoggingModeDebug4 = 0x08, + eLoggingModeDebug5 = 0x10, + eLoggingModeDebug6 = 0x20, + eLoggingModeDebug7 = 0x40, + eLoggingModeDebug8 = 0x80, + eLoggingModeMask = 0xFF }; cSatipConfig(); unsigned int GetOperatingMode(void) const { return operatingModeM; } @@ -49,15 +49,8 @@ public: bool IsOperatingModeNormal(void) const { return (operatingModeM == eOperatingModeNormal); } bool IsOperatingModeHigh(void) const { return (operatingModeM == eOperatingModeHigh); } void ToggleOperatingMode(void) { operatingModeM = (operatingModeM + 1) % eOperatingModeCount; } - unsigned int GetLogging(void) const { return loggingM; } - bool IsLoggingDebug1(void) const { return (loggingM & eLoggingDebug1); } - bool IsLoggingDebug2(void) const { return (loggingM & eLoggingDebug2); } - bool IsLoggingDebug3(void) const { return (loggingM & eLoggingDebug3); } - bool IsLoggingDebug4(void) const { return (loggingM & eLoggingDebug4); } - bool IsLoggingDebug5(void) const { return (loggingM & eLoggingDebug5); } - bool IsLoggingDebug6(void) const { return (loggingM & eLoggingDebug6); } - bool IsLoggingDebug7(void) const { return (loggingM & eLoggingDebug7); } - bool IsLoggingDebug8(void) const { return (loggingM & eLoggingDebug8); } + unsigned int GetLoggingMode(void) const { return loggingModeM; } + bool IsLoggingMode(eLoggingMode modeP) const { return (loggingModeM & modeP); } unsigned int GetEITScan(void) const { return eitScanM; } unsigned int GetUseBytes(void) const { return useBytesM; } const char *GetConfigDirectory(void) const { return configDirectoryM; } @@ -67,7 +60,7 @@ public: int GetDisabledFilters(unsigned int indexP) const; void SetOperatingMode(unsigned int operatingModeP) { operatingModeM = operatingModeP; } - void SetLogging(unsigned int logLevelP) { loggingM = (logLevelP & eLoggingMask); } + void SetLoggingMode(unsigned int modeP) { loggingModeM = (modeP & eLoggingModeMask); } void SetEITScan(unsigned int onOffP) { eitScanM = onOffP; } void SetUseBytes(unsigned int onOffP) { useBytesM = onOffP; } void SetConfigDirectory(const char *directoryP); diff --git a/discover.c b/discover.c index 7e78c28..caa1cd0 100644 --- a/discover.c +++ b/discover.c @@ -199,7 +199,7 @@ void cSatipDiscover::Fetch(const char *urlP) CURLcode res = CURLE_OK; // Verbose output - if (SatipConfig.IsLoggingDebug2()) { + if (SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug2)) { SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_VERBOSE, 1L); SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGFUNCTION, cSatipDiscover::DebugCallback); SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGDATA, this); diff --git a/log.h b/log.h index d8ef820..9d9a4bd 100644 --- a/log.h +++ b/log.h @@ -12,14 +12,14 @@ #define error(x...) esyslog("SATIP-ERROR: " x) #define info(x...) isyslog("SATIP: " x) -#define debug1(x...) void( SatipConfig.IsLoggingDebug1() ? dsyslog("SATIP: " x) : void() ) -#define debug2(x...) void( SatipConfig.IsLoggingDebug2() ? dsyslog("SATIP: " x) : void() ) -#define debug3(x...) void( SatipConfig.IsLoggingDebug3() ? dsyslog("SATIP: " x) : void() ) -#define debug4(x...) void( SatipConfig.IsLoggingDebug4() ? dsyslog("SATIP: " x) : void() ) -#define debug5(x...) void( SatipConfig.IsLoggingDebug5() ? dsyslog("SATIP: " x) : void() ) -#define debug6(x...) void( SatipConfig.IsLoggingDebug6() ? dsyslog("SATIP: " x) : void() ) -#define debug7(x...) void( SatipConfig.IsLoggingDebug7() ? dsyslog("SATIP: " x) : void() ) -#define debug8(x...) void( SatipConfig.IsLoggingDebug8() ? dsyslog("SATIP: " x) : void() ) +#define debug1(x...) void( SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug1) ? dsyslog("SATIP1: " x) : void() ) +#define debug2(x...) void( SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug2) ? dsyslog("SATIP2: " x) : void() ) +#define debug3(x...) void( SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug3) ? dsyslog("SATIP3: " x) : void() ) +#define debug4(x...) void( SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug4) ? dsyslog("SATIP4: " x) : void() ) +#define debug5(x...) void( SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug5) ? dsyslog("SATIP5: " x) : void() ) +#define debug6(x...) void( SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug6) ? dsyslog("SATIP6: " x) : void() ) +#define debug7(x...) void( SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug7) ? dsyslog("SATIP7: " x) : void() ) +#define debug8(x...) void( SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug8) ? dsyslog("SATIP8: " x) : void() ) #endif // __SATIP_LOG_H diff --git a/rtsp.c b/rtsp.c index 1158c42..eea5521 100644 --- a/rtsp.c +++ b/rtsp.c @@ -21,7 +21,7 @@ cSatipRtsp::cSatipRtsp(cSatipTunerIf &tunerP) CURLcode res = CURLE_OK; // Verbose output - if (SatipConfig.IsLoggingDebug2()) { + if (SatipConfig.IsLoggingMode(cSatipConfig::eLoggingModeDebug2)) { SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_VERBOSE, 1L); SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGFUNCTION, cSatipRtsp::DebugCallback); SATIP_CURL_EASY_SETOPT(handleM, CURLOPT_DEBUGDATA, this); diff --git a/satip.c b/satip.c index 770c46a..808ac37 100644 --- a/satip.c +++ b/satip.c @@ -103,7 +103,7 @@ bool cPluginSatip::ProcessArgs(int argc, char *argv[]) deviceCountM = strtol(optarg, NULL, 0); break; case 'l': - SatipConfig.SetLogging(strtol(optarg, NULL, 0)); + SatipConfig.SetLoggingMode(strtol(optarg, NULL, 0)); break; case 's': ParseServer(optarg); @@ -405,8 +405,8 @@ cString cPluginSatip::SVDRPCommand(const char *commandP, const char *optionP, in } else if (strcasecmp(commandP, "LOGG") == 0) { if (optionP && *optionP) - SatipConfig.SetLogging(strtol(optionP, NULL, 0)); - return cString::sprintf("SAT>IP logging: 0x%02X\n", SatipConfig.GetLogging()); + SatipConfig.SetLoggingMode(strtol(optionP, NULL, 0)); + return cString::sprintf("SAT>IP logging: 0x%02X\n", SatipConfig.GetLoggingMode()); } return NULL;