home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c185 / 2.ddi / OWLSRC.EXE / CSCAPE / SOURCE / OBJFUNCS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  4.2 KB  |  147 lines

  1. /*
  2.     objfuncs.c    7/29/88
  3.  
  4.     % Object primitive definitions.
  5.     Also contains common object dispatch function.
  6.  
  7.     by Ted.
  8.  
  9.     OWL 1.1
  10.     Copyright (c) 1988, by Oakland Group, Inc.
  11.     ALL RIGHTS RESERVED.
  12.  
  13.     Revision History:
  14.     -----------------
  15.      8/09/88 jmd    Rewrote with new scheme
  16.      9/12/88 jmd    Added in and out data to objects
  17.     10/14/88 jdc    Now passes opendata along in the OBJM_GETDATASIZE
  18.                         message, this allows for varible size obj_od!
  19.     11/20/88 jmd    Added ID to obj struct
  20.     11/30/88 jmd    Added 0 preload to obj_Open
  21.      3/23/89 ted    Added xdata stuff
  22.      7/07/89 gam    Changed NULL to FNULL where necessary
  23.      8/06/89 ted    Changed omalloc to ocalloc for object alloc.
  24. */
  25.  
  26. #include "oakhead.h"
  27. #include "commonod.h"
  28. /* -------------------------------------------------------------------------- */
  29.  
  30. obj_type obj_Open(dispatch, opendata)
  31.     class_fptr dispatch;
  32.     VOID *opendata;
  33. /*
  34.     Create a new object.
  35.     dispatch is the object's dispatch function
  36.     opendata is creation data that is passed to the dispatch function
  37.     (opendta may be removed in the future, it is not advised to use it)
  38.  
  39.     Uses the object ID as an omalloc tag.
  40. */
  41. {
  42.     obj_type     obj;
  43.     ogds_struct ogds;
  44.  
  45.     /* Get size of object data (preload it to -1 for safety check) */
  46.     ogds.xdsize = (unsigned) -1;
  47.     ogds.odsize = (unsigned) -1;
  48.     ogds.id = 0;
  49.     if (obj_DoRaw(dispatch, NULL, OBJM_GETDATASIZE, opendata, &ogds) == FALSE) {
  50.         return(NULL);
  51.     }
  52.     /* Make sure both xdsize and odsize were initialized */
  53.     owl_Assert((ogds.odsize != (unsigned) -1), OE_OO_ODSIZE);
  54.     owl_Assert((ogds.xdsize != (unsigned) -1), OE_OO_XDSIZE);
  55.     owl_Assert((ogds.id != 0), OE_OO_ID);
  56.  
  57.     /* Allocate object and object data */
  58.     obj = (obj_type) ocalloc(ogds.id,
  59.                         sizeof(struct obj_struct) + ogds.xdsize + ogds.odsize,
  60.                         sizeof(byte));
  61.     if (obj == NULL) {
  62.         return(NULL);
  63.     }
  64.     /* Initialize object elements */
  65.     obj->dispatch = dispatch;
  66.  
  67.     obj->od = (VOID *) (((char *) obj_getxd(obj)) + ogds.xdsize);
  68.     /* Initialize object xdata (= id) */
  69.     /* NOTE: This line assumes that the common_xd is first in the nested _xd */
  70.     /* structures. Memory trashing will occur if this is not the case. */
  71.     /* This is the idea the xdata scheme is based on anyway. */
  72.     obj_setid(obj, ogds.id);
  73.  
  74.     /* Initialize object odata (= self) */
  75.     /* NOTE: This line assumes that the common_od is first in the nested _od */
  76.     /* structures. Memory trashing will occur if this is not the case. */
  77.     ((common_od *) obj->od)->self = obj;
  78.  
  79.     /* Call object's OPEN message */
  80.     /* NOTE: ogds is passed in place of outdata because outdata is not needed, */
  81.     /* and ogds can be used to kluge variable-size xd/od's with inheritance. */
  82.     /* (Implicit here is that opendata is not touched between GETDATASIZE and */
  83.     /*  OPEN so that each level in OPEN can re-compute the variable data it  */
  84.     /*  requested in GETDATASIZE.) */
  85.  
  86.     if (obj_Do(obj, OBJM_OPEN, opendata, &ogds) == FALSE) {
  87.         ofree(OA_OBJ, (VOID *) obj);
  88.         return(NULL);
  89.     }
  90.     return(obj);
  91. }
  92. /* -------------------------------------------------------------------------- */
  93.  
  94. void obj_Close(obj)
  95.     obj_type obj;
  96. /*
  97.     Destoy an object.
  98. */
  99. {
  100.     /* call object's CLOSE message */
  101.     obj_Do(obj, OBJM_CLOSE, NULL, NULL);
  102.  
  103.     /* set object elements to bad values
  104.        in case someone accidentally tries to use it after it gets closed */
  105.     obj->dispatch = FNULL;
  106.     obj_setid(obj, OA_NOTAG - 1);
  107.  
  108.     /* release storage */
  109.     ofree(OA_OBJ, (VOID *) obj);
  110. }
  111.  
  112. /* -------------------------------------------------------------------------- */
  113.  
  114. boolean obj_Who(obj, type)
  115.     obj_type obj;
  116.     int type;
  117. /*
  118.     Returns TRUE if the object is of the given type
  119. */
  120. {
  121.     return((obj == NULL) ? 
  122.         FALSE : (boolean) obj_Do(obj, OBJM_WHO, &type, NULL));
  123. }
  124.  
  125. /* -------------------------------------------------------------------------- */
  126.  
  127. int objreq_Null(objdata, msg, indata, outdata)
  128.     VOID *objdata;
  129.     int msg;                /* message */
  130.     VOID *indata;            /* message input data */
  131.     VOID *outdata;            /* message output data */
  132. /*
  133.     Empty object request message handler. Used for initializing function
  134.     pointers so they can point somewhere.
  135. */
  136. {
  137.     oak_notused(objdata);
  138.     oak_notused(msg);
  139.     oak_notused(indata);
  140.     oak_notused(outdata);
  141.  
  142.     return(FALSE);
  143. }
  144. /* -------------------------------------------------------------------------- */
  145.  
  146.  
  147.