/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla FastLoad code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2001
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Brendan Eich <brendan@mozilla.org> (original author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsrootidl.idl"
/**
* An interface for access to a buffering stream implementation's underlying
* memory buffer.
*
* Stream implementations that QueryInterface to nsIStreamBufferAccess must
* ensure that all buffers are aligned on the most restrictive type size for
* the current architecture (e.g., sizeof(double) for RISCy CPUs). malloc(3)
* satisfies this requirement.
*/
interface nsIStreamBufferAccess : nsISupports
{
/**
* Get access to a contiguous, aligned run of bytes in the stream's buffer.
* Exactly one successful getBuffer call must occur before a putBuffer call
* taking the non-null pointer returned by the successful getBuffer.
*
* The run of bytes are the next bytes (modulo alignment padding) to read
* for an input stream, and the next bytes (modulo alignment padding) to
* store before (eventually) writing buffered data to an output stream.
* There can be space beyond this run of bytes in the buffer for further
* accesses before the fill or flush point is reached.
*
* @param aLength
* Count of contiguous bytes requested at the address A that satisfies
* (A & aAlignMask) == 0 in the buffer, starting from the current stream
* position, mapped to a buffer address B. The stream implementation
* must pad from B to A by skipping bytes (if input stream) or storing
* zero bytes (if output stream).
*
* @param aAlignMask
* Bit-mask computed by subtracting 1 from the power-of-two alignment
* modulus (e.g., 3 or sizeof(PRUint32)-1 for PRUint32 alignment).
*
* @return
* The aligned pointer to aLength bytes in the buffer, or null if the
* buffer has no room for aLength bytes starting at the next address A
* after the current position that satisfies (A & aAlignMask) == 0.
*/
/**
* Relinquish access to the stream's buffer, filling if at end of an input
* buffer, flushing if completing an output buffer. After a getBuffer call
* that returns non-null, putBuffer must be called.
*
* @param aBuffer
* A non-null pointer returned by getBuffer on the same stream buffer
* access object.
*
* @param aLength
* The same count of contiguous bytes passed to the getBuffer call that
* returned aBuffer.
*/
/**
* Disable and enable buffering on the stream implementing this interface.
* DisableBuffering flushes an output stream's buffer, and invalidates an
* input stream's buffer.
*/
void disableBuffering();
void enableBuffering();
/**
* The underlying, unbuffered input or output stream.
*/
};
%{C++
// We want to avoid casting to 32-bit types if possible, since that violates
// aliasing rules (a standard compiler may assume that pointers of two types
// do not address overlapping storage).
//
// XXX What if we have a compiler that follows aliasing rules strictly but
// doesn't have a 64-bit int type?
//
// XXXbe shouldn't NSPR's LL_INIT work for non-constant arguments in all cases?
# if defined HAVE_LONG_LONG
# if PR_BYTES_PER_LONG == 8
# else
# endif
(((x) /* & ULL_(0x00000000000000ff) */) << 56))
# else
# endif
#else
# error "Unknown byte order"
/**
* These macros get and put a buffer given either an sba parameter that may
* point to an object implementing nsIStreamBufferAccess, nsIObjectInputStream,
* or nsIObjectOutputStream.
*/
%}