FireBirdLib - Topfield TMS PVR TAP Programming Library
FlashServiceReindex.c
Go to the documentation of this file.
1#include <string.h>
2#include "FBLib_flash.h"
3
4//Set FromSvcNum = -1 when adding a service entry
5//or ToSvcNum = -1 to deleting a service entry
6void FlashReindexFavorites(int SvcType, int FromSvcNum, int ToSvcNum)
7{
8 tFavorites *Favorites;
9 int i, j;
10
11 TRACEENTER();
12
14
15 for(i = 0; i < MAXFAVS; i++)
16 {
17 if(Favorites->GroupName[0] && Favorites->NrEntries)
18 {
19 j = 0;
20 while(j < Favorites->NrEntries)
21 {
22 if(Favorites->SvcType[j] == SvcType)
23 {
24 if(FromSvcNum == -1)
25 {
26 //Case 1: a new service has been inserted at ToSvcNum
27 if(Favorites->SvcNum[j] >= ToSvcNum) Favorites->SvcNum[j]++;
28 }
29 else if(ToSvcNum == -1)
30 {
31 //Case 2: a service has been deleted at FromSvcNum
32 if(Favorites->SvcNum[j] >= FromSvcNum)
33 {
34 if(Favorites->SvcNum[j] == FromSvcNum)
35 {
36 memcpy(&Favorites->SvcNum[j], &Favorites->SvcNum[j + 1], (100 - j - 1) * sizeof(word));
37 Favorites->SvcNum[99] = 0;
38 Favorites->NrEntries--;
39 }
40 else
41 Favorites->SvcNum[j]--;
42 }
43 }
44 else if(FromSvcNum < ToSvcNum)
45 {
46 //Case 3: a service has been moved up
47 if((Favorites->SvcNum[j] >= FromSvcNum) && (Favorites->SvcNum[j] <= ToSvcNum))
48 {
49 if(Favorites->SvcNum[j] == FromSvcNum)
50 Favorites->SvcNum[j] = ToSvcNum;
51 else
52 Favorites->SvcNum[j]--;
53 }
54 }
55 else
56 {
57 //Case 4: a service has been moved down
58 if((Favorites->SvcNum[j] <= FromSvcNum) && (Favorites->SvcNum[j] >= ToSvcNum))
59 {
60 if(Favorites->SvcNum[j] == FromSvcNum)
61 Favorites->SvcNum[j] = ToSvcNum;
62 else
63 Favorites->SvcNum[j]++;
64 }
65 }
66 }
67 j++;
68 }
69 }
70 Favorites++;
71 }
72
73 TRACEEXIT();
74}
75
76void FlashReindexTimers(int SvcType, int FromSvcNum, int ToSvcNum)
77{
78 int NrTimer, i;
79 TYPE_TimerInfo TimerInfo;
80
81 TRACEENTER();
82
83 NrTimer = TAP_Timer_GetTotalNum();
84 for(i = NrTimer - 1; i >= 0; i--)
85 {
86 TAP_Timer_GetInfo(i, &TimerInfo);
87 if(TimerInfo.svcType == SvcType)
88 {
89 if(FromSvcNum == -1)
90 {
91 //Case 1: a new service has been inserted at ToSvcNum
92 if(TimerInfo.svcNum >= ToSvcNum)
93 {
94 TimerInfo.svcNum++;
95 TAP_Timer_Modify(i, &TimerInfo);
96 }
97 }
98 else if(ToSvcNum == -1)
99 {
100 //Case 2: a service has been deleted at FromSvcNum
101 if(TimerInfo.svcNum >= FromSvcNum)
102 {
103 if(TimerInfo.svcNum == FromSvcNum)
104 {
105 TAP_Timer_Delete(i);
106 }
107 else
108 {
109 TimerInfo.svcNum--;
110 TAP_Timer_Modify(i, &TimerInfo);
111 }
112 }
113 }
114 else if(FromSvcNum < ToSvcNum)
115 {
116 //Case 3: a service has been moved up
117 if((TimerInfo.svcNum >= FromSvcNum) && (TimerInfo.svcNum <= ToSvcNum))
118 {
119 if(TimerInfo.svcNum == FromSvcNum)
120 {
121 TimerInfo.svcNum = ToSvcNum;
122 TAP_Timer_Modify(i, &TimerInfo);
123 }
124 else
125 {
126 TimerInfo.svcNum--;
127 TAP_Timer_Modify(i, &TimerInfo);
128 }
129 }
130 }
131 else
132 {
133 //Case 4: a service has been moved down
134 if((TimerInfo.svcNum <= FromSvcNum) && (TimerInfo.svcNum >= ToSvcNum))
135 {
136 if(TimerInfo.svcNum == FromSvcNum)
137 {
138 TimerInfo.svcNum = ToSvcNum;
139 TAP_Timer_Modify(i, &TimerInfo);
140 }
141 else
142 {
143 TimerInfo.svcNum++;
144 TAP_Timer_Modify(i, &TimerInfo);
145 }
146 }
147 }
148 }
149 }
150
151 TRACEEXIT();
152}
#define MAXFAVS
Definition: FBLib_flash.h:8
dword FIS_vFlashBlockFavoriteGroup(void)
void FlashReindexTimers(int SvcType, int FromSvcNum, int ToSvcNum)
void FlashReindexFavorites(int SvcType, int FromSvcNum, int ToSvcNum)
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
byte NrEntries
Definition: libFireBird.h:1736
byte SvcType[100]
Definition: libFireBird.h:1735
word SvcNum[100]
Definition: libFireBird.h:1734
char GroupName[12]
Definition: libFireBird.h:1733