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.1
- 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.
- */
-
- #include "oakhead.h"
- #include "commonod.h"
- /* -------------------------------------------------------------------------- */
-
- obj_type obj_Open(dispatch, opendata)
- 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;
- if (obj_DoRaw(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);
-
- /* 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)
- obj_type obj;
- /*
- Destoy an object.
- */
- {
- /* 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_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(objdata, msg, indata, outdata)
- VOID *objdata;
- int msg; /* message */
- VOID *indata; /* message input data */
- VOID *outdata; /* message output data */
- /*
- 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);
- }
- /* -------------------------------------------------------------------------- */
-
-
-