michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: /** michael@0: * An interface for access to a buffering stream implementation's underlying michael@0: * memory buffer. michael@0: * michael@0: * Stream implementations that QueryInterface to nsIStreamBufferAccess must michael@0: * ensure that all buffers are aligned on the most restrictive type size for michael@0: * the current architecture (e.g., sizeof(double) for RISCy CPUs). malloc(3) michael@0: * satisfies this requirement. michael@0: */ michael@0: [scriptable, uuid(ac923b72-ac87-4892-ac7a-ca385d429435)] michael@0: interface nsIStreamBufferAccess : nsISupports michael@0: { michael@0: /** michael@0: * Get access to a contiguous, aligned run of bytes in the stream's buffer. michael@0: * Exactly one successful getBuffer call must occur before a putBuffer call michael@0: * taking the non-null pointer returned by the successful getBuffer. michael@0: * michael@0: * The run of bytes are the next bytes (modulo alignment padding) to read michael@0: * for an input stream, and the next bytes (modulo alignment padding) to michael@0: * store before (eventually) writing buffered data to an output stream. michael@0: * There can be space beyond this run of bytes in the buffer for further michael@0: * accesses before the fill or flush point is reached. michael@0: * michael@0: * @param aLength michael@0: * Count of contiguous bytes requested at the address A that satisfies michael@0: * (A & aAlignMask) == 0 in the buffer, starting from the current stream michael@0: * position, mapped to a buffer address B. The stream implementation michael@0: * must pad from B to A by skipping bytes (if input stream) or storing michael@0: * zero bytes (if output stream). michael@0: * michael@0: * @param aAlignMask michael@0: * Bit-mask computed by subtracting 1 from the power-of-two alignment michael@0: * modulus (e.g., 3 or sizeof(uint32_t)-1 for uint32_t alignment). michael@0: * michael@0: * @return michael@0: * The aligned pointer to aLength bytes in the buffer, or null if the michael@0: * buffer has no room for aLength bytes starting at the next address A michael@0: * after the current position that satisfies (A & aAlignMask) == 0. michael@0: */ michael@0: [notxpcom,noscript] charPtr getBuffer(in uint32_t aLength, in uint32_t aAlignMask); michael@0: michael@0: /** michael@0: * Relinquish access to the stream's buffer, filling if at end of an input michael@0: * buffer, flushing if completing an output buffer. After a getBuffer call michael@0: * that returns non-null, putBuffer must be called. michael@0: * michael@0: * @param aBuffer michael@0: * A non-null pointer returned by getBuffer on the same stream buffer michael@0: * access object. michael@0: * michael@0: * @param aLength michael@0: * The same count of contiguous bytes passed to the getBuffer call that michael@0: * returned aBuffer. michael@0: */ michael@0: [notxpcom,noscript] void putBuffer(in charPtr aBuffer, in uint32_t aLength); michael@0: michael@0: /** michael@0: * Disable and enable buffering on the stream implementing this interface. michael@0: * DisableBuffering flushes an output stream's buffer, and invalidates an michael@0: * input stream's buffer. michael@0: */ michael@0: void disableBuffering(); michael@0: void enableBuffering(); michael@0: michael@0: /** michael@0: * The underlying, unbuffered input or output stream. michael@0: */ michael@0: readonly attribute nsISupports unbufferedStream; michael@0: }; michael@0: michael@0: %{C++ michael@0: michael@0: /** michael@0: * These macros get and put a buffer given either an sba parameter that may michael@0: * point to an object implementing nsIStreamBufferAccess, nsIObjectInputStream, michael@0: * or nsIObjectOutputStream. michael@0: */ michael@0: #define NS_GET_BUFFER(sba,n,a) ((sba)->GetBuffer(n, a)) michael@0: #define NS_PUT_BUFFER(sba,p,n) ((sba)->PutBuffer(p, n)) michael@0: michael@0: %}