From e59911a1f65af17fd71f9dc1b4007df037052eb2 Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sat, 17 Oct 2009 16:44:02 +0000 Subject: [PATCH] Network logging --- command.cc | 18 ++++++++++++++++++ log.cc | 30 +++++++++++++++++++++++++++--- log.h | 7 +++++++ vdr.cc | 14 ++++++++++++++ vdr.h | 3 +++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/command.cc b/command.cc index 34f56e0..a4f7ae6 100644 --- a/command.cc +++ b/command.cc @@ -507,6 +507,7 @@ void Command::doStandby() boxstack->update(wallpaper); VDR::getInstance()->configSave("General", "Last Power State", "Off"); + logger->netLogOff(); VDR::getInstance()->disconnect(); Led::getInstance()->off(); isStandby = 1; @@ -547,6 +548,7 @@ void Command::doFromTheTop(bool which) } else { + logger->netLogOff(); VDR::getInstance()->disconnect(); boxstack->removeAll(); boxstack->update(wallpaper); @@ -565,6 +567,7 @@ void Command::doFromTheTop(bool which) void Command::doReboot() { + logger->netLogOff(); VDR::getInstance()->disconnect(); // just kill it... logger->log("Command", Log::NOTICE, "Reboot"); @@ -575,6 +578,7 @@ void Command::doReboot() void Command::connectionLost() { + logger->netLogOff(); Message* m = new Message(); // break into master mutex m->message = Message::CONNECTION_LOST; m->to = this; @@ -624,6 +628,20 @@ void Command::doJustConnected(VConnect* vconnect) VDR* vdr = VDR::getInstance(); char* config; + // See if we're supposed to do network logging + config = vdr->configLoad("Advanced", "Network logging"); + if (config && !STRCASECMP(config, "On")) + { + logger->log("Command", Log::INFO, "Turning on network logging"); + logger->netLogOn(); + } + else + { + logger->netLogOn(); + logger->log("Command", Log::INFO, "Turned off network logging"); + } + if (config) delete[] config; + // See if config says to override video format (PAL/NTSC) config = vdr->configLoad("General", "Override Video Format"); if (config) diff --git a/log.cc b/log.cc index 89b6dce..3aff96c 100644 --- a/log.cc +++ b/log.cc @@ -21,6 +21,8 @@ #include "log.h" +#include "vdr.h" + Log* Log::instance = NULL; Log::Log() @@ -30,6 +32,7 @@ Log::Log() logfile = NULL; initted = 0; logLevel = 0; + netLog = false; } Log::~Log() @@ -91,7 +94,7 @@ int Log::log(char *fromModule, int level, char* message, ...) { if (!instance || !logfile) return 0; - if (!enabled) return 1; + if (!enabled && !netLog) return 1; if (level > logLevel) return 1; char buffer[151]; @@ -146,9 +149,15 @@ int Log::log(char *fromModule, int level, char* message, ...) buffer[149] = '\n'; buffer[150] = '\0'; } + + int success = 1; + if (enabled) + { + success = fputs(buffer, logfile); + fflush(NULL); + } - int success = fputs(buffer, logfile); - fflush(NULL); + if (netLog) vdr->networkLog(buffer); if (success != EOF) return 1; @@ -162,3 +171,18 @@ int Log::status() if (instance && logfile) return 1; else return 0; } + +void Log::netLogOn() +{ + vdr = VDR::getInstance(); + netLog = true; + log("Log", Log::DEBUG, "Network logging started"); +} + +void Log::netLogOff() +{ + netLog = false; + vdr = NULL; +} + + diff --git a/log.h b/log.h index 3556883..5e5e11e 100644 --- a/log.h +++ b/log.h @@ -36,6 +36,8 @@ #include #include "defines.h" +class VDR; + class Log { public: @@ -49,6 +51,8 @@ class Log int status(); void upLogLevel(); void downLogLevel(); + void netLogOn(); + void netLogOff(); const static int CRAZY = 0; // mad crazy things that should never happen const static int EMERG = 1; // human assist required NOW @@ -67,6 +71,9 @@ class Log int enabled; FILE *logfile; + + bool netLog; + VDR* vdr; }; #endif diff --git a/vdr.cc b/vdr.cc index 5bd4fdd..c28d41e 100644 --- a/vdr.cc +++ b/vdr.cc @@ -623,6 +623,20 @@ int VDR::doLogin() return 1; } +bool VDR::networkLog(const char* logString) +{ + if (!connected) return false; + int stringLength = strlen(logString); + int packetLength = stringLength + 8; + char buffer[packetLength + 1]; + *(ULONG*)&buffer[0] = htonl(CHANNEL_NETLOG); + *(ULONG*)&buffer[4] = htonl(stringLength); + strcpy(&buffer[8], logString); + + if ((ULONG)tcp->sendData(buffer, packetLength) != packetLength) return false; + return true; +} + bool VDR::getRecordingsList(RecMan* recman) { VDR_RequestPacket vrp; diff --git a/vdr.h b/vdr.h index 8bed05e..c3ff0f1 100644 --- a/vdr.h +++ b/vdr.h @@ -118,6 +118,7 @@ class VDR : public Thread_TYPE, public EventDispatcher, public MediaProvider const static ULONG CHANNEL_REQUEST_RESPONSE = 1; const static ULONG CHANNEL_STREAM = 2; const static ULONG CHANNEL_KEEPALIVE = 3; + const static ULONG CHANNEL_NETLOG = 4; VDR(); ~VDR(); @@ -178,6 +179,8 @@ class VDR : public Thread_TYPE, public EventDispatcher, public MediaProvider char* configLoad(const char* section, const char* key); ULONG setEventTimer(char* timerString); RecTimerList* getRecTimersList(); + bool networkLog(const char* buffer); + /** * the MediaProvider functions * -- 2.39.5