Commit | Line | Data |
---|---|---|
805e021f CE |
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 object interface. | |
13 | * | |
14 | *------------------------------------------------------------------------*/ | |
15 | ||
16 | #include <afsconfig.h> | |
17 | #include <afs/param.h> | |
18 | ||
19 | #include <roken.h> | |
20 | ||
21 | #include "gtxobjects.h" /*Interface for this module */ | |
22 | #include "gtxtextobj.h" /*Text object interface */ | |
23 | #include "gtxlightobj.h" /*Light object interface */ | |
24 | #include "gtxobjdict.h" /*Object dictionary module */ | |
25 | ||
26 | /* | |
27 | * Number of known gator object types. | |
28 | */ | |
29 | #define GATOR_NUM_OBJTYPES 3 | |
30 | ||
31 | static char mn[] = "gator_objects"; /*Module name */ | |
32 | int objects_debug; /*Is debugging output on? */ | |
33 | ||
34 | int (*on_create[GATOR_NUM_OBJTYPES]) (struct onode *, | |
35 | struct onode_createparams *); | |
36 | /*Array of ptrs to creation functions */ | |
37 | ||
38 | struct onodeops objops[GATOR_NUM_OBJTYPES]; /*Per-type op arrays */ | |
39 | ||
40 | ||
41 | /*-------------------------------------------------------------------------------- | |
42 | * gator_objects_init | |
43 | * | |
44 | * Description: | |
45 | * Initialize the gator object package. | |
46 | * | |
47 | * Arguments: | |
48 | * struct onode_initparams *params: Initialization parameters. | |
49 | * | |
50 | * Returns: | |
51 | * 0 on success, | |
52 | * Error value otherwise. | |
53 | * | |
54 | * Environment: | |
55 | * *** MUST BE THE FIRST ROUTINE CALLED FROM | |
56 | * THIS PACKAGE *** | |
57 | * | |
58 | * Side Effects: | |
59 | * | |
60 | *--------------------------------------------------------------------------------*/ | |
61 | ||
62 | int | |
63 | gator_objects_init(struct onode_initparams *params) | |
64 | { /*gator_objects_init */ | |
65 | ||
66 | static char rn[] = "gator_objects_init"; /*Routine name */ | |
67 | static int initialized = 0; /*Have we been called? */ | |
68 | int code; /*Return code */ | |
69 | ||
70 | /* | |
71 | * If we've already been called, just return. | |
72 | */ | |
73 | if (initialized) { | |
74 | initialized++; | |
75 | if (objects_debug) | |
76 | fprintf(stderr, "[%s:%s] Called more than once!! (%d time[s])\n", | |
77 | mn, rn, initialized); | |
78 | return (0); | |
79 | } | |
80 | ||
81 | /* | |
82 | * Remember our debugging level. | |
83 | */ | |
84 | objects_debug = params->i_debug; | |
85 | ||
86 | /* | |
87 | * Set up the onode op array, one entry for each known gator object type. | |
88 | */ | |
89 | if (objects_debug) | |
90 | fprintf(stderr, "[%s:%s] Setting up objops array\n", mn, rn); | |
91 | objops[GATOR_OBJ_TEXT] = gator_text_ops; | |
92 | objops[GATOR_OBJ_LIGHT] = gator_light_ops; | |
93 | ||
94 | /* | |
95 | * Initialize the object dictionary. | |
96 | */ | |
97 | if (objects_debug) | |
98 | fprintf(stderr, "[%s:%s] Initializing object dictionary\n", mn, rn); | |
99 | code = gator_objdict_init(objects_debug); | |
100 | if (code) { | |
101 | fprintf(stderr, | |
102 | "[%s:%s] Can't initialize object dictionary: error code is %d\n", | |
103 | mn, rn, code); | |
104 | return (code); | |
105 | } | |
106 | ||
107 | /* | |
108 | * Initialize the chosen window package. Remember the base window | |
109 | * is accessible as gator_basegwin. | |
110 | */ | |
111 | if (objects_debug) { | |
112 | fprintf(stderr, | |
113 | "[%s:%s] Initializing gator window module for package %d.\n", | |
114 | mn, rn, params->i_gwparams->i_type); | |
115 | fprintf(stderr, | |
116 | "\tWindow init params are: type %d, (%d, %d), width=%d, height=%d, debug=%d\n", | |
117 | params->i_gwparams->i_type, params->i_gwparams->i_x, | |
118 | params->i_gwparams->i_y, params->i_gwparams->i_width, | |
119 | params->i_gwparams->i_height, params->i_gwparams->i_debug); | |
120 | } | |
121 | code = gw_init(params->i_gwparams); | |
122 | if (code) { | |
123 | fprintf(stderr, | |
124 | "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n", | |
125 | mn, rn, params->i_gwparams->i_type, code); | |
126 | return (code); | |
127 | } | |
128 | ||
129 | /* | |
130 | * Set up the array of creation functions. | |
131 | */ | |
132 | if (objects_debug) | |
133 | fprintf(stderr, | |
134 | "[%s:%s] Initializing gator object creation function array.\n", | |
135 | mn, rn); | |
136 | on_create[GATOR_OBJ_TEXT] = gator_text_create; | |
137 | on_create[GATOR_OBJ_LIGHT] = gator_light_create; | |
138 | ||
139 | /* | |
140 | * Finally, return the good news. | |
141 | */ | |
142 | return (0); | |
143 | ||
144 | } /*gator_objects_init */ | |
145 | ||
146 | /*-------------------------------------------------------------------------------- | |
147 | * gator_objects_create | |
148 | * | |
149 | * Description: | |
150 | * Create an onode of the given type. | |
151 | * | |
152 | * Arguments: | |
153 | * struct onode_createparams *params: Ptr to creation params. | |
154 | * | |
155 | * Returns: | |
156 | * Ptr to newly-created onode if successful, | |
157 | * Null pointer otherwise. | |
158 | * | |
159 | * Environment: | |
160 | * Nothing interesting. | |
161 | * | |
162 | * Side Effects: | |
163 | * As advertised. | |
164 | *--------------------------------------------------------------------------------*/ | |
165 | ||
166 | struct onode * | |
167 | gator_objects_create(struct onode_createparams *params) | |
168 | { /*gator_objects_create */ | |
169 | ||
170 | static char rn[] = "gator_objects_create"; /*Routine name */ | |
171 | int code; /*Return code */ | |
172 | struct onode *new_onode; /*Ptr to new onode */ | |
173 | ||
174 | if (objects_debug) { | |
175 | fprintf(stderr, "[%s:%s] Creating onode type %d, named '%s'\n", mn, | |
176 | rn, params->cr_type, params->cr_name); | |
177 | fprintf(stderr, "\tOrigin at (%d, %d)\n", params->cr_x, params->cr_y); | |
178 | fprintf(stderr, "\tWidth=%d, height=%d\n", params->cr_width, | |
179 | params->cr_height); | |
180 | fprintf(stderr, "\tHelpstring='%s'\n", params->cr_helpstring); | |
181 | fprintf(stderr, "\tWindow struct at %p\n", params->cr_window); | |
182 | } | |
183 | ||
184 | if (objects_debug) | |
185 | fprintf(stderr, | |
186 | "[%s:%s] Allocating %" AFS_SIZET_FMT " bytes for new onode structure\n", mn, | |
187 | rn, sizeof(struct onode)); | |
188 | new_onode = malloc(sizeof(struct onode)); | |
189 | if (new_onode == NULL) { | |
190 | fprintf(stderr, | |
191 | "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for new onode structure; errno is %d\n", | |
192 | mn, rn, sizeof(struct onode), errno); | |
193 | return (NULL); | |
194 | } | |
195 | ||
196 | /* | |
197 | * Fill in the onode fields we can do right away. | |
198 | * **** Don't do anything with cr_helpstring yet - eventually, | |
199 | * we'll create a scrollable text help object with it **** | |
200 | */ | |
201 | if (objects_debug) | |
202 | fprintf(stderr, "[%s:%s] Filling in onode fields\n", mn, rn); | |
203 | new_onode->o_type = params->cr_type; | |
204 | strcpy(new_onode->o_name, params->cr_name); | |
205 | new_onode->o_x = params->cr_x; | |
206 | new_onode->o_y = params->cr_y; | |
207 | new_onode->o_width = params->cr_width; | |
208 | new_onode->o_height = params->cr_height; | |
209 | new_onode->o_changed = 1; | |
210 | new_onode->o_refcount = 1; | |
211 | new_onode->o_window = params->cr_window; | |
212 | new_onode->o_op = &(objops[params->cr_type]); | |
213 | new_onode->o_home = params->cr_home_obj; | |
214 | new_onode->o_help = NULL; | |
215 | new_onode->o_nextobj = NULL; | |
216 | new_onode->o_upobj = params->cr_parent_obj; | |
217 | new_onode->o_downobj = NULL; | |
218 | ||
219 | /* | |
220 | * Call the proper routine to initialize the private parts of the | |
221 | * given object. | |
222 | */ | |
223 | if (objects_debug) | |
224 | fprintf(stderr, | |
225 | "[%s:%s] Calling the creation routine for gator object type %d\n", | |
226 | mn, rn, params->cr_type); | |
227 | code = (on_create[params->cr_type]) (new_onode, params); | |
228 | if (code) { | |
229 | if (objects_debug) | |
230 | fprintf(stderr, | |
231 | "[%s:%s] Error %d in creation routine for gator object type %d\n", | |
232 | mn, rn, code, params->cr_type); | |
233 | free(new_onode); | |
234 | return (NULL); | |
235 | } | |
236 | ||
237 | /* | |
238 | * Set the links on the parent and previous objects, if so directed. | |
239 | */ | |
240 | if (params->cr_prev_obj != NULL) { | |
241 | if (objects_debug) | |
242 | fprintf(stderr, | |
243 | "[%s:%s] Setting o_nextobj pointer in the previous object located at %p (previous value was %p)\n", | |
244 | mn, rn, params->cr_prev_obj, | |
245 | params->cr_prev_obj->o_nextobj); | |
246 | params->cr_prev_obj->o_nextobj = new_onode; | |
247 | } | |
248 | if (params->cr_parent_obj != NULL) { | |
249 | if (objects_debug) | |
250 | fprintf(stderr, | |
251 | "[%s:%s] Setting o_downobj pointer in the parent object located at %p (previous value was %p)\n", | |
252 | mn, rn, params->cr_parent_obj, | |
253 | params->cr_parent_obj->o_downobj); | |
254 | params->cr_parent_obj->o_downobj = new_onode; | |
255 | } | |
256 | ||
257 | /* | |
258 | * Return the location of the completely-initialized onode object. | |
259 | */ | |
260 | return (new_onode); | |
261 | ||
262 | } /*gator_objects_create */ | |
263 | ||
264 | /*-------------------------------------------------------------------------------- | |
265 | * gator_objects_lookup | |
266 | * | |
267 | * Description: | |
268 | * | |
269 | * | |
270 | * Arguments: | |
271 | * char *onode_name: Onode string name to find. | |
272 | * | |
273 | * Returns: | |
274 | * Ptr to onode matching the given name if one exists, | |
275 | * Null pointer otherwise. | |
276 | * | |
277 | * Environment: | |
278 | * Nothing interesting. | |
279 | * | |
280 | * Side Effects: | |
281 | * As advertised. | |
282 | *--------------------------------------------------------------------------------*/ | |
283 | ||
284 | struct onode * | |
285 | gator_objects_lookup(char *onode_name) | |
286 | { /*gator_objects_lookup */ | |
287 | ||
288 | static char rn[] = "gator_objects_lookup"; /*Routine name */ | |
289 | ||
290 | /* | |
291 | * Life is very simple here - just call the dictionary routine. | |
292 | */ | |
293 | if (objects_debug) | |
294 | fprintf(stderr, "[%s:%s] Looking up gator object '%s'\n", mn, rn, | |
295 | onode_name); | |
296 | return (gator_objdict_lookup(onode_name)); | |
297 | ||
298 | } /*gator_objects_lookup */ |