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

  1. /* @(#)Z 1.9 os2/src/storage/ilnktrgt.cpp, oddataxfer, od96os2, odos29712d 97/03/21 17:39:58 (96/09/03 11:09:21) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: oddataxfer
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29.  
  30. #ifdef _PLATFORM_OS2_
  31. #include <odpagtun.h>
  32. #endif
  33.  
  34. #ifdef _PLATFORM_OS2_
  35. #ifndef SOM_Module_ILnkTrgt_Source
  36. #define SOM_Module_ILnkTrgt_Source
  37. #endif
  38. #define IODLinkTarget_Class_Source
  39.  
  40. #define METHOD_MACROS
  41. #define VARIABLE_MACROS
  42.  
  43. #ifdef _PLATFORM_OS2_
  44. #ifdef _OSA_SUPPORT_
  45. #define INCL_OSAAPI
  46. #define INCL_OSA
  47. #endif
  48. #include <os2.h>
  49. #endif
  50.  
  51. #ifndef _ODTYPESB_
  52. #include <ODTypesB.xh>
  53. #endif
  54.  
  55. #ifndef _ODTYPESF_
  56. #include <ODTypesF.h>
  57. #endif
  58.  
  59. #ifndef _ALTPOINT_
  60. #include <AltPoint.h>
  61. #endif
  62.  
  63. #ifndef _ODTYPESM_
  64. #include <ODTypesM.xh>
  65. #endif
  66.  
  67. #include <process.h>
  68. #include <odmemory.h>
  69.  
  70. #include <ISOStr.h>
  71. #include <IODDefs.xh>
  72. #include <iciditr.xh>
  73.  
  74. #ifndef _STDTYPIO_
  75.   #include <StdTypIO.h>
  76. #endif
  77. #ifndef _STORUTIL_
  78.   #include <StorUtil.h>
  79. #endif
  80.  
  81. #ifndef SOM_Module_StdPropsOpenDoc_StdDefs_defined
  82.   #include "StdDefs.xh"
  83. #endif
  84.  
  85. #ifndef SOM_Module_StdPropsOpenDoc_StdProps_defined
  86.   #include "StdProps.xh"
  87. #endif
  88.  
  89. #ifndef SOM_Module_StdTypes_OpenDoc_StdTypes_defined
  90.   #include <StdTypes.xh>
  91. #endif
  92.  
  93.  
  94. #ifndef SOM_ODDraft_xh
  95.   #include <Draft.xh>
  96. #endif
  97.  
  98. #ifndef SOM_CMDocument_xh
  99. #include <CMDoc.xh>
  100. #endif
  101. #ifndef SOM_ODContainer_xh
  102. #include <ODCtr.xh>
  103. #endif
  104. #ifndef SOM_ODStorageSystem_xh
  105. #include <ODStor.xh>
  106. #endif
  107. #ifndef SOM_ODSession_xh
  108. #include <ODSessn.xh>
  109. #endif
  110.  
  111. #ifndef SOM_ODFrame_xh
  112.   #include <Frame.xh>
  113. #endif
  114.  
  115. #ifndef SOM_ODLink_xh
  116.   #include <link.xh>
  117. #endif
  118.  
  119. #ifndef SOM_ODStorageUnit_xh
  120.   #include <StorageU.xh>
  121. #endif
  122.  
  123.  
  124. #ifndef SOM_IODLinkSource_xh
  125.   #include <ILinkSrc.xh>
  126. #endif
  127.  
  128. #ifndef SOM_IODLinkTargetToLinkSource_xh
  129.   #include <ILTr2LSr.xh>
  130. #endif
  131.  
  132. #ifndef SOM_ODLinkSpec_xh
  133.   #include <LinkSpec.xh>
  134. #endif
  135.  
  136. #ifndef _ITEXT_
  137. #include <IText.h>
  138. #endif
  139.  
  140. #include <lmgrdefs.h>
  141.  
  142. #include <somd.xh>
  143.  
  144. #include "ILnkTrgt.xih"
  145.  
  146. const ODPropertyName   kODPropCloneOfALink = "OpenDoc:Property:Link:Cloned";
  147.  
  148.  
  149. void GetPartDescriptionProp (Environment *ev,
  150.                              ODStorageUnit *su,
  151.                              ODPropertyName prop,
  152.                              ODValueType val,
  153.                              ODLinkConnectionData &partDesc);
  154.  
  155. void SetPartDescriptionProp (Environment *ev,
  156.                              ODStorageUnit *su,
  157.                              ODPropertyName prop,
  158.                              ODValueType val,
  159.                              ODLinkConnectionData &partDesc);
  160.  
  161. void GetISOStrProp (Environment *ev,
  162.                     ODStorageUnit *su,
  163.                     ODPropertyName prop,
  164.                     ODValueType val,
  165.                     ODISOStr &isoStr);
  166.  
  167. void CopyPartDescription(ODLinkConnectionData &dest,
  168.                                     ODLinkConnectionData &src);
  169.  
  170. void CleanupPartDescription (ODLinkConnectionData &partDesc);
  171.  
  172.  
  173. /* ************************************************************************* */
  174. /* The following are copied from FEB13 build in file:                        */
  175. /* opendoc\src\opendoc\common\include\IText.h.                               */
  176. /* Otto and Chris are working on NLS design and the following                */
  177. /* might need to be redesigned when they are done. 5/14/96                   */
  178. /* ************************************************************************* */
  179. // typedef unsigned long CodePage;                      // (defined in odosacom.h)
  180. // typedef CodePage      ODCodePage;
  181. // ODCodePage APIENTRY GetITextCodePage(ODIText*);
  182. // void       APIENTRY SetITextCodePage(ODIText*, ODCodePage);
  183.  
  184. /*
  185.  *=============================================================================
  186.  * Called by target Part or draft to retrieve the
  187.  *   description of the source Part.
  188.  *
  189.  * <1>  Make sure link is not broken.
  190.  * <2>  Invoke GetSourcePartDescription method of LinkTargetToLinkSource.
  191.  *=============================================================================
  192.  */
  193.  
  194. SOM_Scope void
  195. SOMLINK GetLinkSourceConnectionData (IODLinkTarget *somSelf,
  196.                                      Environment *ev,
  197.                                      ODLinkConnectionData** srcConnData)
  198. {
  199.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  200.     IODLinkTargetMethodDebug("IODLinkTarget","GetLinkSourceConnectionData");
  201.  
  202.     //---<1>
  203.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  204.     {
  205.       ODSetSOMException(ev, kODErrBrokenLink);
  206.       return;
  207.     }
  208.  
  209.     //---<2>
  210.     _fLinkSrc->GetSourcePartDescription(ev, _fLinkID, srcConnData);
  211. }
  212.  
  213. /*
  214.  *=============================================================================
  215.  * <1>  Acquire fMutex before accessing fTrgtPartDesc.
  216.  * <2>  Allocate memory for the out parameter trgtPartDesc.
  217.  *      Copy the target part description to the out parameter trgtPartDesc.
  218.  *      Release fMutex and return.
  219.  * <3>  An exception is caught.
  220.  *      Release fMutex.
  221.  *      Cleanup trgtPartDesc.
  222.  *      Set SOM exception and return.
  223.  *=============================================================================
  224.  */
  225.  
  226. SOM_Scope void
  227. SOMLINK GetConnectionData(IODLinkTarget *somSelf,
  228.                           Environment *ev,
  229.                           ODLinkConnectionData** trgtPartDesc)
  230. {
  231.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  232.     IODLinkTargetMethodDebug("IODLinkTarget","GetConnectionData");
  233.  
  234.     // Out parameter
  235.     *trgtPartDesc = kODNULL;
  236.  
  237.     //---<1>
  238. //    _fMutex->Acquire(ev);
  239.     if (ODGetSOMException(ev) != kODNoError)
  240.     {
  241.       return;
  242.     }
  243.  
  244.     TRY
  245.  
  246.       //---<2>
  247.       *trgtPartDesc = new ODLinkConnectionData;
  248.       THROW_IF_NULL(*trgtPartDesc);
  249.  
  250.     //  CopyPartDescription(**trgtPartDesc, _fTrgtPartDesc);
  251.         CopyPartDescription(**trgtPartDesc, _fTrgtConnData);
  252.  
  253. //      _fMutex->Release(ev);
  254.  
  255.     CATCH_ALL
  256.  
  257.       //---<3>
  258. //      _fMutex->Release(ev);
  259.  
  260.       if (*trgtPartDesc != kODNULL)
  261.       {
  262.     //  CleanupPartDescription(**trgtPartDesc);
  263.         CleanupPartDescription(**trgtPartDesc);
  264.         delete *trgtPartDesc;
  265.         *trgtPartDesc = kODNULL;
  266.       }
  267.  
  268. //      SET_SOM_EV;
  269.  
  270.     ENDTRY
  271. }
  272. /*
  273.  *=============================================================================
  274.  * Called by target Part to set its commentary.
  275.  *
  276.  * <1>  Delete Old commentary.
  277.  * <2>  Save new commentary.
  278.  * <3>  Check if this is a legally tracked target, and if so:
  279.  * <4>  If a link source exists, then:
  280.  * <5>  Pass the new commentary to the source.
  281.  *=============================================================================
  282.  */
  283. SOM_Scope void  SOMLINK SetDescription(IODLinkTarget *somSelf,
  284.                                         Environment *ev, ODLinkDescription* Desc)
  285. {
  286.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  287.     IODLinkTargetMethodDebug("IODLinkTarget","SetDescription");
  288.  
  289.     //---<1>
  290.     DisposeITextStruct(_fTrgtConnData.LinkDesc);
  291.  
  292.     //---<2>
  293.     _fTrgtConnData.LinkDesc= CopyITextStruct (Desc);
  294.  
  295.     //---<3>
  296.     if (  (_fTracked)
  297.         ||(_fIsLocal)
  298.         ||(_fIsRegistered)
  299.        )
  300.     {
  301.     //---<4>
  302.       if (_fLinkSrc != (IODLinkTargetToLinkSource*)kODNULL)
  303.       {
  304.     //---<5>
  305.         _fLinkSrc->TargetPartDescriptionChanged(ev,
  306.                                                _fLinkID,
  307.                                                _fConnID,
  308.                                                _fIsLocal,
  309.                                                &_fTrgtConnData);
  310.       } /* end if non-null fLinkSrc               */
  311.     } /* end if this is a legally tracked target */
  312.  
  313. }
  314.  
  315. /*
  316.  *=============================================================
  317.  * Called by target Part to retrieve the description of itself.
  318.  *
  319.  * <1>  Acquire fMutex before accessing fSrcConnData.
  320.  * <2>  Copy commentary.
  321.  * <3>  Release fMutex.
  322.  *=============================================================
  323.  */
  324.  
  325. SOM_Scope void  SOMLINK GetDescription(IODLinkTarget *somSelf,
  326.                                               Environment *ev,
  327.                                              ODLinkDescription* desc)
  328. {
  329.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  330.     IODLinkTargetMethodDebug("IODLinkTarget","GetDescription");
  331.  
  332.  
  333.     //---<1>
  334. //    _fMutex->Acquire(ev);
  335.     if (ODGetSOMException(ev) != kODNoError)
  336.     {
  337.       return;
  338.     }
  339.  
  340.     //---<2>
  341.     *desc = CopyITextStruct(&_fTrgtConnData.LinkDesc);
  342.  
  343.     //---<3>
  344. //    _fMutex->Release(ev);
  345.  
  346.  
  347. }
  348.  
  349. /*
  350.  *=============================================================================
  351.  * Returns wether or not a part is registered to receive updates
  352.  *=============================================================================
  353.  */
  354.  
  355.  
  356. SOM_Scope ODBoolean  SOMLINK IsRegistered(IODLinkTarget *somSelf,
  357.                                                  Environment *ev)
  358. {
  359.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  360.     IODLinkTargetMethodDebug("IODLinkTarget","IsRegistered");
  361.  
  362.  
  363.     return (_fIsRegistered);
  364.  
  365. }
  366.  
  367. /*
  368.  *=============================================================================
  369.  * Called in Draft::GetLink to establish a link from the given LinkSpec.
  370.  *
  371.  * <1>  Invoke EstablishLink of LinkSpec and obtain values for the following
  372.  *      variables in return.
  373.  *
  374.  *      ODStorageUnitID           fTrgtPartSUID;
  375.  *      ODLinkConnectionData        fTrgtConnData;
  376.  *      ODLinkID                  fLinkID;
  377.  *      IODLinkTargetToLinkSource fLinkSrc;
  378.  *      ODLinkConnectionID           fConnID;
  379.  *      ODBoolean                 fIsLocal;
  380.  *      ODBoolean                 fTracked;
  381.  *      ODISOStr                  fASName;
  382.  *=============================================================================
  383.  */
  384.  
  385. SOM_Scope void
  386. SOMLINK EstablishLink(IODLinkTarget *somSelf,
  387.                       Environment *ev,
  388.                       ODLinkSpec* linkSpec,
  389.                       IODLinkService* trgtLinkService)
  390. {
  391.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  392.     IODLinkTargetMethodDebug("IODLinkTarget","EstablishLink");
  393.  
  394.     //---<1>
  395.     linkSpec->EstablishLink(ev,
  396.                             (IODLinkTarget*)somSelf,
  397.                             _fPID,
  398.                             &_fTrgtConnData,
  399.                             trgtLinkService,
  400.                             &_fTrgtPartSUID,
  401.                             &_fLinkID,
  402.                             &_fLinkSrc,
  403.                             &_fConnID,
  404.                             &_fIsLocal,
  405.                             &_fTracked,
  406.                             &_fASName);
  407. }
  408.  
  409. /*
  410.  *=============================================================================
  411.  * Called in Draft::GetLink to initialize the LinkTarget after it is
  412.  *   created.
  413.  *
  414.  * <1>  Init BaseLink.
  415.  * <2>  create target part description.
  416.  * <3>  Add the property kODPropAvailabilityServerName
  417.  *      so that draft can distinguish link targets from other persistent objs.
  418.  *=============================================================================
  419.  */
  420.  
  421. SOM_Scope void
  422. SOMLINK InitLinkTarget(IODLinkTarget *somSelf,
  423.                        Environment *ev,
  424.                        ODStorageUnit* su,
  425.                        IODFileName pathName)
  426. {
  427.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  428.     IODLinkTargetMethodDebug("IODLinkTarget","InitLinkTarget");
  429.  
  430.     //---<1>
  431.     _InitBaseLink(ev, su);
  432.  
  433.     //---<2>
  434.      char            hostName[256];
  435.      strcpy(hostName, getenv("HOSTNAME"));
  436.  
  437.      //_fTrgtConnData.HostName = ODISOStrFromCStr(hostName);
  438.      _fTrgtConnData.HostName.format = kODIBMCodePageText;
  439.      _fTrgtConnData.HostName.text._buffer = kODNULL;
  440.      SetITextCString(&_fTrgtConnData.HostName, hostName);
  441.      SetITextLangCode(&_fTrgtConnData.HostName, 0);
  442.      SetITextScriptCode(&_fTrgtConnData.HostName, 0);
  443.  
  444.      //_fTrgtConnData.DocumentName  = ODISOStrFromCStr(pathName);
  445.      _fTrgtConnData.DocumentName.format = kODIBMCodePageText;
  446.      _fTrgtConnData.DocumentName.text._buffer = kODNULL;
  447.      SetITextCString(&_fTrgtConnData.DocumentName, pathName);
  448.      SetITextLangCode(&_fTrgtConnData.DocumentName, 0);
  449.      SetITextScriptCode(&_fTrgtConnData.DocumentName, 0);
  450.  
  451.      //_fTrgtConnData.LinkDesc     = ODISOStrFromCStr("");
  452.      _fTrgtConnData.LinkDesc.format = kODIBMCodePageText;
  453.      _fTrgtConnData.LinkDesc.text._buffer = kODNULL;
  454.      SetITextCString(&_fTrgtConnData.LinkDesc, "");
  455.      SetITextLangCode(&_fTrgtConnData.LinkDesc, 0);
  456.      SetITextScriptCode(&_fTrgtConnData.LinkDesc, 0);
  457.  
  458.  
  459.    //---<3>
  460.     ODSUAddPropValue(ev, su, kODPropAvailabilityServerName, kODISOStr);
  461.  
  462. }
  463.  
  464. /*
  465.  *=============================================================================
  466.  * Called in Draft::GetLink to initialize the LinkTarget from a
  467.  *   pre-existing storage unit.
  468.  *
  469.  * <1>  Init BaseLink from the storagte.
  470.  * <2>  Internalize the following variables from the storage:
  471.  *        ODLinkConnectionID fConnID;
  472.  *        ODBoolean       fIsLocal;
  473.  *        ODLinkID        fLinkID;
  474.  * <3>  LinkTarget was originally local:
  475. *      <3.1> Convert SUID reference to an SUID
  476.  *      This may fail if the LT was cloned and the LS it referred to wasn't.
  477.  *      <3.1.A.1>If SUID exists, then obtain a pointer to the LS object
  478.  *         <3.1.A.1.A> If you get a pointer, this is a pointer to the correct LS,
  479.  *         but the LS-LT pair may have been cloned, so call GetPersistentLinkInfo
  480.  *         to get the correct LinkID and the ASName
  481.  *         <3.1.A.1.B> If you fail to get a pointer, this is a broken link.
  482.  *         Restore the ASName from the SU and set the LinkSrc to null.
  483.  *      <3.1.B.1> If SUID doesn't exist, this means the LT is a clone
  484.  *         and may or may not still be local.
  485.  *         Restore the ASName from the SU and set the LinkSrc to the
  486.  *         availability server.  The correct LinkSrc pointer will
  487.  *         be set in step 7.
  488.  *
  489.  *      Read SUID of LinkTargetToLinkSource from the SU.
  490.  *      Convert the SUID to the reference of LinkTargetToLinkSource.
  491.  *      Ask the linksource to tell me the linkid and ASName
  492.  * <4>  LinkTarget was originally remote:
  493.  *      Read Availability Server's name from the SU.
  494.  *      Ask DSOM to find the server by the name just read.
  495.  *      Ask the server found to create an instance of IODAvailServer.
  496.  * <5>  Internalize the following variables from the storage:
  497.  *        ODLinkConnectionData fTrgtPartDesc;
  498.  *        ODStorageUnitID    fTrgtPartSUID;
  499.  *        ODBoolean          fTracked;
  500.  *        ODULong            fNumOfRegParts;
  501.  * <6>  Reset the target part description hostName and docName to new values.
  502. * <7>  If this is a Clone of a link,
  503.  *      <7.1> Clear CloneOfALink property
  504.  *      <7.2> If there is no SUID,
  505.  *            <7.2.1> Call AddLinkTarget to tell LS that we have a new target.
  506.  *            <7.2.2> If LS is now local, set isLocal, and replace
  507.  *                    the reference to the AS with a reference to linkSrc
  508.  *            <7.2.3> If LS is now remote, set isLocal false (leaving
  509.  *                    linkSrc pointing to the AS).
  510.  *=============================================================================
  511.  */
  512.  
  513. SOM_Scope void
  514. SOMLINK InitLinkTargetFromStorage(IODLinkTarget *somSelf,
  515.                                   Environment *ev,
  516.                                   ODStorageUnit* su,
  517.                                   IODFileName pathName)
  518.  
  519. {
  520.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  521.     IODLinkTargetMethodDebug("IODLinkTarget","InitLinkTargetFromStorage");
  522.     ODID linkSourceSUID; // identifies the linksource if it's local
  523.     //---<1>
  524.     _InitBaseLinkFromStorage(ev, su);
  525.  
  526.     //---<2>
  527.     _fConnID = ODGetULongProp(ev,su, kODPropConnectionID, kODULong);
  528.     _fIsLocal = ODGetBooleanProp(ev,su, kODPropLinkLocality, kODBoolean);
  529.     _fLinkID = ODGetULongProp(ev,su, kODPropLinkID, kODULong);
  530.  
  531.     if (_fIsLocal)
  532.     {
  533.       //---<3>
  534.       //---<3.1.>
  535.  
  536.       linkSourceSUID = ODGetWeakSURefProp(ev,su,
  537.                                           kODPropLinkTargetToLinkSource,
  538.                                           kODWeakStorageUnitRef);
  539.       if (linkSourceSUID != 0)
  540.       {
  541.         //---<3.1.A.1>
  542.         TRY
  543.           _fLinkSrc = (IODLinkTargetToLinkSource*)
  544.                       su->GetDraft(ev)->AcquireLinkSource(ev, linkSourceSUID);
  545.           //---<3.1.A.1.A>
  546.           ((IODLinkSource*)_fLinkSrc)->GetPersistentLinkInfo(ev, &_fLinkID, &_fASName);
  547.         CATCH_ALL
  548.           //---<3.1.A.1.B>
  549.           _fLinkSrc = kODNULL;
  550.           GetISOStrProp(ev,
  551.                         su,
  552.                         kODPropAvailabilityServerName,
  553.                         kODISOStr,
  554.                         _fASName);
  555.  
  556.         ENDTRY
  557.       }  /* linkSourceSUID != 0 */
  558.     else
  559.       {
  560.         //---<3.1.B.1>
  561.         GetISOStrProp(ev,
  562.                       su,
  563.                       kODPropAvailabilityServerName,
  564.                       kODISOStr,
  565.                       _fASName);
  566.         SOMDServer *server = SOMD_ObjectMgr->somdFindServerByName(ev, _fASName);
  567.         if (ODGetSOMException(ev) == kODNoError)
  568.         {
  569.           _fLinkSrc = (IODLinkTargetToLinkSource*)
  570.                       server->somdCreateObj(ev, "IODAvailServer", "");
  571.         }
  572.         else
  573.         {
  574.           _fLinkSrc = kODNULL;
  575.           return;
  576.         }
  577.       }  /* linksourceSUID == 0 */
  578.     }    /* isLocal */
  579.     else
  580.     {
  581.       //---<4>
  582.      linkSourceSUID = 0;
  583.      GetISOStrProp(ev,
  584.                    su,
  585.                    kODPropAvailabilityServerName,
  586.                   kODISOStr,
  587.                   _fASName);
  588.  
  589.      _GetStorageUnit(ev)->GetDraft(ev)->GetDocument(ev)->GetContainer(ev)->GetStorageSystem(ev)->GetSession(ev)->StartServer(ev, (char*)kODNULL);
  590.      SOMDServer *server = SOMD_ObjectMgr->somdFindServerByName(ev, _fASName);
  591.      if (ODGetSOMException(ev) == kODNoError)
  592.      {
  593.        _fLinkSrc = (IODLinkTargetToLinkSource*)
  594.                    server->somdCreateObj(ev, "IODAvailServer", "");
  595.      }
  596.      else
  597.      {
  598.        _fLinkSrc = kODNULL;
  599.        return;
  600.      }
  601.  
  602.   }   /* !isLocal */
  603.  
  604.     //---<5>
  605.     GetPartDescriptionProp(ev,
  606.                            su,
  607.                            kODPropPartDescription,
  608.                            kODPartDescription,
  609.                            _fTrgtConnData);
  610.  
  611.     _fTrgtPartSUID = ODGetWeakSURefProp(ev,su,
  612.                                         kODPropTargetPart,
  613.                                         kODWeakStorageUnitRef);
  614.  
  615.     _fTracked = ODGetBooleanProp(ev,su,
  616.                                  kODPropLinkSourceTrackMode,
  617.                                  kODBoolean);
  618.  
  619.     //---<6>
  620.      char            hostName[256];
  621.      strcpy(hostName, getenv("HOSTNAME"));
  622.  
  623.        DisposeITextStruct(_fTrgtConnData.HostName);
  624.        _fTrgtConnData.HostName.format = kODIBMCodePageText;
  625.        _fTrgtConnData.HostName.text._buffer = kODNULL;
  626.        SetITextCString(&_fTrgtConnData.HostName, hostName);
  627.        SetITextLangCode(&_fTrgtConnData.HostName, 0);
  628.        SetITextScriptCode(&_fTrgtConnData.HostName, 0);
  629.  
  630.        DisposeITextStruct(_fTrgtConnData.DocumentName);
  631.        _fTrgtConnData.DocumentName.format = kODIBMCodePageText;
  632.        _fTrgtConnData.DocumentName.text._buffer = kODNULL;
  633.        SetITextCString(&_fTrgtConnData.DocumentName, pathName);
  634.        SetITextLangCode(&_fTrgtConnData.DocumentName, 0);
  635.        SetITextScriptCode(&_fTrgtConnData.DocumentName, 0);
  636.  
  637.  
  638.      //---<7>
  639.      if (su->Exists(ev, kODPropCloneOfALink, kODNULL, 0))
  640.        {
  641.        //---<7.1>
  642.        su->Focus(ev, kODPropCloneOfALink, 0, kODNULL, 0, 0);
  643.        su->Remove(ev);
  644.  
  645.        //---<7.2>
  646.        if (linkSourceSUID == 0)
  647.          {
  648.          ODBoolean IsNowLocal;  // is the cloned link target local to the LS?
  649.          TRY
  650.            //---<7.2.1>
  651.            _fLinkSrc->AddLinkTarget(ev,
  652.                                     _fLinkID,
  653.                                     _fPID,
  654.                                     &_fTrgtConnData,
  655.                                     somSelf,
  656.                                     &linkSourceSUID,
  657.                                     &_fConnID,
  658.                                     &IsNowLocal,
  659.                                     &_fTracked);
  660.  
  661.            //---<7.2.2.>
  662.            if (IsNowLocal) {
  663.              _fIsLocal = kODTrue;
  664.              if (((SOMDObject*)_fLinkSrc)->is_proxy(ev))
  665.              {
  666.                SOMD_ObjectMgr->somdReleaseObject(ev, _fLinkSrc);
  667.              }
  668.  
  669.              _fLinkSrc = (IODLinkTargetToLinkSource*)
  670.                          su->GetDraft(ev)->AcquireLinkSource(ev, linkSourceSUID);
  671.  
  672.              } else /* IsNowLocal false */
  673.                _fIsLocal = kODFalse;
  674.          CATCH_ALL
  675.              if (((SOMDObject*)_fLinkSrc)->is_proxy(ev))
  676.              {
  677.                SOMD_ObjectMgr->somdReleaseObject(ev, _fLinkSrc);
  678.              }
  679.              _fLinkSrc = kODNULL;
  680.          ENDTRY
  681.          }  /* end if linkSourceSUID == 0 */
  682.        }  /* end if this is a clone of a link */
  683. }
  684.  
  685. /*
  686.  *=============================================================================
  687.  * Called by LinkSource to inform that source Part has broken the link.
  688.  *
  689.  * <1>  Release the old LinkTargetToLinkSource proxy if LinkSource is remote.
  690.  * <2>  Set fLinkSrc to NULL so Part will get an broken link exception if
  691.  *      a method invoked on it.
  692.  *=============================================================================
  693.  */
  694.  
  695. SOM_Scope void
  696. SOMLINK RemoveLink(IODLinkTarget *somSelf,
  697.                    Environment *ev)
  698. {
  699.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  700.     IODLinkTargetMethodDebug("IODLinkTarget","RemoveLink");
  701.  
  702.     //---<1>
  703.     if (_fLinkSrc != (IODLinkTargetToLinkSource*)kODNULL)
  704.     {
  705.       if (!_fIsLocal)
  706.       {
  707.         if (((SOMDObject*)_fLinkSrc)->is_proxy(ev))
  708.         {
  709.           SOMD_ObjectMgr->somdReleaseObject(ev, _fLinkSrc);
  710.         }
  711.         SOMFree(_fASName);
  712.         _fASName = (ODISOStr)kODNULL;
  713.       }
  714.     }
  715.  
  716.     //---<2>
  717.     _fLinkSrc = (IODLinkTargetToLinkSource*)kODNULL;
  718. }
  719.  
  720. /*
  721.  *=============================================================================
  722.  * Called by LinkSource to reset the reference to it when it is closed
  723.  *   or reopened.
  724.  * LinkTarget gets this call only when it is registered with the
  725.  *   LinkSource.
  726.  *
  727.  * <1>  Release the old LinkTargetToLinkSource proxy if LinkSource is remote.
  728.  * <2>  Save the new LinkTargetToLinkSource proxy.
  729.  *=============================================================================
  730.  */
  731. //SOM_Scope void
  732. //SOMLINK ResetLinkSource(IODLinkTarget *somSelf,
  733. //                        Environment *ev,
  734. //                        IODLinkTargetToLinkSource* linkSrc)
  735. //{
  736. //    IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  737. //    IODLinkTargetMethodDebug("IODLinkTarget","ResetLinkSource");
  738. //
  739. //    //---<1>
  740. //    if (_fLinkSrc != (IODLinkTargetToLinkSource*)kODNULL)
  741. //    {
  742. //      if (!_fIsLocal)
  743. //      {
  744. //        SOMD_ObjectMgr->somdReleaseObject(ev, _fLinkSrc);
  745. //      }
  746. //    }
  747. //
  748. //    //---<2>
  749. //    _fLinkSrc = linkSrc;
  750. //}
  751.  
  752. /*
  753.  *=============================================================================
  754.  *=============================================================================
  755.  */
  756.  
  757. SOM_Scope void
  758. SOMLINK somInit(IODLinkTarget *somSelf)
  759. {
  760.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  761.     IODLinkTargetMethodDebug("IODLinkTarget","somInit");
  762.  
  763.     IODLinkTarget_parent_ODLink_somInit(somSelf);
  764.  
  765.     _fConnID = 0;
  766.     _fIsLocal = kODFalse;
  767.     _fLinkID = 0;
  768.     _fLinkSrc = (IODLinkTargetToLinkSource*)kODNULL;
  769.     _fNumOfRegParts = 0;
  770.  
  771.     _fTrgtConnData.HostName.format = kODIBMCodePageText;
  772.     _fTrgtConnData.HostName.text._buffer = kODNULL;
  773.     SetITextCString(&_fTrgtConnData.HostName, "");
  774.     SetITextLangCode(&_fTrgtConnData.HostName, 0);
  775.     SetITextScriptCode(&_fTrgtConnData.HostName, 0);
  776.  
  777.     _fTrgtConnData.DocumentName.format = kODIBMCodePageText;
  778.     _fTrgtConnData.DocumentName.text._buffer = kODNULL;
  779.     SetITextCString(&_fTrgtConnData.DocumentName, "");
  780.     SetITextLangCode(&_fTrgtConnData.DocumentName, 0);
  781.     SetITextScriptCode(&_fTrgtConnData.DocumentName, 0);
  782.  
  783.     _fTrgtConnData.LinkDesc.format = kODIBMCodePageText;
  784.     _fTrgtConnData.LinkDesc.text._buffer = kODNULL;
  785.     SetITextCString(&_fTrgtConnData.LinkDesc, "");
  786.     SetITextLangCode(&_fTrgtConnData.LinkDesc, 0);
  787.     SetITextScriptCode(&_fTrgtConnData.LinkDesc, 0);
  788.     _fTrgtPartSUID = 0;
  789.     _fTracked = kODFalse;
  790.     _fPID = _getpid();
  791.     _fASName = (ODISOStr)kODNULL;
  792. }
  793.  
  794. /*
  795.  *=============================================================================
  796.  *=============================================================================
  797.  */
  798.  
  799. SOM_Scope void
  800. SOMLINK somUninit(IODLinkTarget *somSelf)
  801. {
  802.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  803.     IODLinkTargetMethodDebug("IODLinkTarget","somUninit");
  804.  
  805.     IODLinkTarget_parent_ODLink_somUninit(somSelf);
  806. }
  807.  
  808. /*
  809.  *=============================================================================
  810.  * <1>  Invoke parent's Externalize method.
  811.  * <2>  Externalize the following variables to the storage.
  812.  *        ODLinkConnectionID fConnID;
  813.  *        ODBoolean       fIsLocal;
  814.  *        ODLinkID        fLinkID;
  815.  *        ODISOStr        fASName;
  816.  * <3>  LinkTarget is local:
  817.  *      Write the weak SU reference of LinkTargetToLinkSource to the storage.
  818.  * <4>  LinkTarget is remote: (nothing)
  819.  * <5>  Externalize the following variables to the storage:
  820.  *        ODLinkConnectionData fTrgtPartDesc;
  821.  *        ODStorageUnitID    fTrgtPartSUID;
  822.  *        ODBoolean          fTracked;
  823.  *=============================================================================
  824.  */
  825.  
  826. SOM_Scope void
  827. SOMLINK Externalize(IODLinkTarget *somSelf,
  828.                     Environment *ev)
  829. {
  830.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  831.     IODLinkTargetMethodDebug("IODLinkTarget","Externalize");
  832.  
  833.     ODISOStr      externalizedID = (ODISOStr)kODNULL;
  834.     ODStorageUnit *su = _GetStorageUnit(ev);
  835.  
  836.     //---<1>
  837.     IODLinkTarget_parent_ODLink_Externalize(somSelf, ev);
  838.  
  839.     //---<2>
  840.     ODSetULongProp(ev, su, kODPropConnectionID, kODULong, _fConnID);
  841.     ODSetBooleanProp(ev, su, kODPropLinkLocality, kODBoolean, _fIsLocal);
  842.     ODSetULongProp(ev, su, kODPropLinkID, kODULong, _fLinkID);
  843.     ODSetISOStrProp(ev, su,
  844.                     kODPropAvailabilityServerName,
  845.                     kODISOStr,
  846.                     _fASName);
  847.  
  848.     if (_fIsLocal)
  849.     {
  850.       //---<3>
  851.       ODSetWeakSURefProp(ev, su,
  852.                          kODPropLinkTargetToLinkSource,
  853.                          kODWeakStorageUnitRef,
  854.                          ((IODLinkSource*)_fLinkSrc)->GetID(ev));
  855.     }
  856.     else
  857.     {
  858.       //---<4>
  859.     }
  860.  
  861.     //---<5>
  862.     SetPartDescriptionProp(ev,
  863.                            su,
  864.                            kODPropPartDescription,
  865.                            kODPartDescription,
  866.                            _fTrgtConnData);
  867.  
  868.     if (_fTrgtPartSUID)
  869.       ODSetWeakSURefProp(ev, su,
  870.                          kODPropTargetPart,
  871.                          kODWeakStorageUnitRef,
  872.                          _fTrgtPartSUID);
  873.  
  874.     ODSetBooleanProp(ev, su, kODPropLinkSourceTrackMode, kODBoolean, _fTracked);
  875. }
  876. /*
  877.  *=============================================================================
  878.  * <1>  Make sure this object is not already cloned in the toSU.
  879.  * <2>  Invoke parent's CloneInto method.
  880.  * <3>  Clone the following variables into toSU:
  881.  *        ODLinkConnectionID fConnID;
  882.  *        ODBoolean       fIsLocal;
  883.  *        ODLinkID        fLinkID;
  884.  *        ODISOStr        fASName;
  885.  * <4>  LinkTarget is local:
  886.  *      Ask the Draft to weak clone the LinkTargetToLinkSource.
  887.  *      Clone the returned SUID into toSU.
  888.  * <5>  LinkTarget is remote:(nothing)
  889.  * <6>  Clone ODLinkConnectionData fTrgtPartDesc into toSU.
  890.  * <7>  Ask the Draft to weak clone the target Part.
  891.  *      Clone the returned SUID into toSU.
  892.  * <8>  Clone ODBoolean fTracked into toSU.
  893.  *=============================================================================
  894.  */
  895.  
  896. SOM_Scope void
  897. SOMLINK CloneInto(IODLinkTarget *somSelf,
  898.                   Environment *ev,
  899.                   ODDraftKey key,
  900.                   ODStorageUnit* toSU,
  901.                   ODFrame* scopeFrame)
  902. {
  903.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  904.     IODLinkTargetMethodDebug("IODLinkTarget","CloneInto");
  905.  
  906.     ODDraft* draft = _GetStorageUnit(ev)->GetDraft(ev);
  907.     ODID     srcSUID;
  908.     ODID     trgtPartSUID;
  909.  
  910.     //---<1>
  911.     if (toSU->Exists(ev, kODPropConnectionID, kODULong, 0)) return;
  912.  
  913.     //---<2>
  914.     IODLinkTarget_parent_ODLink_CloneInto(somSelf,
  915.                                           ev,
  916.                                           key,
  917.                                           toSU,
  918.                                           scopeFrame);
  919.  
  920.     //---<3>
  921.     ODSetULongProp(ev, toSU, kODPropConnectionID, kODULong, _fConnID);
  922.     ODSetBooleanProp(ev, toSU, kODPropLinkLocality, kODBoolean, _fIsLocal);
  923.     ODSetULongProp(ev, toSU, kODPropLinkID, kODULong, _fLinkID);
  924.     ODSetISOStrProp(ev, toSU,
  925.                     kODPropAvailabilityServerName,
  926.                     kODISOStr,
  927.                     _fASName);
  928.  
  929.     if (_fIsLocal)
  930.     {
  931.       //---<4>
  932.       srcSUID = draft->WeakClone(ev,
  933.                                  key,
  934.                                  ((IODLinkSource*)_fLinkSrc)->GetID(ev),
  935.                                  0,
  936.                                  (scopeFrame ? scopeFrame->GetID(ev) : 0));
  937.       ODSetWeakSURefProp(ev, toSU,
  938.                          kODPropLinkTargetToLinkSource,
  939.                          kODWeakStorageUnitRef,
  940.                          srcSUID);
  941.     }
  942.     else
  943.     {
  944.       //---<5>
  945.       ODSetISOStrProp(ev, toSU,
  946.                       kODPropAvailabilityServerName,
  947.                       kODISOStr,
  948.                       _fASName);
  949.     }
  950.  
  951.     //---<6>
  952.     SetPartDescriptionProp(ev,
  953.                            toSU,
  954.                            kODPropPartDescription,
  955.                            kODPartDescription,
  956.                            _fTrgtConnData);
  957.  
  958.     //---<7>
  959.     trgtPartSUID = draft->WeakClone(ev,
  960.                                     key,
  961.                                     _fTrgtPartSUID,
  962.                                     0,
  963.                                     (scopeFrame ? scopeFrame->GetID(ev) : 0));
  964.     ODSetWeakSURefProp(ev, toSU,
  965.                        kODPropTargetPart,
  966.                        kODWeakStorageUnitRef,
  967.                        trgtPartSUID);
  968.  
  969.     //---<8>
  970.     ODSetBooleanProp(ev, toSU,
  971.                      kODPropLinkSourceTrackMode,
  972.                      kODBoolean,
  973.                      _fTracked);
  974. }
  975.  
  976. /*
  977.  *=============================================================================
  978.  * <1>  Make sure link is not broken.
  979.  * <2>  Invoke ForwardGetUpdateID method of LinkTargetToLinkSource.
  980.  *=============================================================================
  981.  */
  982.  
  983. SOM_Scope ODUpdateID
  984. SOMLINK GetUpdateID(IODLinkTarget *somSelf,
  985.                     Environment *ev)
  986. {
  987.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  988.     IODLinkTargetMethodDebug("IODLinkTarget","GetUpdateID");
  989.  
  990.     //---<1>
  991.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  992.     {
  993.       ODSetSOMException(ev, kODErrBrokenLink);
  994.       return kODUnknownUpdate;
  995.     }
  996.  
  997.     TRY
  998.       //---<2>
  999.       ODUpdateID id = _fLinkSrc->ForwardGetUpdateID(ev, _fLinkID);
  1000.       return id;
  1001.     CATCH_ALL
  1002.       ODSetSOMException(ev, kODErrBrokenLink);
  1003.       return kODUnknownUpdate;
  1004.     ENDTRY  }
  1005.  
  1006. /*
  1007.  *=============================================================================
  1008.  * <1>  Make sure link is not broken.
  1009.  * <2>  Invoke ForwardGetChangeTime method of LinkTargetToLinkSource.
  1010.  *=============================================================================
  1011.  */
  1012.  
  1013. SOM_Scope ODTime
  1014. SOMLINK GetChangeTime(IODLinkTarget *somSelf,
  1015.                       Environment *ev)
  1016. {
  1017.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1018.     IODLinkTargetMethodDebug("IODLinkTarget","GetChangeTime");
  1019.  
  1020.     //---<1>
  1021.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  1022.     {
  1023.       ODSetSOMException(ev, kODErrBrokenLink);
  1024.       return (ODTime)0;
  1025.     }
  1026.  
  1027.     TRY
  1028.       //---<2>
  1029.       ODTime t = _fLinkSrc->ForwardGetChangeTime(ev, _fLinkID);
  1030.       return t;
  1031.     CATCH_ALL
  1032.       ODSetSOMException(ev, kODErrBrokenLink);
  1033.       return (ODTime)0;
  1034.     ENDTRY     }
  1035.  
  1036. /*
  1037.  *=============================================================================
  1038.  * <1>  Make sure link is not broken.
  1039.  * <2>  Invoke ForwardGetContentStorageUnit method of LinkTargetToLinkSource.
  1040.  *=============================================================================
  1041.  */
  1042.  
  1043. SOM_Scope ODStorageUnit*
  1044. SOMLINK GetContentStorageUnit(IODLinkTarget *somSelf,
  1045.                               Environment *ev,
  1046.                               ODLinkKey key)
  1047. {
  1048.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1049.     IODLinkTargetMethodDebug("IODLinkTarget","GetContentStorageUnit");
  1050.  
  1051.     //---<1>
  1052.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  1053.     {
  1054.       ODSetSOMException(ev, kODErrBrokenLink);
  1055.       return (ODStorageUnit*)kODNULL;
  1056.     }
  1057.  
  1058.     TRY
  1059.       //---<2>
  1060.       ODStorageUnit* su = _fLinkSrc->ForwardGetContentStorageUnit(ev,
  1061.                                                                   _fLinkID,
  1062.                                                                   key);
  1063.       return su;
  1064.     CATCH_ALL
  1065.       ODSetSOMException(ev, kODErrBrokenLink);
  1066.       return (ODStorageUnit*)kODNULL;
  1067.     ENDTRY          }
  1068.  
  1069. /*
  1070.  *=============================================================================
  1071.  *=============================================================================
  1072.  */
  1073.  
  1074. SOM_Scope ODLinkSource*
  1075. SOMLINK GetLinkSource(IODLinkTarget *somSelf,
  1076.                       Environment *ev)
  1077. {
  1078.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1079.     IODLinkTargetMethodDebug("IODLinkTarget","GetLinkSource");
  1080.  
  1081.     return (ODLinkSource*)_fLinkSrc;
  1082. }
  1083.  
  1084. /*
  1085.  *=============================================================================
  1086.  * <1>  Make sure link is not broken.
  1087.  * <2>  Invoke ForwardLock method of LinkTargetToLinkSource.
  1088.  *=============================================================================
  1089.  */
  1090.  
  1091. SOM_Scope ODBoolean
  1092. SOMLINK Lock(IODLinkTarget *somSelf,
  1093.              Environment *ev,
  1094.              ODULong wait,
  1095.              ODLinkKey* key)
  1096. {
  1097.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1098.     IODLinkTargetMethodDebug("IODLinkTarget","Lock");
  1099.  
  1100.     //---<1>
  1101.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  1102.     {
  1103.       ODSetSOMException(ev, kODErrBrokenLink);
  1104.       return kODFalse;
  1105.     }
  1106.  
  1107.     TRY
  1108.       //---<2>
  1109.       ODBoolean rc = _fLinkSrc->ForwardLock(ev, _fLinkID, wait, key);
  1110.       return rc;
  1111.     CATCH_ALL
  1112.       ODSetSOMException(ev, kODErrBrokenLink);
  1113.       return kODFalse;
  1114.     ENDTRY       }
  1115.  
  1116. /*
  1117.  *=============================================================================
  1118.  * <1>  Make sure link is not broken.
  1119.  * <2>  Invoke parent's RegisterDependent method.
  1120.  * <3>  Increase counter of registered parts.
  1121.  * <4>  Set the fIsRegistered instant variable to true.
  1122.  * <5>  If counter of registered parts change from 0 to 1 then register with
  1123.  *      LinkTargetToLinkSource.
  1124.  *=============================================================================
  1125.  */
  1126.  
  1127. SOM_Scope void
  1128. SOMLINK RegisterDependent(IODLinkTarget *somSelf,
  1129.                           Environment *ev,
  1130.                           ODPart* clientPart,
  1131.                           ODUpdateID id)
  1132. {
  1133.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1134.     IODLinkTargetMethodDebug("IODLinkTarget","RegisterDependent");
  1135.  
  1136.     //---<1>
  1137.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  1138.     {
  1139.       ODSetSOMException(ev, kODErrBrokenLink);
  1140.       return;
  1141.     }
  1142.  
  1143.     //---<2>
  1144.     IODLinkTarget_parent_ODLink_RegisterDependent(somSelf,
  1145.                                                   ev,
  1146.                                                   clientPart,
  1147.                                                   id);
  1148.  
  1149.     if (ODGetSOMException(ev) == kODNoError)
  1150.     {
  1151.       //---<3>
  1152.       _fNumOfRegParts++;
  1153.  
  1154.       //---<4>
  1155.       _fIsRegistered = kODTrue;
  1156.  
  1157.       //---<5>
  1158.       if (   (_fNumOfRegParts == 1)
  1159.            &&(_fLinkSrc != (IODLinkTargetToLinkSource*)kODNULL)
  1160.          )
  1161.       {
  1162.         TRY
  1163.         if (_fTracked)
  1164.         {
  1165.           _fLinkSrc->RegisterTrackedLinkTarget(ev,
  1166.                                                _fLinkID,
  1167.                                                _fConnID,
  1168.                                                _fIsLocal);
  1169.         }// end of _ftracked
  1170.         else
  1171.         {
  1172.           _fLinkSrc->RegisterUntrackedLinkTarget(ev,
  1173.                                                  _fLinkID,
  1174.                                                  (IODLinkTarget*)somSelf,
  1175.                                                  &_fTrgtConnData,
  1176.                                                  _fIsLocal,
  1177.                                                  &_fConnID);
  1178.         }// end of !_fTracked
  1179.         CATCH_ALL
  1180.         _fNumOfRegParts = 0;
  1181.         _fIsRegistered = kODFalse;
  1182.         ODSetSOMException(ev, kODErrBrokenLink);
  1183.         return;
  1184.       ENDTRY
  1185.       }
  1186.     }
  1187. }
  1188.  
  1189. /*
  1190.  *=============================================================================
  1191.  * <1>  Invoke parent's Release method.
  1192.  * <2>  If LinkTarget's reference count goes down to zero inform the Draft
  1193.  *      to release the LinkTarget.
  1194.  *=============================================================================
  1195.  */
  1196.  
  1197. SOM_Scope void
  1198. SOMLINK Release(IODLinkTarget *somSelf,
  1199.                 Environment *ev)
  1200. {
  1201.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1202.     IODLinkTargetMethodDebug("IODLinkTarget","Release");
  1203.  
  1204.     IODLinkTarget_parent_ODLink_Release(somSelf, ev);
  1205.  
  1206.     if (_GetRefCount(ev) == 0)
  1207.     {
  1208.       _GetStorageUnit(ev)->GetDraft(ev)->ReleaseLink(ev, somSelf);
  1209.     }
  1210. }
  1211.  
  1212. /*
  1213.  *=============================================================================
  1214.  * <1>  Invoke parent's ReleaseAll method.
  1215.  *=============================================================================
  1216.  */
  1217.  
  1218. SOM_Scope void
  1219. SOMLINK ReleaseAll(IODLinkTarget *somSelf,
  1220.                    Environment *ev)
  1221. {
  1222.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1223.     IODLinkTargetMethodDebug("IODLinkTarget","ReleaseAll");
  1224.  
  1225.     //---<1>
  1226.     IODLinkTarget_parent_ODLink_ReleaseAll(somSelf, ev);
  1227.  
  1228.     // <dmy> Make sure that the link target is unregistered
  1229.     // ( _fNumOfRegParts == 0 ).  Otherwise unregister it.
  1230.     if (   (_fNumOfRegParts != 0)
  1231.          &&(!_fIsLocal)
  1232.          &&(_fLinkSrc != (IODLinkTargetToLinkSource*)kODNULL)
  1233.         )
  1234.     {
  1235.       TRY
  1236.       _fLinkSrc->UnregisterLinkTarget(somGetGlobalEnvironment(), _fLinkID, _fConnID, _fIsLocal);
  1237.       CATCH_ALL
  1238.       ENDTRY
  1239.     }
  1240.  
  1241.     //---<2>
  1242.     if (_fLinkSrc != (IODLinkTargetToLinkSource*)kODNULL)
  1243.     {
  1244.       if (!_fIsLocal)
  1245.       {
  1246.         if (((SOMDObject*)_fLinkSrc)->is_proxy(ev))
  1247.         {
  1248.           SOMD_ObjectMgr->somdReleaseObject(ev, _fLinkSrc);
  1249.         }
  1250.       }
  1251.       else {
  1252.         TRY
  1253.         ((IODLinkSource*)_fLinkSrc)->Release(ev);
  1254.         CATCH_ALL
  1255.         ENDTRY
  1256.       }
  1257.     }
  1258.     _fLinkSrc = (IODLinkTargetToLinkSource*)kODNULL;
  1259.  
  1260.     //---<3>
  1261.     _fConnID = 0;
  1262.     _fIsLocal = kODFalse;
  1263.     _fLinkID = 0;
  1264.     _fNumOfRegParts = 0;
  1265.     _fTrgtPartSUID = 0;
  1266.     _fTracked = kODFalse;
  1267. }
  1268.  
  1269.  
  1270. #ifndef _PLATFORM_OS2_
  1271. /*
  1272.  *=============================================================================
  1273.  * <1>  Make sure link is not broken.
  1274.  * <2>  Invoke ShowLinkDestinationInfo of BaseLink for now.
  1275.  *=============================================================================
  1276.  */
  1277.  
  1278. SOM_Scope ODBoolean
  1279. SOMLINK ShowLinkDestinationInfo(IODLinkTarget *somSelf,
  1280.                                 Environment *ev,
  1281.                                 ODFacet* facet,
  1282.                                 ODLinkInfo* info,
  1283.                                 ODBoolean changesAllowed,
  1284.                                 ODLinkInfoResult* infoResult)
  1285. {
  1286.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1287.     IODLinkTargetMethodDebug("IODLinkTarget","ShowLinkDestinationInfo");
  1288.  
  1289.     //---<1>
  1290.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  1291.     {
  1292.       ODSetSOMException(ev, kODErrBrokenLink);
  1293.       return kODFalse;
  1294.     }
  1295.  
  1296.     TRY
  1297.     //---<2>
  1298.     ODBoolean rc = IODLinkTarget_parent_ODLink_ShowLinkDestinationInfo(
  1299.                        somSelf,
  1300.                        ev,
  1301.                        facet,
  1302.                        info,
  1303.                        changesAllowed,
  1304.                        infoResult);
  1305.     return rc;
  1306.     CATCH_ALL
  1307.       ODSetSOMException(ev, kODErrBrokenLink);
  1308.       return kODFalse;
  1309.     ENDTRY
  1310.     }
  1311. #endif
  1312.  
  1313. /*
  1314.  *=============================================================================
  1315.  * <1>  Make sure link is not broken.
  1316.  * <2>  Invoke ShowSourceContentFor method of LinkTargetToLinkSource.
  1317.  *=============================================================================
  1318.  */
  1319.  
  1320. SOM_Scope void
  1321. SOMLINK ShowSourceContent(IODLinkTarget *somSelf,
  1322.                           Environment *ev)
  1323. {
  1324.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1325.     IODLinkTargetMethodDebug("IODLinkTarget","ShowSourceContent");
  1326.  
  1327.     //---<1>
  1328.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  1329.     {
  1330.       ODSetSOMException(ev, kODErrBrokenLink);
  1331.       return;
  1332.     }
  1333.  
  1334.  
  1335.     //---<2>
  1336.      SOM_TRY
  1337.      _fLinkSrc->ShowSourceContentFor(ev, _fLinkID, GetCStringFromIText(&_fTrgtConnData.HostName));
  1338.      SOM_CATCH_ALL
  1339.      if (ODGetSOMException(ev) != kODErrSourceDocNotOpen)
  1340.        {
  1341.         ODSetSOMException(ev, kODErrBrokenLink);
  1342.        }
  1343.      return;
  1344.      SOM_ENDTRY
  1345. }
  1346.  
  1347. /*
  1348.  *=============================================================================
  1349.  * <1>  Make sure link is not broken.
  1350.  * <2>  Invoke ForwardUnlock method of LinkTargetToLinkSource.
  1351.  *=============================================================================
  1352.  */
  1353.  
  1354. SOM_Scope void
  1355. SOMLINK Unlock(IODLinkTarget *somSelf,
  1356.                Environment *ev,
  1357.                ODLinkKey key)
  1358. {
  1359.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1360.     IODLinkTargetMethodDebug("IODLinkTarget","Unlock");
  1361.  
  1362.     //---<1>
  1363.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  1364.     {
  1365.       ODSetSOMException(ev, kODErrBrokenLink);
  1366.       return;
  1367.     }
  1368.  
  1369.     //---<2>
  1370.    TRY
  1371.     _fLinkSrc->ForwardUnlock(ev, _fLinkID, key, _fIsLocal);
  1372.   CATCH_ALL
  1373.     ODSetSOMException(ev, kODErrBrokenLink);
  1374.     return;
  1375.   ENDTRY
  1376.   }
  1377.  
  1378. /*
  1379.  *=============================================================================
  1380.  * <1>  Make sure link is not broken.
  1381.  * <2>  Invoke parent's UnregisterDependent method.
  1382.  * <3>  Decrease counter of registered parts.
  1383.  * <4>  If counter of registered parts change from 1 to 0 then do <5> and <6>
  1384.  * <5>  Set the fIsRegistered instant variable to false.
  1385.  * <6>  Unregister with LinkTargetToLinkSource.
  1386.  *=============================================================================
  1387.  */
  1388.  
  1389. SOM_Scope void
  1390. SOMLINK UnregisterDependent(IODLinkTarget *somSelf,
  1391.                             Environment *ev,
  1392.                             ODPart* clientPart)
  1393. {
  1394.     IODLinkTargetData *somThis = IODLinkTargetGetData(somSelf);
  1395.     IODLinkTargetMethodDebug("IODLinkTarget","UnregisterDependent");
  1396.  
  1397.     //---<1>
  1398.     if (_fLinkSrc == (IODLinkTargetToLinkSource*)kODNULL)
  1399.     {
  1400.       ODSetSOMException(ev, kODErrBrokenLink);
  1401.       return;
  1402.     }
  1403.  
  1404.     //---<2>
  1405.     IODLinkTarget_parent_ODLink_UnregisterDependent(somSelf, ev, clientPart);
  1406.  
  1407.     if (ODGetSOMException(ev) == kODNoError)
  1408.     {
  1409.       //---<3>
  1410.       _fNumOfRegParts--;
  1411.  
  1412.       //---<4>
  1413.       if (_fNumOfRegParts == 0)
  1414.       {
  1415.         //---<5>
  1416.         _fIsRegistered = kODFalse;
  1417.         //---<6>
  1418.         TRY
  1419.         _fLinkSrc->UnregisterLinkTarget(ev, _fLinkID, _fConnID, _fIsLocal);
  1420.         CATCH_ALL
  1421.         ENDTRY
  1422.         }
  1423.     }
  1424. }
  1425.  
  1426. #endif
  1427.  
  1428.