Files
lcdproc/server/screenlist.c
T

280 lines
5.2 KiB
C
Raw Normal View History

1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include "shared/LL.h"
#include "shared/sockets.h"
2001-11-29 14:09:13 +00:00
#include "shared/report.h"
1999-12-09 23:15:14 +00:00
#include "screenlist.h"
#include "screen.h"
#include "clients.h"
int screenlist_action = 0;
1999-12-09 23:15:14 +00:00
int timer = 0;
1999-12-09 23:15:14 +00:00
LinkedList *screenlist;
1999-12-09 23:15:14 +00:00
int screenlist_add_end (screen * screen);
screen *screenlist_next_roll ();
screen *screenlist_prev_roll ();
screen *screenlist_next_priority ();
1999-12-09 23:15:14 +00:00
int compare_priority (void *one, void *two);
int compare_addresses (void *one, void *two);
1999-12-09 23:15:14 +00:00
int
screenlist_init ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "screenlist_init()");
2000-04-03 22:13:57 +00:00
screenlist = LL_new ();
if (!screenlist) {
2001-11-29 14:09:13 +00:00
report(RPT_ERR, "screenlist_init: error allocating list");
2000-04-03 22:13:57 +00:00
return -1;
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
screenlist_action = 0;
timer = 0;
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
int
screenlist_shutdown ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "screenlist_shutdown()");
2000-04-03 22:13:57 +00:00
LL_Destroy (screenlist);
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
int
screenlist_remove (screen * s)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "screenlist_remove()");
2000-04-03 22:13:57 +00:00
if (!LL_Remove (screenlist, s))
return -1;
else
return 0;
1999-12-09 23:15:14 +00:00
}
int
screenlist_remove_all (screen * s)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
int i = 0;
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "screenlist_remove_all()");
2000-04-03 22:13:57 +00:00
while (LL_Remove (screenlist, s))
i++;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
debug (RPT_DEBUG, "screenlist_remove_all()... got %i", i);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return i;
1999-12-09 23:15:14 +00:00
}
LinkedList *
screenlist_getlist ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
report (RPT_INFO, "screenlist_getlist()");
2000-04-03 22:13:57 +00:00
return screenlist;
1999-12-09 23:15:14 +00:00
}
screen *
screenlist_current ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
char str[256];
screen *s;
static screen *old_s = NULL;
client *c;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
debug( RPT_INFO, "screenlist_current:");
2000-04-03 22:13:57 +00:00
//LL_dprint(screenlist);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
s = (screen *) LL_GetFirst (screenlist);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
// FIXME: Make sure the screen/client exists!
if (s != old_s) {
2001-11-29 14:09:13 +00:00
//debug (RPT_DEBUG, "screenlist_current: new screen");
2000-04-03 22:13:57 +00:00
timer = 0;
2000-04-03 22:13:57 +00:00
// Tell the client we're done with the current screen
if (old_s) {
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "screenlist_current: ignoring old screen");
2000-04-03 22:13:57 +00:00
LL_Rewind (screenlist);
if (old_s != LL_Find (screenlist, compare_addresses, old_s)) {
2001-11-29 14:09:13 +00:00
report (RPT_WARNING, "screenlist: Didn't find screen 0x%8x!", (int) old_s);
2000-04-03 22:13:57 +00:00
} else {
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "screenlist_current: ... sending ignore");
2000-04-03 22:13:57 +00:00
c = old_s->parent;
if (c) // Tell the client we're not listening any more...
{
snprintf (str, sizeof(str), "ignore %s\n", old_s->id);
2000-04-03 22:13:57 +00:00
sock_send_string (c->sock, str);
} else // The server has the display, so do nothing
{
;
2000-04-03 22:13:57 +00:00
}
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "screenlist_current: ... sent ignore");
2000-04-03 22:13:57 +00:00
}
}
if (s) {
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "screenlist_current: listening to new screen");
2000-04-03 22:13:57 +00:00
c = s->parent;
if (c) // Tell the client we're paying attention...
{
snprintf (str, sizeof(str), "listen %s\n", s->id);
2000-04-03 22:13:57 +00:00
sock_send_string (c->sock, str);
} else // The server has the display, so do nothing
{
;
2000-04-03 22:13:57 +00:00
}
}
}
2000-04-03 22:13:57 +00:00
old_s = s;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "screenlist_current: return %8x", s);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return s;
1999-12-09 23:15:14 +00:00
}
int
screenlist_add (screen * s)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
// TODO: Different queueing modes...
return screenlist_add_end (s);
1999-12-09 23:15:14 +00:00
}
screen *
screenlist_next ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
screen *s;
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "Screenlist_next()");
2000-04-03 22:13:57 +00:00
s = screenlist_current ();
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
// If we're on hold, don't advance!
if (screenlist_action == SCR_HOLD)
return s;
if (screenlist_action == RENDER_HOLD)
return s;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
// Otherwise, reset it to regular operation
screenlist_action = 0;
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "Screenlist_next: calling handler...");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
// Call the selected queuing function...
// TODO: Different queueing modes...
s = screenlist_next_priority ();
//s = screenlist_next_roll();
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "Screenlist_next() done");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return s;
1999-12-09 23:15:14 +00:00
}
screen *
screenlist_prev ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
screen *s;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
s = screenlist_current ();
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
// If we're on hold, don't advance!
if (screenlist_action == SCR_HOLD)
return s;
if (screenlist_action == RENDER_HOLD)
return s;
2000-04-03 22:13:57 +00:00
// Otherwise, reset it no regular operation
screenlist_action = 0;
2000-04-03 22:13:57 +00:00
// Call the selected queuing function...
// TODO: Different queueing modes...
s = screenlist_prev_roll ();
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return s;
1999-12-09 23:15:14 +00:00
}
// Adds new screens to the end of the screenlist...
int
screenlist_add_end (screen * screen)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
debug (RPT_DEBUG, "screenlist_add_end()");
2000-04-03 22:13:57 +00:00
return LL_Push (screenlist, (void *) screen);
1999-12-09 23:15:14 +00:00
}
// Simple round-robin approach to screen cycling...
screen *
screenlist_next_roll ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "screenlist_next_roll()");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if (LL_UnRoll (screenlist) != 0)
return NULL;
2000-04-03 22:13:57 +00:00
return screenlist_current ();
1999-12-09 23:15:14 +00:00
}
// Strict priority queue approach...
screen *
screenlist_next_priority ()
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
//screen *s, *t;
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "screenlist_next_priority");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if (LL_UnRoll (screenlist) != 0)
return NULL;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
LL_Sort (screenlist, compare_priority);
2000-04-03 22:13:57 +00:00
return screenlist_current ();
1999-12-09 23:15:14 +00:00
}
// Simple round-robin approach to screen cycling...
screen *
screenlist_prev_roll ()
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "screenlist_prev_roll()");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if (LL_Roll (screenlist) != 0)
return NULL;
2000-04-03 22:13:57 +00:00
return screenlist_current ();
1999-12-09 23:15:14 +00:00
}
int
compare_priority (void *one, void *two)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
screen *a, *b;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "compare_priority: %8x %8x", one, two);
2000-04-03 22:13:57 +00:00
if (!one)
return 0;
if (!two)
return 0;
2000-04-03 22:13:57 +00:00
a = (screen *) one;
b = (screen *) two;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
//debug(RPT_DEBUG, "compare_priority: done?");
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return (a->priority - b->priority);
1999-12-09 23:15:14 +00:00
}
int
compare_addresses (void *one, void *two)
1999-12-09 23:15:14 +00:00
{
2001-11-29 14:09:13 +00:00
//printf(RPT_DEBUG, "compare_addresses: %p == %p ???", one, two);
2000-04-03 22:13:57 +00:00
return (one != two);
1999-12-09 23:15:14 +00:00
}