some more fixes

This commit is contained in:
louis 2014-05-09 16:53:56 +02:00
parent 5d7fb01f67
commit 31f55fb489
12 changed files with 369 additions and 316 deletions

View File

@ -14,7 +14,9 @@ Version 0.1.0
- fixed bug that scraped events are not displayed randomly - fixed bug that scraped events are not displayed randomly
Version 0.1.1 Version 0.1.1
- ...
Version 0.1.2
- update of db api - update of db api
- prepare statements only once - prepare statements only once
- added statement statistic - added statement statistic
@ -23,5 +25,3 @@ Version 0.1.1
- added path detection for libmysql - added path detection for libmysql
- fixed epgd state detection - fixed epgd state detection
- added cppcheck to Makefile - added cppcheck to Makefile
Version 0.1.2

View File

@ -4,10 +4,11 @@
# $Id$ # $Id$
# External image lib to use: imagemagick, graphicsmagick # External image lib to use: imagemagick, graphicsmagick
IMAGELIB = imagemagick IMAGELIB = imagemagick
PLUGIN = scraper2vdr PLUGIN = scraper2vdr
HLIB = -L./lib -lhorchi HLIB = -L./lib -lhorchi
### The version number of this plugin (taken from the main source file): ### The version number of this plugin (taken from the main source file):
@ -36,7 +37,7 @@ APIVERSION = $(call PKGCFG,apiversion)
-include $(PLGCFG) -include $(PLGCFG)
LIBS = $(HLIB) $(shell mysql_config --libs_r) -luuid LIBS = $(HLIB) $(shell mysql_config --libs_r) -luuid -lcrypto
### The name of the distribution archive: ### The name of the distribution archive:

View File

@ -32,7 +32,7 @@ CFLAGS += -fPIC -Wreturn-type -Wall -Wno-parentheses -Wformat -pedantic -Wunused
CFLAGS += $(shell mysql_config --include) CFLAGS += $(shell mysql_config --include)
DEFINES = -DPLGDIR='"."' -DUSEUUID -DUSEMD5 DEFINES = -DPLGDIR='"."' -DUSEUUID -DUSEMD5 -USELIBXML
all: lib $(TEST) $(DEMO) all: lib $(TEST) $(DEMO)
lib: $(LIBTARGET).a lib: $(LIBTARGET).a

View File

