X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/abea0c85ea0e0f9e7197664b70753fbe5f110b8d..0d34f9703fc13e99c4d76a0ee539d58d39dded2d:/lib/dvb/db.cpp diff --git a/lib/dvb/db.cpp b/lib/dvb/db.cpp index 2665877a..65b42def 100644 --- a/lib/dvb/db.cpp +++ b/lib/dvb/db.cpp @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include #include @@ -34,26 +36,37 @@ RESULT eBouquet::moveService(const eServiceReference &ref, unsigned int pos) { if ( pos < 0 || pos >= m_services.size() ) return -1; + ++pos; list::iterator source=m_services.end(); list::iterator dest=m_services.end(); + bool forward = false; for (list::iterator it(m_services.begin()); it != m_services.end(); ++it) { - if (dest == m_services.end() && !pos--) + if (dest == m_services.end() && !--pos) dest = it; if (*it == ref) + { source = it; + forward = pos>0; + } if (dest != m_services.end() && source != m_services.end()) break; } if (dest == m_services.end() || source == m_services.end() || source == dest) return -1; - std::iter_swap(source,dest); + while (source != dest) + { + if (forward) + std::iter_swap(source++, source); + else + std::iter_swap(source--, source); + } return 0; } RESULT eBouquet::flushChanges() { - FILE *f=fopen(m_path.c_str(), "wt"); + FILE *f=fopen((CONFIGDIR"/enigma2/"+m_filename).c_str(), "w"); if (!f) return -1; if ( fprintf(f, "#NAME %s\r\n", m_bouquet_name.c_str()) < 0 ) @@ -90,7 +103,7 @@ RESULT eBouquet::flushChanges() return 0; err: fclose(f); - eDebug("couldn't write file %s", m_path.c_str()); + eDebug("couldn't write file %s", m_filename.c_str()); return -1; } @@ -119,7 +132,7 @@ void eDVBService::genSortName() makeUpper(m_service_name_sort); while ((!m_service_name_sort.empty()) && m_service_name_sort[0] == ' ') m_service_name_sort.erase(0, 1); - + /* put unnamed services at the end, not at the beginning. */ if (m_service_name_sort.empty()) m_service_name_sort = "\xFF"; @@ -128,7 +141,7 @@ void eDVBService::genSortName() RESULT eDVBService::getName(const eServiceReference &ref, std::string &name) { if (!ref.name.empty()) - name = ref.name; + name = ref.name; // use renamed service name.. else if (!m_service_name.empty()) name = m_service_name; else @@ -136,9 +149,24 @@ RESULT eDVBService::getName(const eServiceReference &ref, std::string &name) return 0; } -int eDVBService::getLength(const eServiceReference &ref) +RESULT eDVBService::getEvent(const eServiceReference &ref, ePtr &ptr, time_t start_time) { - return -1; + return eEPGCache::getInstance()->lookupEventTime(ref, start_time, ptr); +} + +bool eDVBService::isPlayable(const eServiceReference &ref, const eServiceReference &ignore) +{ + ePtr res_mgr; + if ( eDVBResourceManager::getInstance( res_mgr ) ) + eDebug("isPlayble... no res manager!!"); + else + { + eDVBChannelID chid, chid_ignore; + ((const eServiceReferenceDVB&)ref).getChannelID(chid); + ((const eServiceReferenceDVB&)ignore).getChannelID(chid_ignore); + return res_mgr->canAllocateChannel(chid, chid_ignore); + } + return false; } int eDVBService::checkFilter(const eServiceReferenceDVB &ref, const eDVBChannelQuery &query) @@ -201,9 +229,17 @@ DEFINE_REF(eDVBDB); void eDVBDB::load() { eDebug("---- opening lame channel db"); - FILE *f=fopen("lamedb", "rt"); + FILE *f=fopen(CONFIGDIR"/enigma2/lamedb", "rt"); if (!f) + { + struct stat s; + if ( !stat("lamedb", &s) ) + { + rename("lamedb", CONFIGDIR"/enigma2/lamedb" ); + load(); + } return; + } char line[256]; if ((!fgets(line, 256, f)) || strncmp(line, "eDVB services", 13)) { @@ -251,7 +287,8 @@ void eDVBDB::load() sat.symbol_rate = symbol_rate; sat.polarisation = polarisation; sat.fec = fec; - sat.orbital_position = orbital_position; + sat.orbital_position = + orbital_position < 0 ? orbital_position + 3600 : orbital_position; sat.inversion = inversion; feparm->setDVBS(sat); } else if (line[1]=='t') @@ -268,7 +305,7 @@ void eDVBDB::load() ter.guard_interval = guard_interval; ter.hierarchy = hierarchy; ter.inversion = inversion; - + feparm->setDVBT(ter); } else if (line[1]=='c') { @@ -316,7 +353,7 @@ void eDVBDB::load() s->m_service_name = line; s->genSortName(); - + fgets(line, 256, f); if (strlen(line)) line[strlen(line)-1]=0; @@ -370,7 +407,7 @@ void eDVBDB::load() void eDVBDB::save() { eDebug("---- saving lame channel db"); - FILE *f=fopen("lamedb", "wt"); + FILE *f=fopen(CONFIGDIR"/enigma2/lamedb", "w"); int channels=0, services=0; if (!f) eFatal("couldn't save lame channel db!"); @@ -390,7 +427,8 @@ void eDVBDB::save() { fprintf(f, "\ts %d:%d:%d:%d:%d:%d\n", sat.frequency, sat.symbol_rate, - sat.polarisation, sat.fec, sat.orbital_position, + sat.polarisation, sat.fec, + sat.orbital_position > 1800 ? sat.orbital_position - 3600 : sat.orbital_position, sat.inversion); } if (!ch.m_frontendParameters->getDVBT(ter)) @@ -453,15 +491,24 @@ void eDVBDB::loadBouquet(const char *path) return; } eBouquet &bouquet = m_bouquets[bouquet_name]; - bouquet.m_path = path; + bouquet.m_filename = bouquet_name; std::list &list = bouquet.m_services; list.clear(); - eDebug("loading bouquet... %s", path); - FILE *fp=fopen(path, "rt"); + std::string p = CONFIGDIR"/enigma2/"; + p+=path; + eDebug("loading bouquet... %s", p.c_str()); + FILE *fp=fopen(p.c_str(), "rt"); int entries=0; if (!fp) { + struct stat s; + if ( !stat(path, &s) ) + { + rename(path, p.c_str() ); + loadBouquet(path); + return; + } eDebug("failed to open."); if ( strstr(path, "bouquets.tv") ) { @@ -502,18 +549,17 @@ void eDVBDB::loadBouquet(const char *path) } if ( (tmp.flags&eServiceReference::flagDirectory) == eServiceReference::flagDirectory ) { - std::string str = tmp.path; - unsigned int pos = str.rfind('/'); + unsigned int pos = tmp.path.rfind('/'); if ( pos != std::string::npos ) - str.erase(0, pos+1); - if (str.empty()) + tmp.path.erase(0, pos+1); + if (tmp.path.empty()) { eDebug("Bouquet load failed.. no filename given.."); continue; } loadBouquet(tmp.path.c_str()); char buf[256]; - snprintf(buf, 256, "(type == %d) FROM BOUQUET \"%s\" ORDER BY bouquet", tmp.data[0], str.c_str()); + snprintf(buf, 256, "(type == %d) FROM BOUQUET \"%s\" ORDER BY bouquet", tmp.data[0], tmp.path.c_str()); tmp.path = buf; } list.push_back(tmp); @@ -535,11 +581,6 @@ void eDVBDB::loadBouquet(const char *path) eDebug("%d entries in Bouquet %s", entries, bouquet_name.c_str()); } -void eDVBDB::saveBouquet(const char *path) -{ - -} - void eDVBDB::loadBouquets() { loadBouquet("bouquets.tv"); @@ -548,7 +589,7 @@ void eDVBDB::loadBouquets() if ( m_bouquets.find("userbouquet.favourites.tv") == m_bouquets.end() ) { eBouquet &b = m_bouquets["userbouquet.favourites.tv"]; - b.m_path = "userbouquet.favourites.tv"; + b.m_filename = "userbouquet.favourites.tv"; b.m_bouquet_name = "Favourites (TV)"; b.flushChanges(); eServiceReference ref; @@ -564,7 +605,7 @@ void eDVBDB::loadBouquets() if ( m_bouquets.find("userbouquet.favourites.radio") == m_bouquets.end() ) { eBouquet &b = m_bouquets["userbouquet.favourites.radio"]; - b.m_path = "userbouquet.favourites.radio"; + b.m_filename = "userbouquet.favourites.radio"; b.m_bouquet_name = "Favourites (Radio)"; b.flushChanges(); eServiceReference ref; @@ -579,11 +620,6 @@ void eDVBDB::loadBouquets() } } -void eDVBDB::saveBouquets() -{ - -} - eDVBDB::eDVBDB() { load(); @@ -683,8 +719,17 @@ RESULT eDVBDB::getBouquet(const eServiceReference &ref, eBouquet* &bouquet) RESULT eDVBDB::startQuery(ePtr &query, eDVBChannelQuery *q, const eServiceReference &source) { - if ( q && q->m_bouquet_name.length() ) - query = new eDVBDBBouquetQuery(this, source, q); + if ( source.path.find("FROM") != std::string::npos ) + { + if ( source.path.find("BOUQUET") != std::string::npos ) + query = new eDVBDBBouquetQuery(this, source, q); + else if ( source.path.find("SATELLITES") != std::string::npos ) + query = new eDVBDBSatellitesQuery(this, source, q); + else if ( source.path.find("PROVIDERS") != std::string::npos ) + query = new eDVBDBProvidersQuery(this, source, q); + else + eFatal("invalid query %s", source.toString().c_str()); + } else query = new eDVBDBQuery(this, source, q); return 0; @@ -783,6 +828,121 @@ RESULT eDVBDBBouquetQuery::getNextResult(eServiceReferenceDVB &ref) return 1; } +eDVBDBListQuery::eDVBDBListQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query) + :eDVBDBQueryBase(db, source, query), m_cursor(m_list.end()) +{ +} + +RESULT eDVBDBListQuery::getNextResult(eServiceReferenceDVB &ref) +{ + if (m_cursor != m_list.end()) + { + ref = *m_cursor++; + return 0; + } + ref.type = eServiceReference::idInvalid; + return 1; +} + +int eDVBDBListQuery::compareLessEqual(const eServiceReferenceDVB &a, const eServiceReferenceDVB &b) +{ + if ( m_query->m_sort == eDVBChannelQuery::tSatellitePosition ) + { + int x = (a.getDVBNamespace().get() >> 16); + int y = (b.getDVBNamespace().get() >> 16); + if ( x > 1800 ) + x -= 3600; + if ( y > 1800 ) + y -= 3600; + return x < y; + } + return a.name < b.name; +} + +eDVBDBSatellitesQuery::eDVBDBSatellitesQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query) + :eDVBDBListQuery(db, source, query) +{ + for (std::map >::iterator it(m_db->m_services.begin()); + it != m_db->m_services.end(); ++it) + { + int res = it->second->checkFilter(it->first, *query); + if (res) + { + unsigned int dvbnamespace = it->first.getDVBNamespace().get()&0xFFFF0000; + bool found=0; + for (std::list::iterator i(m_list.begin()); i != m_list.end(); ++i) + if ( (i->getDVBNamespace().get()&0xFFFF0000) == dvbnamespace ) + { + found=true; + break; + } + if (!found) + { + eServiceReferenceDVB ref; + ref.setDVBNamespace(dvbnamespace); + ref.flags=eServiceReference::flagDirectory; + char buf[64]; + snprintf(buf, 64, "(satellitePosition == %d) && ", dvbnamespace>>16); + + ref.path=buf+source.path; + unsigned int pos=ref.path.find("FROM"); + ref.path.erase(pos); + ref.path+="ORDER BY name"; +// eDebug("ref.path now %s", ref.path.c_str()); + m_list.push_back(ref); + + ref.path=buf+source.path; + pos=ref.path.find("FROM"); + ref.path.erase(pos+5); + ref.path+="PROVIDERS ORDER BY name"; +// eDebug("ref.path now %s", ref.path.c_str()); + m_list.push_back(ref); + } + } + } + m_cursor=m_list.begin(); +} + +eDVBDBProvidersQuery::eDVBDBProvidersQuery(eDVBDB *db, const eServiceReference &source, eDVBChannelQuery *query) + :eDVBDBListQuery(db, source, query) +{ + for (std::map >::iterator it(m_db->m_services.begin()); + it != m_db->m_services.end(); ++it) + { + int res = it->second->checkFilter(it->first, *query); + if (res) + { + bool found=0; + + const char *provider_name = it->second->m_provider_name.length() ? + it->second->m_provider_name.c_str() : + "Unknown"; + + for (std::list::iterator i(m_list.begin()); i != m_list.end(); ++i) + if (i->name == provider_name) + { + found=true; + break; + } + if (!found) + { + eServiceReferenceDVB ref; + char buf[64]; + ref.name=provider_name; + snprintf(buf, 64, "(provider == \"%s\") && ", provider_name); + ref.path=buf+source.path; + unsigned int pos = ref.path.find("FROM"); + ref.flags=eServiceReference::flagDirectory; + ref.path.erase(pos); + ref.path+="ORDER BY name"; +// eDebug("ref.path now %s", ref.path.c_str()); + m_list.push_back(ref); + } + } + } + m_cursor=m_list.begin(); +} + /* ( <==|...> <"string"|int>)[||,&& (..)] */ static int decodeType(const std::string &type) @@ -974,37 +1134,41 @@ RESULT eDVBChannelQuery::compile(ePtr &res, std::string query) int sort = eDVBChannelQuery::tName; /* check for "ORDER BY ..." */ - while (tokens.size() > 2) + std::list::iterator it = tokens.begin(); + while (it != tokens.end()) { - std::list::iterator it = tokens.end(); - --it; --it; --it; if (*it == "ORDER") { - ++it; - if (*it == "BY") + tokens.erase(it++); + if (it != tokens.end() && *it == "BY") { - ++it; + tokens.erase(it++); sort = decodeType(*it); - tokens.pop_back(); // ... - tokens.pop_back(); // BY - tokens.pop_back(); // ORDER + tokens.erase(it++); } else sort = -1; } else if (*it == "FROM") { - ++it; - if (*it == "BOUQUET") + tokens.erase(it++); + if (it != tokens.end() && *it == "BOUQUET") { - ++it; + tokens.erase(it++); bouquet_name = *it; - tokens.pop_back(); // ... - tokens.pop_back(); // FROM - tokens.pop_back(); // BOUQUET + tokens.erase(it++); + } + else if (it != tokens.end() && *it == "SATELLITES") + tokens.erase(it++); + else if (it != tokens.end() && *it == "PROVIDERS") + tokens.erase(it++); + else + { + eDebug("FROM unknown %s", (*it).c_str()); + tokens.erase(it++); } } else - break; + ++it; } if (sort == -1)