DEVEL15-openafs-string-header-cleanup-20071030
[openafs.git] / src / gtx / lightobject.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * Description:
12  *      Implementation of the gator light object.
13  *
14  *------------------------------------------------------------------------*/
15
16 #include <afsconfig.h>
17 #include <afs/param.h>
18
19 RCSID
20     ("$Header$");
21
22 #include "gtxlightobj.h"        /*Interface for this module */
23 #include <stdio.h>              /*Standard I/O stuff */
24 #include <errno.h>
25 #include <string.h>
26 #include <stdlib.h>
27
28 /*Externally-advertised array of light onode operations*/
29 struct onodeops gator_light_ops = {
30     gator_light_destroy,
31     gator_light_display,
32     gator_light_release
33 };
34
35 static char mn[] = "gator_lightobject"; /*Module name */
36
37 /*------------------------------------------------------------------------
38  * gator_light_create
39  *
40  * Description:
41  *      Create a gator light object.
42  *
43  * Arguments:
44  *      struct onode *light_onp : Ptr to the light onode to fill out.
45  *      struct onode_createparams *params : Generic ptr to creation
46  *          parameters.
47  *
48  * Returns:
49  *      Zero if successful,
50  *      Error value otherwise.
51  *
52  * Environment:
53  *      The base onode fields have already been set.  Lights are turned
54  *      off at creation.
55  *
56  * Side Effects:
57  *      Creates and initializes the light private data area, including
58  *      a window string-drawing parameter structure.  These areas are
59  *      garbage-collected upon failure.
60  *------------------------------------------------------------------------*/
61
62 int
63 gator_light_create(light_onp, params)
64      struct onode *light_onp;
65      struct onode_createparams *params;
66
67 {                               /*gator_light_create */
68
69     static char rn[] = "gator_light_create";    /*Routine name */
70     struct gator_light_crparams *light_params;  /*My specific creation params */
71     struct gator_lightobj *light_data;  /*Ptr to private data */
72     struct gwin_strparams *light_strparams;     /*Light label params */
73
74     light_params = (struct gator_light_crparams *)params;
75     if (objects_debug) {
76         fprintf(stderr, "[%s:%s] Private data passed to light object:\n", mn,
77                 rn);
78         fprintf(stderr,
79                 "\tAppearance: %d, flashfreq: %d, label at offset (%d, %d): '%s'\n",
80                 light_params->appearance, light_params->flashfreq,
81                 light_params->label_x, light_params->label_y,
82                 light_params->label);
83     }
84
85     /*
86      * Allocate the private data area, including the lower-level
87      * structure, then fill it in.
88      */
89     light_data =
90         (struct gator_lightobj *)malloc(sizeof(struct gator_lightobj));
91     if (light_data == (struct gator_lightobj *)0) {
92         fprintf(stderr,
93                 "[%s:%s] Can't allocate %d bytes for light object private data region, errno is %d\n",
94                 mn, rn, sizeof(struct gator_lightobj), errno);
95         return (errno);
96     }
97
98     light_strparams =
99         (struct gwin_strparams *)malloc(sizeof(struct gwin_strparams));
100     if (light_strparams == (struct gwin_strparams *)0) {
101         fprintf(stderr,
102                 "[%s:%s] Can't allocate %d bytes for light object label in private data region, errno is %d\n",
103                 mn, rn, sizeof(struct gwin_strparams), errno);
104         free(light_data);
105         return (errno);
106     }
107
108     /*
109      * Now that we have the private structures allocated, set them up.
110      */
111     light_data->setting = 0;
112     light_data->appearance = light_params->appearance;
113     light_data->flashfreq = light_params->flashfreq;
114     light_data->lasttoggletime = 0;
115     strcpy(light_data->label, light_params->label);
116
117     light_strparams->x = light_onp->o_x + light_params->label_x;
118     light_strparams->y = light_onp->o_y + light_params->label_y;
119     light_strparams->s = light_data->label;
120     light_strparams->highlight = 0;
121     light_data->llrock = (int *)light_strparams;
122
123     /*
124      * Attach the private data to the onode, then return the happy news.
125      */
126     light_onp->o_data = (int *)light_data;
127     return (0);
128
129 }                               /*gator_light_create */
130
131 /*------------------------------------------------------------------------
132  * gator_light_destroy
133  *
134  * Description:
135  *      Destroy a gator light object.
136  *
137  * Arguments:
138  *      struct onode *onp : Ptr to the light onode to delete.
139  *
140  * Returns:
141  *      0: Success
142  *      Error value otherwise.
143  *
144  * Environment:
145  *      Nothing interesting.
146  *
147  * Side Effects:
148  *      As advertised.
149  *------------------------------------------------------------------------*/
150
151 int
152 gator_light_destroy(onp)
153      struct onode *onp;
154
155 {                               /*gator_light_destroy */
156
157     /*
158      * For now, this is a no-op.
159      */
160     return (0);
161
162 }                               /*gator_light_destroy */
163
164 /*------------------------------------------------------------------------
165  * gator_light_display
166  *
167  * Description:
168  *      Display/redraw a gator light object.
169  *
170  * Arguments:
171  *      struct onode *onp: Ptr to the light onode to display.
172  *
173  * Returns:
174  *      0: Success
175  *      Error value otherwise.
176  *
177  * Environment:
178  *      Light objects have a pointer to string-drawing params in the
179  *      lower-level rock, with the proper highlighting set according
180  *      to whether the light is on or off, so we just have to draw
181  *      that string to get the proper effect.
182  *
183  * Side Effects:
184  *      As advertised.
185  *------------------------------------------------------------------------*/
186
187 int
188 gator_light_display(onp)
189      struct onode *onp;
190
191 {                               /*gator_light_display */
192
193     static char rn[] = "gator_light_display";   /*Routine name */
194     struct gator_lightobj *light_data;  /*Ptr to light obj data */
195     struct gwin_strparams *label_strparams;     /*String-drawing params */
196
197     /*
198      * Draw the label, with proper highlighting depending on whether
199      * the light is on.
200      */
201     light_data = (struct gator_lightobj *)(onp->o_data);
202     label_strparams = (struct gwin_strparams *)(light_data->llrock);
203     if (objects_debug)
204         fprintf(stderr, "[%s:%s] Printing out light label '%s' at (%d, %d)\n",
205                 mn, rn, label_strparams->s, label_strparams->x,
206                 label_strparams->y);
207     WOP_DRAWSTRING(onp->o_window, label_strparams);
208     return (0);
209
210 }                               /*gator_light_display */
211
212 /*------------------------------------------------------------------------
213  * gator_light_release
214  *
215  * Description:
216  *      Drop the refcount on a gator light object.
217  *
218  * Arguments:
219  *      struct onode *onp : Ptr to the onode whose refcount is
220  *                                   to be dropped.
221  *
222  * Returns:
223  *      0: Success
224  *      Error value otherwise.
225  *
226  * Environment:
227  *      Nothing interesting.
228  *
229  * Side Effects:
230  *      As advertised.
231  *------------------------------------------------------------------------*/
232
233 int
234 gator_light_release(onp)
235      struct onode *onp;
236
237 {                               /*gator_light_release */
238
239     /*
240      * For now, this is a no-op.
241      */
242     return (0);
243
244 }                               /*gator_light_release */
245
246 /*------------------------------------------------------------------------
247  * gator_light_set
248  *
249  * Description:
250  *      Set the value of the given gator light object.
251  *
252  * Arguments:
253  *        struct onode *onp : Ptr to the light onode to be set.
254  *        int setting       : Non-zero for ``on'', zero for ``off''.
255  *
256  * Returns:
257  *      0: Success
258  *      Error value otherwise.
259  *
260  * Environment:
261  *      We need to set not only the setting field, but the lower-
262  *      level structure stored in the rock must have its highlight
263  *      field set correctly.
264  *
265  * Side Effects:
266  *      Does NOT redisplay the light object.
267  *------------------------------------------------------------------------*/
268
269 int
270 gator_light_set(onp, setting)
271      struct onode *onp;
272      int setting;
273
274 {                               /*gator_light_set */
275
276     static char rn[] = "gator_light_set";       /*Routine name */
277     struct gator_lightobj *light_data;  /*Ptr to light obj data */
278     struct gwin_strparams *label_strparams;     /*String-drawing params */
279
280     /*
281      * Set the object correctly, then set the highlight field in
282      * the lower-level rock.
283      */
284     light_data = (struct gator_lightobj *)(onp->o_data);
285     label_strparams = (struct gwin_strparams *)(light_data->llrock);
286     if (objects_debug)
287         fprintf(stderr, "[%s:%s] Setting light object at 0x%x to %d (%s)", mn,
288                 rn, onp, setting, (setting ? "ON" : "OFF"));
289     light_data->setting = setting;
290     label_strparams->highlight = setting;
291
292     return (0);
293
294 }                               /*gator_light_set */