Files
lcdproc/server/screen.c
T

192 lines
3.3 KiB
C
Raw Normal View History

/*
* screen.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
*
*
* Does screen management
*
*/
1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
2001-11-29 14:09:13 +00:00
#include "shared/report.h"
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
#include "drivers.h"
1999-12-09 23:15:14 +00:00
#include "clients.h"
#include "client_data.h"
#include "widget.h"
#include "screenlist.h"
#include "screen.h"
#include "main.h"
#include "render.h"
1999-12-09 23:15:14 +00:00
2001-09-28 14:23:41 +00:00
int default_duration = 0;
int default_timeout = -1;
screen *
screen_create ()
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 = malloc (sizeof (screen));
if (!s) {
2001-11-29 14:09:13 +00:00
report(RPT_ERR, "screen_create: Error allocating new screen");
2000-04-03 22:13:57 +00:00
return NULL;
}
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
s->id = NULL;
s->name = NULL;
s->priority = DEFAULT_SCREEN_PRIORITY;
2001-09-25 14:03:13 +00:00
s->duration = default_duration;
s->heartbeat = DEFAULT_HEARTBEAT;
2001-12-30 00:15:25 +00:00
s->wid = display_props->width;
s->hgt = display_props->height;
s->keys = NULL;
2000-04-03 22:13:57 +00:00
s->parent = NULL;
s->widgets = NULL;
2001-12-30 00:15:25 +00:00
s->timeout = default_timeout; /*ignored unless greater than 0.*/
s->backlight_state = BACKLIGHT_NOTSET; /*Lets the screen do it's own*/
/*or do what the client says.*/
2001-11-29 14:09:13 +00:00
2000-04-03 22:13:57 +00:00
s->widgets = LL_new ();
if (!s->widgets) {
2001-11-29 14:09:13 +00:00
report(RPT_ERR, "screen_create: Error allocating widget list");
2000-04-03 22:13:57 +00:00
return NULL;
}
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
screen_destroy (screen * s)
1999-12-09 23:15:14 +00:00
{
2000-04-03 22:13:57 +00:00
widget *w;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if (!s)
return -1;
2000-04-03 22:13:57 +00:00
LL_Rewind (s->widgets);
do {
2001-12-30 00:15:25 +00:00
/* Free a widget...*/
2000-04-03 22:13:57 +00:00
w = LL_Get (s->widgets);
widget_destroy (w);
} while (LL_Next (s->widgets) == 0);
LL_Destroy (s->widgets);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if (s->id)
free (s->id);
if (s->name)
free (s->name);
if (s->keys)
free (s->keys);
2000-04-03 22:13:57 +00:00
free (s);
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
screen *
screen_find (client * c, char *id)
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
if (!c)
return NULL;
if (!id)
return NULL;
1999-12-09 23:15:14 +00:00
2001-11-29 14:09:13 +00:00
debug (RPT_INFO, "client_find_screen(%s)", id);
2000-04-03 22:13:57 +00:00
LL_Rewind (c->data->screenlist);
do {
s = LL_Get (c->data->screenlist);
if ((s) && (0 == strcmp (s->id, id))) {
2001-11-29 14:09:13 +00:00
debug (RPT_DEBUG, "client_find_screen: Found %s", id);
2000-04-03 22:13:57 +00:00
return s;
}
} while (LL_Next (c->data->screenlist) == 0);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return NULL;
1999-12-09 23:15:14 +00:00
}
int
screen_add (client * c, char *id)
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
if (!c)
return -1;
if (!id)
return -1;
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* Make sure this screen doesn't already exist...*/
2000-04-03 22:13:57 +00:00
s = screen_find (c, id);
if (s) {
return 1;
}
2000-04-03 22:13:57 +00:00
s = screen_create ();
if (!s) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "screen_add: Error creating screen");
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
s->parent = c;
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
s->id = strdup (id);
if (!s->id) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "screen_add: Error allocating name");
2000-04-03 22:13:57 +00:00
return -1;
}
2001-12-30 00:15:25 +00:00
/* TODO: Check for errors here?*/
2000-04-03 22:13:57 +00:00
LL_Push (c->data->screenlist, (void *) s);
2001-12-30 00:15:25 +00:00
/* Now, add it to the screenlist...*/
2000-04-03 22:13:57 +00:00
if (screenlist_add (s) < 0) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "screen_add: Error queueing new screen");
2000-04-03 22:13:57 +00:00
return -1;
}
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
int
screen_remove (client * c, char *id)
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
if (!c)
return -1;
if (!id)
return -1;
2001-12-30 00:15:25 +00:00
/* Make sure this screen *does* exist...*/
2000-04-03 22:13:57 +00:00
s = screen_find (c, id);
if (!s) {
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "screen_remove: Error finding screen %s", id);
2000-04-03 22:13:57 +00:00
return 1;
}
2001-12-30 00:15:25 +00:00
/* TODO: Check for errors here?*/
2000-04-03 22:13:57 +00:00
LL_Remove (c->data->screenlist, (void *) s);
1999-12-09 23:15:14 +00:00
2001-12-30 00:15:25 +00:00
/* Now, remove it from the screenlist...*/
2000-04-03 22:13:57 +00:00
if (screenlist_remove_all (s) < 0) {
2001-12-30 00:15:25 +00:00
/* Not a serious error..*/
2001-11-29 14:09:13 +00:00
report (RPT_ERR, "screen_remove: Error dequeueing screen");
2000-04-03 22:13:57 +00:00
return 0;
}
2001-12-30 00:15:25 +00:00
/* TODO: Check for errors here too?*/
screen_destroy (s);
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}