@ -25,21 +25,20 @@
# include <archive_entry.h> # include <archive_entry.h>
#endif #endif
#ifdef VDR_PLUGIN
# include <vdr/thread.h>
#endif
#include "common.h" #include "common.h"
#include "config.h" #include "config.h"
#ifdef VDR_PLUGIN cMyMutex logMutex;
cMutex logMutex;
#endif
//*************************************************************************** //***************************************************************************
// Debug // Debug
//*************************************************************************** //***************************************************************************
const char* getLogPrefix()
{
return logPrefix;
}
void tell(int eloquence, const char* format, ...) void tell(int eloquence, const char* format, ...)
{ {
if (EPG2VDRConfig.loglevel < eloquence) if (EPG2VDRConfig.loglevel < eloquence)
@ -49,15 +48,12 @@ void tell(int eloquence, const char* format, ...)
char t[sizeBuffer+100]; *t = 0; char t[sizeBuffer+100]; *t = 0;
va_list ap; va_list ap;
#ifdef VDR_PLUGIN logMutex.Lock();
cMutexLock lock(&logMutex);
#endif
va_start(ap, format); va_start(ap, format);
#ifdef VDR_PLUGIN if (getLogPrefix())
snprintf(t, sizeBuffer, LOG_PREFIX); snprintf(t, sizeBuffer, "%s", getLogPrefix());
#endif
vsnprintf(t+strlen(t), sizeBuffer-strlen(t), format, ap); vsnprintf(t+strlen(t), sizeBuffer-strlen(t), format, ap);
@ -75,11 +71,12 @@ void tell(int eloquence, const char* format, ...)
tp.tv_usec / 1000); tp.tv_usec / 1000);
printf("%s %s\n", buf, t); printf("%s %s\n", buf, t);
} }
else else
syslog(LOG_ERR, "%s", t); syslog(LOG_ERR, "%s", t);
logMutex.Unlock();
va_end(ap); va_end(ap);
} }
@ -959,12 +956,103 @@ int unzip(const char* file, const char* filter, char*& buffer, int& size, char*
#endif #endif
//*************************************************************************** //***************************************************************************
// Class LogDuration // cMyMutex
//*************************************************************************** //***************************************************************************
#ifdef VDR_PLUGIN cMyMutex::cMyMutex (void)
{
locked = 0;
pthread_mutexattr_t attr;
pthread_mutexattr_init(&attr);
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK_NP);
pthread_mutex_init(&mutex, &attr);
}
# include <vdr/plugin.h> cMyMutex::~cMyMutex()
{
pthread_mutex_destroy(&mutex);
}
void cMyMutex::Lock(void)
{
pthread_mutex_lock(&mutex);
locked++;
}
void cMyMutex::Unlock(void)
{
if (!--locked)
pthread_mutex_unlock(&mutex);
}
//***************************************************************************
// cMyTimeMs
//***************************************************************************
cMyTimeMs::cMyTimeMs(int Ms)
{
if (Ms >= 0)
Set(Ms);
else
begin = 0;
}
uint64_t cMyTimeMs::Now(void)
{
#define MIN_RESOLUTION 5 // ms
static bool initialized = false;
static bool monotonic = false;
struct timespec tp;
if (!initialized) {
// check if monotonic timer is available and provides enough accurate resolution:
if (clock_getres(CLOCK_MONOTONIC, &tp) == 0) {
// long Resolution = tp.tv_nsec;
// require a minimum resolution:
if (tp.tv_sec == 0 && tp.tv_nsec <= MIN_RESOLUTION * 1000000) {
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
monotonic = true;
}
else
tell(0, "cMyTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
}
else
tell(0, "cMyTimeMs: not using monotonic clock - resolution is too bad (%ld s %ld ns)", tp.tv_sec, tp.tv_nsec);
}
else
tell(0, "cMyTimeMs: clock_getres(CLOCK_MONOTONIC) failed");
initialized = true;
}
if (monotonic) {
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
return (uint64_t(tp.tv_sec)) * 1000 + tp.tv_nsec / 1000000;
tell(0, "cMyTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
monotonic = false;
// fall back to gettimeofday()
}
struct timeval t;
if (gettimeofday(&t, NULL) == 0)
return (uint64_t(t.tv_sec)) * 1000 + t.tv_usec / 1000;
return 0;
}
void cMyTimeMs::Set(int Ms)
{
begin = Now() + Ms;
}
bool cMyTimeMs::TimedOut(void)
{
return Now() >= begin;
}
uint64_t cMyTimeMs::Elapsed(void)
{
return Now() - begin;
}
//***************************************************************************
// Class LogDuration
//***************************************************************************
LogDuration::LogDuration(const char* aMessage, int aLogLevel) LogDuration::LogDuration(const char* aMessage, int aLogLevel)
{ {
@ -973,23 +1061,21 @@ LogDuration::LogDuration(const char* aMessage, int aLogLevel)
// at last ! // at last !
durationStart = cTimeMs::Now(); durationStart = cMyTimeMs::Now();
} }
LogDuration::~LogDuration() LogDuration::~LogDuration()
{ {
tell(logLevel, "duration '%s' was (%ldms)", tell(logLevel, "duration '%s' was (%ldms)",
message, cTimeMs::Now() - durationStart); message, cMyTimeMs::Now() - durationStart);
} }
void LogDuration::show(const char* label) void LogDuration::show(const char* label)
{ {
tell(logLevel, "elapsed '%s' at '%s' was (%ldms)", tell(logLevel, "elapsed '%s' at '%s' was (%ldms)",
message, label, cTimeMs::Now() - durationStart); message, label, cMyTimeMs::Now() - durationStart);
} }
#endif
//*************************************************************************** //***************************************************************************
// Get Unique ID // Get Unique ID
//*************************************************************************** //***************************************************************************

View File

@ -15,9 +15,10 @@
#include <openssl/md5.h> // MD5_* #include <openssl/md5.h> // MD5_*
#ifdef VDR_PLUGIN //#ifdef VDR_PLUGIN
# include <vdr/tools.h> //# include <vdr/tools.h>
#endif //# include <vdr/thread.h>
//#endif
#ifdef USELIBXML #ifdef USELIBXML
# include <libxslt/transform.h> # include <libxslt/transform.h>
@ -29,10 +30,10 @@
// Misc // Misc
//*************************************************************************** //***************************************************************************
#ifndef VDR_PLUGIN // #ifndef VDR_PLUGIN
inline long min(long a, long b) { return a < b ? a : b; } inline long min(long a, long b) { return a < b ? a : b; }
inline long max(long a, long b) { return a > b ? a : b; } inline long max(long a, long b) { return a > b ? a : b; }
#endif // #endif
enum Misc enum Misc
{ {
@ -69,6 +70,9 @@ const char* toCase(Case cs, char* str);
// Tell // Tell
//*************************************************************************** //***************************************************************************
extern const char* logPrefix;
const char* getLogPrefix();
void __attribute__ ((format(printf, 2, 3))) tell(int eloquence, const char* format, ...); void __attribute__ ((format(printf, 2, 3))) tell(int eloquence, const char* format, ...);
//*************************************************************************** //***************************************************************************
@ -220,7 +224,41 @@ int unzip(const char* file, const char* filter, char*& buffer,
int& size, char* entryName); int& size, char* entryName);
#endif #endif
#ifdef VDR_PLUGIN //***************************************************************************
// cMyMutex
//***************************************************************************
class cMyMutex
{
friend class cCondVar;
private:
pthread_mutex_t mutex;
int locked;
public:
cMyMutex(void);
~cMyMutex();
void Lock(void);
void Unlock(void);
};
//***************************************************************************
// cMyTimeMs
//***************************************************************************
class cMyTimeMs
{
private:
uint64_t begin;
public:
cMyTimeMs(int Ms = 0);
static uint64_t Now(void);
void Set(int Ms = 0);
bool TimedOut(void);
uint64_t Elapsed(void);
};
//*************************************************************************** //***************************************************************************
// Log Duration // Log Duration
@ -241,7 +279,6 @@ class LogDuration
uint64_t durationStart; uint64_t durationStart;
int logLevel; int logLevel;
}; };
#endif
//*************************************************************************** //***************************************************************************
#endif //___COMMON_H #endif //___COMMON_H

