PageRenderTime 258ms CodeModel.GetById 152ms app.highlight 2ms RepoModel.GetById 102ms app.codeStats 0ms

/gecko_sdk/idl/nsIInputStream.idl

http://firefox-mac-pdf.googlecode.com/
IDL | 186 lines | 22 code | 9 blank | 155 comment | 0 complexity | 351ff0544cc94e41db6160efd8b377d9 MD5 | raw file
  1/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2/* ***** BEGIN LICENSE BLOCK *****
  3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  4 *
  5 * The contents of this file are subject to the Mozilla Public License Version
  6 * 1.1 (the "License"); you may not use this file except in compliance with
  7 * the License. You may obtain a copy of the License at
  8 * http://www.mozilla.org/MPL/
  9 *
 10 * Software distributed under the License is distributed on an "AS IS" basis,
 11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 12 * for the specific language governing rights and limitations under the
 13 * License.
 14 *
 15 * The Original Code is mozilla.org code.
 16 *
 17 * The Initial Developer of the Original Code is
 18 * Netscape Communications Corporation.
 19 * Portions created by the Initial Developer are Copyright (C) 1998
 20 * the Initial Developer. All Rights Reserved.
 21 *
 22 * Contributor(s):
 23 *   Warren Harris <warren@netscape.com>
 24 *   Darin Fisher <darin@netscape.com>
 25 *
 26 * Alternatively, the contents of this file may be used under the terms of
 27 * either of the GNU General Public License Version 2 or later (the "GPL"),
 28 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 29 * in which case the provisions of the GPL or the LGPL are applicable instead
 30 * of those above. If you wish to allow use of your version of this file only
 31 * under the terms of either the GPL or the LGPL, and not to allow others to
 32 * use your version of this file under the terms of the MPL, indicate your
 33 * decision by deleting the provisions above and replace them with the notice
 34 * and other provisions required by the GPL or the LGPL. If you do not delete
 35 * the provisions above, a recipient may use your version of this file under
 36 * the terms of any one of the MPL, the GPL or the LGPL.
 37 *
 38 * ***** END LICENSE BLOCK ***** */
 39
 40#include "nsISupports.idl"
 41
 42interface nsIInputStream;
 43
 44%{C++
 45/**
 46 * The signature of the writer function passed to ReadSegments. This
 47 * is the "consumer" of data that gets read from the stream's buffer.
 48 *
 49 * @param aInStream stream being read
 50 * @param aClosure opaque parameter passed to ReadSegments
 51 * @param aFromSegment pointer to memory owned by the input stream.  This is
 52 *                     where the writer function should start consuming data.
 53 * @param aToOffset amount of data already consumed by this writer during this
 54 *                  ReadSegments call.  This is also the sum of the aWriteCount
 55 *                  returns from this writer over the previous invocations of
 56 *                  the writer by this ReadSegments call.
 57 * @param aCount Number of bytes available to be read starting at aFromSegment
 58 * @param [out] aWriteCount number of bytes read by this writer function call
 59 *
 60 * Implementers should return the following:
 61 *
 62 * @return NS_OK and (*aWriteCount > 0) if consumed some data
 63 * @return <any-error> if not interested in consuming any data
 64 *
 65 * Errors are never passed to the caller of ReadSegments.
 66 *
 67 * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior.
 68 *
 69 * @status FROZEN
 70 */
 71typedef NS_CALLBACK(nsWriteSegmentFun)(nsIInputStream *aInStream,
 72                                       void *aClosure,
 73                                       const char *aFromSegment,
 74                                       PRUint32 aToOffset,
 75                                       PRUint32 aCount,
 76                                       PRUint32 *aWriteCount);
 77%}
 78
 79native nsWriteSegmentFun(nsWriteSegmentFun);
 80
 81/**
 82 * nsIInputStream
 83 *
 84 * An interface describing a readable stream of data.  An input stream may be
 85 * "blocking" or "non-blocking" (see the IsNonBlocking method).  A blocking
 86 * input stream may suspend the calling thread in order to satisfy a call to
 87 * Close, Available, Read, or ReadSegments.  A non-blocking input stream, on
 88 * the other hand, must not block the calling thread of execution.
 89 *
 90 * NOTE: blocking input streams are often read on a background thread to avoid
 91 * locking up the main application thread.  For this reason, it is generally
 92 * the case that a blocking input stream should be implemented using thread-
 93 * safe AddRef and Release.
 94 *
 95 * @status FROZEN
 96 */
 97[scriptable, uuid(fa9c7f6c-61b3-11d4-9877-00c04fa0cf4a)]
 98interface nsIInputStream : nsISupports
 99{
100    /** 
101     * Close the stream.  This method causes subsequent calls to Read and
102     * ReadSegments to return 0 bytes read to indicate end-of-file.  Any
103     * subsequent calls to Available should throw NS_BASE_STREAM_CLOSED.
104     */
105    void close();
106
107    /**
108     * Determine number of bytes available in the stream.  A non-blocking
109     * stream that does not yet have any data to read should return 0 bytes
110     * from this method (i.e., it must not throw the NS_BASE_STREAM_WOULD_BLOCK
111     * exception).
112     * 
113     * In addition to the number of bytes available in the stream, this method
114     * also informs the caller of the current status of the stream.  A stream
115     * that is closed will throw an exception when this method is called.  That
116     * enables the caller to know the condition of the stream before attempting
117     * to read from it.  If a stream is at end-of-file, but not closed, then
118     * this method should return 0 bytes available.
119     *
120     * @return number of bytes currently available in the stream, or
121     *   PR_UINT32_MAX if the size of the stream exceeds PR_UINT32_MAX.
122     *
123     * @throws NS_BASE_STREAM_CLOSED if the stream is closed normally or at
124     *   end-of-file
125     * @throws <other-error> if the stream is closed due to some error
126     *   condition
127     */
128    unsigned long available();
129
130    /** 
131     * Read data from the stream.
132     *
133     * @param aBuf the buffer into which the data is to be read
134     * @param aCount the maximum number of bytes to be read
135     *
136     * @return number of bytes read (may be less than aCount).
137     * @return 0 if reached end-of-file
138     *
139     * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
140     *   block the calling thread (non-blocking mode only)
141     * @throws <other-error> on failure
142     *
143     * NOTE: this method should not throw NS_BASE_STREAM_CLOSED.
144     */
145    [noscript] unsigned long read(in charPtr aBuf, in unsigned long aCount);
146
147    /**
148     * Low-level read method that provides access to the stream's underlying
149     * buffer.  The writer function may be called multiple times for segmented
150     * buffers.  ReadSegments is expected to keep calling the writer until
151     * either there is nothing left to read or the writer returns an error.
152     * ReadSegments should not call the writer with zero bytes to consume.
153     *
154     * @param aWriter the "consumer" of the data to be read
155     * @param aClosure opaque parameter passed to writer 
156     * @param aCount the maximum number of bytes to be read
157     *
158     * @return number of bytes read (may be less than aCount)
159     * @return 0 if reached end-of-file (or if aWriter refused to consume data)
160     *
161     * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
162     *   block the calling thread (non-blocking mode only)
163     * @throws NS_ERROR_NOT_IMPLEMENTED if the stream has no underlying buffer
164     * @throws <other-error> on failure
165     *
166     * NOTE: this function may be unimplemented if a stream has no underlying
167     * buffer (e.g., socket input stream).
168     *
169     * NOTE: this method should not throw NS_BASE_STREAM_CLOSED.
170     */
171    [noscript] unsigned long readSegments(in nsWriteSegmentFun aWriter,
172                                          in voidPtr aClosure,
173                                          in unsigned long aCount);
174
175    /**
176     * @return true if stream is non-blocking
177     *
178     * NOTE: reading from a blocking input stream will block the calling thread
179     * until at least one byte of data can be extracted from the stream.
180     *
181     * NOTE: a non-blocking input stream may implement nsIAsyncInputStream to
182     * provide consumers with a way to wait for the stream to have more data
183     * once its read method is unable to return any data without blocking.
184     */
185    boolean isNonBlocking();
186};