source: npl/mediabox/lcdproc_edwin/src/server/screenlist.c

Last change on this file was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100644
File size: 5.2 KB
Line 
1#include <stdlib.h>
2#include <stdio.h>
3
4#include "../shared/LL.h"
5#include "../shared/sockets.h"
6#include "../shared/debug.h"
7#include "screenlist.h"
8#include "screen.h"
9#include "clients.h"
10
11
12
13int screenlist_action=0;
14
15int timer=0;
16
17LL * screenlist;
18
19
20int screenlist_add_end(screen *screen);
21screen * screenlist_next_roll();
22screen * screenlist_prev_roll();
23screen * screenlist_next_priority();
24
25int compare_priority(void *one, void *two);
26int compare_addresses(void *one, void *two);
27
28
29int screenlist_init()
30{
31   debug("screenlist_init()\n");
32   
33   screenlist = LL_new();
34   if(!screenlist)
35   {
36      fprintf(stderr, "screenlist_init: Error allocating list\n");
37      return -1;
38   }
39
40   screenlist_action = 0;
41   timer = 0;
42   
43   return 0;
44}
45
46int screenlist_shutdown()
47{
48   debug("screenlist_shutdown()\n");
49   
50   LL_Destroy(screenlist);
51   
52   return 0;
53}
54
55int screenlist_remove(screen *s)
56{
57   debug("screenlist_remove()\n");
58   
59   if(!LL_Remove(screenlist, s))
60      return -1;
61   else return 0;
62}
63
64int screenlist_remove_all(screen *s)
65{
66   int i=0;
67   
68   debug("screenlist_remove_all()\n");
69   
70   while(LL_Remove(screenlist, s))
71      i++;
72
73   debug("screenlist_remove_all()... got %i\n", i);
74
75   return i;
76}
77
78LL * screenlist_getlist()
79{
80   debug("screenlist_getlist()\n");
81   
82   return screenlist;
83}
84
85screen * screenlist_current()
86{
87   char str[256];
88   screen *s;
89   static screen *old_s = NULL;
90   client *c;
91
92
93   //debug("screenlist_current:\n");
94   //LL_dprint(screenlist);
95   
96
97   s = (screen *)LL_GetFirst(screenlist);
98
99   // FIXME:  Make sure the screen/client exists!
100   if(s != old_s)
101   {
102      debug("screenlist_current: new screen\n");
103      timer = 0;
104     
105      // Tell the client we're done with the current screen
106      if(old_s)
107      {
108         //debug("screenlist_current: ignoring old screen\n");
109         LL_Rewind(screenlist);
110         if(old_s != LL_Find(screenlist, compare_addresses, old_s))
111         {
112            debug("screenlist: Didn't find screen 0x%8x!\n", (int)old_s);
113         }
114         else {
115            //debug("screenlist_current: ... sending ignore\n");
116            c = old_s->parent;
117            if(c)  // Tell the client we're not listening any more...
118            {
119               sprintf(str, "ignore %s\n", old_s->id);
120               sock_send_string(c->sock, str);
121            }
122            else  // The server has the display, so do nothing
123            {
124            }
125            //debug("screenlist_current: ... sent ignore\n");
126         }
127      }
128      if(s)
129      {
130         //debug("screenlist_current: listening to new screen\n");
131         c = s->parent;
132         if(c)  // Tell the client we're paying attention...
133         {
134            sprintf(str, "listen %s\n", s->id);
135            sock_send_string(c->sock, str);
136         }
137         else  // The server has the display, so do nothing
138         {
139         }
140      }
141   }
142   
143   
144
145   old_s = s;
146
147   //debug("screenlist_current: return %8x\n", s);
148
149   return s;
150}
151
152int screenlist_add(screen *s)
153{
154   // TODO:  Different queueing modes...
155   return screenlist_add_end(s);
156}
157
158screen * screenlist_next()
159{
160   screen *s;
161   
162   //debug("Screenlist_next()\n");
163   
164   s = screenlist_current();
165
166   // If we're on hold, don't advance!
167   if(screenlist_action == SCR_HOLD) return s;
168   //if(screenlist_action == RENDER_HOLD) return s;
169
170   // Otherwise, reset it to regular operation
171   screenlist_action = 0;
172   
173
174   //debug("Screenlist_next: calling handler...\n");
175
176   // Call the selected queuing function...
177   // TODO:  Different queueing modes...
178   s = screenlist_next_priority();
179   //s = screenlist_next_roll();
180
181   //debug("Screenlist_next() done\n");
182
183   return s;
184}
185
186screen * screenlist_prev()
187{
188   screen *s;
189
190   s = screenlist_current();
191
192   // If we're on hold, don't advance!
193   if(screenlist_action == SCR_HOLD) return s;
194   if(screenlist_action == RENDER_HOLD) return s;
195   
196   // Otherwise, reset it no regular operation
197   screenlist_action = 0;
198   
199
200   // Call the selected queuing function...
201   // TODO:  Different queueing modes...
202   s = screenlist_prev_roll();
203
204   return s;
205}
206
207
208// Adds new screens to the end of the screenlist...
209int screenlist_add_end(screen *screen)
210{
211   debug("screenlist_add_end()\n");
212   
213   return LL_Push(screenlist, (void *)screen);
214}
215
216// Simple round-robin approach to screen cycling...
217screen * screenlist_next_roll()
218{
219   //debug("screenlist_next_roll()\n");
220   
221   if(LL_UnRoll(screenlist) != 0) return NULL;
222
223   return screenlist_current();
224}
225
226// Strict priority queue approach...
227screen * screenlist_next_priority()
228{
229   //screen *s, *t;
230   //debug("screenlist_next_priority\n");
231
232   if(LL_UnRoll(screenlist) != 0) return NULL;
233
234   LL_Sort(screenlist, compare_priority);
235   
236   return screenlist_current();
237}
238
239// Simple round-robin approach to screen cycling...
240screen * screenlist_prev_roll()
241{
242   //debug("screenlist_prev_roll()\n");
243   
244   if(LL_Roll(screenlist) != 0) return NULL;
245
246   return screenlist_current();
247}
248
249
250int compare_priority(void *one, void *two)
251{
252   screen *a, *b;
253
254   //debug("compare_priority: %8x %8x\n", one, two);
255   
256   if(!one) return 0;
257   if(!two) return 0;
258   
259   a = (screen *)one;
260   b = (screen *)two;
261
262   //debug("compare_priority: done?\n");
263
264   return (a->priority - b->priority);
265}
266
267int compare_addresses(void *one, void *two)
268{
269   //printf("compare_addresses: 0x%x == 0x%x ???\n", one, two);
270   //if(one == two) printf("Yes!\n");
271   //else printf("No!\n");
272   return (one != two);
273}
Note: See TracBrowser for help on using the repository browser.