home *** CD-ROM | disk | FTP | other *** search
- /*
- File: StorPriv.cpp
-
- Contains: Implementation for ODStorageSystem class.
-
- Owned by: Vincent Lo
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <2> 3/15/96 DM 1295410: create list iterators on stack
- (avoid mem thrash during purge)
- <14> 8/22/95 VL 1255362: Removed XMP from header.
- <13> 8/21/95 VL 1278330, 1278315: Error code cleanup.
- <12> 7/21/95 VL 1270320: Dispose ba._buffer from
- container->GetID.
- <11> 5/26/95 VL 1251403: Multithreading naming support.
- <10> 5/25/95 jpa List.h --> LinkList.h [1253324]
- <9> 4/25/95 VL 1210982: Removed 5$.
- <8> 4/15/95 VL 1240014: ContainerList::Add gets the real
- ID from container instead of through a
- parameter.
- <7> 10/19/94 VL Turned off DEBUG_STORPRIV to avoid
- generating unnecessary debug strs.
- <6> 9/23/94 VL 1184272: ContainerID is now a sequence of
- octets.
- <5> 7/7/94 VL Commented out use of ODRecoverHeapID.
- <4> 6/28/94 VL Use ODRecoverHeapID.
- <3> 6/20/94 CC ODMemoryHeap* changed to ODMemoryHeapID.
- <2> 6/15/94 CC ODHeap -> ODMemoryHeap.
- <1> 6/1/94 VL first checked in
-
- To Do:
- In Progress:
- */
-
- #ifndef _STORPRIV_
- #include "StorPriv.h"
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include "ODCtr.xh"
- #endif
-
- #ifndef _LINKLIST_
- #include "LinkList.h"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef _ODNEW_
- #include "ODNew.h"
- #endif
-
- #ifndef _BARRAY_
- #include <BArray.h>
- #endif
-
- #ifndef som_xh
- #include "som.xh"
- #endif
-
- #pragma segment Storage
-
- //==============================================================================
- // Constants
- //==============================================================================
- #define kODErrContainerExistsWithDifferentID 923
-
- #if ODDebug
- // #define DEBUG_STORPRIV 1
- #endif
-
- //==============================================================================
- // ContainerList
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ContainerList::ContainerList
- //------------------------------------------------------------------------------
-
- ContainerList::ContainerList()
- {
- fHeap = kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // ContainerList::~ContainerList
- //------------------------------------------------------------------------------
-
- ContainerList::~ContainerList()
- {
- delete fLinkedList;
- }
-
- //------------------------------------------------------------------------------
- // ContainerList::Initialize
- //------------------------------------------------------------------------------
-
- void ContainerList::Initialize()
- {
- // Using default heap because the Storage System also resides in Default heap.
- fHeap = kDefaultHeapID;
-
- fLinkedList = new(GetHeap()) LinkedList;
- }
-
- //------------------------------------------------------------------------------
- // ContainerList::Get
- //------------------------------------------------------------------------------
-
- ODContainer* ContainerList::Get(ODContainerID* containerID)
- {
- ContainerLink* link = this->GetLink(containerID);
- ODContainer* container = kODNULL;
-
- if (link != kODNULL)
- container = link->fContainer;
-
- #ifdef DEBUG_STORPRIV
- somPrintf("ContainerList:Get containerID %x length %x container %x\n", containerID, containerID->_length, container);
- for (ODULong i = 0; i < containerID->_length; i++)
- somPrintf("%x ", (containerID->_buffer)[i]);
- somPrintf("\n");
- #endif
-
- return container;
- }
-
- //------------------------------------------------------------------------------
- // ContainerList::Add
- //------------------------------------------------------------------------------
-
- void ContainerList::Add(ODContainer* container)
- {
- ODContainer* existingContainer;
- ContainerLink* link;
-
- #ifdef DEBUG_STORPRIV
- somPrintf("ContainerList:Add containerID %x length %x container %x\n", containerID, containerID->_length, container);
- for (ODULong i = 0; i < containerID->_length; i++)
- somPrintf("%x ", (containerID->_buffer)[i]);
- somPrintf("\n");
- #endif
- Environment* ev = somGetGlobalEnvironment();
-
- ODContainerID containerID = container->GetID(ev);
- if ((existingContainer = this->Get(&containerID)) == kODNULL) {
- link = new(GetHeap()) ContainerLink(container);
- fLinkedList->AddLast(link);
- }
- ODDisposePtr(containerID._buffer);
- }
-
- //------------------------------------------------------------------------------
- // ContainerList::Remove
- //------------------------------------------------------------------------------
-
- void ContainerList::Remove(ODContainerID* containerID)
- {
- ContainerLink* link = this->GetLink(containerID);
-
- #ifdef DEBUG_STORPRIV
- somPrintf("ContainerList:Remove containerID %x length %x\n", containerID, containerID->_length, *((ODULong*) containerID->_buffer));
- for (ODULong i = 0; i < containerID->_length; i++)
- somPrintf("%x ", (containerID->_buffer)[i]);
- somPrintf("\n");
- #endif
-
- if (link == kODNULL) {
- THROW(kODErrContainerDoesNotExist);
- }
- else {
- fLinkedList->Remove(*link);
- delete link;
- }
- }
-
- //------------------------------------------------------------------------------
- // ContainerList::GetLink
- //------------------------------------------------------------------------------
-
- ContainerLink* ContainerList::GetLink(ODContainerID* containerID)
- {
- Environment* ev = somGetGlobalEnvironment();
- LinkedListIterator iter(fLinkedList);
- ODBoolean found = kODFalse;
-
- ContainerLink* link = (ContainerLink*) iter.Last();
- while ((link != kODNULL) && (found == kODFalse))
- {
- ODContainerID id = link->fContainer->GetID(ev);
- if (AreByteArraysEqual(&id, containerID))
- found = kODTrue;
- else
- link = (ContainerLink*) iter.Previous();
- ODDisposePtr(id._buffer);
- }
- return link;
- }
-
- //------------------------------------------------------------------------------
- // ContainerList::GetHeap
- //------------------------------------------------------------------------------
-
- ODMemoryHeapID ContainerList::GetHeap()
- {
- return fHeap;
- }
-
- //------------------------------------------------------------------------------
- // ContainerList::GetLinkedList
- //------------------------------------------------------------------------------
-
- LinkedList* ContainerList::GetLinkedList()
- {
- return fLinkedList;
- }
-
- //==============================================================================
- // ContainerListIterator
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ContainerListIterator::ContainerListIterator
- //------------------------------------------------------------------------------
-
- ContainerListIterator::ContainerListIterator(ContainerList* containerList)
- : fContainerList(containerList), fIterator( containerList->GetLinkedList() )
- {
- // fContainerList = containerList;
- // fIterator = kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // ContainerListIterator::~ContainerListIterator
- //------------------------------------------------------------------------------
-
- ContainerListIterator::~ContainerListIterator()
- {
- // delete fIterator;
- }
-
- //------------------------------------------------------------------------------
- // ContainerListIterator::Initialize
- //------------------------------------------------------------------------------
-
- void ContainerListIterator::Initialize()
- {
- // fIterator = new(fContainerList->GetHeap()) LinkedListIterator(fContainerList->GetLinkedList());
- }
-
- //------------------------------------------------------------------------------
- // ContainerListIterator::Last
- //------------------------------------------------------------------------------
-
- ODContainer* ContainerListIterator::Last()
- {
- ContainerLink* link = (ContainerLink*) fIterator.Last();
- if (link == kODNULL)
- return kODNULL;
- return link->fContainer;
- }
-
- //------------------------------------------------------------------------------
- // ContainerListIterator::Previous
- //------------------------------------------------------------------------------
-
- ODContainer* ContainerListIterator::Previous()
- {
- ContainerLink* link = (ContainerLink*) fIterator.Previous();
- if (link == kODNULL)
- return kODNULL;
- return link->fContainer;
- }
-
- //------------------------------------------------------------------------------
- // ContainerListIterator::IsNotComplete
- //------------------------------------------------------------------------------
-
- ODBoolean ContainerListIterator::IsNotComplete()
- {
- return fIterator.IsNotComplete();
- }
-
-