Files
lcdproc/server/screenlist.c
T

294 lines
5.6 KiB
C
Raw Normal View History

/*
* screenlist.c
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 1999, William Ferrell, Scott Scriven
*
*
* All actions that can be performed on the list of screens
*
*/
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:");
2001-12-30 00:15:25 +00:00
/*LL_dprint(screenlist);*/
1999-12-09 23:15:14 +00:00
s = (Screen *) LL_GetFirst (screenlist);
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* FIXME: Make sure the screen/client exists!*/
2000-04-03 22:13:57 +00:00
if (s != old_s) {
2001-12-30 00:15:25 +00:00
/*debug (RPT_DEBUG, "screenlist_current: new screen");*/
2000-04-03 22:13:57 +00:00
timer = 0;
2001-12-30 00:15:25 +00:00
/* Tell the client we're done with the current screen*/
2000-04-03 22:13:57 +00:00
if (old_s) {
2001-12-30 00:15:25 +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-12-30 00:15:25 +00:00
report (RPT_WARNING, "screenlist: Didn't find screen 0x%8x! Client crashed?", (int) old_s);
2000-04-03 22:13:57 +00:00
} else {
2001-12-30 00:15:25 +00:00
/*debug(RPT_DEBUG, "screenlist_current: ... sending ignore");*/
c = old_s->client;
2001-12-30 00:15:25 +00:00
if (c) /* Tell the client we're not listening any more...*/
2000-04-03 22:13:57 +00:00
{
snprintf (str, sizeof(str), "ignore %s\n", old_s->id);
2000-04-03 22:13:57 +00:00
sock_send_string (c->sock, str);
2001-12-30 00:15:25 +00:00
} 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
}
2001-12-30 00:15:25 +00:00
/*debug(RPT_DEBUG, "screenlist_current: ... sent ignore");*/
2000-04-03 22:13:57 +00:00
}
}
if (s) {
2001-12-30 00:15:25 +00:00
/*debug(RPT_DEBUG, "screenlist_current: listening to new screen");*/
c = s->client;
2001-12-30 00:15:25 +00:00
if (c) /* Tell the client we're paying attention...*/
2000-04-03 22:13:57 +00:00
{
snprintf (str, sizeof(str), "listen %s\n", s->id);
2000-04-03 22:13:57 +00:00
sock_send_string (c->sock, str);
2001-12-30 00:15:25 +00:00
} 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
}
}
}
2000-04-03 22:13:57 +00:00
old_s = s;
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +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
{
2001-12-30 00:15:25 +00:00
/* TODO: Different queueing modes...*/
2000-04-03 22:13:57 +00:00
return screenlist_add_end (s);
1999-12-09 23:15:14 +00:00
}
Screen *
screenlist_next ()
1999-12-09 23:15:14 +00:00
{
Screen *s;
2001-12-30 00:15:25 +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
2001-12-30 00:15:25 +00:00
/* If we're on hold, don't advance!*/
2000-04-03 22:13:57 +00:00
if (screenlist_action == SCR_HOLD)
return s;
if (screenlist_action == RENDER_HOLD)
return s;
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* Otherwise, reset it to regular operation*/
2000-04-03 22:13:57 +00:00
screenlist_action = 0;
2001-12-30 00:15:25 +00:00
/*debug(RPT_DEBUG, "Screenlist_next: calling handler...");*/
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* Call the selected queuing function...*/
/* TODO: Different queueing modes...*/
2000-04-03 22:13:57 +00:00
s = screenlist_next_priority ();
2001-12-30 00:15:25 +00:00
/*s = screenlist_next_roll();*/
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +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
{
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
2001-12-30 00:15:25 +00:00
/* If we're on hold, don't advance!*/
2000-04-03 22:13:57 +00:00
if (screenlist_action == SCR_HOLD)
return s;
if (screenlist_action == RENDER_HOLD)
return s;
2001-12-30 00:15:25 +00:00
/* Otherwise, reset it no regular operation*/
2000-04-03 22:13:57 +00:00
screenlist_action = 0;
2001-12-30 00:15:25 +00:00
/* Call the selected queuing function...*/
/* TODO: Different queueing modes...*/
2000-04-03 22:13:57 +00:00
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
}
2001-12-30 00:15:25 +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
}
2001-12-30 00:15:25 +00:00
/* Simple round-robin approach to screen cycling...*/
Screen *
screenlist_next_roll ()
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +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
}
2001-12-30 00:15:25 +00:00
/* Strict priority queue approach...*/
Screen *
screenlist_next_priority ()
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +00:00
/*screen *s, *t;*/
/*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
}
2001-12-30 00:15:25 +00:00
/* Simple round-robin approach to screen cycling...*/
Screen *
screenlist_prev_roll ()
1999-12-09 23:15:14 +00:00
{
2001-12-30 00:15:25 +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
{
Screen *a, *b;
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +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;
a = (Screen *) one;
b = (Screen *) two;
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +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-12-30 00:15:25 +00:00
/*debug(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
}