home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / LinkSpec.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  44KB  |  1,308 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: oddataxfer
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 82,27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. // @(#) 1.7 com/src/storage/LinkSpec.cpp, oddataxfer, od96os2, odos29712d 8/15/96 17:25:23 [ 3/21/97 17:18:55 ]
  28. /*
  29.         File:           LinkSpec.cpp
  30.  
  31.         Contains:       Implementation for ODLinkSpec class.
  32.  
  33.         Owned by:       Craig Carper
  34.  
  35.         Copyright:      ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37.         Change History (most recent first):
  38.  
  39.                 <14>     10/8/95        TJ              Fixes Recomended by Refball
  40.                 <13>     8/16/95        NP              1274946: ErrorDef.idl problems. Add include
  41.                                                                         file.
  42.                 <12>     8/12/95        Té              1276812 Need to use TempObjs and TempRefs
  43.                                                                         for exception safety and to avoid TRY
  44.                                                                         blocks, 1276807 Opt./Bug: use StdTypIO
  45.                                                                         routines for portable streaming & smaller
  46.                                                                         footprint
  47.                 <11>      8/3/95        RR              #1257260: Collapse B classes. Remove
  48.                                                                         somInit methods. Don't call IsInitialized
  49.                                                                         or SubclassResponsibility
  50.                 <10>     5/26/95        VL              1251403: Multithreading naming support.
  51.                  <9>     4/27/95        CC              1242555: GetOriginatingProcessID:  Removed
  52.                                                                         obsolete $5 comment.
  53.                  <8>     3/10/95        CC              1225926:  Fixed typo in FromThisDraft().
  54.                  <7>     1/27/95        TJ              Changed ODAppleEvent to AppleEvent.
  55.                  <6>    12/20/94        VL              1195012: Make Storage calls be
  56.                                                                         marshallable.
  57.                  <5>    12/15/94        CC              1205709 LinkSpec.cpp - Removed AcquirePart(),
  58.                                                                         GetData(), and GetDataSize() methods;
  59.                                                                         changed ReadLinkSpec(), WriteLinkSpec(),
  60.                                                                         ReadFromAppleEvent(), and
  61.                                                                         WriteToAppleEvent().
  62.                  <4>     12/8/94        CC              1203864 WriteToAppleEvent: changed &_fData
  63.                                                                         to _fData, to copy the link data correctly.
  64.                  <3>     9/15/94        CC              1186775 - Added SOM_CATCH to
  65.                                                                         FromThisDraft(); Return som error from
  66.                                                                         WriteToAppleEvent().
  67.                  <2>     7/27/94        CC              Removed GetProcessLaunchDate, added
  68.                                                                         FromThisDraft, changed GetProcessID to
  69.                                                                         GetOriginatingProcessID.
  70.                  <1>     6/21/94        CC              first checked in
  71.  
  72.                 ------------------- CC ---- Converted to SOM
  73.  
  74.                  <2>      5/9/94        MB              #1162181: Changes necessary to install MMM.
  75.                  <1>     3/25/94        CC              first checked in
  76.  
  77.                 ------------------- CC ---- Moved from Core to Storage subsystem
  78.  
  79.                  <3>     3/24/94        CC              Changed WriteToProperty() to
  80.                                                                         WriteLinkSpec(), ReadFromProperty() to
  81.                                                                         ReadLinkSpec() (1153049); write version in
  82.                                                                         WriteToAppleEvent().
  83.                  <2>     3/15/94        MB              Changes to support SCpp/ASLM builds,
  84.                                                                         #1150864.
  85.                  <2>      2/8/94        Té              Throw -> THROW & some code clean up
  86.                  <1>     1/21/94        CC              first checked in
  87.                  <4>    12/21/93        VL              Changed XMPStorageUnit::GetValueSize to
  88.                                                                         StorageUnit::GetSize.
  89.                  <3>     12/8/93        CC              Added WriteToAppleEvent,
  90.                                                                         ReadFromAppleEvent, and accessors for
  91.                                                                         fields.
  92.                  <2>     12/3/93        Té              Stop including XMPError.h, it is included
  93.                                                                         as ErrorDef.h inside Except.h
  94.                  <1>    11/15/93        CC              first checked in
  95.         To Do:
  96. */
  97.  
  98. #define VARIABLE_MACROS
  99. #define METHOD_MACROS
  100.  
  101. #define ODLinkSpec_Class_Source
  102. #include <LinkSpec.xih>
  103.  
  104. #ifndef SOM_Module_OpenDoc_StdProps_defined
  105. #include "StdProps.xh"
  106. #endif
  107.  
  108. #ifdef _PLATFORM_OS2_
  109.  
  110.  #ifdef _OSA_SUPPORT_
  111.   #define INCL_OSAAPI
  112.   #define INCL_OSA
  113.  #endif
  114.   #include <os2.h>
  115.  
  116.   #ifndef _ISOSTR_
  117.   #include <ISOStr.h>
  118.   #endif
  119.  
  120.   #ifndef _IODDEFS_
  121.   #include <IODDefs.xh>
  122.   #endif
  123.  
  124.   #ifndef _STORUTIL_
  125.   #include <storutil.h>
  126.   #endif
  127.  
  128.   #include <ODPagtun.h>
  129.  
  130.   #ifndef _ODMEMORY_
  131.   #include <ODMemory.h>
  132.   #endif
  133.  
  134.  
  135.   #include <iciditr.xh>
  136.  
  137.   #ifndef SOM_IODLinkService_xh
  138.     #include <ILnkSrvc.xh>
  139.   #endif
  140.  
  141.   #ifndef SOM_ODLink_xh
  142.     #include <link.xh>
  143.   #endif
  144.  
  145.   #ifndef SOM_IODLinkSource_xh
  146.     #include <ILinkSrc.xh>
  147.   #endif
  148.   #include <ILnkTrgt.xh>
  149.  
  150.   #ifndef SOM_ODStorageUnit_xh
  151.     #include <StorageU.xh>
  152.   #endif
  153.  
  154.   #ifndef SOM_ODPart_xh
  155.    #include <Part.xh>
  156.   #endif
  157.  
  158.   #include <process.h>
  159.   #include <somd.xh>
  160.   #include <stdio.h>
  161.  
  162.   #ifndef SOM_Module_OpenDoc_StdTypes_defined
  163.   #include <StdTypes.xh>
  164.   #endif
  165.  
  166.   #ifndef SOM_ODDraft_xh
  167.   #include <Draft.xh>
  168.   #endif
  169.  
  170.   #ifndef _ITEXT_
  171.   #include <IText.h>
  172.   #endif
  173.  
  174. #endif
  175.  
  176.  
  177. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  178. #include "StdTypes.xh"
  179. #endif
  180.  
  181. #ifndef SOM_ODDraft_xh
  182. #include "Draft.xh"
  183. #endif
  184.  
  185. #ifndef SOM_ODStorageUnit_xh
  186. #include "StorageU.xh"
  187. #endif
  188.  
  189. #ifndef _EXCEPT_
  190. #include "Except.h"
  191. #endif
  192.  
  193. #ifndef _ODMEMORY_
  194. #include "ODMemory.h"
  195. #endif
  196.  
  197. #ifdef _PLATFORM_OS2_ // CED
  198. #include <builtin.h>
  199. #else
  200. #ifndef __ERRORS__
  201. #include <Errors.h>
  202. #endif
  203. #endif
  204.  
  205.  
  206. #ifndef _BARRAY_
  207. #include <BArray.h>
  208. #endif
  209.  
  210. #ifndef _STDTYPIO_
  211. #include <StdTypIO.h>
  212. #endif
  213.  
  214. #ifndef _TEMPOBJ_
  215. #include <TempObj.h>
  216. #endif
  217.  
  218. #ifndef _STORUTIL_
  219. #include <StorUtil.h>
  220. #endif
  221.  
  222. #ifndef _UTILERRS_
  223. #include "UtilErrs.h"
  224. #endif
  225.  
  226. #ifndef _PLATFORM_OS2_
  227. #pragma segment ODLinkSpec
  228. #endif
  229.  
  230. //==============================================================================
  231. // Constants
  232. //==============================================================================
  233. #ifdef _PLATFORM_OS2_
  234. #define kODULongLen          4
  235. const kODOS2 = 1;
  236. const kODDSOMExternalizedIDSize = 1024;
  237. #endif  // _PLATFORM_OS2_
  238.  
  239. #ifdef _PLATFORM_MACINTOSH_
  240. const ODULong kLinkSpecVersion = 1;     // Second version
  241.  
  242. // ÑÑÑÑ kODSourcePartKey also defined for Drag & Drop ÑÑÑÑ
  243. // ÑÑÑÑ These don't belong here ÑÑÑÑ
  244. #define kODProcessLaunchDateKey 'pldt'
  245. #define kODSourcePartKey                        'part'
  246. #define kODLinkSpecDataKey                      'data'
  247. #define kODLinkSpecDataSizeKey          'size'
  248. #define kODLinkSpecVersionKey           'vers'
  249. #endif // _PLATFORM_MACINTOSH
  250.  
  251. //==============================================================================
  252. // ODLinkSpec
  253. //==============================================================================
  254.  
  255. //------------------------------------------------------------------------------
  256. // ODLinkSpec::somUninit
  257. //------------------------------------------------------------------------------
  258.  
  259. SOM_Scope void  SOMLINK ODLinkSpecsomUninit(ODLinkSpec *somSelf)
  260. {
  261.     /* ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf); */
  262.     ODLinkSpecMethodDebug("ODLinkSpec","somUninit");
  263.  
  264.     #ifdef _PLATFORM_OS2_
  265.     ODLinkSpec_parent_ODBaseLinkSpec_somUninit(somSelf);
  266.     #else
  267.     parent_somUninit(somSelf);
  268.     #endif
  269. }
  270.  
  271. #ifdef _PLATFORM_OS2_
  272.  
  273.  SOM_Scope void  SOMLINK ODLinkSpecsomInit(ODLinkSpec *somSelf)
  274. {
  275.  
  276. /*
  277. -------------------------------------------------------------------------------
  278.  1. Initialize the Base LinkSpec.
  279.  2. Initialize constants:  version id
  280. //  3. Go into U state.
  281. -------------------------------------------------------------------------------
  282. */
  283.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  284.     ODLinkSpecMethodDebug("ODLinkSpec","ODLinkSpecsomInit");
  285.  
  286.     // 1.
  287.     ODLinkSpec_parent_ODBaseLinkSpec_somInit(somSelf);
  288.  
  289.     // 2.
  290.     _fVersion=kODOS2;
  291.  
  292.     // 3.
  293.     _fState=ODLinkSpec_UNINIT;
  294.  
  295.  
  296. }
  297.  
  298.  
  299. /*
  300.  * Called in LinkTarget::EstablishLink to establish a new link with the
  301.  *   source part.
  302.  * If aState is TRANSIENTLINKABLE, it internalizes fSourceLinkService and
  303.  *   invokes its EstablishLinkFromTSpec method.
  304.  * If aState is PERSISTENTLINKABLE, it internalizes aLinkRegistry and
  305.  *   queries the LinkRegistry for the reference of the LinkSource to
  306.  *   invokes its AddTarget method.
  307.  */
  308.  
  309. SOM_Scope void
  310. SOMLINK ODLinkSpecEstablishLink(ODLinkSpec *somSelf,
  311.                                 Environment *ev,
  312.                                 IODLinkTarget* linkTrgt,
  313.                                 ODULong pid,
  314.                                 ODLinkConnectionData* trgtPartDesc,
  315.                                 IODLinkService* trgtLinkService,
  316.                                 ODStorageUnitID* trgtPartSUID,
  317.                                 ODLinkID* linkID,
  318.                                 IODLinkTargetToLinkSource** linkSrc,
  319.                                 ODLinkConnectionID* trgtID,
  320.                                 ODBoolean* isLocal,
  321.                                 ODBoolean* trackTrgt,
  322.                                 ODISOStr* asName)
  323. {
  324.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  325.     ODLinkSpecMethodDebug("ODLinkSpec","ODLinkSpecEstablishLink");
  326.  
  327.  
  328. /*
  329. -------------------------------------------------------------------------------
  330. 0. Return targetpart SUID
  331. 1. If state is T,
  332.    1.1. internalize fSourceLinkService,
  333.    1.2. invoke EstablishLinkFromTSpec
  334.    1.2. invoke RegisterLinkTarget
  335. 2. If state is P,
  336.    2.1. internalize aLinkRegistry (Avail Server name) into LTToLS pointer,
  337.    2.2. extract linkRegistry as asName, linkID as linkID
  338.    2.3. invoke AddTarget on LinkSource via avail server
  339.   2.4. If local, get linkSrc pointer from SUID;
  340.         else use AvailServer dispatcher as linkSrc pointer
  341.  
  342. -------------------------------------------------------------------------------
  343. */
  344.   #ifndef _PLATFORM_OS2_
  345.    SOM_CATCH return;
  346.   #else
  347.    SOM_TRY
  348.   #endif
  349.  
  350.   IODLinkService *sourceLinkService;
  351.  
  352.   // 0.
  353.   *trgtPartSUID = _fTargetPartSUID;
  354.  
  355.   switch (_fState) {
  356.     case ODLinkSpec_TRANSIENTLINKABLE:
  357.       // 1.
  358.       {
  359.         ODStorageUnitID linkSrcSUID;
  360.         // 1.1
  361.  
  362.         //sourceLinkService = (IODLinkService*)
  363.         //                    SOMD_ObjectMgr->
  364.         //                      somdGetObjectFromId(ev, _fSourceLinkService);
  365.  
  366.         SOMDObject* objRef = SOMD_ORBObject->
  367.                                string_to_object(ev, _fSourceLinkService);
  368.  
  369.         sourceLinkService = (IODLinkService*)
  370.                             SOMD_ServerObject->
  371.                               somdSOMObjFromRef(ev, objRef);
  372.  
  373.  
  374.         // 1.2.
  375.         sourceLinkService->EstablishLinkFromTSpec(ev,
  376.                                                   pid,
  377.                                                   _fSourcePartSUID,
  378.                                                   &_fData,
  379.                                                   trgtPartDesc,
  380.                                                   linkTrgt,
  381.                                                   linkID,
  382.                                                   linkSrc,
  383.                                                   trgtID,
  384.                                                   isLocal,
  385.                                                   trackTrgt,
  386.                                                   asName);
  387.  
  388.         // 1.3.
  389.        trgtLinkService->RegisterLinkTarget(ev,
  390.                                            _fTargetPartSUID,
  391.                                            linkTrgt);
  392.       }
  393.       break;
  394.  
  395.     case ODLinkSpec_PERSISTENTLINKABLE:
  396.       // 2.
  397.       {
  398.         //ODISOStr asName = _fASName; /* no use to save it anymore */
  399.         ODStorageUnitID sourceSUID;
  400.  
  401.         //2.1.
  402.         SOMDServer *server = SOMD_ObjectMgr->somdFindServerByName(ev, _fASName);
  403.         if (ODGetSOMException(ev) == kODNoError)
  404.         {
  405.           *linkSrc = (IODLinkTargetToLinkSource*)
  406.                       server->somdCreateObj(ev, "IODAvailServer", "");
  407.         }
  408.         else
  409.         {
  410.           *linkSrc = kODNULL;
  411.           THROW(kODErrCorruptLinkSpecValue);
  412.         }
  413.  
  414.         // 2.2.
  415.         *linkID = _fLinkID;
  416.         *asName = _fASName;
  417.  
  418.         // 2.3.
  419.         ((*linkSrc))->AddLinkTarget(ev,
  420.                                     *linkID,
  421.                                     pid,
  422.                                     trgtPartDesc,
  423.                                     linkTrgt,
  424.                                     &sourceSUID,
  425.                                     trgtID,
  426.                                     isLocal,
  427.                                     trackTrgt);
  428.  
  429.         // 2.4.
  430.         if (*isLocal)
  431.           {
  432.             *linkSrc = (IODLinkTargetToLinkSource*)linkTrgt->GetStorageUnit(ev)->GetDraft(ev)->AcquireLinkSource(ev, sourceSUID);
  433.           }
  434.  
  435.       }
  436.       break;
  437.     default:
  438.       {THROW(kODErrCorruptLinkSpecValue);}
  439.  
  440.   }
  441.  
  442.   #ifdef _PLATFORM_OS2_
  443.     SOM_CATCH_ALL
  444.     SOM_ENDTRY
  445.       return;
  446.   #endif
  447.  
  448. }
  449.  
  450.  
  451. /*
  452.  *=============================================================================
  453.  * Called by target Part or draft to retrieve the
  454.  *   description of the source Part.
  455.  *
  456.  * <1>  Make sure you are in the P state
  457.  * <2>  Use the ASName to get access to the dispatcher
  458.  * <3>  Invoke GetSourcePartDescription method of LinkTargetToLinkSource.
  459.  *=============================================================================
  460.  */
  461.  
  462. SOM_Scope void
  463. SOMLINK ODLinkSpecGetLinkSourceConnectionData (ODLinkSpec *somSelf,
  464.                                                         Environment *ev,
  465.                                                         ODLinkConnectionData** srcConnData)
  466. {
  467.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  468.     ODLinkSpecMethodDebug("ODLinkSpec","GetLinkSourceConnectionData");
  469.  
  470.  
  471.    //---<1>
  472.     if (_fState != ODLinkSpec_PERSISTENTLINKABLE)
  473.       {
  474.       THROW(kODErrNoLinkSource);
  475.       return;
  476.       }
  477.  
  478.     //---<2>
  479.      IODLinkTargetToLinkSource* myLinkSrc;
  480.      SOMDServer *server = SOMD_ObjectMgr->somdFindServerByName(ev, _fASName);
  481.      if (ODGetSOMException(ev) == kODNoError)
  482.         {
  483.           myLinkSrc = (IODLinkTargetToLinkSource*)
  484.                       server->somdCreateObj(ev, "IODAvailServer", "");
  485.         }
  486.      else
  487.         {
  488.           THROW(kODErrBrokenLinkSource);
  489.           return;
  490.         }
  491.  
  492.     //---<3>
  493.      TRY
  494.        myLinkSrc->GetSourcePartDescription(ev, _fLinkID, srcConnData);
  495.      CATCH_ALL
  496.        THROW(kODErrBrokenLinkSource);
  497.      ENDTRY
  498. }
  499.  
  500.  
  501. /*
  502.  * Called in Draft::CreateLinkSpec to initialize the LinkSpec after it
  503.  *   is created.
  504.  * If caller is the draft of a source part, it must provide the
  505.  *   linkService and source partSUID for call back to establish a link.
  506.  * If caller is the draft of a target part, it only needs to provide
  507.  *   the target partSUID for the LinkSpec to query the part attributes.
  508.  * In either case the TI state will be entered.
  509.  *
  510.  */
  511.  
  512. SOM_Scope void
  513. SOMLINK ODLinkSpecInitLinkSpec(ODLinkSpec *somSelf,
  514.                                Environment *ev,
  515.                                IODDSOMExternalizedID linkService,
  516.                                //XXXXX ODStorageUnitID partSUID,
  517.                                ODPart* part,
  518.                                ODByteArray* data)
  519. {
  520.  
  521. /*
  522. -------------------------------------------------------------------------------
  523. 1. Error if not currently in U state.
  524. 2. Initialize the ODObject
  525. 3. Save linkService, partSUID, data, and size; Enter the TI state.
  526. -------------------------------------------------------------------------------
  527. */
  528.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  529.     ODLinkSpecMethodDebug("ODLinkSpec","ODLinkSpecInitLinkSpec");
  530.  
  531. // 1.
  532.     if (_fState != ODLinkSpec_UNINIT)
  533.       {
  534.         THROW(kODErrCorruptLinkSpecValue);
  535.       }
  536.  
  537. // 2.
  538.     #ifndef _PLATFORM_OS2_
  539.      SOM_CATCH return;
  540.     #else
  541.      SOM_TRY
  542.     #endif
  543.  
  544. //   Can not call IsInitialized any more. Make sure InitObject can handle
  545. //   initialization.
  546.  
  547. //    if ( !_IsInitialized(ev) )
  548.       _InitObject(ev);
  549.  
  550.  
  551. // 3.
  552.     _fState=ODLinkSpec_TRANSIENT_INIT;
  553.     _fSourcePartSUID=kODNULL; /* in case TRY fails */
  554.     _fSourceLinkService = (IODDSOMExternalizedID) kODNULL; /* in case TRY fails */
  555.     //_fData = (ODByteArray*) kODNULL;
  556.     _fData = CreateEmptyByteArrayStruct(0);
  557.     TRY
  558.       //XXXXX __set_aSourcePartSUID(ev, partSUID);
  559.       if (part != (ODPart*)kODNULL)
  560.         _fSourcePartSUID=part->GetID(ev);
  561.       else
  562.         _fSourcePartSUID=0;
  563.  
  564.       _fSourceLinkService = ODISOStrFromCStr(linkService);
  565.       if (data != (ODByteArray*) kODNULL)
  566.         {
  567.           _fData = CopyByteArrayStruct(data);
  568.         }
  569.       somSelf->InitBaseLinkSpec(ev, part, data); //XXXXX
  570.  
  571.     CATCH_ALL
  572.       _VoidLinkSpec(ev);
  573.       RERAISE;
  574.     ENDTRY
  575.  
  576.     #ifdef _PLATFORM_OS2_
  577.      SOM_CATCH_ALL
  578.      SOM_ENDTRY
  579.     return;
  580.     #endif
  581.  }
  582.  
  583.  
  584. /*
  585.  * Called to void this LinkSpec.
  586.  */
  587.  
  588. SOM_Scope void  SOMLINK ODLinkSpecVoidLinkSpec(ODLinkSpec *somSelf,
  589.                                                 Environment *ev)
  590. {
  591.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  592.     ODLinkSpecMethodDebug("ODLinkSpec","ODLinkSpecVoidLinkSpec");
  593.  
  594. /*
  595. -------------------------------------------------------------------------------
  596. 1. Uninit all the storage and go to U state
  597. -------------------------------------------------------------------------------
  598. */
  599.  
  600.    switch (_fState) {
  601.      case ODLinkSpec_TRANSIENT_INIT: /* free space for Data, fSourceLinkService */
  602.      case ODLinkSpec_TRANSIENTLINKABLE: /* same */
  603.        if (_fSourceLinkService != (IODDSOMExternalizedID) kODNULL)
  604.        {
  605.          ODDisposePtr (_fSourceLinkService);
  606.          _fSourceLinkService = (IODDSOMExternalizedID) kODNULL;
  607.        }
  608.        DisposeByteArrayStruct(_fData);
  609.        _fState=ODLinkSpec_UNINIT;
  610.        break;
  611.      case ODLinkSpec_PERSISTENTLINKABLE: /* free ASName */
  612.      {
  613.        ;
  614.        if (_fASName !=  kODNULL)
  615.        {
  616.          SOMFree(_fASName);
  617.          _fASName=kODNULL ;
  618.         }
  619.        _fState=ODLinkSpec_UNINIT;
  620.        break;
  621.      }
  622.  
  623.      default:
  624.        break;
  625.    }
  626. }
  627.  
  628. #endif // _PLATFORM_OS2_
  629.  
  630.  
  631. #ifdef _PLATFORM_MACINTOSH_
  632.  
  633. //------------------------------------------------------------------------------
  634. // ODLinkSpec::InitLinkSpec
  635. //------------------------------------------------------------------------------
  636.  
  637. SOM_Scope void  SOMLINK ODLinkSpecInitLinkSpec(ODLinkSpec *somSelf, Environment *ev,
  638.                 ODPart* part,
  639.                 ODByteArray* partData)
  640. {
  641.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  642.     ODLinkSpecMethodDebug("ODLinkSpec","InitLinkSpec");
  643.  
  644.         SOM_CATCH return;
  645.  
  646.         /* Moved from somInit. SOM itself sets fields to zero
  647.         _fProcessLaunchDate = 0;
  648.         */
  649.         _fProcessID.lowLongOfPSN = kNoProcess;
  650.         _fProcessID.highLongOfPSN = 0;
  651.  
  652.         somSelf->InitBaseLinkSpec(ev, part, partData);
  653.  
  654.         if ( part )
  655.         {
  656.                 ProcessSerialNumber psn;
  657.                 ProcessInfoRec myProcessInfo;
  658.  
  659.                 psn.lowLongOfPSN = kCurrentProcess;
  660.                 psn.highLongOfPSN = 0;
  661.                 myProcessInfo.processAppSpec = NULL;
  662.                 myProcessInfo.processName = NULL;
  663.                 myProcessInfo.processInfoLength = sizeof(myProcessInfo);
  664.  
  665.                 OSErr error = GetProcessInformation(&psn, &myProcessInfo);
  666.                 ASSERT((error == 0), kODErrAssertionFailed);
  667.  
  668.                 _fProcessID = myProcessInfo.processNumber;
  669.                 _fProcessLaunchDate = myProcessInfo.processLaunchDate;
  670.         }
  671. }
  672. #endif // _PLATFORM_MACINTOSH_
  673.  
  674. //------------------------------------------------------------------------------
  675. // ODLinkSpec::FromThisDraft (OVERRIDE)
  676. //------------------------------------------------------------------------------
  677.  
  678. SOM_Scope ODBoolean  SOMLINK ODLinkSpecFromThisDraft(ODLinkSpec *somSelf, Environment *ev)
  679. {
  680.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  681.     ODLinkSpecMethodDebug("ODLinkSpec","FromThisDraft");
  682.  
  683.         #ifdef _PLATFORM_MACINTOSH_
  684.         SOM_CATCH return kODFalse;
  685.  
  686.         ProcessSerialNumber myPSN;
  687.         ProcessInfoRec myProcessInfo;
  688.         Boolean isSamePSN;
  689.  
  690.         myPSN.lowLongOfPSN = kCurrentProcess;
  691.         myPSN.highLongOfPSN = 0;
  692.         myProcessInfo.processAppSpec = NULL;
  693.         myProcessInfo.processName = NULL;
  694.         myProcessInfo.processInfoLength = sizeof(myProcessInfo);
  695.         THROW_IF_ERROR(GetProcessInformation(&myPSN, &myProcessInfo));
  696.         THROW_IF_ERROR(SameProcess(&_fProcessID, &myProcessInfo.processNumber, &isSamePSN));
  697.  
  698.         return (isSamePSN && (myProcessInfo.processLaunchDate == _fProcessLaunchDate));
  699.         #else
  700.         return(kODFalse);
  701.         #endif
  702. }
  703.  
  704. //------------------------------------------------------------------------------
  705. // ODLinkSpec::GetOriginatingProcessID
  706. //------------------------------------------------------------------------------
  707.  
  708. SOM_Scope void  SOMLINK ODLinkSpecGetOriginatingProcessID(ODLinkSpec *somSelf, Environment *ev,
  709.                 ProcessSerialNumber *psn)
  710. {
  711.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  712.     ODLinkSpecMethodDebug("ODLinkSpec","GetProcessLaunchDate");
  713.  
  714.         #ifdef _PLATFORM_OS2_
  715.         _interrupt( 3 );
  716.         #else
  717.         ProcessInfoRec info;
  718.  
  719.         info.processAppSpec = NULL;
  720.         info.processName = NULL;
  721.         info.processInfoLength = sizeof(info);
  722.  
  723.         if ( (GetProcessInformation(&_fProcessID, &info) == noErr) &&
  724.                         (info.processLaunchDate == _fProcessLaunchDate) )
  725.         {
  726.                 *psn = _fProcessID;
  727.         }
  728.         else
  729.         {
  730.                 psn->lowLongOfPSN = kNoProcess;
  731.                 psn->highLongOfPSN = 0;
  732.                 ODSetSOMException(ev, kODErrCannotGetExternalLink);
  733.         }
  734.         #endif
  735. }
  736.  
  737. //------------------------------------------------------------------------------
  738. // ODLinkSpec::WriteLinkSpec (OVERRIDE)
  739. //------------------------------------------------------------------------------
  740.  
  741. SOM_Scope void  SOMLINK ODLinkSpecWriteLinkSpec(ODLinkSpec *somSelf, Environment *ev,
  742.                 ODStorageUnit* su)
  743. {
  744.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  745.     ODLinkSpecMethodDebug("ODLinkSpec","WriteLinkSpec");
  746.  
  747. /*
  748. -------------------------------------------------------------------------------
  749. 1. If state is U, reject
  750. 2. (no longer focus to a property; assume already focussed)
  751. 2. Assumes su has been focused to a property and link spec value
  752. 3. If state is P, write version, Persistent, aLinkID, aLinkRegistry
  753. 4. If state is TI or T, write version, Transient, aSourcePartSUID, fSourceLinkService, fDataSize, fData
  754. -------------------------------------------------------------------------------
  755. */
  756.  
  757. #ifdef _PLATFORM_OS2_
  758.  
  759. //    ODLinkSpec_parent_ODBaseLinkSpec_WriteLinkSpec(somSelf, ev, su);
  760.          ODULong version = _fVersion;
  761.       ODULong subVersion;
  762.       ODLinkID linkID;
  763.       ODISOStr asName;
  764.       ODStorageUnitID sourcePartSUID;
  765.  
  766.       #ifndef _PLATFORM_OS2_
  767.          SOM_CATCH return;
  768.       #else
  769.          SOM_TRY
  770.       #endif
  771.  
  772.   ODVolatile(su);
  773.  
  774.  
  775.   ODSUForceFocus(ev, su, kODNULL, kODLinkSpec);
  776.  
  777.  
  778.   // 1.
  779.   if (_fState == ODLinkSpec_UNINIT)
  780.     {
  781.       THROW(kODErrCorruptLinkSpecValue);
  782.     }
  783.  
  784.   // 2.
  785.  
  786.   switch (_fState) {
  787.     case ODLinkSpec_PERSISTENTLINKABLE:
  788.       // 3.
  789.       TRY
  790.         StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &version);
  791.         subVersion = ODLinkSpec_PERSISTENT_LINKSPEC_VALUE;
  792.         StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &subVersion);
  793.         linkID = _fLinkID;
  794.         StorageUnitSetValue(su, ev, sizeof(ODLinkID), (ODValue) &linkID);
  795.         asName = _fASName;
  796.         ODULong strLength = strlen(asName) + 1;/* length of string + null terminator */
  797.         StorageUnitSetValue(su, ev, kODULongLen, (ODValue)&strLength);
  798.         StorageUnitSetValue(su,
  799.                             ev,
  800.                             strLength,
  801.                             (ODValue)asName);
  802.       CATCH_ALL
  803.         su->Remove(ev);    //??????
  804.         RERAISE;
  805.       ENDTRY
  806.  
  807.       break;
  808.     case ODLinkSpec_TRANSIENTLINKABLE:
  809.     case ODLinkSpec_TRANSIENT_INIT:
  810.       // 4.
  811.       TRY
  812.         StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &version);
  813.         subVersion = ODLinkSpec_TRANSIENT_LINKSPEC_VALUE;
  814.         StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &subVersion);
  815.         sourcePartSUID = _fSourcePartSUID;
  816.         StorageUnitSetValue(su, ev, sizeof(ODStorageUnitID), (ODValue) &sourcePartSUID);
  817.         StorageUnitSetValue(su, ev, kODDSOMExternalizedIDSize, (ODValue) _fSourceLinkService);
  818.         StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &_fData._length);
  819.         StorageUnitSetValue(su, ev, _fData._length, (ODValue) _fData._buffer);
  820.       CATCH_ALL
  821.         su->Remove(ev);
  822.         RERAISE;
  823.       ENDTRY
  824.  
  825.     }
  826.  
  827.  
  828. #endif  // _PLATFORM_OS2_
  829.  
  830. #ifdef _PLATFORM_MACINTOSH_
  831.         SOM_CATCH return;
  832.  
  833.         ODVolatile(su);
  834.  
  835.         ODULong version = kLinkSpecVersion;
  836.         ODULong size;
  837.  
  838.         ODSUForceFocus(ev, su, kODNULL, kODLinkSpec);
  839.         size = su->GetSize(ev);
  840.         su->DeleteValue(ev, size);
  841.  
  842.         TRY
  843.                 StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &version);
  844.                 StorageUnitSetValue(su, ev, sizeof(ProcessSerialNumber), (ODValue) &_fProcessID);
  845.                 StorageUnitSetValue(su, ev, sizeof(ODULong), (ODValue) &_fProcessLaunchDate);
  846.  
  847.                 parent_WriteLinkSpec(somSelf, ev, su);
  848.         CATCH_ALL
  849.                 su->Remove(ev);
  850.                 RERAISE;
  851.         ENDTRY
  852. #endif // _PLATFORM_MACINTOSH_
  853.  
  854.  
  855. #ifdef _PLATFORM_OS2_
  856.   SOM_CATCH_ALL
  857.   SOM_ENDTRY
  858.     return;
  859. #endif
  860.  
  861. }
  862.  
  863. //------------------------------------------------------------------------------
  864. // ODLinkSpec::ReadLinkSpec (OVERRIDE)
  865. //------------------------------------------------------------------------------
  866.  
  867. SOM_Scope void  SOMLINK ODLinkSpecReadLinkSpec(ODLinkSpec *somSelf, Environment *ev,
  868.                 ODStorageUnit* su)
  869. {
  870.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  871.     ODLinkSpecMethodDebug("ODLinkSpec","ReadLinkSpec");
  872.  
  873. /*
  874. -------------------------------------------------------------------------------
  875. 1. If state is U, reject
  876. 2. If state is T or P, coerce down to TI
  877. 3. Move SourcePartSUID to TargetPartSUID; kill fSourceLinkService, fData
  878. 4. (we assume su has been focused to a property and link spec value,
  879.    and the current offset is where the base link spec was written.) nop.
  880. 5. If version isn't kODOS2, reject
  881. 6. Check sub-version:
  882. 6.1. Transient: Read aSourcePartSUID, fSourceLinkService, fData.size, fData.value, and go to T
  883. 6.2. Persistent: Read aLinkID, aLinkRegistry, and go to P
  884. -------------------------------------------------------------------------------
  885. */
  886.  
  887. #ifdef _PLATFORM_OS2_
  888.  
  889.     ODULong version;
  890.  
  891.    #ifndef _PLATFORM_OS2_
  892.     SOM_CATCH return;
  893.    #else
  894.     SOM_TRY
  895.    #endif
  896.  
  897.     // Pre-focused property must contain a link spec value
  898.     if (! su)
  899.       THROW(kODErrIllegalNullStorageUnitInput);
  900.     if (!ODSUExistsThenFocus(ev, su, (ODPropertyName) kODNULL, kODLinkSpec))
  901.       THROW(kODErrNoLinkSpecValue);
  902.  
  903.     // 1.
  904.     if (_fState == ODLinkSpec_UNINIT)
  905.       {
  906.         THROW(kODErrCorruptLinkSpecValue);
  907.       }
  908.  
  909.     // 2.
  910.     if (_fState == ODLinkSpec_TRANSIENTLINKABLE)
  911.       {
  912.         _fState= ODLinkSpec_TRANSIENT_INIT;
  913.       }
  914.  
  915.     if (_fState == ODLinkSpec_PERSISTENTLINKABLE)
  916.       {
  917.         ODDisposePtr(_fASName);
  918.         _fState= ODLinkSpec_TRANSIENT_INIT;
  919.         _fSourcePartSUID=_fTargetPartSUID;
  920.         DisposeByteArrayStruct(_fData);
  921.         _fSourceLinkService = (IODDSOMExternalizedID) kODNULL;
  922.        }
  923.  
  924.     // 3.
  925.     _fTargetPartSUID=_fSourcePartSUID;
  926.     if (_fSourceLinkService != (IODDSOMExternalizedID) kODNULL)
  927.     {
  928.       ODDisposePtr (_fSourceLinkService);
  929.       _fSourceLinkService = (IODDSOMExternalizedID) kODNULL;
  930.     }
  931.     DisposeByteArrayStruct(_fData);
  932.  
  933.     // 4.
  934.  
  935.     // 5.
  936.     ODULong    valueSize; //-- used to check integrity of bytestream
  937.  
  938.     TRY
  939.       {
  940.         valueSize = StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &version);
  941.         if (valueSize != sizeof(ODULong)) {
  942.           _VoidLinkSpec(ev);
  943.           THROW(kODErrCorruptLinkSpecValue);
  944.         }
  945.         if (version != _fVersion)
  946.         {
  947.           _VoidLinkSpec(ev);
  948.           THROW(kODErrUnknownLinkSpecVersion);
  949.         }
  950.       }
  951.     CATCH_ALL
  952.       _VoidLinkSpec(ev);
  953.       RERAISE;
  954.     ENDTRY
  955.  
  956.    // 6.
  957.     TRY
  958.       {
  959.         ODULong subVersion;
  960.         ODLinkID linkID;
  961.         ODISOStr asName;
  962.         ODStorageUnitID sourcePartSUID;
  963.         ODULong dataSize;
  964.  
  965.         valueSize = StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &subVersion);
  966.         if (valueSize != sizeof(ODULong))
  967.         {
  968.           THROW(kODErrCorruptLinkSpecValue);
  969.         }
  970.  
  971.         switch (subVersion) {
  972.           case ODLinkSpec_TRANSIENT_LINKSPEC_VALUE:
  973.             // 6.1
  974.             _fSourceLinkService = (IODDSOMExternalizedID) kODNULL;
  975.             _fState=ODLinkSpec_TRANSIENTLINKABLE;
  976.  
  977.             valueSize = StorageUnitGetValue(su, ev, sizeof(ODStorageUnitID), (ODValue) &sourcePartSUID);
  978.             if (valueSize != sizeof(ODStorageUnitID))
  979.             {
  980.               THROW(kODErrCorruptLinkSpecValue);
  981.             }
  982.             _fSourcePartSUID= sourcePartSUID;
  983.             _fSourceLinkService = (IODDSOMExternalizedID) ODNewPtr(kODDSOMExternalizedIDSize, kDefaultHeapID);
  984.             valueSize = StorageUnitGetValue(su, ev, kODDSOMExternalizedIDSize, (ODValue) _fSourceLinkService);
  985.             if (valueSize != kODDSOMExternalizedIDSize)
  986.             {
  987.               THROW(kODErrCorruptLinkSpecValue);
  988.             }
  989.  
  990.             valueSize = StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &dataSize);
  991.             if (valueSize != sizeof(ODULong))
  992.             {
  993.               THROW(kODErrCorruptLinkSpecValue);
  994.             }
  995.             _fData = CreateEmptyByteArrayStruct(dataSize);
  996.             if (dataSize > 0)
  997.             {
  998.               valueSize = StorageUnitGetValue(su, ev, dataSize, (ODValue) _fData._buffer);
  999.               _fData._length = dataSize;
  1000.               if (valueSize != dataSize)
  1001.               {
  1002.                 THROW(kODErrCorruptLinkSpecValue);
  1003.               }
  1004.  
  1005.             }
  1006.             break;
  1007.           case ODLinkSpec_PERSISTENT_LINKSPEC_VALUE:
  1008.  
  1009.             // 6.2
  1010.             _fASName=kODNULL;
  1011.             _fState=ODLinkSpec_PERSISTENTLINKABLE;
  1012.             valueSize = StorageUnitGetValue(su, ev, sizeof(ODLinkID), (ODValue) &linkID);
  1013.             if (valueSize != sizeof(ODLinkID))
  1014.             {
  1015.               THROW(kODErrCorruptLinkSpecValue);
  1016.             }
  1017.             _fLinkID=linkID;
  1018.            ODULong strLength;
  1019.             StorageUnitGetValue(su, ev, kODULongLen, (ODValue)&strLength);
  1020.             asName = (ODISOStr) SOMMalloc(strLength);
  1021.             valueSize = StorageUnitGetValue(su,
  1022.                                 ev,
  1023.                                 strLength,
  1024.                                 (ODValue)asName);
  1025.             if (valueSize != strLength)
  1026.             {
  1027.               THROW(kODErrCorruptLinkSpecValue);
  1028.             }
  1029.             _fASName=asName;
  1030.             break;
  1031.           default:
  1032.             THROW(kODErrUnknownLinkSpecVersion);
  1033.           }
  1034.      }
  1035.     CATCH_ALL
  1036.       _VoidLinkSpec(ev);
  1037.       RERAISE;
  1038.     ENDTRY
  1039.  
  1040. #endif // _PLATFORM_OS2_
  1041.  
  1042. #ifdef _PLATFORM_MACINTOSH_
  1043.  
  1044.         SOM_CATCH return;
  1045.  
  1046.         ODULong                         version;
  1047.         ProcessSerialNumber processID;
  1048.         ODULong                         processLaunchDate;
  1049.         ODULong                         valueSize;
  1050.  
  1051.         // Pre-focused property must contain a link spec value
  1052.         if (!ODSUExistsThenFocus(ev, su, (ODPropertyName) kODNULL, kODLinkSpec))
  1053.                 THROW(kODErrNoLinkSpecValue);
  1054.  
  1055.         StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &version);
  1056.         if (version != kLinkSpecVersion)
  1057.                 THROW(kODErrUnknownLinkSpecVersion);
  1058.  
  1059.         valueSize = StorageUnitGetValue(su, ev, sizeof(ProcessSerialNumber), (ODValue) &processID);
  1060.         if ( valueSize != sizeof(ProcessSerialNumber) )
  1061.                 THROW(kODErrCorruptLinkSpecValue);
  1062.  
  1063.         valueSize = StorageUnitGetValue(su, ev, sizeof(ODULong), (ODValue) &processLaunchDate);
  1064.         if ( valueSize != sizeof(ODULong) )
  1065.                 THROW(kODErrCorruptLinkSpecValue);
  1066.  
  1067.         parent_ReadLinkSpec(somSelf, ev, su);
  1068.  
  1069.         _fProcessID = processID;
  1070.         _fProcessLaunchDate = processLaunchDate;
  1071.  
  1072. #endif // _PLATFORM_MACINTOSH
  1073.  
  1074. #ifdef _PLATFORM_OS2_
  1075.     SOM_CATCH_ALL
  1076.     SOM_ENDTRY
  1077.       return;
  1078. #endif
  1079. }
  1080.  
  1081. #ifdef _OSA_SUPPORT_
  1082. //------------------------------------------------------------------------------
  1083. // ODLinkSpec::WriteToOSAEvent
  1084. //------------------------------------------------------------------------------
  1085.  
  1086. #ifdef _PLATFORM_MACINTOSH_
  1087. SOM_Scope void  SOMLINK ODLinkSpecWriteToAppleEvent(ODLinkSpec *somSelf, Environment *ev,
  1088.                 AppleEvent* theAppleEvent)
  1089. #endif
  1090.  
  1091. #ifdef _PLATFORM_OS2_
  1092. SOM_Scope void  SOMLINK ODLinkSpecWriteToOSAEvent(ODLinkSpec *somSelf,
  1093.                                                    Environment *ev,
  1094.                                                   OSAEvent* theOSAEvent)
  1095. #endif
  1096. {
  1097.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  1098.     ODLinkSpecMethodDebug("ODLinkSpec","WriteToAppleEvent");
  1099.  
  1100. #ifdef _PLATFORM_OS2_ // CED
  1101.   _interrupt(3);
  1102. #endif
  1103.  
  1104. #ifdef _PLATFORM_MACINTOSH_
  1105.         SOM_TRY
  1106.  
  1107.         OSErr error;
  1108.         ODPart* part = somSelf->GetPart(ev);
  1109.         ODByteArray partData = somSelf->GetPartData(ev);
  1110.  
  1111.         ODULong version = kLinkSpecVersion;
  1112.         error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecVersionKey, typeLongInteger,
  1113.                                                 &version, sizeof(version));
  1114.  
  1115.         if ( error == noErr )
  1116.                 error = AEPutParamPtr((AppleEvent*) theAppleEvent, keyProcessSerialNumber, typeProcessSerialNumber,
  1117.                                                         &_fProcessID, sizeof(_fProcessID));
  1118.  
  1119.         if ( error == noErr )
  1120.                 error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODProcessLaunchDateKey, typeLongInteger,
  1121.                                                         &_fProcessLaunchDate, sizeof(_fProcessLaunchDate));
  1122.  
  1123.         if ( error == noErr )
  1124.                 error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODSourcePartKey, typeLongInteger,
  1125.                                                         &part, sizeof(part));
  1126.  
  1127.         if ( error == noErr )
  1128.                 error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataSizeKey, typeLongInteger,
  1129.                                                         &partData._length, sizeof(ODULong));
  1130.  
  1131.         if ( (error == noErr) && (partData._length > 0) )
  1132.                 error = AEPutParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataKey, typeChar /* ÑÑÑ need better type here ÑÑÑÑ */,
  1133.                                                         partData._buffer, partData._length);
  1134.  
  1135.         DisposeByteArrayStruct(partData);
  1136.  
  1137.         THROW_IF_ERROR(error);
  1138.  
  1139.         SOM_CATCH_ALL
  1140.         SOM_ENDTRY
  1141.  
  1142. #endif // _PLATFORM_MACINTOSH_
  1143.  
  1144. }
  1145.  
  1146. //------------------------------------------------------------------------------
  1147. // ODLinkSpec::ReadFromAppleEvent
  1148. //------------------------------------------------------------------------------
  1149.  
  1150. #ifdef _PLATFORM_MACINTOSH_
  1151. SOM_Scope void  SOMLINK ODLinkSpecReadFromAppleEvent(ODLinkSpec *somSelf, Environment *ev,
  1152.                 AppleEvent* theAppleEvent)
  1153. #endif
  1154.  
  1155. #ifdef _PLATFORM_OS2_
  1156. SOM_Scope void  SOMLINK ODLinkSpecReadFromOSAEvent(ODLinkSpec *somSelf,
  1157.                                                     Environment *ev,
  1158.                                                    OSAEvent* theOSAEvent)
  1159. #endif
  1160.  
  1161. {
  1162.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  1163.     ODLinkSpecMethodDebug("ODLinkSpec","ReadFromAppleEvent");
  1164.  
  1165.         #ifdef _PLATFORM_OS2_ // CED
  1166.         _interrupt(3);
  1167.         #endif // _PLATFORM_OS2_
  1168.  
  1169.         #ifdef _PLATFORM_MACINTOSH_
  1170.  
  1171.         SOM_CATCH return;
  1172.  
  1173.         /* Moved from somInit. SOM itself sets fields to zero
  1174.         _fProcessLaunchDate = 0;
  1175.         _fProcessID.lowLongOfPSN = kNoProcess;
  1176.         _fProcessID.highLongOfPSN = 0;
  1177.         */
  1178.  
  1179.         OSErr                           result;
  1180.         DescType                        returnedType;
  1181.         Size                            actualSize;
  1182.         ODPart*                         part;
  1183.         ODByteArray                     partData;
  1184.         ProcessSerialNumber processID;
  1185.         ODULong                         processLaunchDate;
  1186.         ODULong                         dataSize;
  1187.  
  1188.         result = AEGetParamPtr((AppleEvent*) theAppleEvent, keyProcessSerialNumber, typeProcessSerialNumber, &returnedType,
  1189.                                                         &processID, sizeof(processID), &actualSize);
  1190.         THROW_IF_ERROR(result);
  1191.  
  1192.         result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODProcessLaunchDateKey, typeLongInteger, &returnedType,
  1193.                                                         &processLaunchDate, sizeof(processLaunchDate), &actualSize);
  1194.         THROW_IF_ERROR(result);
  1195.  
  1196.         result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODSourcePartKey, typeLongInteger, &returnedType,
  1197.                                                         &part, sizeof(part), &actualSize);
  1198.         THROW_IF_ERROR(result);
  1199.  
  1200.         result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataSizeKey, typeLongInteger, &returnedType,
  1201.                                                         &dataSize, sizeof(ODULong), &actualSize);
  1202.         THROW_IF_ERROR(result);
  1203.  
  1204.         partData = CreateEmptyByteArrayStruct(dataSize);
  1205.  
  1206.         TRY
  1207.                 if ( dataSize > 0 )
  1208.                 {
  1209.                         result = AEGetParamPtr((AppleEvent*) theAppleEvent, kODLinkSpecDataKey, typeChar, &returnedType,
  1210.                                                                         partData._buffer, dataSize, &actualSize);
  1211.                         THROW_IF_ERROR(result);
  1212.                         partData._length = dataSize;
  1213.                 }
  1214.                 somSelf->InitBaseLinkSpec(ev, part, &partData);
  1215.         CATCH_ALL
  1216.                 DisposeByteArrayStruct(partData);
  1217.                 RERAISE;
  1218.         ENDTRY
  1219.  
  1220.         DisposeByteArrayStruct(partData);
  1221.  
  1222.         _fProcessID = processID;
  1223.         _fProcessLaunchDate = processLaunchDate;
  1224.         #endif // _PLATFORM_MACINTOSH_
  1225. }
  1226. #endif // _OSA_SUPPORT_
  1227.  
  1228.  
  1229. SOM_Scope void
  1230. SOMLINK ODLinkSpecConvertToPersistent(ODLinkSpec *somSelf,
  1231.                                 Environment *ev)
  1232. {
  1233.  
  1234. /*
  1235. -------------------------------------------------------------------------------
  1236. 1. If state is U or TI, reject
  1237. 2. If state is P, do nothing
  1238. 3. If state is T,
  1239.    3.1 get Linksrvc
  1240.    3.2 get Persistent Link Info
  1241.    3.3 save the ASName and LinkID
  1242.    3.4 erase the transient Link Info
  1243.    3.5 Change the state to P
  1244. -------------------------------------------------------------------------------
  1245. */
  1246.     ODLinkSpecData *somThis = ODLinkSpecGetData(somSelf);
  1247.     ODLinkSpecMethodDebug("ODLinkSpec","ODLinkSpecWriteLinkSpec");
  1248. #ifdef _PLATFORM_OS2_
  1249.  
  1250.   switch (_fState) {
  1251.  
  1252.     // 1.
  1253.     case ODLinkSpec_UNINIT:
  1254.      THROW(kODErrCorruptLinkSpecValue);
  1255.  
  1256.     case ODLinkSpec_TRANSIENT_INIT:
  1257.      THROW(kODErrCorruptLinkSpecValue);
  1258.  
  1259.     // 2.
  1260.     case ODLinkSpec_PERSISTENTLINKABLE:
  1261.     return;
  1262.  
  1263.     // 3.
  1264.     case ODLinkSpec_TRANSIENTLINKABLE:
  1265.     IODLinkService* sourceLinkService=kODNULL;
  1266.  
  1267.     TRY
  1268.         // 3.1
  1269.         SOMDObject* objRef = SOMD_ORBObject->
  1270.                                string_to_object(ev, _fSourceLinkService);
  1271.  
  1272.         sourceLinkService = (IODLinkService*)
  1273.                             SOMD_ServerObject->
  1274.                               somdSOMObjFromRef(ev, objRef);
  1275.  
  1276.         // 3.2
  1277.         sourceLinkService->GetPersistentLinkInfoFromTSpec(ev, _fSourcePartSUID, &_fData, &_fLinkID, &_fASName);
  1278.  
  1279.         // 3.3
  1280.         DisposeByteArrayStruct(_fData);
  1281.         ODDisposePtr(_fSourceLinkService);
  1282. /*
  1283. //HAVING PROBLEM HERE
  1284.          if (((SOMDObject*)sourceLinkService)->is_proxy(ev))
  1285.             {
  1286.              SOMD_ObjectMgr->somdReleaseObject(ev, sourceLinkService);
  1287.              }
  1288. */
  1289.  
  1290.         // 3.4
  1291.         _fState = ODLinkSpec_PERSISTENTLINKABLE;
  1292.  
  1293.     CATCH_ALL
  1294.       if (sourceLinkService!=kODNULL)
  1295.        {
  1296.           if (((SOMDObject*)sourceLinkService)->is_proxy(ev))
  1297.             {
  1298.              SOMD_ObjectMgr->somdReleaseObject(ev, sourceLinkService);
  1299.              }
  1300.         }
  1301.       _VoidLinkSpec(ev);
  1302.       THROW(kODErrCorruptLinkSpecValue);
  1303.     ENDTRY
  1304.     break;
  1305.     } //end of switch
  1306.     #endif
  1307. }
  1308.