1 | #ifndef CHANNELCACHE_H |
---|
2 | #define CHANNELCACHE_H |
---|
3 | |
---|
4 | void debugchannelcache() |
---|
5 | { |
---|
6 | int i, count = 0, maxcount = 0;; |
---|
7 | struct channelcache* node = NULL; |
---|
8 | |
---|
9 | for(i = 0; i < CHANNELCACHEMAX; i++) |
---|
10 | { |
---|
11 | node = channelcache[i]; |
---|
12 | count = 0; |
---|
13 | while(node != NULL) |
---|
14 | { |
---|
15 | maxcount++; |
---|
16 | count++; |
---|
17 | node = node->next; |
---|
18 | } |
---|
19 | printf("hash=%d, count=%d\n", i, count); |
---|
20 | } |
---|
21 | printf("maxcount=%d\n", maxcount); |
---|
22 | } |
---|
23 | |
---|
24 | struct channel* getchannel(int serviceid, unsigned long transponderid) |
---|
25 | { |
---|
26 | unsigned int hash; |
---|
27 | struct channelcache* node = NULL; |
---|
28 | |
---|
29 | hash = (transponderid + serviceid) % CHANNELCACHEMAX; |
---|
30 | if(hash < 0 || hash >= CHANNELCACHEMAX) hash = 0; |
---|
31 | node = channelcache[hash]; |
---|
32 | |
---|
33 | while(node != NULL) |
---|
34 | { |
---|
35 | if(node->serviceid == serviceid && node->transponderid == transponderid) |
---|
36 | return node->chnode; |
---|
37 | |
---|
38 | node = node->next; |
---|
39 | } |
---|
40 | return NULL; |
---|
41 | } |
---|
42 | |
---|
43 | struct channelcache* modifychannelcache(int serviceid, unsigned long transponderid, struct channel* chnode) |
---|
44 | { |
---|
45 | unsigned int hash; |
---|
46 | //struct channelcache* node = NULL, *prev = NULL, *newnode = NULL; |
---|
47 | struct channelcache* node = NULL, *newnode = NULL; |
---|
48 | |
---|
49 | hash = (transponderid + serviceid) % CHANNELCACHEMAX; |
---|
50 | if(hash < 0 || hash >= CHANNELCACHEMAX) hash = 0; |
---|
51 | |
---|
52 | newnode = (struct channelcache*)malloc(sizeof(struct channelcache)); |
---|
53 | if(newnode == NULL) |
---|
54 | { |
---|
55 | err("no memory"); |
---|
56 | return NULL; |
---|
57 | } |
---|
58 | memset(newnode, 0, sizeof(struct channelcache)); |
---|
59 | |
---|
60 | newnode->serviceid = serviceid; |
---|
61 | newnode->transponderid = transponderid; |
---|
62 | newnode->chnode = chnode; |
---|
63 | |
---|
64 | node = channelcache[hash]; |
---|
65 | /* |
---|
66 | prev = channelcache[hash]; |
---|
67 | |
---|
68 | if(node != NULL) |
---|
69 | { |
---|
70 | while(node != NULL) |
---|
71 | { |
---|
72 | prev = node; |
---|
73 | node = node->next; |
---|
74 | } |
---|
75 | prev->next = newnode; |
---|
76 | } |
---|
77 | else |
---|
78 | channelcache[hash] = newnode; |
---|
79 | */ |
---|
80 | channelcache[hash] = newnode; |
---|
81 | newnode->next = node; |
---|
82 | |
---|
83 | return newnode; |
---|
84 | } |
---|
85 | |
---|
86 | void delchannelcache(int serviceid, unsigned long transponderid) |
---|
87 | { |
---|
88 | unsigned int hash; |
---|
89 | struct channelcache *node = NULL, *prev = NULL; |
---|
90 | |
---|
91 | hash = (transponderid + serviceid) % CHANNELCACHEMAX; |
---|
92 | if(hash < 0 || hash >= CHANNELCACHEMAX) hash = 0; |
---|
93 | node = channelcache[hash]; |
---|
94 | prev = channelcache[hash]; |
---|
95 | |
---|
96 | while(node != NULL) |
---|
97 | { |
---|
98 | if(serviceid == node->serviceid && transponderid == node->transponderid) |
---|
99 | { |
---|
100 | if(node == channelcache[hash]) |
---|
101 | channelcache[hash] = node->next; |
---|
102 | else |
---|
103 | prev->next = node->next; |
---|
104 | |
---|
105 | free(node); |
---|
106 | node = NULL; |
---|
107 | break; |
---|
108 | } |
---|
109 | |
---|
110 | prev = node; |
---|
111 | node = node->next; |
---|
112 | } |
---|
113 | } |
---|
114 | |
---|
115 | #endif |
---|