26 char *sourcebuf = NULL;
31 int fields = sscanf(s,
"%m[^-]-%d-%d-%d-%d", &sourcebuf, &
nid, &
tid, &
sid, &
rid);
32 if (fields == 4 || fields == 5) {
137 switch (toupper(Polarization)) {
142 default:
esyslog(
"ERROR: invalid value for Polarization '%c'", Polarization);
153 const char *p = strpbrk(
parameters,
"HVLRhvlr");
230 if (Channels &&
Number()) {
231 dsyslog(
"changing id of channel %d (%s) from %d-%d-%d-%d to %d-%d-%d-%d",
Number(),
name,
nid,
tid,
sid,
rid,
Nid,
Tid,
Sid,
Rid);
264 if (nn || ns || np) {
305 for (
int i = 0; a[i] || b[i]; i++) {
306 if (!a[i] || !b[i]) {
310 if (na && nb && strcmp(na[i], nb[i]) != 0)
322 while (a[i] || i == 0) {
323 q += sprintf(q, Base == 16 ?
"%s%X" :
"%s%d", i ?
"," :
"", a[i]);
324 const char *Delim =
"=";
327 q += sprintf(q,
"%s%s", Delim, n[i]);
331 q += sprintf(q,
"%s@%d", Delim, t[i]);
341 bool cChannel::SetPids(
int Vpid,
int Ppid,
int Vtype,
int *Apids,
int *Atypes,
char ALangs[][
MAXLANGCODE2],
int *Dpids,
int *Dtypes,
char DLangs[][
MAXLANGCODE2],
int *Spids,
char SLangs[][
MAXLANGCODE2],
int Tpid)
348 int m =
IntArraysDiffer(
apids,
Apids,
alangs, ALangs) |
IntArraysDiffer(
atypes, Atypes) |
IntArraysDiffer(
dpids,
Dpids,
dlangs, DLangs) |
IntArraysDiffer(
dtypes, Dtypes) |
IntArraysDiffer(
spids,
Spids,
slangs, SLangs);
355 char OldApidsBuf[BufferSize];
356 char NewApidsBuf[BufferSize];
357 char *q = OldApidsBuf;
372 char OldSpidsBuf[SBufferSize];
373 char NewSpidsBuf[SBufferSize];
381 dsyslog(
"changing pids of channel %d (%s) from %d+%d=%d:%s:%s:%d to %d+%d=%d:%s:%s:%d",
Number(),
name,
vpid,
ppid,
vtype, OldApidsBuf, OldSpidsBuf,
tpid,
Vpid,
Ppid,
Vtype, NewApidsBuf, NewSpidsBuf,
Tpid);
385 for (
int i = 0; i <
MAXAPIDS; i++) {
391 for (
int i = 0; i <
MAXDPIDS; i++) {
397 for (
int i = 0; i <
MAXSPIDS; i++) {
411 bool Modified =
false;
412 if (SubtitlingTypes) {
413 for (
int i = 0; i <
MAXSPIDS; i++) {
418 if (CompositionPageIds) {
419 for (
int i = 0; i <
MAXSPIDS; i++) {
424 if (AncillaryPageIds) {
425 for (
int i = 0; i <
MAXSPIDS; i++) {
442 if (lc->Channel() == LinkChannel) {
459 char OldCaIdsBuf[
MAXCAIDS * 5 + 10];
460 char NewCaIdsBuf[
MAXCAIDS * 5 + 10];
464 dsyslog(
"changing caids of channel %d (%s) from %s to %s",
Number(),
name, OldCaIdsBuf, NewCaIdsBuf);
465 for (
int i = 0; i <=
MAXCAIDS; i++) {
480 if (
Number() && Level > 1)
509 q += sprintf(q,
"linking channel %d (%s) from",
Number(),
name);
512 lc->Channel()->SetRefChannel(NULL);
513 q += sprintf(q,
" %d", lc->Channel()->Number());
518 q += sprintf(q,
" none");
519 q += sprintf(q,
" to");
523 lc->Channel()->SetRefChannel(
this);
524 q += sprintf(q,
" %d", lc->Channel()->Number());
529 q += sprintf(q,
" none");
549 char FullName[strlen(Channel->
name) + 1 + strlen(Channel->
shortName) + 1 + strlen(Channel->
provider) + 1 + 10];
551 q += sprintf(q,
"%s", Channel->
name);
554 q += sprintf(q,
",%s", Channel->
shortName);
555 else if (strchr(Channel->
name,
','))
556 q += sprintf(q,
",");
558 q += sprintf(q,
";%s", Channel->
provider);
572 q += snprintf(q,
sizeof(vpidbuf),
"%d", Channel->
vpid);
574 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"+%d", Channel->
ppid);
576 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"=%d", Channel->
vtype);
579 char apidbuf[ABufferSize];
582 if (Channel->
dpids[0]) {
588 char tpidbuf[TBufferSize];
590 q += snprintf(q,
sizeof(tpidbuf),
"%d", Channel->
tpid);
591 if (Channel->
spids[0]) {
599 buffer =
cString::sprintf(
"%s:%d:%s:%s:%d:%s:%s:%s:%s:%d:%d:%d:%d", FullName, Channel->
frequency, *Channel->
parameters, *
cSource::ToString(Channel->
source), Channel->
srate, vpidbuf, apidbuf, tpidbuf, caidbuf, Channel->
sid, Channel->
nid, Channel->
tid, Channel->
rid);
614 if (*++s ==
'@' && *++s) {
617 int n = strtol(s, &p, 10);
618 if (!errno && p != s && n > 0) {
628 char *namebuf = NULL;
629 char *sourcebuf = NULL;
630 char *parambuf = NULL;
631 char *vpidbuf = NULL;
632 char *apidbuf = NULL;
633 char *tpidbuf = NULL;
634 char *caidbuf = NULL;
635 int fields = sscanf(s,
"%m[^:]:%d :%m[^:]:%m[^:] :%d :%m[^:]:%m[^:]:%m[^:]:%m[^:]:%d :%d :%d :%d ", &namebuf, &
frequency, ¶mbuf, &sourcebuf, &
srate, &vpidbuf, &apidbuf, &tpidbuf, &caidbuf, &
sid, &
nid, &
tid, &
rid);
642 if (sscanf(tpidbuf,
"%d", &
tpid) != 1)
656 if (parambuf && sourcebuf && vpidbuf && apidbuf) {
661 if ((p = strchr(vpidbuf,
'=')) != NULL) {
663 if (sscanf(p,
"%d", &
vtype) != 1)
666 if ((p = strchr(vpidbuf,
'+')) != NULL) {
668 if (sscanf(p,
"%d", &
ppid) != 1)
671 if (sscanf(vpidbuf,
"%d", &
vpid) != 1)
678 char *dpidbuf = strchr(apidbuf,
';');
685 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
688 char *l = strchr(q,
'=');
691 char *t = strchr(l,
'@');
694 atypes[NumApids] = strtol(t, NULL, 10);
700 if ((
apids[NumApids] = strtol(q, NULL, 10)) != 0)
704 esyslog(
"ERROR: too many APIDs!");
714 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
717 char *l = strchr(q,
'=');
720 char *t = strchr(l,
'@');
723 dtypes[NumDpids] = strtol(t, NULL, 10);
729 if ((
dpids[NumDpids] = strtol(q, NULL, 10)) != 0)
733 esyslog(
"ERROR: too many DPIDs!");
740 if ((p = strchr(tpidbuf,
';')) != NULL) {
744 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
746 char *l = strchr(q,
'=');
753 spids[NumSpids++] = strtol(q, NULL, 10);
756 esyslog(
"ERROR: too many SPIDs!");
761 if (sscanf(tpidbuf,
"%d", &
tpid) != 1)
768 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
770 caids[NumCaIds++] = strtol(q, NULL, 16) & 0xFFFF;
775 esyslog(
"ERROR: too many CA ids!");
783 char *p = strchr(namebuf,
';');
788 p = strrchr(namebuf,
',');
806 esyslog(
"ERROR: channel data results in invalid ID!");
818 return fprintf(f,
"%s\n", *
ToText()) > 0;
864 if (!Channel->GroupSep())
867 ChannelSorter.
Sort();
903 while (Channel && !(Channel->
GroupSep() && *Channel->
Name()))
904 Channel =
Get(++Idx);
905 return Channel ? Idx : -1;
911 while (Channel && !(Channel->
GroupSep() && *Channel->
Name()))
912 Channel =
Get(--Idx);
913 return Channel ? Idx : -1;
919 while (Channel && Channel->
GroupSep())
920 Channel =
Get(++Idx);
921 return Channel ? Idx : -1;
927 while (Channel && Channel->
GroupSep())
928 Channel =
Get(--Idx);
929 return Channel ? Idx : -1;
941 if (!Channel->GroupSep()) {
947 for (
int i = 0; i < FoundLcn.
Size(); ++i) {
948 if (FoundLcn[i] == Number) {
958 Channel->SetNumber(Number);
962 Channel->SetNumber(Overflow++);
969 if (channel->GroupSep()) {
970 if (channel->Number() > Number)
971 Number = channel->Number();
976 channel->SetNumber(Number++);
984 int Number = From->
Number();
985 if (Number < To->Number()) {
989 if (Channel->GroupSep()) {
990 if (Channel->Number() > Number)
991 Number = Channel->Number();
996 return Number == To->
Number();
1005 ch->DelLinkChannel(Channel);
1013 if (!Channel->GroupSep()) {
1014 if (Channel->Number() == Number)
1016 else if (SkipGap && Channel->Number() > Number)
1017 return SkipGap > 0 ? Channel : Previous;
1039 int sid = ChannelID.
Sid();
1047 if (TryWithoutRid) {
1055 if (TryWithoutPolarization) {
1069 int source = ChannelID.
Source();
1070 int nid = ChannelID.
Nid();
1071 int tid = ChannelID.
Tid();
1073 if (Channel->Tid() == tid && Channel->Nid() == nid && Channel->Source() == source)
1083 if (!Channel->GroupSep() && Channel != OldChannel && Channel->
GetChannelID() == NewChannelID)
1099 for (
const cChannel *Channel = Channels->First(); Channel; Channel = Channels->
Next(Channel)) {
1100 if (!Channel->GroupSep())
1111 for (
const cChannel *Channel = Channels->First(); Channel; Channel = Channels->
Next(Channel)) {
1112 if (!Channel->GroupSep())
1135 dsyslog(
"creating new channel '%s,%s;%s' on %s transponder %d with id %d-%d-%d-%d", Name, ShortName, Provider, *
cSource::ToString(Transponder->
Source()), Transponder->
Transponder(), Nid, Tid, Sid, Rid);
1148 #define CHANNELMARKOBSOLETE "OBSOLETE"
1149 #define CHANNELTIMEOBSOLETE 3600
1153 bool ChannelsModified =
false;
1155 if (time(NULL) - Channel->Seen() >
CHANNELTIMEOBSOLETE && Channel->Source() == Source && Channel->Nid() == Nid && Channel->Tid() == Tid && Channel->Rid() == 0) {
1163 return ChannelsModified;
1171 snprintf(buffer,
sizeof(buffer),
"%s", Channel->
Name());
1173 snprintf(buffer,
sizeof(buffer),
"%d%s %s", Channel->
Number(), Number ?
"-" :
"", Channel->
Name());
1176 snprintf(buffer,
sizeof(buffer),
"%d-", Number);
1178 snprintf(buffer,
sizeof(buffer),
"%s",
tr(
"*** Invalid Channel ***"));
1186 bool ChannelsModified =
false;
1189 int e = strlen(
name) - mlen - 1;
1199 return ChannelsModified;
#define CHANNELMARKOBSOLETE
static int IntArrayToString(char *s, const int *a, int Base=10, const char n[][MAXLANGCODE2]=NULL, const int *t=NULL)
#define CHANNELTIMEOBSOLETE
static int IntArraysDiffer(const int *a, const int *b, const char na[][MAXLANGCODE2]=NULL, const char nb[][MAXLANGCODE2]=NULL)
cString ChannelString(const cChannel *Channel, int Number)
#define LCN_OVERFLOW_OFFSET
#define CHANNELMOD_TRANSP
#define LOCK_CHANNELS_READ
#define ISTRANSPONDER(f1, f2)
#define LOCK_CHANNELS_WRITE
cChannelSorter(cChannel *Channel)
virtual int Compare(const cListObject &ListObject) const
Must return 0 if this object is equal to ListObject, a positive value if it is "greater",...
bool Parse(const char *s)
const cChannel * RefChannel(void) const
const int * Dpids(void) const
static cString ToText(const cChannel *Channel)
cString TransponderDataToString(void) const
bool SetCaIds(const int *CaIds)
bool SetName(const char *Name, const char *ShortName, const char *Provider)
cString ToText(void) const
bool SetPortalName(const char *PortalName)
bool SetLinkChannels(cLinkChannels *LinkChannels)
const char * Name(void) const
tChannelID GetChannelID(void) const
bool SetPids(int Vpid, int Ppid, int Vtype, int *Apids, int *Atypes, char ALangs[][MAXLANGCODE2], int *Dpids, int *Dtypes, char DLangs[][MAXLANGCODE2], int *Spids, char SLangs[][MAXLANGCODE2], int Tpid)
const cSchedule * schedule
char alangs[MAXAPIDS][MAXLANGCODE2]
char dlangs[MAXDPIDS][MAXLANGCODE2]
bool GroupSep(void) const
void CopyTransponderData(const cChannel *Channel)
int Frequency(void) const
Returns the actual frequency, as given in 'channels.conf'.
void SetRefChannel(cChannel *RefChannel)
bool ClearObsoleteChannel(void)
const char * ShortName(bool OrName=false) const
bool SetTransponderData(int Source, int Frequency, int Srate, const char *Parameters, bool Quiet=false)
char slangs[MAXSPIDS][MAXLANGCODE2]
uchar subtitlingTypes[MAXSPIDS]
const char * Parameters(void) const
bool SetSource(int Source)
const int * Spids(void) const
bool SetId(cChannels *Channels, int Nid, int Tid, int Sid, int Rid=0)
int Modification(int Mask=CHANNELMOD_ALL) const
bool SetCaDescriptors(int Level)
cLinkChannels * linkChannels
int Transponder(void) const
Returns the transponder frequency in MHz, plus the polarization in case of sat.
uint16_t ancillaryPageIds[MAXSPIDS]
const int * Apids(void) const
void DelLinkChannel(cChannel *LinkChannel)
const cLinkChannels * LinkChannels(void) const
bool SetSubtitlingDescriptors(uchar *SubtitlingTypes, uint16_t *CompositionPageIds, uint16_t *AncillaryPageIds)
const char * PortalName(void) const
const char * Provider(void) const
uint16_t compositionPageIds[MAXSPIDS]
cChannel & operator=(const cChannel &Channel)
static cChannels * GetChannelsWrite(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of channels for write access.
void UnhashChannel(cChannel *Channel)
static int MaxChannelNameLength(void)
int GetNextGroup(int Idx) const
Get next channel group.
bool HasUniqueChannelID(const cChannel *NewChannel, const cChannel *OldChannel=NULL) const
bool MoveNeedsDecrement(cChannel *From, cChannel *To)
int GetPrevNormal(int Idx) const
Get previous normal channel (not group)
static int maxChannelNameLength
const cChannel * GetByServiceID(int Source, int Transponder, unsigned short ServiceID) const
bool ModifiedByUser(int &State) const
Returns true if the channels have been modified by the user since the last call to this function with...
static int MaxShortChannelNameLength(void)
static int maxShortChannelNameLength
void HashChannel(cChannel *Channel)
static const cChannels * GetChannelsRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of channels for read access.
cHash< cChannel > channelsHashSid
void ReNumber(void)
Recalculate 'number' based on channel type.
const cChannel * GetByNumber(int Number, int SkipGap=0) const
void SetModifiedByUser(void)
static cChannels channels
cChannel * NewChannel(const cChannel *Transponder, const char *Name, const char *ShortName, const char *Provider, int Nid, int Tid, int Sid, int Rid=0)
const cChannel * GetByTransponderID(tChannelID ChannelID) const
bool MarkObsoleteChannels(int Source, int Nid, int Tid)
const cChannel * GetByChannelID(tChannelID ChannelID, bool TryWithoutRid=false, bool TryWithoutPolarization=false) const
bool SwitchTo(int Number) const
void DeleteDuplicateChannels(void)
int GetPrevGroup(int Idx) const
Get previous channel group.
static bool Load(const char *FileName, bool AllowComments=false, bool MustExist=false)
void Del(cChannel *Channel)
Delete the given Channel from the list.
int GetNextNormal(int Idx) const
Get next normal channel (not group)
const char * FileName(void)
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
static cDevice * PrimaryDevice(void)
Returns the primary device.
void Del(cListObject *Object, unsigned int Id)
cList< cHashObject > * GetList(unsigned int Id) const
void Add(cListObject *Object, unsigned int Id)
void Del(cListObject *Object, bool DeleteObject=true)
bool Lock(cStateKey &StateKey, bool Write=false, int TimeoutMs=0) const
Tries to get a lock on this list and returns true if successful.
void Add(cListObject *Object, cListObject *After=NULL)
cListObject * Next(void) const
const T * Next(const T *Object) const
< Returns the element immediately before Object in this list, or NULL if Object is the first element ...
const T * First(void) const
Returns the first element in this list, or NULL if the list is empty.
const cChannel * Get(int Index) const
Returns the list element at the given Index, or NULL if no such element exists.
int ShowChannelNamesWithSource
static int FromString(const char *s)
static bool IsTerr(int Code)
static cString ToString(int Code)
static char ToChar(int Code)
static cString sprintf(const char *fmt,...) __attribute__((format(printf
virtual void Append(T Data)
tChannelID & ClrRid(void)
static const tChannelID InvalidID
int nid
actually the "original" network id
static tChannelID FromString(const char *s)
cString ToString(void) const
tChannelID & ClrPolarization(void)