home *** CD-ROM | disk | FTP | other *** search
- /*
- objfuncs.c 7/29/88
-
- % Object primitive definitions.
- Also contains common object dispatch function.
-
- by Ted.
-
- OWL 1.2
- Copyright (c) 1988, by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 8/09/88 jmd Rewrote with new scheme
- 9/12/88 jmd Added in and out data to objects
- 10/14/88 jdc Now passes opendata along in the OBJM_GETDATASIZE
- message, this allows for varible size obj_od!
- 11/20/88 jmd Added ID to obj struct
- 11/30/88 jmd Added 0 preload to obj_Open
- 3/23/89 ted Added xdata stuff
- 7/07/89 gam Changed NULL to FNULL where necessary
- 8/06/89 ted Changed omalloc to ocalloc for object alloc.
-
- 11/06/89 jmd removed DoRaw macros
- 12/12/89 jmd added object names
- 1/21/89 jdc changed oslist stuff
- 3/28/90 jmd ansi-fied
- 6/22/90 ted added "void" to no-parameter function per ansii.
- 7/29/90 jmd added auxiliary func to objects, added objDoAux, obj_SetAux
- 9/07/90 jmd renamed oslist stuff
- 12/05/90 jmd now sends the AUX_END message before closing the object
- */
-
- #include "oakhead.h"
- #include "commonod.h"
-
- /* -------------------------------------------------------------------------- */
- /* the object name list */
- OGLOBAL oslist_type objnamelist = NULL;
-
- void oak_Close(void)
- /*
- Close down the object name list, if there is one.
- */
- {
- if (objnamelist != NULL) {
- oslist_Close(objnamelist);
- objnamelist = NULL;
- }
- }
-
- /* -------------------------------------------------------------------------- */
-
- obj_type obj_Open(class_fptr dispatch, VOID *opendata)
- /*
- Create a new object.
- dispatch is the object's dispatch function
- opendata is creation data that is passed to the dispatch function
- (opendta may be removed in the future, it is not advised to use it)
- Uses the object ID as an omalloc tag.
- */
- {
- obj_type obj;
- ogds_struct ogds;
-
- /* Get size of object data (preload it to -1 for safety check) */
- ogds.xdsize = (unsigned) -1;
- ogds.odsize = (unsigned) -1;
- ogds.id = 0;
-
- /* we don't have an object yet, call the dispatch function directly */
- if ((*dispatch)(NULL, OBJM_GETDATASIZE, opendata, &ogds) == FALSE) {
- return(NULL);
- }
-
- /* Make sure both xdsize and odsize were initialized */
- owl_Assert((ogds.odsize != (unsigned) -1), OE_OO_ODSIZE);
- owl_Assert((ogds.xdsize != (unsigned) -1), OE_OO_XDSIZE);
- owl_Assert((ogds.id != 0), OE_OO_ID);
-
- /* Allocate object and object data */
- obj = (obj_type) ocalloc(ogds.id,
- sizeof(struct obj_struct) + ogds.xdsize + ogds.odsize,
- sizeof(byte));
- if (obj == NULL) {
- return(NULL);
- }
- /* Initialize object elements */
- obj->dispatch = dispatch;
-
- obj->od = (VOID *) (((char *) obj_getxd(obj)) + ogds.xdsize);
- /* Initialize object xdata (= id) */
- /* NOTE: This line assumes that the common_xd is first in the nested _xd */
- /* structures. Memory trashing will occur if this is not the case. */
- /* This is the idea the xdata scheme is based on anyway. */
- obj_setid(obj, ogds.id);
-
- /* init object to no name */
- obj_SetNameHandle(obj, -1);
-
- /* Initialize object odata (= self) */
- /* NOTE: This line assumes that the common_od is first in the nested _od */
- /* structures. Memory trashing will occur if this is not the case. */
- ((common_od *) obj->od)->self = obj;
-
- /* Call object's OPEN message */
- /* NOTE: ogds is passed in place of outdata because outdata is not needed, */
- /* and ogds can be used to kluge variable-size xd/od's with inheritance. */
- /* (Implicit here is that opendata is not touched between GETDATASIZE and */
- /* OPEN so that each level in OPEN can re-compute the variable data it */
- /* requested in GETDATASIZE.) */
-
- if (obj_Do(obj, OBJM_OPEN, opendata, &ogds) == FALSE) {
- ofree(OA_OBJ, (VOID *) obj);
- return(NULL);
- }
- return(obj);
- }
- /* -------------------------------------------------------------------------- */
-
- void obj_Close(obj_type obj)
- /*
- Destroy an object.
- */
- {
- /* remove object from the name list */
- obj_RemoveName(obj);
-
- /* close the aux function (send the AUX_END message) */
- obj_SetAux(obj, FNULL);
-
- /* call object's CLOSE message */
- obj_Do(obj, OBJM_CLOSE, NULL, NULL);
-
- /* set object elements to bad values
- in case someone accidentally tries to use it after it gets closed */
- obj->dispatch = FNULL;
- obj_setid(obj, OA_NOTAG - 1);
-
- /* release storage */
- ofree(OA_OBJ, (VOID *) obj);
- }
-
- /* -------------------------------------------------------------------------- */
-
- boolean obj_Who(obj_type obj, int type)
- /*
- Returns TRUE if the object is of the given type
- */
- {
- return((obj == NULL) ?
- FALSE : (boolean) obj_Do(obj, OBJM_WHO, &type, NULL));
- }
-
- /* -------------------------------------------------------------------------- */
-
- int objreq_Null(VOID *objdata, int msg, VOID *indata, VOID *outdata)
- /*
- Empty object request message handler. Used for initializing function
- pointers so they can point somewhere.
- */
- {
- oak_notused(objdata);
- oak_notused(msg);
- oak_notused(indata);
- oak_notused(outdata);
-
- return(FALSE);
- }
-
- /* -------------------------------------------------------------------------- */
-
- void obj_RemoveName(obj_type obj)
- /*
- Removes an object name.
- Removes the object name from the name list.
- If the name is used by another object, doesn't remove the object,
- instead it decrements the hit count for the name.
- */
- {
- objname_struct *oldname;
-
- oldname = (objname_struct *)oslist_GetData(objnamelist, obj_GetNameHandle(obj));
-
- if (oldname != NULL) {
- if (oldname->hits <= 1) { /* only instance, delete old name */
- oslist_Delete(objnamelist, obj_GetNameHandle(obj));
- }
- else {
- oldname->hits--; /* reduce hit count */
- oldname->obj = NULL; /* reset name data */
- }
- }
-
- obj_SetNameHandle(obj, -1);
- }
-
- /* -------------------------------------------------------------------------- */
-
- int obj_DoAux(obj_type obj, int msg, VOID *indata, VOID *outdata)
- /*
- Call the obj's auxillary function.
- Returns 1 if there is no auxillary function
- else it returns the auxillary function's return value.
- */
- {
- if (obj == NULL || obj_GetAux(obj) == FNULL) {
- return(1);
- }
-
- return((*(obj_GetAux(obj)))(obj, msg, indata, outdata));
- }
-
- /* -------------------------------------------------------------------------- */
-
- void obj_SetAux(obj_type obj, aux_fptr aux)
- /*
- sets the obj's auxiliary function
- sends appropriate AUXSTART and AUXEND messages
- call with aux == FNULL to end aux function action
- */
- {
- if (obj_GetAux(obj) != FNULL) {
- obj_DoAux(obj, AUX_END, NULL, NULL);
- obj_setox(obj, FNULL);
- }
-
- if (aux != FNULL) {
- obj_setox(obj, aux);
- obj_DoAux(obj, AUX_START, NULL, NULL);
- }
- }
-
-