View File

@ -39,10 +39,13 @@ cEPG2VDRConfig::cEPG2VDRConfig(void)
seriesPort = 2006; seriesPort = 2006;
storeSeriesToFs = no; storeSeriesToFs = no;
#ifdef VDR_PLUGIN // for VDR_PLUGIN
activeOnEpgd = no; activeOnEpgd = no;
scheduleBoot = no; scheduleBoot = no;
#else
// for epgd
sstrcpy(cachePath, "/var/cache/epgd", sizeof(cachePath)); sstrcpy(cachePath, "/var/cache/epgd", sizeof(cachePath));
sstrcpy(httpPath, "/var/epgd/www", sizeof(httpPath)); sstrcpy(httpPath, "/var/epgd/www", sizeof(httpPath));
sstrcpy(pluginPath, PLGDIR, sizeof(pluginPath)); sstrcpy(pluginPath, PLGDIR, sizeof(pluginPath));
@ -51,7 +54,8 @@ cEPG2VDRConfig::cEPG2VDRConfig(void)
updateThreshold = 200; updateThreshold = 200;
maintanance = no; maintanance = no;
httpPort = 9999; httpPort = 9999;
#endif
//
sstrcpy(dbHost, "localhost", sizeof(dbHost)); sstrcpy(dbHost, "localhost", sizeof(dbHost));
dbPort = 3306; dbPort = 3306;

View File

@ -42,10 +42,13 @@ struct cEPG2VDRConfig
int seriesPort; int seriesPort;
int storeSeriesToFs; int storeSeriesToFs;
#ifdef VDR_PLUGIN // for VDR_PLUGIN
int activeOnEpgd; int activeOnEpgd;
int scheduleBoot; int scheduleBoot;
#else
// for epgd
char cachePath[256+TB]; char cachePath[256+TB];
char httpPath[256+TB]; char httpPath[256+TB];
char pluginPath[256+TB]; char pluginPath[256+TB];
@ -54,7 +57,8 @@ struct cEPG2VDRConfig
int updateThreshold; int updateThreshold;
int maintanance; int maintanance;
int httpPort; int httpPort;
#endif
//
char dbHost[100+TB]; char dbHost[100+TB];
int dbPort; int dbPort;

