1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/io/nsIUnicharInputStream.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "nsISupports.idl" 1.10 + 1.11 +interface nsIUnicharInputStream; 1.12 +interface nsIInputStream; 1.13 + 1.14 +%{C++ 1.15 +/** 1.16 + * The signature of the writer function passed to ReadSegments. This 1.17 + * is the "consumer" of data that gets read from the stream's buffer. 1.18 + * 1.19 + * @param aInStream stream being read 1.20 + * @param aClosure opaque parameter passed to ReadSegments 1.21 + * @param aFromSegment pointer to memory owned by the input stream 1.22 + * @param aToOffset amount already read (since ReadSegments was called) 1.23 + * @param aCount length of fromSegment 1.24 + * @param aWriteCount number of bytes read 1.25 + * 1.26 + * Implementers should return the following: 1.27 + * 1.28 + * @throws <any-error> if not interested in consuming any data 1.29 + * 1.30 + * Errors are never passed to the caller of ReadSegments. 1.31 + * 1.32 + * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior. 1.33 + */ 1.34 +typedef NS_CALLBACK(nsWriteUnicharSegmentFun)(nsIUnicharInputStream *aInStream, 1.35 + void *aClosure, 1.36 + const char16_t *aFromSegment, 1.37 + uint32_t aToOffset, 1.38 + uint32_t aCount, 1.39 + uint32_t *aWriteCount); 1.40 +%} 1.41 +native nsWriteUnicharSegmentFun(nsWriteUnicharSegmentFun); 1.42 + 1.43 +/** 1.44 + * Abstract unicode character input stream 1.45 + * @see nsIInputStream 1.46 + */ 1.47 +[scriptable, uuid(d5e3bd80-6723-4b92-b0c9-22f6162fd94f)] 1.48 +interface nsIUnicharInputStream : nsISupports { 1.49 + /** 1.50 + * Reads into a caller-provided character array. 1.51 + * 1.52 + * @return The number of characters that were successfully read. May be less 1.53 + * than aCount, even if there is more data in the input stream. 1.54 + * A return value of 0 means EOF. 1.55 + * 1.56 + * @note To read more than 2^32 characters, call this method multiple times. 1.57 + */ 1.58 + [noscript] unsigned long read([array, size_is(aCount)] in char16_t aBuf, 1.59 + in unsigned long aCount); 1.60 + 1.61 + /** 1.62 + * Low-level read method that has access to the stream's underlying buffer. 1.63 + * The writer function may be called multiple times for segmented buffers. 1.64 + * ReadSegments is expected to keep calling the writer until either there is 1.65 + * nothing left to read or the writer returns an error. ReadSegments should 1.66 + * not call the writer with zero characters to consume. 1.67 + * 1.68 + * @param aWriter the "consumer" of the data to be read 1.69 + * @param aClosure opaque parameter passed to writer 1.70 + * @param aCount the maximum number of characters to be read 1.71 + * 1.72 + * @return number of characters read (may be less than aCount) 1.73 + * @return 0 if reached end of file (or if aWriter refused to consume data) 1.74 + * 1.75 + * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would 1.76 + * block the calling thread (non-blocking mode only) 1.77 + * @throws <other-error> on failure 1.78 + * 1.79 + * NOTE: this function may be unimplemented if a stream has no underlying 1.80 + * buffer 1.81 + */ 1.82 + [noscript] unsigned long readSegments(in nsWriteUnicharSegmentFun aWriter, 1.83 + in voidPtr aClosure, 1.84 + in unsigned long aCount); 1.85 + 1.86 + /** 1.87 + * Read into a string object. 1.88 + * @param aCount The number of characters that should be read 1.89 + * @return The number of characters that were read. 1.90 + */ 1.91 + unsigned long readString(in unsigned long aCount, out AString aString); 1.92 + 1.93 + /** 1.94 + * Close the stream and free associated resources. This also closes the 1.95 + * underlying stream, if any. 1.96 + */ 1.97 + void close(); 1.98 +};