summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJochen Dolze <vdr@dolze.de>2012-05-29 23:48:01 +0200
committerJochen Dolze <vdr@dolze.de>2012-05-29 23:48:01 +0200
commit68eae31a0fca0a2f2d218a5cf41ec668f08530f6 (patch)
tree2f41441581796d7896d56584e4632d907c4fad94
parent997e0905ee1c042edb7d624d429281b7c6f76455 (diff)
downloadvdr-plugin-xmltv2vdr-68eae31a0fca0a2f2d218a5cf41ec668f08530f6.tar.gz
vdr-plugin-xmltv2vdr-68eae31a0fca0a2f2d218a5cf41ec668f08530f6.tar.bz2
Added start/stop of epgsearch searchtimer
-rw-r--r--source.cpp23
-rw-r--r--source.h7
-rw-r--r--xmltv2vdr.cpp91
-rw-r--r--xmltv2vdr.h13
4 files changed, 134 insertions, 0 deletions
diff --git a/source.cpp b/source.cpp
index d8b5d63..668d9d9 100644
--- a/source.cpp
+++ b/source.cpp
@@ -51,6 +51,15 @@ void cEPGExecutor::Action()
esyslog("failed to set ioprio to 3,7");
}
+ cSVDRPMsg msg;
+ if (sources->EPGSearchExists())
+ {
+ if (!msg.Send("SETS OFF"))
+ {
+ esyslog("failed to stop epgsearch searchthread");
+ }
+ }
+
for (cEPGSource *epgs=sources->First(); epgs; epgs=sources->Next(epgs))
{
if (epgs->RunItNow(forcedownload))
@@ -102,6 +111,14 @@ void cEPGExecutor::Action()
}
forceimportsrc=-1;
forcedownload=false;
+
+ if (sources->EPGSearchExists())
+ {
+ if (!msg.Send("SETS ON"))
+ {
+ esyslog("failed to start epgsearch searchthread");
+ }
+ }
}
// -------------------------------------------------------------
@@ -789,6 +806,11 @@ void cEPGSource::Add2Log(struct tm *Tm, const char Prefix, const char *Line)
// -------------------------------------------------------------
+cEPGSources::cEPGSources()
+{
+ epgsearchexists=false;
+}
+
bool cEPGSources::Exists(const char* Name)
{
if (!Name) return false;
@@ -862,6 +884,7 @@ time_t cEPGSources::NextRunTime()
void cEPGSources::ReadIn(cGlobals *Global, const char *SourceOrder,
bool Reload)
{
+ epgsearchexists=Global->EPGSearchExists();
if (Reload) Remove();
DIR *dir=opendir(EPGSOURCES);
if (!dir) return;
diff --git a/source.h b/source.h
index 80ff92e..64ed651 100644
--- a/source.h
+++ b/source.h
@@ -169,7 +169,10 @@ public:
class cEPGSources : public cList<cEPGSource>
{
+private:
+ bool epgsearchexists;
public:
+ cEPGSources();
void ReadIn(cGlobals *Global, const char *SourceOrder,
bool Reload=false);
bool RunItNow();
@@ -179,6 +182,10 @@ public:
cEPGSource *GetSourceDB(const char *EpgFile);
int GetSourceIdx(const char *Name);
void Remove();
+ bool EPGSearchExists()
+ {
+ return epgsearchexists;
+ }
};
class cPluginXmltv2vdr;
diff --git a/xmltv2vdr.cpp b/xmltv2vdr.cpp
index 4ba7d6f..e79d428 100644
--- a/xmltv2vdr.cpp
+++ b/xmltv2vdr.cpp
@@ -16,6 +16,7 @@
#include <time.h>
#include <sys/types.h>
#include <pwd.h>
+#include <netdb.h>
#include "setup.h"
#include "xmltv2vdr.h"
@@ -127,6 +128,95 @@ void logger(cEPGSource *source, char logtype, const char* format, ...)
// -------------------------------------------------------------
+bool cSVDRPMsg::readreply(int fd)
+{
+ usleep(400000);
+ char c=' ';
+ do
+ {
+ struct pollfd fds;
+ fds.fd=fd;
+ fds.events=POLLIN;
+ fds.revents=0;
+ int ret=poll(&fds,1,600);
+
+ if (ret<=0) return false;
+ if (fds.revents!=POLLIN) return false;
+ if (read(fd,&c,1)<0) return false;
+ }
+ while (c!='\n');
+ return true;
+}
+
+bool cSVDRPMsg::Send(const char *format, ...)
+{
+ char *msg;
+ va_list ap;
+ va_start(ap, format);
+ if (vasprintf(&msg,format,ap)==-1) return false;
+ va_end(ap);
+
+ int port;
+ struct servent *serv=getservbyname("svdrp","tcp");
+ if (serv)
+ {
+ port=htons(serv->s_port);
+ }
+ else
+ {
+#if VDRVERSNUM < 10715
+ port=2001;
+#else
+ port=6419;
+#endif
+ }
+
+ struct sockaddr_in name;
+ name.sin_family = AF_INET;
+ name.sin_port = htons(port);
+ name.sin_addr.s_addr=inet_addr("127.0.0.1");
+ uint size = sizeof(name);
+
+ int sock;
+ sock=socket(PF_INET, SOCK_STREAM, 0);
+ if (sock<0) return false;
+
+ if (connect(sock, (struct sockaddr *)&name,size)!=0)
+ {
+ close(sock);
+ free(msg);
+ return false;
+ }
+
+ if (!readreply(sock))
+ {
+ close(sock);
+ free(msg);
+ return false;
+ }
+
+ ssize_t ret;
+ ret=write(sock,"PLUG epgsearch ",15);
+ if (ret!=(ssize_t)-1) ret=write(sock,msg,strlen(msg));
+ if (ret!=(ssize_t)-1) ret=write(sock,"\r\n",2);
+
+ if (!readreply(sock) || (ret==(ssize_t)-1))
+ {
+ close(sock);
+ free(msg);
+ return false;
+ }
+
+ ret=write(sock,"QUIT\r\n",6);
+
+ if (ret!=(ssize_t)-1) readreply(sock);
+ close(sock);
+ free(msg);
+ return true;
+}
+
+// -------------------------------------------------------------
+
cGlobals::cGlobals()
{
confdir=NULL;
@@ -135,6 +225,7 @@ cGlobals::cGlobals()
epcodeset=NULL;
imgdir=NULL;
codeset=NULL;
+ epgsearchexists=(cPluginManager::GetPlugin("epgsearch")!=NULL);
imgdelafter=30;
if (asprintf(&epgfile,"%s/epg.db",VideoDirectory)==-1) {};
diff --git a/xmltv2vdr.h b/xmltv2vdr.h
index a26c009..e140160 100644
--- a/xmltv2vdr.h
+++ b/xmltv2vdr.h
@@ -26,6 +26,14 @@ static const char *DESCRIPTION = trNOOP("Imports xmltv epg into vdr");
int ioprio_set(int which, int who, int ioprio);
+class cSVDRPMsg
+{
+private:
+ bool readreply(int fd);
+public:
+ bool Send(const char *format, ...);
+};
+
class cGlobals
{
private:
@@ -35,6 +43,7 @@ private:
char *epcodeset;
char *imgdir;
char *codeset;
+ bool epgsearchexists;
int imgdelafter;
cEPGMappings epgmappings;
cTEXTMappings textmappings;
@@ -99,6 +108,10 @@ public:
{
return imgdelafter;
}
+ bool EPGSearchExists()
+ {
+ return epgsearchexists;
+ }
};
#if VDRVERSNUM < 10726 && !EPGHANDLER