View File

@ -7,6 +7,7 @@
#include "tabledef.h" #include "tabledef.h"
cDbConnection* connection = 0; cDbConnection* connection = 0;
const char* logPrefix = "demo";
//*************************************************************************** //***************************************************************************
// Init Connection // Init Connection

View File

@ -13,25 +13,7 @@
#include "dbdict.h" #include "dbdict.h"
cDbConnection* connection = 0; cDbConnection* connection = 0;
const char* logPrefix = "test";
//***************************************************************************
//
//***************************************************************************
class cTimeMs
{
private:
uint64_t begin;
public:
cTimeMs(int Ms = 0);
static uint64_t Now(void);
void Set(int Ms = 0);
bool TimedOut(void);
uint64_t Elapsed(void);
};
//*************************************************************************** //***************************************************************************
// Init Connection // Init Connection
@ -273,69 +255,6 @@ void chkStatement3()
delete mapDb; delete mapDb;
} }
// --- cTimeMs ---------------------------------------------------------------
cTimeMs::cTimeMs(int Ms)
{
if (Ms >= 0)
Set(Ms);
else
begin = 0;
}
uint64_t cTimeMs::Now(void)
{
#define MIN_RESOLUTION 5 // ms
static bool initialized = false;
static bool monotonic = false;
struct timespec tp;
if (!initialized) {
// check if monotonic timer is available and provides enough accurate resolution:
if (clock_getres(CLOCK_MONOTONIC, &tp) == 0) {
// long Resolution = tp.tv_nsec;
// require a minimum resolution:
if (tp.tv_sec == 0 && tp.tv_nsec <= MIN_RESOLUTION * 1000000) {
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
monotonic = true;
}
else
tell(0, "cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
}
else
tell(0, "cTimeMs: not using monotonic clock - resolution is too bad (%ld s %ld ns)", tp.tv_sec, tp.tv_nsec);
}
else
tell(0, "cTimeMs: clock_getres(CLOCK_MONOTONIC) failed");
initialized = true;
}
if (monotonic) {
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
return (uint64_t(tp.tv_sec)) * 1000 + tp.tv_nsec / 1000000;
tell(0, "cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
monotonic = false;
// fall back to gettimeofday()
}
struct timeval t;
if (gettimeofday(&t, NULL) == 0)
return (uint64_t(t.tv_sec)) * 1000 + t.tv_usec / 1000;
return 0;
}
void cTimeMs::Set(int Ms)
{
begin = Now() + Ms;
}
bool cTimeMs::TimedOut(void)
{
return Now() >= begin;
}
uint64_t cTimeMs::Elapsed(void)
{
return Now() - begin;
}
//*************************************************************************** //***************************************************************************
// //
//*************************************************************************** //***************************************************************************

View File

@ -7,6 +7,7 @@
*/ */
#include "scraper2vdr.h" #include "scraper2vdr.h"
const char* logPrefix = LOG_PREFIX;
#if defined (APIVERSNUM) && (APIVERSNUM < 10600) #if defined (APIVERSNUM) && (APIVERSNUM < 10600)
# error VDR API versions < 1.6.0 are not supported ! # error VDR API versions < 1.6.0 are not supported !

View File

@ -354,7 +354,7 @@ void cScrapManager::DumpMovies(void) {
} }
void cScrapManager::DumpRecordings(void) { void cScrapManager::DumpRecordings(void) {
tell(0, "%d recordings in memory:", (int)recordings.size()); tell(0, "%ld recordings in memory:", recordings.size());
for (map<sRecordingsKey, sEventsValue>::iterator it = recordings.begin(); it != recordings.end(); it++) { for (map<sRecordingsKey, sEventsValue>::iterator it = recordings.begin(); it != recordings.end(); it++) {
sRecordingsKey key = it->first; sRecordingsKey key = it->first;
sEventsValue val = it->second; sEventsValue val = it->second;