~benklop/+junk/lcdproc

« back to all changes in this revision

Viewing changes to server/screen.c

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Tallon
  • Date: 2006-07-23 20:23:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060723202348-w65hrbvpwniqn9by
Tags: 0.5.0-1
* New upstream version (Closes: #367945)
  - New maintainer. Thank you for your previous work, Jon!
  - Upstream added suport for 'imon' devices (Closes: #365496)
  - Upstream fixed descriptor leak (Closes: #355460)
  - Upstream fixed placing widgets in frame (Closes: #355458)

* Packaging
  - Depend on debconf-2.0; Allow transition (Closes: #331885)
  - Remove dependency on automake (Closes: #376449)
  - Include missing INSTALL instructions (Closes: #365436)
  - Changed most "by hand" installation steps into debhelper-based ones
  - Updated to 3.7.2 standards version

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * COPYING file distributed with this package.
7
7
 *
8
8
 * Copyright (c) 1999, William Ferrell, Scott Scriven
 
9
 *               2003, Joris Robijn
9
10
 *
10
11
 *
11
12
 * Does screen management
18
19
 
19
20
#include "shared/report.h"
20
21
 
21
 
#include "drivers/lcd.h"
 
22
#include "drivers.h"
22
23
 
23
24
#include "clients.h"
24
 
#include "client_data.h"
25
25
#include "widget.h"
26
26
#include "screenlist.h"
27
27
#include "screen.h"
 
28
#include "menuscreens.h"
28
29
#include "main.h"
29
30
#include "render.h"
30
31
 
31
32
int  default_duration = 0;
32
33
int  default_timeout  = -1;
33
34
 
34
 
screen *
35
 
screen_create ()
 
35
char *pri_names[] = {
 
36
        "hidden",
 
37
        "background",
 
38
        "info",
 
39
        "foreground",
 
40
        "alert",
 
41
        "input",
 
42
        NULL,
 
43
};
 
44
 
 
45
Screen *
 
46
screen_create (char * id, Client * client)
36
47
{
37
 
        screen *s;
38
 
 
39
 
        s = malloc (sizeof (screen));
 
48
        Screen *s;
 
49
 
 
50
        debug( RPT_DEBUG, "%s( id=\"%.40s\", client=[%d] )", __FUNCTION__, id, (client?client->sock:-1));
 
51
 
 
52
        s = malloc (sizeof (Screen));
40
53
        if (!s) {
41
 
                report(RPT_ERR, "screen_create: Error allocating new screen");
42
 
                return NULL;
43
 
        }
44
 
 
45
 
        s->id = NULL;
 
54
                report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
 
55
                return NULL;
 
56
        }
 
57
        if (!id) {
 
58
                report (RPT_ERR, "%s: Need id string", __FUNCTION__);
 
59
                return NULL;
 
60
        }
 
61
        /* Client can be NULL for serverscreens and other client-less screens */
 
62
 
 
63
        s->id = strdup(id);
 
64
        if (!s->id) {
 
65
                report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
 
66
                return NULL;
 
67
        }
 
68
 
46
69
        s->name = NULL;
47
 
        s->priority = DEFAULT_SCREEN_PRIORITY;
 
70
        s->priority = PRI_INFO;
48
71
        s->duration = default_duration;
49
 
        s->heartbeat = DEFAULT_HEARTBEAT;
50
 
        s->wid = lcd_ptr->wid;
51
 
        s->hgt = lcd_ptr->hgt;
 
72
        s->backlight = BACKLIGHT_OPEN;
 
73
        s->heartbeat = HEARTBEAT_OPEN;
 
74
        s->width = display_props->width;
 
75
        s->height = display_props->height;
52
76
        s->keys = NULL;
53
 
        s->parent = NULL;
54
 
        s->widgets = NULL;
55
 
        s->timeout = default_timeout; /*ignored unless greater than 0.*/
56
 
        s->backlight_state = BACKLIGHT_NOTSET;  /*Lets the screen do it's own*/
 
77
        s->client = client;
 
78
        s->widgetlist = NULL;
 
79
        s->timeout = default_timeout;   /*ignored unless greater than 0.*/
 
80
        s->backlight = BACKLIGHT_OPEN;          /*Lets the screen do it's own*/
57
81
                                                /*or do what the client says.*/
 
82
        s->cursor = CURSOR_OFF;
 
83
        s->cursor_x = 1;
 
84
        s->cursor_y = 1;
58
85
 
59
 
        s->widgets = LL_new ();
60
 
        if (!s->widgets) {
61
 
                report(RPT_ERR, "screen_create:  Error allocating widget list");
 
86
        s->widgetlist = LL_new ();
 
87
        if (!s->widgetlist) {
 
88
                report(RPT_ERR, "%s: Error allocating", __FUNCTION__);
62
89
                return NULL;
63
90
        }
64
91
 
 
92
        menuscreen_add_screen (s);
 
93
 
65
94
        return s;
66
95
}
67
96
 
68
97
int
69
 
screen_destroy (screen * s)
 
98
screen_destroy (Screen * s)
70
99
{
71
 
        widget *w;
72
 
 
73
 
        if (!s)
74
 
                return -1;
75
 
 
76
 
        LL_Rewind (s->widgets);
77
 
        do {
 
100
        Widget *w;
 
101
 
 
102
        debug( RPT_DEBUG, "%s( s=[%.40s] )", __FUNCTION__, s->id );
 
103
 
 
104
        menuscreen_remove_screen (s);
 
105
 
 
106
        screenlist_remove (s);
 
107
 
 
108
        for (w=LL_GetFirst(s->widgetlist); w; w=LL_GetNext(s->widgetlist)) {
78
109
                /* Free a widget...*/
79
 
                w = LL_Get (s->widgets);
80
110
                widget_destroy (w);
81
 
        } while (LL_Next (s->widgets) == 0);
82
 
        LL_Destroy (s->widgets);
 
111
        }
 
112
        LL_Destroy (s->widgetlist);
83
113
 
84
114
        if (s->id)
85
115
                free (s->id);
86
116
        if (s->name)
87
117
                free (s->name);
88
 
        if (s->keys)
89
 
                free (s->keys);
90
118
 
91
119
        free (s);
92
120
 
93
121
        return 0;
94
122
}
95
123
 
96
 
screen *
97
 
screen_find (client * c, char *id)
98
 
{
99
 
        screen *s;
100
 
 
101
 
        if (!c)
 
124
int
 
125
screen_add_widget (Screen * s, Widget * w)
 
126
{
 
127
        debug( RPT_DEBUG, "%s( s=[%.40s], widget=[%.40s] )", __FUNCTION__, s->id, w->id );
 
128
 
 
129
        LL_Push (s->widgetlist, (void *) w);
 
130
 
 
131
        return 0;
 
132
}
 
133
 
 
134
int
 
135
screen_remove_widget (Screen * s, Widget * w)
 
136
{
 
137
        debug( RPT_DEBUG, "%s( s=[%.40s], widget=[%.40s] )", __FUNCTION__, s->id, w->id );
 
138
 
 
139
        LL_Remove (s->widgetlist, (void *) w);
 
140
 
 
141
        return 0;
 
142
}
 
143
 
 
144
Widget *
 
145
screen_find_widget (Screen * s, char *id)
 
146
{
 
147
        Widget * w;
 
148
 
 
149
        if (!s)
102
150
                return NULL;
103
151
        if (!id)
104
152
                return NULL;
105
153
 
106
 
        debug (RPT_INFO, "client_find_screen(%s)", id);
107
 
 
108
 
        LL_Rewind (c->data->screenlist);
109
 
        do {
110
 
                s = LL_Get (c->data->screenlist);
111
 
                if ((s) && (0 == strcmp (s->id, id))) {
112
 
                        debug (RPT_DEBUG, "client_find_screen:  Found %s", id);
113
 
                        return s;
114
 
                }
115
 
        } while (LL_Next (c->data->screenlist) == 0);
116
 
 
 
154
        debug( RPT_DEBUG, "%s( s=[%.40s], id=\"%.40s\" )", __FUNCTION__, s->id, id );
 
155
 
 
156
        for ( w=LL_GetFirst(s->widgetlist); w; w=LL_GetNext(s->widgetlist) ) {
 
157
                if (0 == strcmp (w->id, id)) {
 
158
                        debug (RPT_DEBUG, "%s: Found %s", __FUNCTION__, id);
 
159
                        return w;
 
160
                }
 
161
                /* Search subscreens recursively */
 
162
                if (w->type == WID_FRAME) {
 
163
                        w = widget_search_subs (w, id);
 
164
                        if (w)
 
165
                                return w;
 
166
                }
 
167
        }
 
168
        debug (RPT_DEBUG, "%s: Not found", __FUNCTION__);
117
169
        return NULL;
118
170
}
119
171
 
120
 
int
121
 
screen_add (client * c, char *id)
 
172
Priority
 
173
screen_pri_name_to_pri (char * priname)
122
174
{
123
 
        screen *s;
124
 
 
125
 
        if (!c)
126
 
                return -1;
127
 
        if (!id)
128
 
                return -1;
129
 
 
130
 
        /* Make sure this screen doesn't already exist...*/
131
 
        s = screen_find (c, id);
132
 
        if (s) {
133
 
                return 1;
134
 
        }
135
 
 
136
 
        s = screen_create ();
137
 
        if (!s) {
138
 
                report (RPT_ERR, "screen_add:  Error creating screen");
139
 
                return -1;
140
 
        }
141
 
 
142
 
        s->parent = c;
143
 
 
144
 
        s->id = strdup (id);
145
 
        if (!s->id) {
146
 
                report (RPT_ERR, "screen_add:  Error allocating name");
147
 
                return -1;
148
 
        }
149
 
        /* TODO:  Check for errors here?*/
150
 
        LL_Push (c->data->screenlist, (void *) s);
151
 
 
152
 
        /* Now, add it to the screenlist...*/
153
 
        if (screenlist_add (s) < 0) {
154
 
                report (RPT_ERR, "screen_add:  Error queueing new screen");
155
 
                return -1;
156
 
        }
157
 
 
158
 
        return 0;
 
175
        Priority pri = WID_NONE;
 
176
        int i;
 
177
 
 
178
        for (i = 0; pri_names[i]; i++) {
 
179
                if (strcmp (pri_names[i], priname) == 0) {
 
180
                        pri = i;
 
181
                        break; /* it's valid: skip out...*/
 
182
                }
 
183
        }
 
184
        return pri;
159
185
}
160
186
 
161
 
int
162
 
screen_remove (client * c, char *id)
 
187
char *
 
188
screen_pri_to_pri_name (Priority pri)
163
189
{
164
 
        screen *s;
165
 
 
166
 
        if (!c)
167
 
                return -1;
168
 
        if (!id)
169
 
                return -1;
170
 
 
171
 
        /* Make sure this screen *does* exist...*/
172
 
        s = screen_find (c, id);
173
 
        if (!s) {
174
 
                report (RPT_ERR, "screen_remove:  Error finding screen %s", id);
175
 
                return 1;
176
 
        }
177
 
        /* TODO:  Check for errors here?*/
178
 
        LL_Remove (c->data->screenlist, (void *) s);
179
 
 
180
 
        /* Now, remove it from the screenlist...*/
181
 
        if (screenlist_remove_all (s) < 0) {
182
 
                /* Not a serious error..*/
183
 
                report (RPT_ERR, "screen_remove:  Error dequeueing screen");
184
 
                return 0;
185
 
        }
186
 
 
187
 
        /* TODO:  Check for errors here too?*/
188
 
        screen_destroy (s);
189
 
 
190
 
        return 0;
 
190
        return pri_names[pri];
191
191
}