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>
20 #include "gtxobjects.h" /*Interface for this module */
21 #include "gtxtextobj.h" /*Text object interface */
22 #include "gtxlightobj.h" /*Light object interface */
23 #include "gtxobjdict.h" /*Object dictionary module */
24 #include <stdio.h> /*Standard I/O stuff */
31 * Number of known gator object types.
33 #define GATOR_NUM_OBJTYPES 3
35 static char mn
[] = "gator_objects"; /*Module name */
36 int objects_debug
; /*Is debugging output on? */
38 int (*on_create
[GATOR_NUM_OBJTYPES
]) (struct onode
*,
39 struct onode_createparams
*);
40 /*Array of ptrs to creation functions */
42 struct onodeops objops
[GATOR_NUM_OBJTYPES
]; /*Per-type op arrays */
45 /*--------------------------------------------------------------------------------
49 * Initialize the gator object package.
52 * struct onode_initparams *params: Initialization parameters.
56 * Error value otherwise.
59 * *** MUST BE THE FIRST ROUTINE CALLED FROM
64 *--------------------------------------------------------------------------------*/
67 gator_objects_init(struct onode_initparams
*params
)
68 { /*gator_objects_init */
70 static char rn
[] = "gator_objects_init"; /*Routine name */
71 static int initialized
= 0; /*Have we been called? */
72 int code
; /*Return code */
75 * If we've already been called, just return.
80 fprintf(stderr
, "[%s:%s] Called more than once!! (%d time[s])\n",
86 * Remember our debugging level.
88 objects_debug
= params
->i_debug
;
91 * Set up the onode op array, one entry for each known gator object type.
94 fprintf(stderr
, "[%s:%s] Setting up objops array\n", mn
, rn
);
95 objops
[GATOR_OBJ_TEXT
] = gator_text_ops
;
96 objops
[GATOR_OBJ_LIGHT
] = gator_light_ops
;
99 * Initialize the object dictionary.
102 fprintf(stderr
, "[%s:%s] Initializing object dictionary\n", mn
, rn
);
103 code
= gator_objdict_init(objects_debug
);
106 "[%s:%s] Can't initialize object dictionary: error code is %d\n",
112 * Initialize the chosen window package. Remember the base window
113 * is accessible as gator_basegwin.
117 "[%s:%s] Initializing gator window module for package %d.\n",
118 mn
, rn
, params
->i_gwparams
->i_type
);
120 "\tWindow init params are: type %d, (%d, %d), width=%d, height=%d, debug=%d\n",
121 params
->i_gwparams
->i_type
, params
->i_gwparams
->i_x
,
122 params
->i_gwparams
->i_y
, params
->i_gwparams
->i_width
,
123 params
->i_gwparams
->i_height
, params
->i_gwparams
->i_debug
);
125 code
= gw_init(params
->i_gwparams
);
128 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
129 mn
, rn
, params
->i_gwparams
->i_type
, code
);
134 * Set up the array of creation functions.
138 "[%s:%s] Initializing gator object creation function array.\n",
140 on_create
[GATOR_OBJ_TEXT
] = gator_text_create
;
141 on_create
[GATOR_OBJ_LIGHT
] = gator_light_create
;
144 * Finally, return the good news.
148 } /*gator_objects_init */
150 /*--------------------------------------------------------------------------------
151 * gator_objects_create
154 * Create an onode of the given type.
157 * struct onode_createparams *params: Ptr to creation params.
160 * Ptr to newly-created onode if successful,
161 * Null pointer otherwise.
164 * Nothing interesting.
168 *--------------------------------------------------------------------------------*/
171 gator_objects_create(struct onode_createparams
*params
)
172 { /*gator_objects_create */
174 static char rn
[] = "gator_objects_create"; /*Routine name */
175 int code
; /*Return code */
176 struct onode
*new_onode
; /*Ptr to new onode */
179 fprintf(stderr
, "[%s:%s] Creating onode type %d, named '%s'\n", mn
,
180 rn
, params
->cr_type
, params
->cr_name
);
181 fprintf(stderr
, "\tOrigin at (%d, %d)\n", params
->cr_x
, params
->cr_y
);
182 fprintf(stderr
, "\tWidth=%d, height=%d\n", params
->cr_width
,
184 fprintf(stderr
, "\tHelpstring='%s'\n", params
->cr_helpstring
);
185 fprintf(stderr
, "\tWindow struct at %p\n", params
->cr_window
);
190 "[%s:%s] Allocating %" AFS_SIZET_FMT
" bytes for new onode structure\n", mn
,
191 rn
, sizeof(struct onode
));
192 new_onode
= (struct onode
*)malloc(sizeof(struct onode
));
193 if (new_onode
== NULL
) {
195 "[%s:%s] Can't allocate %" AFS_SIZET_FMT
" bytes for new onode structure; errno is %d\n",
196 mn
, rn
, sizeof(struct onode
), errno
);
201 * Fill in the onode fields we can do right away.
202 * **** Don't do anything with cr_helpstring yet - eventually,
203 * we'll create a scrollable text help object with it ****
206 fprintf(stderr
, "[%s:%s] Filling in onode fields\n", mn
, rn
);
207 new_onode
->o_type
= params
->cr_type
;
208 strcpy(new_onode
->o_name
, params
->cr_name
);
209 new_onode
->o_x
= params
->cr_x
;
210 new_onode
->o_y
= params
->cr_y
;
211 new_onode
->o_width
= params
->cr_width
;
212 new_onode
->o_height
= params
->cr_height
;
213 new_onode
->o_changed
= 1;
214 new_onode
->o_refcount
= 1;
215 new_onode
->o_window
= params
->cr_window
;
216 new_onode
->o_op
= &(objops
[params
->cr_type
]);
217 new_onode
->o_home
= params
->cr_home_obj
;
218 new_onode
->o_help
= NULL
;
219 new_onode
->o_nextobj
= NULL
;
220 new_onode
->o_upobj
= params
->cr_parent_obj
;
221 new_onode
->o_downobj
= NULL
;
224 * Call the proper routine to initialize the private parts of the
229 "[%s:%s] Calling the creation routine for gator object type %d\n",
230 mn
, rn
, params
->cr_type
);
231 code
= (on_create
[params
->cr_type
]) (new_onode
, params
);
235 "[%s:%s] Error %d in creation routine for gator object type %d\n",
236 mn
, rn
, code
, params
->cr_type
);
242 * Set the links on the parent and previous objects, if so directed.
244 if (params
->cr_prev_obj
!= NULL
) {
247 "[%s:%s] Setting o_nextobj pointer in the previous object located at %p (previous value was %p)\n",
248 mn
, rn
, params
->cr_prev_obj
,
249 params
->cr_prev_obj
->o_nextobj
);
250 params
->cr_prev_obj
->o_nextobj
= new_onode
;
252 if (params
->cr_parent_obj
!= NULL
) {
255 "[%s:%s] Setting o_downobj pointer in the parent object located at %p (previous value was %p)\n",
256 mn
, rn
, params
->cr_parent_obj
,
257 params
->cr_parent_obj
->o_downobj
);
258 params
->cr_parent_obj
->o_downobj
= new_onode
;
262 * Return the location of the completely-initialized onode object.
266 } /*gator_objects_create */
268 /*--------------------------------------------------------------------------------
269 * gator_objects_lookup
275 * char *onode_name: Onode string name to find.
278 * Ptr to onode matching the given name if one exists,
279 * Null pointer otherwise.
282 * Nothing interesting.
286 *--------------------------------------------------------------------------------*/
289 gator_objects_lookup(char *onode_name
)
290 { /*gator_objects_lookup */
292 static char rn
[] = "gator_objects_lookup"; /*Routine name */
295 * Life is very simple here - just call the dictionary routine.
298 fprintf(stderr
, "[%s:%s] Looking up gator object '%s'\n", mn
, rn
,
300 return (gator_objdict_lookup(onode_name
));
302 } /*gator_objects_lookup */