michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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: interface nsIUnicharInputStream; michael@0: interface nsIInputStream; michael@0: michael@0: %{C++ michael@0: /** michael@0: * The signature of the writer function passed to ReadSegments. This michael@0: * is the "consumer" of data that gets read from the stream's buffer. michael@0: * michael@0: * @param aInStream stream being read michael@0: * @param aClosure opaque parameter passed to ReadSegments michael@0: * @param aFromSegment pointer to memory owned by the input stream michael@0: * @param aToOffset amount already read (since ReadSegments was called) michael@0: * @param aCount length of fromSegment michael@0: * @param aWriteCount number of bytes read michael@0: * michael@0: * Implementers should return the following: michael@0: * michael@0: * @throws if not interested in consuming any data michael@0: * michael@0: * Errors are never passed to the caller of ReadSegments. michael@0: * michael@0: * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior. michael@0: */ michael@0: typedef NS_CALLBACK(nsWriteUnicharSegmentFun)(nsIUnicharInputStream *aInStream, michael@0: void *aClosure, michael@0: const char16_t *aFromSegment, michael@0: uint32_t aToOffset, michael@0: uint32_t aCount, michael@0: uint32_t *aWriteCount); michael@0: %} michael@0: native nsWriteUnicharSegmentFun(nsWriteUnicharSegmentFun); michael@0: michael@0: /** michael@0: * Abstract unicode character input stream michael@0: * @see nsIInputStream michael@0: */ michael@0: [scriptable, uuid(d5e3bd80-6723-4b92-b0c9-22f6162fd94f)] michael@0: interface nsIUnicharInputStream : nsISupports { michael@0: /** michael@0: * Reads into a caller-provided character array. michael@0: * michael@0: * @return The number of characters that were successfully read. May be less michael@0: * than aCount, even if there is more data in the input stream. michael@0: * A return value of 0 means EOF. michael@0: * michael@0: * @note To read more than 2^32 characters, call this method multiple times. michael@0: */ michael@0: [noscript] unsigned long read([array, size_is(aCount)] in char16_t aBuf, michael@0: in unsigned long aCount); michael@0: michael@0: /** michael@0: * Low-level read method that has access to the stream's underlying buffer. michael@0: * The writer function may be called multiple times for segmented buffers. michael@0: * ReadSegments is expected to keep calling the writer until either there is michael@0: * nothing left to read or the writer returns an error. ReadSegments should michael@0: * not call the writer with zero characters to consume. michael@0: * michael@0: * @param aWriter the "consumer" of the data to be read michael@0: * @param aClosure opaque parameter passed to writer michael@0: * @param aCount the maximum number of characters to be read michael@0: * michael@0: * @return number of characters read (may be less than aCount) michael@0: * @return 0 if reached end of file (or if aWriter refused to consume data) michael@0: * michael@0: * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would michael@0: * block the calling thread (non-blocking mode only) michael@0: * @throws on failure michael@0: * michael@0: * NOTE: this function may be unimplemented if a stream has no underlying michael@0: * buffer michael@0: */ michael@0: [noscript] unsigned long readSegments(in nsWriteUnicharSegmentFun aWriter, michael@0: in voidPtr aClosure, michael@0: in unsigned long aCount); michael@0: michael@0: /** michael@0: * Read into a string object. michael@0: * @param aCount The number of characters that should be read michael@0: * @return The number of characters that were read. michael@0: */ michael@0: unsigned long readString(in unsigned long aCount, out AString aString); michael@0: michael@0: /** michael@0: * Close the stream and free associated resources. This also closes the michael@0: * underlying stream, if any. michael@0: */ michael@0: void close(); michael@0: };