home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Storage / Bento / UpdatCtr.cpp < prev   
Encoding:
C/C++ Source or Header  |  1996-08-28  |  4.4 KB  |  185 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        UpdatCtr.cpp
  3.  
  4.     Contains:    Implementation of ODMemContainer class.
  5.  
  6.     Owned by:    Vincent Lo
  7.  
  8.     Copyright:    © 1995 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     8/13/96    DM        1376080: TempSuppressFatalBentoError
  13.                                     spelling
  14.          <3>     5/24/96    jpa        1246074: SOM_CATCH --> SOM_TRY..SOM_ENDTRY
  15.          <2>     5/23/96    DH        1344338: Force quit of document when
  16.                                     dragging 'Bad' file or Container. Turned
  17.                                     off fatal Bento errors for Open and Create
  18.                                     container operations.
  19.  
  20. To Do:
  21.     In Progress:
  22.         
  23. */
  24.  
  25. #define ODUpdateContainer_Class_Source
  26.  
  27. #define VARIABLE_MACROS
  28.  
  29. #include <UpdatCtr.xih>
  30.  
  31. #ifndef _PLFMDEF_
  32. #include "PlfmDef.h"
  33. #endif
  34.  
  35. #ifndef SOM_ODStorageSystem_xh
  36. #include <ODStor.xh>
  37. #endif
  38.  
  39. #ifndef SOM_CMDocument_xh
  40. #include <CMDoc.xh>
  41. #endif
  42.  
  43. #ifndef _MEMHDR_
  44. #include "MemHdr.h"
  45. #endif
  46.  
  47. #ifndef _TARGTHDR_
  48. #include "TargtHdr.h"
  49. #endif
  50.  
  51. #ifndef __CM_API__
  52. #include "CMAPI.h"
  53. #endif
  54.  
  55. #ifndef _EXCEPT_
  56. #include <Except.h>
  57. #endif
  58.  
  59. #ifndef _ODNEW_
  60. #include <ODNew.h>
  61. #endif
  62.  
  63. #ifndef _STORUTIL_
  64. #include <StorUtil.h>
  65. #endif
  66.  
  67. #ifndef _PLFMFILE_
  68. #include <PlfmFile.h>
  69. #endif
  70.  
  71. #ifndef _BARRAY_
  72. #include <BArray.h>
  73. #endif
  74.  
  75. #ifndef _ODMEMORY_
  76. #include <ODMemory.h>
  77. #endif
  78.  
  79. #ifndef _BENTOSUPPRESS_
  80. #include <BentoSuppress.h>
  81. #endif
  82.  
  83. #pragma segment ODUpdateContainer
  84.  
  85. //==============================================================================
  86. // ODUpdateContainer
  87. //==============================================================================
  88.  
  89. //------------------------------------------------------------------------------
  90. // ODUpdateContainer: ~ODUpdateContainer
  91. //------------------------------------------------------------------------------
  92.  
  93. SOM_Scope void  SOMLINK ODUpdateContainersomUninit(ODUpdateContainer *somSelf)
  94. {
  95.     ODUpdateContainerData *somThis = ODUpdateContainerGetData(somSelf);
  96.     ODUpdateContainerMethodDebug("ODUpdateContainer","somUninit");
  97.     
  98.     ODSafeReleaseObject(_fTargetDocument);
  99.     ODSafeReleaseObject(_fTargetContainer);
  100.  
  101.     ODDisposeHandle(_fHandle);
  102. }
  103.  
  104. //------------------------------------------------------------------------------
  105. // ODUpdateContainer: InitContainer
  106. //------------------------------------------------------------------------------
  107.  
  108. SOM_Scope void  SOMLINK ODUpdateContainerInitContainer(ODUpdateContainer *somSelf, Environment *ev,
  109.         ODStorageSystem* storage, ODContainerID* id)
  110. {
  111.     ODUpdateContainerData *somThis = ODUpdateContainerGetData(somSelf);
  112.     ODUpdateContainerMethodDebug("ODUpdateContainer","InitContainer");
  113.     
  114.     SOM_TRY
  115.  
  116.     /* Moved from somInit. SOM itself sets fields to zero
  117.         _fTargetContainer = kODNULL;
  118.         _fTargetDocument = kODNULL;
  119.         _fHandle = kODNULL;
  120.     */
  121.     
  122.     ODBoolean        fileLocked = kODTrue;
  123.     PlatformFile    file;
  124.     
  125.     ODVolatile(fileLocked);
  126.     TRY
  127.         file.Specify((FSSpec*) id->_buffer);
  128.         fileLocked = file.IsLocked();
  129.         if (fileLocked == kODFalse)
  130.             file.Lock();
  131.     
  132.         {    
  133.             TempSuppressFatalBentoError temp;
  134.                 
  135.             _fTargetContainer = (ODBentoContainer*) GetFileContainer(ev,
  136.                             storage->GetSession(ev),     
  137.                             (FSSpec*) id->_buffer);
  138.         }
  139.         _fTargetDocument = (CMDocument*) _fTargetContainer->AcquireDocument(ev, kODDefaultDocument);
  140.         if (fileLocked == kODFalse)
  141.             file.Unlock();
  142.             
  143.     CATCH_ALL
  144.     
  145.         if (fileLocked == kODFalse)
  146.             file.Unlock();
  147.  
  148.         RERAISE;
  149.         
  150.     ENDTRY
  151.  
  152.     _fHandle = ODNewHandle(0);
  153.     
  154.     ODByteArray* ba = CreateByteArray(&_fHandle, sizeof(ODHandle));    
  155.     parent_InitContainer(somSelf, ev, storage, ba);
  156.     DisposeByteArray(ba);
  157.  
  158.     SOM_CATCH_ALL
  159.     SOM_ENDTRY
  160. }
  161.  
  162. //------------------------------------------------------------------------------
  163. // ODUpdateContainer: GetTargetFileContainer
  164. //------------------------------------------------------------------------------
  165.  
  166. SOM_Scope ODBentoContainer*  SOMLINK ODUpdateContainerGetTargetContainer(ODUpdateContainer *somSelf, Environment *ev)
  167. {
  168.     ODUpdateContainerData *somThis = ODUpdateContainerGetData(somSelf);
  169.     ODUpdateContainerMethodDebug("ODUpdateContainer","GetTargetContainer");
  170.  
  171.     return _fTargetContainer;
  172. }
  173.  
  174. //------------------------------------------------------------------------------
  175. // ODUpdateContainer: GetTargetDocument
  176. //------------------------------------------------------------------------------
  177.  
  178. SOM_Scope CMDocument*  SOMLINK ODUpdateContainerGetTargetDocument(ODUpdateContainer *somSelf, Environment *ev)
  179. {
  180.     ODUpdateContainerData *somThis = ODUpdateContainerGetData(somSelf);
  181.     ODUpdateContainerMethodDebug("ODUpdateContainer","GetTargetDocument");
  182.  
  183.     return _fTargetDocument;
  184. }
  185.