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) {
145 switch (toupper(Polarization)) {
150 default:
esyslog(
"ERROR: invalid value for Polarization '%c'", Polarization);
162 const char *p = strpbrk(
parameters,
"HVLRhvlr");
241 if (Channels &&
Number()) {
242 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);
275 if (nn || ns || np) {
313 for (
int i = 0; a[i] || b[i]; i++) {
314 if (!a[i] || !b[i]) {
318 if (na && nb && strcmp(na[i], nb[i]) != 0)
330 while (a[i] || i == 0) {
331 q += sprintf(q, Base == 16 ?
"%s%X" :
"%s%d", i ?
"," :
"", a[i]);
332 const char *Delim =
"=";
335 q += sprintf(q,
"%s%s", Delim, n[i]);
339 q += sprintf(q,
"%s@%d", Delim, t[i]);
349 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)
356 int m =
IntArraysDiffer(
apids,
Apids,
alangs, ALangs) |
IntArraysDiffer(
atypes, Atypes) |
IntArraysDiffer(
dpids,
Dpids,
dlangs, DLangs) |
IntArraysDiffer(
dtypes, Dtypes) |
IntArraysDiffer(
spids,
Spids,
slangs, SLangs);
363 char OldApidsBuf[BufferSize];
364 char NewApidsBuf[BufferSize];
365 char *q = OldApidsBuf;
380 char OldSpidsBuf[SBufferSize];
381 char NewSpidsBuf[SBufferSize];
389 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);
393 for (
int i = 0; i <
MAXAPIDS; i++) {
399 for (
int i = 0; i <
MAXDPIDS; i++) {
405 for (
int i = 0; i <
MAXSPIDS; i++) {
419 bool Modified =
false;
420 if (SubtitlingTypes) {
421 for (
int i = 0; i <
MAXSPIDS; i++) {
426 if (CompositionPageIds) {
427 for (
int i = 0; i <
MAXSPIDS; i++) {
432 if (AncillaryPageIds) {
433 for (
int i = 0; i <
MAXSPIDS; i++) {
450 if (lc->Channel() == LinkChannel) {
467 char OldCaIdsBuf[
MAXCAIDS * 5 + 10];
468 char NewCaIdsBuf[
MAXCAIDS * 5 + 10];
472 dsyslog(
"changing caids of channel %d (%s) from %s to %s",
Number(),
name, OldCaIdsBuf, NewCaIdsBuf);
473 for (
int i = 0; i <=
MAXCAIDS; i++) {
488 if (
Number() && Level > 1)
517 q += sprintf(q,
"linking channel %d (%s) from",
Number(),
name);
520 lc->Channel()->SetRefChannel(NULL);
521 q += sprintf(q,
" %d", lc->Channel()->Number());
526 q += sprintf(q,
" none");
527 q += sprintf(q,
" to");
531 lc->Channel()->SetRefChannel(
this);
532 q += sprintf(q,
" %d", lc->Channel()->Number());
537 q += sprintf(q,
" none");
557 char FullName[strlen(Channel->
name) + 1 + strlen(Channel->
shortName) + 1 + strlen(Channel->
provider) + 1 + 10];
559 q += sprintf(q,
"%s", Channel->
name);
562 q += sprintf(q,
",%s", Channel->
shortName);
563 else if (strchr(Channel->
name,
','))
564 q += sprintf(q,
",");
566 q += sprintf(q,
";%s", Channel->
provider);
580 q += snprintf(q,
sizeof(vpidbuf),
"%d", Channel->
vpid);
582 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"+%d", Channel->
ppid);
584 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"=%d", Channel->
vtype);
587 char apidbuf[ABufferSize];
590 if (Channel->
dpids[0]) {
596 char tpidbuf[TBufferSize];
598 q += snprintf(q,
sizeof(tpidbuf),
"%d", Channel->
tpid);
599 if (Channel->
spids[0]) {
607 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);
622 if (*++s ==
'@' && *++s) {
625 int n = strtol(s, &p, 10);
626 if (!errno && p != s && n > 0) {
636 char *namebuf = NULL;
637 char *sourcebuf = NULL;
638 char *parambuf = NULL;
639 char *vpidbuf = NULL;
640 char *apidbuf = NULL;
641 char *tpidbuf = NULL;
642 char *caidbuf = NULL;
643 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);
650 if (sscanf(tpidbuf,
"%d", &
tpid) != 1)
664 if (parambuf && sourcebuf && vpidbuf && apidbuf) {
670 if ((p = strchr(vpidbuf,
'=')) != NULL) {
672 if (sscanf(p,
"%d", &
vtype) != 1)
675 if ((p = strchr(vpidbuf,
'+')) != NULL) {
677 if (sscanf(p,
"%d", &
ppid) != 1)
680 if (sscanf(vpidbuf,
"%d", &
vpid) != 1)
687 char *dpidbuf = strchr(apidbuf,
';');
694 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
697 char *l = strchr(q,
'=');
700 char *t = strchr(l,
'@');
703 atypes[NumApids] = strtol(t, NULL, 10);
709 if ((
apids[NumApids] = strtol(q, NULL, 10)) != 0)
713 esyslog(
"ERROR: too many APIDs!");
723 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
726 char *l = strchr(q,
'=');
729 char *t = strchr(l,
'@');
732 dtypes[NumDpids] = strtol(t, NULL, 10);
738 if ((
dpids[NumDpids] = strtol(q, NULL, 10)) != 0)
742 esyslog(
"ERROR: too many DPIDs!");
749 if ((p = strchr(tpidbuf,
';')) != NULL) {
753 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
755 char *l = strchr(q,
'=');
762 spids[NumSpids++] = strtol(q, NULL, 10);
765 esyslog(
"ERROR: too many SPIDs!");
770 if (sscanf(tpidbuf,
"%d", &
tpid) != 1)
777 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
779 caids[NumCaIds++] = strtol(q, NULL, 16) & 0xFFFF;
784 esyslog(
"ERROR: too many CA ids!");
792 char *p = strchr(namebuf,
';');
797 p = strrchr(namebuf,
',');
813 esyslog(
"ERROR: channel data results in invalid ID!");
825 return fprintf(f,
"%s\n", *
ToText()) > 0;
871 if (!Channel->GroupSep())
874 ChannelSorter.
Sort();
910 while (Channel && !(Channel->
GroupSep() && *Channel->
Name()))
911 Channel =
Get(++Idx);
912 return Channel ? Idx : -1;
918 while (Channel && !(Channel->
GroupSep() && *Channel->
Name()))
919 Channel =
Get(--Idx);
920 return Channel ? Idx : -1;
926 while (Channel && Channel->
GroupSep())
927 Channel =
Get(++Idx);
928 return Channel ? Idx : -1;
934 while (Channel && Channel->
GroupSep())
935 Channel =
Get(--Idx);
936 return Channel ? Idx : -1;
948 if (!Channel->GroupSep()) {
954 for (
int i = 0; i < FoundLcn.
Size(); ++i) {
955 if (FoundLcn[i] == Number) {
965 Channel->SetNumber(Number);
969 Channel->SetNumber(Overflow++);
976 if (channel->GroupSep()) {
977 if (channel->Number() > Number)
978 Number = channel->Number();
983 channel->SetNumber(Number++);
991 int Number = From->
Number();
992 if (Number < To->Number()) {
996 if (Channel->GroupSep()) {
997 if (Channel->Number() > Number)
998 Number = Channel->Number();
1003 return Number == To->
Number();
1012 ch->DelLinkChannel(Channel);
1020 if (!Channel->GroupSep()) {
1021 if (Channel->Number() == Number)
1023 else if (SkipGap && Channel->Number() > Number)
1024 return SkipGap > 0 ? Channel : Previous;
1046 int sid = ChannelID.
Sid();
1054 if (TryWithoutRid) {
1062 if (TryWithoutPolarization) {
1076 int source = ChannelID.
Source();
1077 int nid = ChannelID.
Nid();
1078 int tid = ChannelID.
Tid();
1080 if (Channel->Tid() == tid && Channel->Nid() == nid && Channel->Source() == source)
1090 if (!Channel->GroupSep() && Channel != OldChannel && Channel->
GetChannelID() == NewChannelID)
1106 for (
const cChannel *Channel = Channels->First(); Channel; Channel = Channels->
Next(Channel)) {
1107 if (!Channel->GroupSep())
1118 for (
const cChannel *Channel = Channels->First(); Channel; Channel = Channels->
Next(Channel)) {
1119 if (!Channel->GroupSep())
1142 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);
1155 #define CHANNELMARKOBSOLETE "OBSOLETE"
1156 #define CHANNELTIMEOBSOLETE 3600
1160 bool ChannelsModified =
false;
1162 if (time(NULL) - Channel->Seen() >
CHANNELTIMEOBSOLETE && Channel->Source() == Source && Channel->Nid() == Nid && Channel->Tid() == Tid && Channel->Rid() == 0) {
1170 return ChannelsModified;
1178 snprintf(buffer,
sizeof(buffer),
"%s", Channel->
Name());
1180 snprintf(buffer,
sizeof(buffer),
"%d%s %s", Channel->
Number(), Number ?
"-" :
"", Channel->
Name());
1183 snprintf(buffer,
sizeof(buffer),
"%d-", Number);
1185 snprintf(buffer,
sizeof(buffer),
"%s",
tr(
"*** Invalid Channel ***"));
1193 bool ChannelsModified =
false;
1196 int e = strlen(
name) - mlen - 1;
1206 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 override
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
void UpdateNameSource(void)
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)