FireBirdLib - Topfield TMS PVR TAP Programming Library
EPGInfo_CloneToCache.c
Go to the documentation of this file.
1#include <string.h>
2#include "FBLib_EPG.h"
3
4void EPGInfo_CloneToCache(dword *TreePointer, byte StructOffset, tEPGFilter *EPGFilter)
5{
7
8 tTreeEntry *ListStart, *Entry;
9 TYPE_EvtInfo *EvtInfo;
10 int EvtInfoOffset;
11 TYPE_EPGInfo *CurrentCacheRecord;
12 short Offset;
13 dword EventStartTime, EventEndTime;
14 bool isWithinTimeFrame, isValidChannel, isWithinDuration, isGenreOK;
15
17 CurrentCacheRecord = EPGInfoCache;
18 EPGAbortLoad = FALSE;
19
20 if(TreePointer)
21 {
22 EvtInfoOffset = StructOffset / sizeof(tTreeEntry);
23
24 ListStart = (tTreeEntry*)*TreePointer;
25
26 //If the list points to itself, no data is available
27 if(ListStart == (tTreeEntry*)ListStart->Next)
28 {
29 TRACEEXIT();
30 return;
31 }
32
33 //Loop until we're back at the beginning of the pool
34 Entry = ListStart;
35 do
36 {
37 EvtInfo = (TYPE_EvtInfo*)(Entry - EvtInfoOffset);
38
39 if(FlashServiceFindNum(EvtInfo->SatIndex, EvtInfo->NetworkID, EvtInfo->TSID, EvtInfo->ServiceID, NULL, NULL))
40 {
41 if((dword)EvtInfo->TreeFull.Next != 0 && (dword)EvtInfo->TreeFull.Prev != 0) //Only take events that are not scheduled for garbage collection
42 {
43 //Make the decisions, to add a pool record, here
44 EventStartTime = UTC2LocalTime(EvtInfo->StartTime, &Offset);
45 EventEndTime = UTC2LocalTime(EvtInfo->EndTime, NULL);
47 isWithinTimeFrame = ((EPGFilter->StartTime == 0) || (EventStartTime >= EPGFilter->StartTime)) && ((EPGFilter->EndTime == 0) || (EventEndTime <= EPGFilter->EndTime));
48 else
49 isWithinTimeFrame = TRUE;
50
51
53 isValidChannel = (EvtInfo->SatIndex == EPGFilter->SatIndex) && (EvtInfo->NetworkID == EPGFilter->NetworkID) && (EvtInfo->TSID == EPGFilter->TSID) && (EvtInfo->ServiceID == EPGFilter->ServiceID);
54 else
55 isValidChannel = TRUE;
56
57
59 {
60 isWithinDuration = ((EPGFilter->MinDuration == 0) || (EvtInfo->durationHour * 60 + EvtInfo->durationMin >= EPGFilter->MinDuration)) &&
61 ((EPGFilter->MaxDuration == 0) || (EvtInfo->durationHour * 60 + EvtInfo->durationMin <= EPGFilter->MaxDuration));
62 }
63 else
64 isWithinDuration = TRUE;
65
67 {
68 byte *pGenre;
69 int i;
70
71 //Loop through the genre array and check if there is a match
72 isGenreOK = FALSE;
73 pGenre = &EPGFilter->GenreArray[0];
74 for(i = 0; i < EPGFilter->GenreArraySize; i++)
75 {
76 if(EvtInfo->ContentIdentifier == *pGenre)
77 {
78 isGenreOK = TRUE;
79 break;
80 }
81 pGenre++;
82 }
83 }
84 else
85 isGenreOK = TRUE;
86
87 //Call the Callback only if all other tests passed
88 if(isWithinTimeFrame && isValidChannel && isWithinDuration && isGenreOK)
89 {
90 EPGInfo_CopyData(EvtInfo, CurrentCacheRecord, EventStartTime, EventEndTime, Offset);
91
93 {
94 bool (*EPGFilterCallback)(TYPE_EPGInfo*) = EPGFilter->Callback;
95
96 if(EPGFilterCallback(CurrentCacheRecord))
97 {
98 CurrentCacheRecord++;
100 }
101 }
102 else
103 {
104 CurrentCacheRecord++;
106 }
107 }
108 }//END test for garbage collection value
109 }
110
111 Entry = (tTreeEntry*)Entry->Next;
112 } while(Entry && (Entry->Next != ListStart->Prev));
113 }
114
115 TRACEEXIT();
116}
#define bool
Definition: ELF.h:26
void EPGInfo_CloneToCache(dword *TreePointer, byte StructOffset, tEPGFilter *EPGFilter)
void EPGInfo_CopyData(TYPE_EvtInfo *EvtInfo, TYPE_EPGInfo *EPGInfo, dword EventStartTime, dword EventEndTime, short Offset)
tEPGFilter EPGFilter
int EPGAbortLoad
int EPGInfoNrEntries
TYPE_EPGInfo * EPGInfoCache
bool isValidChannel(TAPCOM_Channel Channel)
Definition: isValidChannel.c:3
bool FlashServiceFindNum(byte SatIndex, word NetworkID, word TSID, word ServiceID, TYPE_ServiceType *SvcType, int *SvcNum)
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
dword UTC2LocalTime(dword UTCTime, short *Offset)
Definition: UTC2LocalTime.c:3
tTreeEntry TreeFull
Definition: FBLib_EPG.h:62
word SatIndex
Definition: FBLib_EPG.h:57
word ServiceID
Definition: FBLib_EPG.h:56
dword durationHour
Definition: FBLib_EPG.h:46
word NetworkID
Definition: FBLib_EPG.h:54
dword EndTime
Definition: FBLib_EPG.h:51
byte ContentIdentifier
Definition: FBLib_EPG.h:80
dword StartTime
Definition: FBLib_EPG.h:50
dword durationMin
Definition: FBLib_EPG.h:45
bool UseCallback
Definition: FBLib_EPG.h:30
dword StartTime
Definition: FBLib_EPG.h:12
bool GenreFilter
Definition: FBLib_EPG.h:26
word MaxDuration
Definition: FBLib_EPG.h:24
byte * GenreArray
Definition: FBLib_EPG.h:27
byte SatIndex
Definition: FBLib_EPG.h:19
word TSID
Definition: FBLib_EPG.h:17
dword EndTime
Definition: FBLib_EPG.h:13
void * Callback
Definition: FBLib_EPG.h:31
byte GenreArraySize
Definition: FBLib_EPG.h:28
bool TimeFilter
Definition: FBLib_EPG.h:11
bool ChannelFilter
Definition: FBLib_EPG.h:15
bool DurationFilter
Definition: FBLib_EPG.h:22
word MinDuration
Definition: FBLib_EPG.h:23
word ServiceID
Definition: FBLib_EPG.h:18
word NetworkID
Definition: FBLib_EPG.h:16
dword * Next
Definition: FBLib_EPG.h:36
dword * Prev
Definition: FBLib_EPG.h:37