2 * Copyright 2000, International Business Machines Corporation and others.
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
12 * Implementation of the gator object interface.
14 *------------------------------------------------------------------------*/
16 #include <afsconfig.h>
17 #include <afs/param.h>
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 */
27 * Number of known gator object types.
29 #define GATOR_NUM_OBJTYPES 3
31 static char mn
[] = "gator_objects"; /*Module name */
32 int objects_debug
; /*Is debugging output on? */
34 int (*on_create
[GATOR_NUM_OBJTYPES
]) (struct onode
*,
35 struct onode_createparams
*);
36 /*Array of ptrs to creation functions */
38 struct onodeops objops
[GATOR_NUM_OBJTYPES
]; /*Per-type op arrays */
41 /*--------------------------------------------------------------------------------
45 * Initialize the gator object package.
48 * struct onode_initparams *params: Initialization parameters.
52 * Error value otherwise.
55 * *** MUST BE THE FIRST ROUTINE CALLED FROM
60 *--------------------------------------------------------------------------------*/
63 gator_objects_init(struct onode_initparams
*params
)
64 { /*gator_objects_init */
66 static char rn
[] = "gator_objects_init"; /*Routine name */
67 static int initialized
= 0; /*Have we been called? */
68 int code
; /*Return code */
71 * If we've already been called, just return.
76 fprintf(stderr
, "[%s:%s] Called more than once!! (%d time[s])\n",
82 * Remember our debugging level.
84 objects_debug
= params
->i_debug
;
87 * Set up the onode op array, one entry for each known gator object type.
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
;
95 * Initialize the object dictionary.
98 fprintf(stderr
, "[%s:%s] Initializing object dictionary\n", mn
, rn
);
99 code
= gator_objdict_init(objects_debug
);
102 "[%s:%s] Can't initialize object dictionary: error code is %d\n",
108 * Initialize the chosen window package. Remember the base window
109 * is accessible as gator_basegwin.
113 "[%s:%s] Initializing gator window module for package %d.\n",
114 mn
, rn
, params
->i_gwparams
->i_type
);
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
);
121 code
= gw_init(params
->i_gwparams
);
124 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
125 mn
, rn
, params
->i_gwparams
->i_type
, code
);
130 * Set up the array of creation functions.
134 "[%s:%s] Initializing gator object creation function array.\n",
136 on_create
[GATOR_OBJ_TEXT
] = gator_text_create
;
137 on_create
[GATOR_OBJ_LIGHT
] = gator_light_create
;
140 * Finally, return the good news.
144 } /*gator_objects_init */
146 /*--------------------------------------------------------------------------------
147 * gator_objects_create
150 * Create an onode of the given type.
153 * struct onode_createparams *params: Ptr to creation params.
156 * Ptr to newly-created onode if successful,
157 * Null pointer otherwise.
160 * Nothing interesting.
164 *--------------------------------------------------------------------------------*/
167 gator_objects_create(struct onode_createparams
*params
)
168 { /*gator_objects_create */
170 static char rn
[] = "gator_objects_create"; /*Routine name */
171 int code
; /*Return code */
172 struct onode
*new_onode
; /*Ptr to new onode */
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
,
180 fprintf(stderr
, "\tHelpstring='%s'\n", params
->cr_helpstring
);
181 fprintf(stderr
, "\tWindow struct at %p\n", params
->cr_window
);
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
) {
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
);
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 ****
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
;
220 * Call the proper routine to initialize the private parts of the
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
);
231 "[%s:%s] Error %d in creation routine for gator object type %d\n",
232 mn
, rn
, code
, params
->cr_type
);
238 * Set the links on the parent and previous objects, if so directed.
240 if (params
->cr_prev_obj
!= NULL
) {
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
;
248 if (params
->cr_parent_obj
!= NULL
) {
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
;
258 * Return the location of the completely-initialized onode object.
262 } /*gator_objects_create */
264 /*--------------------------------------------------------------------------------
265 * gator_objects_lookup
271 * char *onode_name: Onode string name to find.
274 * Ptr to onode matching the given name if one exists,
275 * Null pointer otherwise.
278 * Nothing interesting.
282 *--------------------------------------------------------------------------------*/
285 gator_objects_lookup(char *onode_name
)
286 { /*gator_objects_lookup */
288 static char rn
[] = "gator_objects_lookup"; /*Routine name */
291 * Life is very simple here - just call the dictionary routine.
294 fprintf(stderr
, "[%s:%s] Looking up gator object '%s'\n", mn
, rn
,
296 return (gator_objdict_lookup(onode_name
));
298 } /*gator_objects_lookup */