home *** CD-ROM | disk | FTP | other *** search
- /*
- IXStore.h
- Copyright 1991, NeXT Computer, Inc.
- */
-
- #import "protocols.h"
- #import <mach/mach.h>
- #import <objc/hashtable.h>
- #import <objc/Object.h>
-
- @class NXData;
-
- // This pasteboard type is used to copy store images created by
- // getContents:andLength: between processes via the pasteboard server.
-
- extern NXAtom IXStorePboardType;
-
- @interface IXStore: Object
- {
- @public
- unsigned changeCount;
- @private
- unsigned nestingLevel;
- struct StoreBlockServer *blockServer;
- struct StoreBroker *storeBroker;
- struct StoreTransRecord *queueForward;
- struct StoreTransRecord *queueReverse;
- struct {
- unsigned exceptions:1;
- unsigned freeOnWrite:1;
- unsigned RESERVED1:30;
- } _storeStatus;
- }
-
- // These two methods set and report the interface error reporting policy. For
- // compatibility with 3.0 FCS, most of the methods implemented by this class
- // raise an exception when passed an invalid argument, such as an invalid block
- // handle. This can be quite cumbersome to use. When exceptions are disabled,
- // the method return values indicate success or failure.
-
- - enableExceptions:(BOOL)aBoolean;
- - (BOOL)areExceptionsEnabled;
-
- // Copying a store creates an independent concurrent context. The number of
- // contexts is limited only by resource consumption. Changes made by one
- // context do not affect another context until they are committed.
-
- - copy;
-
- // The underlying objects shared by all contexts are reference counted. When
- // the last context is freed, the underlying objects are also freed. Freeing
- // the underlying objects destroys the contents of the store.
-
- - free;
-
- - init; // Creates a memory based store.
-
- // These two methods are used when archiving stores. If freeOnWrite is sent,
- // the receiver will free itsself after archiving. willFreeOnWrite returns
- // true if the receiver will free itsself after archiving.
-
- - freeOnWrite;
- - (BOOL)willFreeOnWrite;
-
- // The effects of methods that create and free blocks are delayed until
- // transaction commit, even if transactions are not enabled.
-
- // Opening or resizing a block locks it against access by other contexts.
- // Closing a block unlocks it, unless transactions are enabled and the block
- // has been modified; in that case, the close is deferred until transaction
- // commit. Blocks are closed automatically when the opening transaction ends.
-
- // Attempting to open or resize a locked block will result in an IX_LockedError
- // exception. This permits the implementation of a two phase locking strategy.
-
- // Creates a new block of the requested size. A block size of zero is valid.
- // The contents of the block are initialized to zero. Returns the block handle
- // by reference.
-
- - createBlock:(unsigned *)handle ofSize:(unsigned)size;
-
- // Frees an existing block. Once freed, the block may not be operated upon
- // except by closeBlock: or abortBlock:, unless the transaction is aborted.
- // Returns self, or nil if the supplied handle is invalid.
-
- - freeBlock:(unsigned)handle;
-
- - (BOOL)blockExists:(unsigned)blockHandle; // tests existence of the block
- - abortBlock:(unsigned)handle; // aborts all changes to the block
- - closeBlock:(unsigned)handle; // commits all changes and closes the block
-
- // Copies the designated block, returning the handle of the copy, or zero if
- // the supplied handle is not valid.
-
- - (unsigned)copyBlock:(unsigned)handle
- atOffset:(unsigned)offset forLength:(unsigned)length;
-
- // These two methods return a pointer to the contents of the designated block,
- // or NULL if the supplied handle is invalid. openBlock:atOffset:forLength:
- // copies the block first, if transactions are enabled, and returns a pointer
- // to the copy. readBlock:atOffset:forLength: does not copy the block.
-
- - (void *)openBlock:(unsigned)handle
- atOffset:(unsigned)offset forLength:(unsigned)length;
- - (void *)readBlock:(unsigned)handle
- atOffset:(unsigned)offset forLength:(unsigned)length;
-
- // This method copies data into a block in the store in the most efficient
- // manner possible. Data should never by copied into a block with vm_copy,
- // unless the store is known to be a member of the class IXStore, since the
- // subclasses of IXStore may use file paging that does not support vm_copy.
- - copyData:(void *)data toBlock:(unsigned)handle
- atOffset:(unsigned)offset forLength:(unsigned)length;
-
- // These two methods are designed to permit a store to be used over the wire.
- // exportBlock:atOffset:forLength: returns an NXData containing the contents
- // of the block. importBlock:atOffset:forLength: takes an NXData containing
- // the new contents of the block, and opens the block for writing, then copies
- // from the NXData to the contents of the block.
-
- - (NXData *)exportBlock:(unsigned)handle
- atOffset:(unsigned)offset forLength:(unsigned)length;
- - importBlock:(unsigned)handle
- atOffset:(unsigned)offset fromData:(NXData *)data;
-
- // These two methods report and modify the size of a block, respectively. A
- // size of zero is valid; there are no contents associated with a block of zero
- // size. Resizing a block locks the block, and may cause the block's in memory
- // location to change. If the block must be accessed after resizing, it should
- // be reopened to obtain a pointer to the new in memory location. The contents
- // of the newly created portion of a block that grows are zeroed.
-
- - (unsigned)sizeOfBlock:(unsigned)handle;
- - resizeBlock:(unsigned)handle toSize:(unsigned)size;
-
- // By default, transactions are disabled. Starting the first transaction
- // permanently enables them. There is a performance penalty for enabling
- // transactions, since blocks must be copied before they can be modified when
- // transactions are enabled. With transactions disabled, aborting a block or
- // transaction is equivalent to committing the block or transaction.
-
- // When transactions are enabled, calls to startTransaction are optional,
- // since a new transaction is automatically started by the first operation that
- // modifies the contents of the store. Calling startTransaction more than once
- // before a call to commitTransaction or abortTransaction causes nesting. The
- // nesting level is returned by startTransaction. Within a nested transaction,
- // the effects of createBlock:ofSize: and freeBlock: are reversible relative to
- // the enclosing transaction, as are all changes made to blocks opened by the
- // nested transaction. When a nested transaction is committed, its results are
- // carried into the enclosing transaction as modifications.
-
- - (unsigned)startTransaction;
- - abortTransaction;
- - commitTransaction;
-
- - (unsigned)nestingLevel; // returns the transaction nesting level
- - (BOOL)areTransactionsEnabled; // true if transactions are already enabled
- - (int)changeCount; // increases by one for each commit or abort transaction
-
- // Returns the number of blocks in the store, taking into account changes
- // pending in the receiving context.
-
- - (unsigned)count;
-
- // Returns the largest valid block handle; this provides an upper bound on
- // valid block handles, useful for iterating over all blocks in the store.
-
- - (unsigned)capacity;
-
- // Frees all blocks in the store. This method starts and commits a private
- // transaction, if transactions are enabled. The private transaction will be
- // nested within any outstanding transactions.
-
- - empty;
-
- // These methods remove free space by relocating blocks toward the origin of
- // the virtual address space defined by the store. A timeout of zero allows
- // the compaction to run to completion.
-
- - compact;
- - compactWithTimeout:(int)msecs;
-
- // The resident size limit restricts the amount of backing store that may
- // remain mapped between transactions. Note that it does not affect the amount
- // of backing store that may be mapped during the course of a transaction. A
- // size of zero indicates that the resident size is unlimited.
-
- - setSizeLimit:(vm_size_t)limit;
- - (vm_size_t)sizeLimit;
-
- - (vm_size_t)apparentSize; // size of the backing store's virtual address space
- - (vm_size_t)residentSize; // the amount of backing store that is mapped
-
- // These two methods create and install virtual memory images of stores; this
- // is the most efficient way to copy stores. The images are virtual memory
- // snap shots; if a store is modified after an image is created, the image will
- // diverge from the store via copy- on- write.
-
- - getContents:(vm_address_t *)data andLength:(vm_size_t *)length;
- - setContents:(vm_address_t)data andLength:(vm_size_t)length;
-
- // This is a cover for the two preceding methods for copying one store to another.
- - copyFromStore:(IXStore *)aStore;
-
- @end
-
-