/* * channelmap.c: TVM2VDR plugin for the Video Disk Recorder * * See the README file for copyright information and how to reach the author. * */ #include "channelmap.h" #include "common.h" cChannelMap::cChannelMap(const char* file) { fileName = strdup(file); chanmap.clear(); load(); } cChannelMap::~cChannelMap() { chanmap.clear(); free(fileName); } int cChannelMap::load() { ifstream cmfile; string s; size_t p; int tvmid; totalCount = 0; cmfile.open(fileName); if (!cmfile) { esyslog("TVM2VDR: Error reading '%s'!", fileName); return fail; } isyslog("TVM2VDR: Loading '%s'", fileName); while (!cmfile.eof()) { getline(cmfile, s); if (!s.empty()) { removeChars(s, " \f\n\r\t\v"); // remove comments p = s.find_first_of("//"); if (p != string::npos) s.erase(p); // split line p = s.find_first_of("="); if ((p != string::npos) && (s.substr(p + 1).length())) { char* ptr = 0; tvmid = atoi(s.substr(0, p).c_str()); if ((ptr = strdup(s.substr(p + 1).c_str())) != 0) { char* vpsptr = 0; // one of the chars "1yYjJ" separated from the channelids // by a colon means the sender has VPS vpsmap[tvmid] = false; if ((vpsptr = index(ptr, ':')) != NULL) { *vpsptr++ = '\0'; vpsmap[tvmid] = (index("1yYjJ", *vpsptr) != NULL); } if (*ptr) { chanmap[tvmid].push_back(ptr); totalCount++; } // are there more channelids separated by commas? while ((ptr = index(ptr, ',')) != NULL) { *ptr++ = '\0'; if (*ptr) { chanmap[tvmid].push_back(ptr); totalCount++; } } } } } } cmfile.close(); isyslog("TVM2VDR: %d channel mappings read.", totalCount); return totalCount; } int cChannelMap::GetChanCount(int tvmid) { return chanmap[tvmid].size(); } char *cChannelMap::GetChanStr(int tvmid, int index) { return chanmap[tvmid][index]; } tChannelID cChannelMap::GetChanID(int tvmid, int index) { if (!chanmap[tvmid][index]) return tChannelID::InvalidID; return tChannelID::FromString(chanmap[tvmid][index]); } int cChannelMap::ReloadChannelMap() { chanmap.clear(); return load(); } int cChannelMap::GetTvmidOfChannel(const char* channel) { cChanMap::iterator iter; for (iter = chanmap.begin(); iter != chanmap.end(); iter++) { for (unsigned int index = 0; index < chanmap[iter->first].size(); index++) if (strcmp(chanmap[iter->first][index], channel) == 0) return iter->first; } return na; }