home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Messaging / OSL / OSLInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  7.9 KB  |  286 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        OSLInit.c
  3.  
  4.     Contains:    Initialization routines for the OSL
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1993,4 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     1/15/96    TJ        Cleaned Up
  13.          <7>     7/27/95    eeh        1204615: remove Nick's DebugStr
  14.          <6>     6/27/95    NP        1262792: new version of OSLObjectInit
  15.          <5>      5/3/95    NP        1211084: Remove 5$
  16.          <4>     1/12/95    jpa        Don't use obsolete Toolbox names [1211211]
  17.          <3>     9/29/94    RA        1189812: Mods for 68K build.
  18.          <2>     8/19/94    NP        1181622: Ownership fix.
  19.          <7>      5/2/94    eeh        bug #1160654: various PPC native changes
  20.          <6>      2/7/94    NP        Tiger Team doings.
  21.          <5>     11/5/93    NP        Change in function declaration to satisfy
  22.                                     MPW C.
  23.          <4>     11/2/93    NP        Move pascal keyword.
  24.          <3>    10/11/93    NP        Added DebugStr.
  25.          <2>     7/28/93    NP        Mods for new token type, OSLToken.
  26.          <1>     7/21/93    NP        first checked in
  27.  
  28.     To Do:
  29.     In Progress:
  30. */
  31.  
  32. /*                                            
  33.     ©Apple Computer, Inc.  1992         
  34.           All Rights Reserved.                
  35.     Author: Eric House
  36.                                             */
  37.  
  38. #ifndef _OSLPRIV_
  39. #include "OSLPriv.h"
  40. #endif
  41.  
  42. #pragma segment AEObjSuppt
  43.  
  44. //pascal OSErr
  45. //AEObjectInit(void);
  46. pascal OSErr
  47. iAESetObjectCallbacks( OSLCompareUPP myCompareProc, OSLCountUPP myCountProc,
  48.         OSLDisposeTokenUPP myDisposeTokenProc,
  49.         OSLGetMarkTokenUPP myGetMarkTokenProc, OSLMarkUPP myMarkProc,
  50.         OSLAdjustMarksUPP myAdjustMarksProc,
  51.         OSLGetErrDescUPP reserved );
  52.  
  53. /* WARNING: this struct depends on the current implementation of the hash
  54.  * manager staying the same.  If it changes, this will break! */
  55.  
  56. typedef struct  {        
  57.         long someLongField ;            
  58.         long hashTableSize ;                
  59.     } hashTableRec, *hashTableRecP, **hashTableRecH ;
  60.  
  61. static Boolean IsValidHashTable( HHand ahp )
  62. {
  63.     long hSize ;
  64.     Boolean retVal = false ;            /* the safe thing to assume */
  65.  
  66.     hSize = GetHandleSize( (Handle)ahp ) ;
  67.     if ( (MemError() == noErr)
  68.             && (hSize == (*(hashTableRecH)ahp)->hashTableSize) )
  69.         retVal = true ;
  70.     return retVal;
  71. }
  72.  
  73.  
  74. #pragma segment AEObjGlue
  75. //#if GENERATINGCFM
  76. void ShouldNotBeHere();
  77. void ShouldNotBeHere()
  78. {
  79.     DebugStr( "\pYou shouldn't be here" ) ;
  80. }
  81. //#endif
  82.  
  83.     /*Initializes the hash table and other goodies required by the object
  84.         resolution stuff */
  85. pascal OSErr
  86. iAEObjectInit(OSLContext* context)
  87. {
  88.  
  89.     GlobalRecHandle appGlobal ;
  90.     GlobalRecHandle sysGlobal ;
  91.     OSErr out ;
  92.     long ignore ;
  93.     HHand tempH ;                /* added to avoid Hlock and Unlock around AENewHashTable calls */
  94.     OSLToken nullDesc ;
  95.     OSErr err;
  96.  
  97.     err = AddContextToTopOfStack(context);
  98.         if (err) return err;
  99.  
  100.     // NOTICE BOGUS PROCPTR HERE FOR NOW. ONLY HERE BECAUSE OF COMMENT BELOW,
  101.     //    "inits app global"
  102.  
  103. #if GENERATINGCFM
  104.     out = AEInstallSpecialHandler( keySelectProc,
  105.             (UniversalProcPtr)ShouldNotBeHere, false ) ;
  106. #else
  107. //    out = AEInstallSpecialHandler( keySelectProc,
  108. //            (UniversalProcPtr)SelectorDispatch, false ) ;    /* inits app global */
  109.     out = AEInstallSpecialHandler( keySelectProc,
  110.             (UniversalProcPtr)ShouldNotBeHere, false ) ;
  111. #endif
  112.     appGlobal = GetGlobalRef();
  113.  
  114.     /* if it is not already inited, we must force the AEM to init the system global */
  115.     sysGlobal = GetSysGlobal() ;
  116.     if ( sysGlobal == NULL ) 
  117.     {
  118.         IgnoreOSErr( AEGetEventHandler( 'go b', 'ears', (AEEventHandlerUPP *)ignore,
  119.                 &ignore, true ) ) ;
  120.         sysGlobal = GetSysGlobal() ;
  121.     }
  122.      
  123.     if ( out == noErr )
  124.         if ( ((*appGlobal)->accessorHashTable == nil)
  125.                 || !IsValidHashTable( (*appGlobal)->accessorHashTable ) )
  126.         {
  127.             out = AENewHashTable( kInitialHashTableSize, 8, 8, NULL, false, &tempH );
  128.             if ( out == noErr )
  129.                 (*appGlobal)->accessorHashTable = tempH ;
  130.         }
  131.  
  132.     if ( ((*sysGlobal)->accessorHashTable == nil) && (out == noErr) )
  133. #ifdef _MPWFIX_
  134.     if ( ((*sysGlobal)->AccessorHashTable == nil )
  135.                     || !IsValidHashTable( (*sysGlobal)->AccessorHashTable ) 
  136. #endif
  137.         {
  138.     //        out = AENewHashTable( kInitialHashTableSize, 8, 8, NULL, true, &tempH ) ;
  139.             if ( out == noErr )
  140.                 (*sysGlobal)->accessorHashTable = tempH ; 
  141.         }
  142.  
  143. // <eeh> removed 7/93 as part of PPC port; will call the coercion directly rather
  144. // than via the AEM.
  145. //    if ( out == noErr )
  146. //        out = AEInstallCoercionHandler( typeWhoseDescriptor, typeWhoseDescriptor,
  147. //                              (EventHandlerUPP)MakeExternalWhose, 0, true, false ) ;
  148.  
  149.     MakeNullToken( &nullDesc ) ;                /* 3/11/92 */
  150.     SetExmn( &nullDesc ) ;
  151.  
  152.     return out ;
  153. }
  154.  
  155. #pragma segment AEObjSuppt
  156.  
  157. OSErr MakeExternalWhose( const AEDesc* desc, AEDesc *result )
  158. {
  159.  
  160.     AEDesc dWhoseRange, dRangeStart ;
  161.     AERecord dWhoseRecord,    dWhoseRangeRec ;
  162.     IndexRecord  index ;
  163.     DescType  typeCode ;
  164.     Size  actualSize ;
  165.     OSErr err ;
  166.  
  167. //    DebugStr("\pOSLInit.MakeExternalWhose: Inside MakeExternalWhose. Call Nick.");
  168.  
  169.     err = AECoerceDesc( desc, typeAERecord, &dWhoseRecord ) ;
  170.     if ( err != noErr ) goto a ;
  171.  
  172.     err = AEGetKeyPtr( &dWhoseRecord, keyAEIndex, typeWhoseRangeInternal, &typeCode,
  173.                              (Ptr)&index, sizeof(index), &actualSize ) ;
  174.     if ( err != noErr ) goto b ;
  175.     
  176.     err = AECreateDesc( index.startCase, (Ptr)&index.startValue, SizeOf(index.startValue),
  177.             &dRangeStart ) ;
  178.     if ( err != noErr ) goto b ;
  179.     
  180.     if ( index.stopCase == typeNull )
  181.         {
  182.             dWhoseRange = dRangeStart ;
  183.             dRangeStart.dataHandle = NULL ;            /* so we don't double dispose */
  184.             dWhoseRangeRec.dataHandle = NULL ;
  185.         }
  186.     else
  187.         {
  188.             err = AECreateList( NULL, 0, true, &dWhoseRangeRec ) ;
  189.             if ( err != noErr ) goto c ;
  190.  
  191.             err = AEPutKeyPtr( &dWhoseRangeRec, keyAEWhoseRangeStop, index.stopCase,
  192.                             (Ptr)&index.stopValue, sizeof(index.stopValue) ) ;
  193.             if ( err != noErr ) goto d ;
  194.  
  195.             err = AEPutKeyDesc( &dWhoseRangeRec, keyAEWhoseRangeStart, &dRangeStart ) ;
  196.             if ( err != noErr ) goto d ;
  197.  
  198.             err = AECoerceDesc( &dWhoseRangeRec, typeWhoseRange, &dWhoseRange) ;
  199.             if ( err != noErr ) goto d ;
  200.         } ;
  201.  
  202.     err = AEPutKeyDesc( &dWhoseRecord, keyAEIndex, &dWhoseRange ) ;
  203.     if ( err != noErr ) goto e ;
  204.     
  205.     err = AECoerceDesc( &dWhoseRecord, typeWhoseDescriptor, result ) ;
  206.  
  207. e:
  208.     IgnoreOSErr( AEDisposeDesc( &dWhoseRange ) ) ;
  209. d:
  210.     IgnoreOSErr( AEDisposeDesc( &dWhoseRangeRec ) ) ;
  211. c:
  212.     IgnoreOSErr( AEDisposeDesc( &dRangeStart ) ) ;
  213. b:
  214.     IgnoreOSErr( AEDisposeDesc( &dWhoseRecord ) ) ;
  215. a:
  216.     return err ;
  217. } // MakeExternalWhose
  218.  
  219.  
  220. //———————————————————————— iAESetObjectCallbacks ————————————————————————
  221. pascal OSErr
  222. iAESetObjectCallbacks( OSLCompareUPP myCompareProc, OSLCountUPP myCountProc,
  223.         OSLDisposeTokenUPP myDisposeTokenProc,
  224.         OSLGetMarkTokenUPP myGetMarkTokenProc, OSLMarkUPP myMarkProc,
  225.         OSLAdjustMarksUPP myAdjustMarksProc,
  226.         OSLGetErrDescUPP reserved )
  227.  
  228.         // changed model to allow nil procs; replace/enter iff non-nil
  229. {
  230.     OSErr out ;
  231.  
  232.     out = noErr ;
  233.  
  234.     if ( myCompareProc != NULL )
  235.         out = AEInstallSpecialHandler( keyAECompareProc,
  236.                 (UniversalProcPtr)myCompareProc, false ) ;
  237. //        ELSE
  238. //        out := errRequiredProcAbsent;
  239.  
  240.     if ( (out == noErr) && (myCountProc != NULL) )
  241.         out = AEInstallSpecialHandler( keyAECountProc, (UniversalProcPtr)myCountProc, false ) ;
  242. //        ELSE
  243. //        out := errRequiredProcAbsent; 
  244.  
  245.     // these procs are optional, so we are less upset about not seeing them        //<eeh> added first two
  246.     if ( (out == noErr) && (myDisposeTokenProc != NULL) )
  247.         out = AEInstallSpecialHandler( keyDisposeTokenProc,
  248.                 (UniversalProcPtr)myDisposeTokenProc, false);
  249.  
  250.     if ( (out == noErr) && (myGetMarkTokenProc != NULL) )
  251.         out = AEInstallSpecialHandler( keyAEMarkTokenProc,
  252.                 (UniversalProcPtr)myGetMarkTokenProc, false);
  253.     if ( (out == noErr) && (myMarkProc != NULL) )
  254.         out = AEInstallSpecialHandler(keyAEMarkProc,
  255.                 (UniversalProcPtr)myMarkProc, false);
  256.     if ( (out == noErr) && (myAdjustMarksProc != NULL) )
  257.         out = AEInstallSpecialHandler( keyAEAdjustMarksProc,
  258.                 (UniversalProcPtr)myAdjustMarksProc, false);
  259.  
  260.     if ( ( out == noErr ) && ( reserved != NULL ) )
  261.         out = AEInstallSpecialHandler( keyAEGetErrDescProc,
  262.                 (UniversalProcPtr)reserved, false ) ;
  263.  
  264.     return out;            // <eeh> in Pascal, this preceeded last if above
  265. } // iAESetObjectCallbacks
  266.  
  267.  
  268. #if 0
  269.     // Currently this routine does nothing...
  270.     
  271.     #ifndef __FRAGLOAD__
  272.     #include <FragLoad.h>
  273.     #endif
  274.     
  275.     #ifndef __MACRUNTIME__
  276.     #include <MacRuntime.h>
  277.     #endif
  278.     
  279.     #pragma lib_export on
  280.     
  281.     pascal OSErr OSLCFMInit (InitBlockPtr initBlkPtr)
  282.     {
  283.         return noErr;
  284.     }
  285.  
  286. #endif /*0*/