eitd/xmlutil.cpp: add support to read epg from directory without index.xml

Origin commit data
------------------
Branch: ni/coolstream
Commit: fc52af49da
Author: [CST] Focus <focus.cst@gmail.com>
Date: 2015-06-01 (Mon, 01 Jun 2015)


------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
[CST] Focus
2015-06-01 15:35:20 +03:00
parent fc163efa6d
commit 075f9c4536

View File

@@ -29,6 +29,7 @@
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <dirent.h>
#include <string> #include <string>
#include <system/helpers.h> #include <system/helpers.h>
@@ -441,6 +442,31 @@ bool readEventsFromFile(std::string &epgname, int &ev_count)
return true; return true;
} }
static int my_filter(const struct dirent *entry)
{
int len = strlen(entry->d_name);
if (len > 3 && entry->d_name[len-3] == 'x' && entry->d_name[len-2] == 'm' && entry->d_name[len-1] == 'l')
return 1;
return 0;
}
bool readEventsFromDir(std::string &epgdir, int &ev_count)
{
struct dirent **namelist;
int n = scandir(epgdir.c_str(), &namelist, my_filter, NULL);
printf("[sectionsd] Reading Information from directory %s, file count %d\n", epgdir.c_str(), n);
if (n <= 0)
return false;
for (int i = 0; i < n; i++) {
std::string epgname = epgdir + namelist[i]->d_name;
readEventsFromFile(epgname, ev_count);
free(namelist[i]);
}
free(namelist);
return true;
}
void *insertEventsfromFile(void * data) void *insertEventsfromFile(void * data)
{ {
set_threadname(__func__); set_threadname(__func__);
@@ -450,16 +476,23 @@ void *insertEventsfromFile(void * data)
std::string epgname; std::string epgname;
xmlNodePtr eventfile; xmlNodePtr eventfile;
int ev_count = 0; int ev_count = 0;
char * epg_dir = (char *) data; if (!data) {
indexname = std::string(epg_dir) + "index.xml";
xmlDocPtr index_parser = parseXmlFile(indexname.c_str());
if (index_parser == NULL) {
reader_ready = true; reader_ready = true;
pthread_exit(NULL); pthread_exit(NULL);
} }
std::string epg_dir = (char *) data;
indexname = epg_dir + "index.xml";
time_t now = time_monotonic_ms(); time_t now = time_monotonic_ms();
xmlDocPtr index_parser = parseXmlFile(indexname.c_str());
if (index_parser == NULL) {
readEventsFromDir(epg_dir, ev_count);
printf("[sectionsd] Reading Information finished after %ld milliseconds (%d events)\n",
time_monotonic_ms()-now, ev_count);
reader_ready = true;
pthread_exit(NULL);
}
printdate_ms(stdout); printdate_ms(stdout);
printf("[sectionsd] Reading Information from file %s:\n", indexname.c_str()); printf("[sectionsd] Reading Information from file %s:\n", indexname.c_str());