source: titan/titan/linkedchannel.h @ 23286

Last change on this file since 23286 was 23286, checked in by nit, 11 years ago

[titan] cleanup

File size: 6.2 KB
Line 
1#ifndef LINKEDCHANNEL_H
2#define LINKEDCHANNEL_H
3
4struct linkedchannel* getlinkedchannel(struct channel* chnode, int serviceid, uint64_t transponderid, time_t starttime, time_t endtime)
5{
6        if(chnode == NULL) return NULL;
7
8        m_lock(&status.linkedchannelmutex, 14);
9        struct linkedchannel* node = chnode->linkedchannel;
10
11        while(node != NULL)
12        {
13                if(node->serviceid == serviceid && node->transponderid == transponderid && node->starttime == starttime && node->endtime == endtime)
14                {
15                        m_unlock(&status.linkedchannelmutex, 14);
16                        return node;
17                }
18                node = node->next;
19        }
20
21        m_unlock(&status.linkedchannelmutex, 14);
22        return NULL;
23}
24
25struct linkedchannel* checklinkedchannel(struct channel* chnode, struct linkedchannel* lchannel)
26{
27        struct linkedchannel* node = NULL;
28
29        if(chnode != NULL)
30        {
31                node = chnode->linkedchannel;
32                while(node != NULL)
33                {
34                        if(node == lchannel)
35                                return node;
36                        node = node->next;
37                }
38        }
39        return NULL;
40}
41
42void screenlinkedchannel()
43{
44        int rcret = 0, treffer = 0, akttime = 0;
45        struct skin* linkedchannel = getscreen("linkedchannel");
46        struct skin* listbox = getscreennode(linkedchannel, "listbox");
47        struct skin* tmp = NULL;
48        struct linkedchannel* node = NULL;
49        struct channel* chnode = channel;
50        struct epg* epgnode = NULL;
51        char* tmpstr = NULL, *buf = NULL;
52        struct tm *loctime = NULL;
53
54        listbox->aktline = 1;
55        listbox->aktpage = -1;
56
57        buf = malloc(7);
58
59        addscreenrc(linkedchannel, listbox);
60start:
61        akttime = time(NULL);
62        tmp = NULL;
63        chnode = channel;
64        delmarkedscreennodes(linkedchannel, 1);
65        if(status.aktservice->channel != NULL)
66        {
67                m_lock(&status.linkedchannelmutex, 14);
68                while(chnode != NULL)
69                {
70                        node = chnode->linkedchannel;
71                        while(node != NULL)
72                        {
73                                if(node->serviceid == status.aktservice->channel->serviceid && node->transponderid == status.aktservice->channel->transponderid && akttime >= node->starttime && akttime < node->endtime)
74                                {
75                                        node = chnode->linkedchannel;
76                                        break;
77                                }
78                                node = node->next;
79                        }
80                        if(node != NULL) break;
81                        chnode = chnode->next;
82                }
83
84                if(node == NULL)
85                        node = status.aktservice->channel->linkedchannel;
86                while(node != NULL)
87                {
88                        if(akttime >= node->starttime && akttime < node->endtime)
89                        {
90                                chnode = getchannel(node->serviceid, node->transponderid);
91                                if(chnode != NULL)
92                                {
93                                        epgnode = getepgakt(chnode);
94                                        //don't show linked channel with start/end 1day
95                                        if(epgnode != NULL && epgnode->endtime - epgnode->starttime >= 86400)
96                                        {
97                                                node = node->next;
98                                                continue;
99                                        }
100                                        tmp = addlistbox(linkedchannel, listbox, tmp, 1);
101                                        if(tmp != NULL)
102                                        {
103                                                if(chnode == status.aktservice->channel)
104                                                        treffer = 1;
105                                                if(treffer == 0)
106                                                        listbox->aktline++;
107                                                tmpstr = ostrcat(tmpstr, chnode->name, 1, 0);
108                                                if(epgnode != NULL)
109                                                {
110                                                        tmpstr = ostrcat(tmpstr, " - ", 1, 0);
111                                                        if(buf != NULL)
112                                                        {
113                                                                loctime = olocaltime(&epgnode->starttime);
114                                                                ostrftime(buf, MINMALLOC, "%H:%M ", loctime);
115                                                                free(loctime); loctime = NULL;
116                                                                tmpstr = ostrcat(tmpstr, buf, 1, 0);
117                                                        }
118                                                        tmpstr = ostrcat(tmpstr, epgnode->title, 1, 0);
119                                                }
120                                                changetext(tmp, tmpstr);
121                                                free(tmpstr); tmpstr = NULL;
122                                                tmp->handle = (char*)chnode;
123                                        }
124                                }
125                        }
126                        node = node->next;
127                }       
128                m_unlock(&status.linkedchannelmutex, 14);
129        }
130
131        if(treffer == 0)
132        {
133                listbox->aktline = 1;
134                treffer = 1;
135        }
136
137        drawscreen(linkedchannel, 0, 0);
138
139        while(1)
140        {
141                rcret = waitrc(linkedchannel, 2000, 0);
142       
143                if(rcret == RCTIMEOUT) goto start;
144       
145                if(rcret == getrcconfigint("rcexit", NULL)) break;
146                if(rcret == getrcconfigint("rcok", NULL))
147                {
148                        if(listbox->select != NULL && listbox->select->handle != NULL)
149                                servicecheckret(servicestart((struct channel*)listbox->select->handle, NULL, NULL, 0), 0);
150                        break;
151                }
152        }
153
154        free(buf);
155        delmarkedscreennodes(linkedchannel, 1);
156        delownerrc(linkedchannel);
157        clearscreen(linkedchannel);
158}
159
160struct linkedchannel* addlinkedchannel(struct channel* chnode, int serviceid, uint64_t transponderid, time_t starttime, time_t endtime, struct linkedchannel* last)
161{
162        struct linkedchannel *newnode = NULL, *prev = NULL, *node = NULL;
163
164        if(chnode == NULL)
165        {
166                err("NULL detect");
167                return NULL;
168        }
169
170        newnode = (struct linkedchannel*)calloc(1, sizeof(struct linkedchannel));
171        if(newnode == NULL)
172        {
173                err("no memory");
174                return NULL;
175        }
176
177        newnode->serviceid = serviceid;
178        newnode->transponderid = transponderid;
179        newnode->starttime = starttime;
180        newnode->endtime = endtime;
181
182        m_lock(&status.linkedchannelmutex, 14);
183        node = chnode->linkedchannel;
184        if(last == NULL)
185        {
186                while(node != NULL)
187                {
188                        prev = node;
189                        node = node->next;
190                }
191        }
192        else
193        {
194                prev = last;
195                node = last->next;
196        }
197
198        if(prev == NULL)
199                chnode->linkedchannel = newnode;
200        else
201                prev->next = newnode;
202
203        newnode->next = node;
204
205        m_unlock(&status.linkedchannelmutex, 14);
206        return newnode;
207}
208
209//flag 0: lock
210//flag 1: nolock
211void dellinkedchannel(struct channel* chnode, struct linkedchannel* lnode, int flag)
212{
213        if(chnode == NULL)
214        {
215                err("NULL detect");
216                return;
217        }
218
219        if(flag == 0) m_lock(&status.linkedchannelmutex, 14);
220
221        struct linkedchannel *node = chnode->linkedchannel, *prev = chnode->linkedchannel;
222
223        while(node != NULL)
224        {
225                if(node == lnode)
226                {
227                        if(node == chnode->linkedchannel)
228                                chnode->linkedchannel = node->next;
229                        else
230                                prev->next = node->next;
231
232                        free(node);
233                        node = NULL;
234                        break;
235                }
236
237                prev = node;
238                node = node->next;
239        }
240        if(flag == 0) m_unlock(&status.linkedchannelmutex, 14);
241}
242
243void freelinkedchannel(struct channel* chnode)
244{
245        struct linkedchannel *node = NULL, *prev = NULL;
246
247        if(chnode == NULL)
248        {
249                err("NULL detect");
250                return;
251        }
252
253        m_lock(&status.linkedchannelmutex, 14);
254        node = chnode->linkedchannel;
255        prev = chnode->linkedchannel;
256
257        while(node != NULL)
258        {
259                prev = node;
260                node = node->next;
261                chnode->linkedchannel = node;
262
263                free(prev);
264                prev = NULL;
265        }
266        m_unlock(&status.linkedchannelmutex, 14);
267}
268
269void deloldlinkedchannel()
270{
271        struct channel* chnode = channel;
272        struct linkedchannel* node = NULL;
273
274        m_lock(&status.linkedchannelmutex, 14);
275        while(chnode != NULL)
276        {
277                if(chnode->linkedchannel != NULL)
278                {
279                        node = channel->linkedchannel;
280                        while(node != NULL)
281                        {
282                                if(node->endtime + 60 < time(NULL))
283                                        dellinkedchannel(chnode, node, 1);
284                                node = node->next;
285                        }
286                }
287                chnode = chnode->next;
288        }
289        m_unlock(&status.linkedchannelmutex, 14);
290}
291
292#endif
Note: See TracBrowser for help on using the repository browser.