summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Make.config5
-rw-r--r--common/setup.cpp2
-rw-r--r--common/tools.cpp20
-rw-r--r--include/tools.h17
-rw-r--r--media/mediaManager.cpp4
-rw-r--r--media/pluginManager.cpp1
-rw-r--r--server/contentDirectory.cpp2
-rw-r--r--server/server.cpp10
-rw-r--r--server/webserver.cpp3
9 files changed, 54 insertions, 10 deletions
diff --git a/Make.config b/Make.config
index 52ed6a6..b8b635e 100644
--- a/Make.config
+++ b/Make.config
@@ -48,9 +48,12 @@ APIVERSION = $(shell sed -ne '/define APIVERSION/s/^.*"\(.*\)".*$$/\1/p' $(VDRDI
INCLUDES += -I$(VDRDIR)/include
+ifdef DEBUG
+DEFINES = -DDEBUG
+endif
+
DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"'
DEFINES += -DPLUGINDIR=\"$(VDRPLUGINLIBDIR)\"
-
# export to subplugins makefiles:
export PRESTRIP VERSION APIVERSION INCLUDES SHAREDDEFINES SHAREDLIBS CXX CXXFLAGS VDRDIR VDRINCDIR LIBDIR TMPDIR VDRPLUGINLIBDIR
diff --git a/common/setup.cpp b/common/setup.cpp
index b559aee..3d2965a 100644
--- a/common/setup.cpp
+++ b/common/setup.cpp
@@ -184,7 +184,7 @@ bool cMenuSetupUPnP::SetupParse(const char *name, const char *value, upnp::cConf
{
if(parsedArgs.find(name) != std::string::npos){
- dsyslog("UPnP\tSkipping %s=%s, was overridden in command line.", name, value);
+ LOG(1, "Skipping %s=%s, was overridden in command line.", name, value);
return true;
}
diff --git a/common/tools.cpp b/common/tools.cpp
index 1e40ccc..797dbfe 100644
--- a/common/tools.cpp
+++ b/common/tools.cpp
@@ -17,6 +17,26 @@
using namespace std;
+#ifdef DEBUG
+
+#define MESSAGE_SIZE 256
+namespace upnp {
+ void log_debug_msg(const char* file, const char* func, int line, int level, const char* msg, ...){
+ char* lvlenv = getenv("UPNP_DEBUG_LEVEL");
+ int debug_level = lvlenv ? atoi(lvlenv) : 0;
+ if(level && debug_level >= level){
+ va_list ap;
+ char message[MESSAGE_SIZE];
+
+ snprintf(message, sizeof(message), "[%s:%d] %s - %s", file, line, func, msg);
+ va_start(ap, msg);
+ vsyslog(LOG_NOTICE, message, ap);
+ va_end(ap);
+ }
+ }
+}
+#endif
+
namespace upnp {
namespace tools {
diff --git a/include/tools.h b/include/tools.h
index 966040d..e640da5 100644
--- a/include/tools.h
+++ b/include/tools.h
@@ -32,6 +32,23 @@ using namespace std;
#define _unused(x) ((void)x)
+#ifdef DEBUG
+
+#if __STDC_VERSION__ < 199901L
+ #if __GNUC__ >= 2
+ #define __func__ __PRETTY_FUNCTION__
+ #else
+ #define __func__ "<unknown>"
+ #endif
+#endif
+
+#define LOG(level, msg...) upnp::log_debug_msg(__FILE__, __func__, __LINE__, level, msg);
+
+namespace upnp {
+ void log_debug_msg(const char* file, const char* func, int line, int level, const char* msg, ...) __attribute__ ((format (printf, 5, 6)));
+}
+#endif
+
namespace upnp {
typedef std::list<std::string> StringList;
diff --git a/media/mediaManager.cpp b/media/mediaManager.cpp
index ce336a4..a15bb1e 100644
--- a/media/mediaManager.cpp
+++ b/media/mediaManager.cpp
@@ -479,7 +479,7 @@ bool cMediaManager::Initialise(){
connection = tntdb::connect(ss.str());
- dsyslog("UPnP\tPreparing database structure...");
+ LOG(2, "Preparing database structure...");
if(!CheckIntegrity()){
try {
@@ -660,7 +660,7 @@ bool cMediaManager::CheckIntegrity(){
}
cResourceStreamer* cMediaManager::GetResourceStreamer(const string& objectID, int resourceID){
- dsyslog("UPnP\tTry to stream resource[%d] of objectID %s", resourceID, objectID.c_str());
+ LOG(5, "Try to stream resource[%d] of objectID %s", resourceID, objectID.c_str());
stringstream resourceSQL;
diff --git a/media/pluginManager.cpp b/media/pluginManager.cpp
index 67b24c6..32a2436 100644
--- a/media/pluginManager.cpp
+++ b/media/pluginManager.cpp
@@ -426,6 +426,7 @@ bool upnp::cPluginManager::LoadPlugins(){
providerFactory[provider->ProvidesSchema()] = (ResourceProviderFuncPtr)dll->GetFunc();
providers.push_back( provider );
provider->SetDescription("%s", provider->ProvidesSchema().c_str());
+ LOG(3, "Started provider: %s", provider->ProvidesSchema().c_str());
provider->Start();
} else {
boost::shared_ptr<cMediaProfiler> profiler((cMediaProfiler*)(dll->GetFunc()()));
diff --git a/server/contentDirectory.cpp b/server/contentDirectory.cpp
index 9b30c5f..45fecff 100644
--- a/server/contentDirectory.cpp
+++ b/server/contentDirectory.cpp
@@ -76,7 +76,7 @@ int cContentDirectory::Subscribe(Upnp_Subscription_Request* Request){
void cContentDirectory::Action(){
int Retry = 5;
- dsyslog("UPnP\tStart Content directory thread");
+ LOG(5, "Start Content directory thread");
while(this->Running()){
IXML_Document* PropertySet = NULL;
diff --git a/server/server.cpp b/server/server.cpp
index 3780d7a..2bac18a 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -192,7 +192,7 @@ bool cMediaServer::Initialize(){
int ret = 0;
- isyslog("UPnP\tInitializing UPnP media server on %s:%d", address.c_str(), port);
+ LOG(1, "Initializing UPnP media server on %s:%d", address.c_str(), port);
ret = UpnpInit(address.c_str(), mCurrentConfiguration.port);
@@ -201,6 +201,8 @@ bool cMediaServer::Initialize(){
return false;
}
+ isyslog("UPnP\tInitialized UPnP media server on %s:%d", UpnpGetServerIpAddress(), UpnpGetServerPort());
+
mWebserver = new cWebserver(GetServerIPAddress());
mMediaManager = new cMediaManager();
@@ -295,7 +297,7 @@ cMediaServer::serviceMap& cMediaServer::GetServices(){
void cMediaServer::RegisterService(cUPnPService* service){
if(service != NULL){
- dsyslog("UPnP\tRegistered service: %s", service->GetServiceDescription().serviceType.c_str());
+ LOG(1, "Registered service: %s", service->GetServiceDescription().serviceType.c_str());
GetServices()[service->GetServiceDescription().serviceID] = service;
}
}
@@ -318,7 +320,7 @@ int cMediaServer::ActionCallback(Upnp_EventType eventtype, void *event, void *co
case UPNP_CONTROL_ACTION_REQUEST:
actionRequest = (Upnp_Action_Request*) event;
- dsyslog("UPnP\tAction request: %s", actionRequest->ActionName);
+ LOG(3, "Action request: %s", actionRequest->ActionName);
if(!mediaServer->CheckDeviceUUID(actionRequest->DevUDN)){
esyslog("UPnP\tUPnP Callback - action request not for this device");
@@ -337,7 +339,7 @@ int cMediaServer::ActionCallback(Upnp_EventType eventtype, void *event, void *co
case UPNP_EVENT_SUBSCRIPTION_REQUEST:
eventRequest = (Upnp_Subscription_Request*) event;
- dsyslog("UPnP\tSubscription request from: %s", eventRequest->ServiceId);
+ LOG(3, "Subscription request from: %s", eventRequest->ServiceId);
if(!mediaServer->CheckDeviceUUID(eventRequest->UDN)){
esyslog("UPnP\tUPnP Callback - event request not for this device");
diff --git a/server/webserver.cpp b/server/webserver.cpp
index c4f39d8..0c6d1b6 100644
--- a/server/webserver.cpp
+++ b/server/webserver.cpp
@@ -6,6 +6,7 @@
*/
#include "../include/webserver.h"
+#include "../include/tools.h"
#include "../upnp.h"
#include <signal.h>
#include <sstream>
@@ -172,7 +173,7 @@ void cWebserver::cWSThread::Action(){
try {
if(Running()){
mWebserver.mApplication.run();
- dsyslog("UPnP\tStarted web server thread.");
+ LOG(3, "Started web server thread.");
}
} catch (const std::exception& e){
esyslog("UPnP\tError while starting web server: %s", e.what());