25 char *sourcebuf = NULL;
30 int fields = sscanf(s,
"%m[^-]-%d-%d-%d-%d", &sourcebuf, &
nid, &
tid, &
sid, &
rid);
31 if (fields == 4 || fields == 5) {
136 switch (toupper(Polarization)) {
141 default:
esyslog(
"ERROR: invalid value for Polarization '%c'", Polarization);
153 const char *p = strpbrk(
parameters,
"HVLRhvlr");
234 if (Channels &&
Number()) {
235 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);
268 if (nn || ns || np) {
309 for (
int i = 0; a[i] || b[i]; i++) {
310 if (!a[i] || !b[i]) {
314 if (na && nb && strcmp(na[i], nb[i]) != 0)
326 while (a[i] || i == 0) {
327 q += sprintf(q, Base == 16 ?
"%s%X" :
"%s%d", i ?
"," :
"", a[i]);
328 const char *Delim =
"=";
331 q += sprintf(q,
"%s%s", Delim, n[i]);
335 q += sprintf(q,
"%s@%d", Delim, t[i]);
345bool 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)
352 int m =
IntArraysDiffer(
apids,
Apids,
alangs, ALangs) |
IntArraysDiffer(
atypes, Atypes) |
IntArraysDiffer(
dpids,
Dpids,
dlangs, DLangs) |
IntArraysDiffer(
dtypes, Dtypes) |
IntArraysDiffer(
spids,
Spids,
slangs, SLangs);
359 char OldApidsBuf[BufferSize];
360 char NewApidsBuf[BufferSize];
361 char *q = OldApidsBuf;
376 char OldSpidsBuf[SBufferSize];
377 char NewSpidsBuf[SBufferSize];
385 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);
389 for (
int i = 0; i <
MAXAPIDS; i++) {
395 for (
int i = 0; i <
MAXDPIDS; i++) {
401 for (
int i = 0; i <
MAXSPIDS; i++) {
415 bool Modified =
false;
416 if (SubtitlingTypes) {
417 for (
int i = 0; i <
MAXSPIDS; i++) {
422 if (CompositionPageIds) {
423 for (
int i = 0; i <
MAXSPIDS; i++) {
428 if (AncillaryPageIds) {
429 for (
int i = 0; i <
MAXSPIDS; i++) {
446 if (lc->Channel() == LinkChannel) {
463 char OldCaIdsBuf[
MAXCAIDS * 5 + 10];
464 char NewCaIdsBuf[
MAXCAIDS * 5 + 10];
468 dsyslog(
"changing caids of channel %d (%s) from %s to %s",
Number(),
name, OldCaIdsBuf, NewCaIdsBuf);
469 for (
int i = 0; i <=
MAXCAIDS; i++) {
484 if (
Number() && Level > 1)
513 q += sprintf(q,
"linking channel %d (%s) from",
Number(),
name);
516 lc->Channel()->SetRefChannel(NULL);
517 q += sprintf(q,
" %d", lc->Channel()->Number());
522 q += sprintf(q,
" none");
523 q += sprintf(q,
" to");
527 lc->Channel()->SetRefChannel(
this);
528 q += sprintf(q,
" %d", lc->Channel()->Number());
533 q += sprintf(q,
" none");
553 char FullName[strlen(Channel->
name) + 1 + strlen(Channel->
shortName) + 1 + strlen(Channel->
provider) + 1 + 10];
555 q += sprintf(q,
"%s", Channel->
name);
558 q += sprintf(q,
",%s", Channel->
shortName);
559 else if (strchr(Channel->
name,
','))
560 q += sprintf(q,
",");
562 q += sprintf(q,
";%s", Channel->
provider);
576 q += snprintf(q,
sizeof(vpidbuf),
"%d", Channel->
vpid);
578 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"+%d", Channel->
ppid);
580 q += snprintf(q,
sizeof(vpidbuf) - (q - vpidbuf),
"=%d", Channel->
vtype);
583 char apidbuf[ABufferSize];
586 if (Channel->
dpids[0]) {
592 char tpidbuf[TBufferSize];
594 q += snprintf(q,
sizeof(tpidbuf),
"%d", Channel->
tpid);
595 if (Channel->
spids[0]) {
603 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);
618 if (*++s ==
'@' && *++s) {
621 int n = strtol(s, &p, 10);
622 if (!errno && p != s && n > 0) {
632 char *namebuf = NULL;
633 char *sourcebuf = NULL;
634 char *parambuf = NULL;
635 char *vpidbuf = NULL;
636 char *apidbuf = NULL;
637 char *tpidbuf = NULL;
638 char *caidbuf = NULL;
639 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);
646 if (sscanf(tpidbuf,
"%d", &
tpid) != 1)
660 if (parambuf && sourcebuf && vpidbuf && apidbuf) {
666 if ((p = strchr(vpidbuf,
'=')) != NULL) {
668 if (sscanf(p,
"%d", &
vtype) != 1)
671 if ((p = strchr(vpidbuf,
'+')) != NULL) {
673 if (sscanf(p,
"%d", &
ppid) != 1)
676 if (sscanf(vpidbuf,
"%d", &
vpid) != 1)
683 char *dpidbuf = strchr(apidbuf,
';');
690 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
693 char *l = strchr(q,
'=');
696 char *t = strchr(l,
'@');
699 atypes[NumApids] = strtol(t, NULL, 10);
705 if ((
apids[NumApids] = strtol(q, NULL, 10)) != 0)
709 esyslog(
"ERROR: too many APIDs!");
719 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
722 char *l = strchr(q,
'=');
725 char *t = strchr(l,
'@');
728 dtypes[NumDpids] = strtol(t, NULL, 10);
734 if ((
dpids[NumDpids] = strtol(q, NULL, 10)) != 0)
738 esyslog(
"ERROR: too many DPIDs!");
745 if ((p = strchr(tpidbuf,
';')) != NULL) {
749 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
751 char *l = strchr(q,
'=');
758 spids[NumSpids++] = strtol(q, NULL, 10);
761 esyslog(
"ERROR: too many SPIDs!");
766 if (sscanf(tpidbuf,
"%d", &
tpid) != 1)
773 while ((q = strtok_r(p,
",", &strtok_next)) != NULL) {
775 caids[NumCaIds++] = strtol(q, NULL, 16) & 0xFFFF;
780 esyslog(
"ERROR: too many CA ids!");
788 char *p = strchr(namebuf,
';');
793 p = strrchr(namebuf,
',');
811 esyslog(
"ERROR: channel data results in invalid ID!");
823 return fprintf(f,
"%s\n", *
ToText()) > 0;
869 if (!Channel->GroupSep())
872 ChannelSorter.
Sort();
908 while (Channel && !(Channel->
GroupSep() && *Channel->
Name()))
909 Channel =
Get(++Idx);
910 return Channel ? Idx : -1;
916 while (Channel && !(Channel->
GroupSep() && *Channel->
Name()))
917 Channel =
Get(--Idx);
918 return Channel ? Idx : -1;
924 while (Channel && Channel->
GroupSep())
925 Channel =
Get(++Idx);
926 return Channel ? Idx : -1;
932 while (Channel && Channel->
GroupSep())
933 Channel =
Get(--Idx);
934 return Channel ? Idx : -1;
943 if (Channel->GroupSep()) {
944 if (Channel->Number() > Number)
945 Number = Channel->Number();
950 Channel->SetNumber(Number++);
957 int Number = From->
Number();
958 if (Number < To->Number()) {
962 if (Channel->GroupSep()) {
963 if (Channel->Number() > Number)
964 Number = Channel->Number();
969 return Number == To->
Number();
978 ch->DelLinkChannel(Channel);
986 if (!Channel->GroupSep()) {
987 if (Channel->Number() == Number)
989 else if (SkipGap && Channel->Number() > Number)
990 return SkipGap > 0 ? Channel : Previous;
1012 int sid = ChannelID.
Sid();
1020 if (TryWithoutRid) {
1028 if (TryWithoutPolarization) {
1042 int source = ChannelID.
Source();
1043 int nid = ChannelID.
Nid();
1044 int tid = ChannelID.
Tid();
1046 if (Channel->Tid() == tid && Channel->Nid() == nid && Channel->Source() == source)
1056 if (!Channel->GroupSep() && Channel != OldChannel && Channel->
GetChannelID() == NewChannelID)
1072 for (
const cChannel *Channel = Channels->First(); Channel; Channel = Channels->
Next(Channel)) {
1073 if (!Channel->GroupSep())
1084 for (
const cChannel *Channel = Channels->First(); Channel; Channel = Channels->
Next(Channel)) {
1085 if (!Channel->GroupSep())
1108 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);
1121#define CHANNELMARKOBSOLETE "OBSOLETE"
1122#define CHANNELTIMEOBSOLETE 3600
1126 bool ChannelsModified =
false;
1128 if (time(NULL) - Channel->Seen() >
CHANNELTIMEOBSOLETE && Channel->Source() == Source && Channel->Nid() == Nid && Channel->Tid() == Tid && Channel->Rid() == 0) {
1136 return ChannelsModified;
1144 snprintf(buffer,
sizeof(buffer),
"%s", Channel->
Name());
1146 snprintf(buffer,
sizeof(buffer),
"%d%s %s", Channel->
Number(), Number ?
"-" :
"", Channel->
Name());
1149 snprintf(buffer,
sizeof(buffer),
"%d-", Number);
1151 snprintf(buffer,
sizeof(buffer),
"%s",
tr(
"*** Invalid Channel ***"));
1159 bool ChannelsModified =
false;
1162 int e = strlen(
name) - mlen - 1;
1172 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 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",...
const int * Dpids(void) const
uchar subtitlingTypes[MAXSPIDS]
const cChannel * RefChannel(void) const
bool Parse(const char *s)
char dlangs[MAXDPIDS][MAXLANGCODE2]
static cString ToText(const cChannel *Channel)
const cSchedule * schedule
cString TransponderDataToString(void) const
bool SetCaIds(const int *CaIds)
bool SetName(const char *Name, const char *ShortName, const char *Provider)
cString ToText(void) const
cLinkChannels * linkChannels
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)
char alangs[MAXAPIDS][MAXLANGCODE2]
bool GroupSep(void) const
const char * Parameters(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)
const char * PortalName(void) const
bool SetSource(int Source)
const int * Apids(void) const
char slangs[MAXSPIDS][MAXLANGCODE2]
bool SetId(cChannels *Channels, int Nid, int Tid, int Sid, int Rid=0)
int Modification(int Mask=CHANNELMOD_ALL) const
bool SetCaDescriptors(int Level)
int Transponder(void) const
Returns the transponder frequency in MHz, plus the polarization in case of sat.
void DelLinkChannel(cChannel *LinkChannel)
uint16_t compositionPageIds[MAXSPIDS]
const char * Provider(void) const
bool SetSubtitlingDescriptors(uchar *SubtitlingTypes, uint16_t *CompositionPageIds, uint16_t *AncillaryPageIds)
const cLinkChannels * LinkChannels(void) const
uint16_t ancillaryPageIds[MAXSPIDS]
const int * Spids(void) const
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)
const cChannel * GetByServiceID(int Source, int Transponder, unsigned short ServiceID) const
static int maxChannelNameLength
static cChannels channels
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)
void HashChannel(cChannel *Channel)
static const cChannels * GetChannelsRead(cStateKey &StateKey, int TimeoutMs=0)
Gets the list of channels for read access.
void ReNumber(void)
Recalculate 'number' based on channel type.
const cChannel * GetByNumber(int Number, int SkipGap=0) const
void SetModifiedByUser(void)
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)
static int maxShortChannelNameLength
cHash< cChannel > channelsHashSid
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)
static cDevice * PrimaryDevice(void)
Returns the primary device.
bool SwitchChannel(const cChannel *Channel, bool LiveView)
Switches the device to the given Channel, initiating transfer mode if necessary.
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 * First(void) const
Returns the first element in this list, or NULL if the list is empty.
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 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
tChannelID & ClrRid(void)
int nid
actually the "original" network id
static tChannelID FromString(const char *s)
cString ToString(void) const
static const tChannelID InvalidID
tChannelID & ClrPolarization(void)