Bug 572417 - Release mouse capture in flash subclass after mouse events get delivered...
[mozilla-central.git] / xpcom / io / nsIInputStream.idl
blob82f4c2b0175639b8c1e1dd0f3d25a65b8f8c1f82
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
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/
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.
15 * The Original Code is mozilla.org code.
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.
22 * Contributor(s):
23 * Warren Harris <warren@netscape.com>
24 * Darin Fisher <darin@netscape.com>
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.
38 * ***** END LICENSE BLOCK ***** */
40 #include "nsISupports.idl"
42 interface nsIInputStream;
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.
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
60 * Implementers should return the following:
62 * @return NS_OK and (*aWriteCount > 0) if consumed some data
63 * @return <any-error> if not interested in consuming any data
65 * Errors are never passed to the caller of ReadSegments.
67 * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior.
69 typedef NS_CALLBACK(nsWriteSegmentFun)(nsIInputStream *aInStream,
70 void *aClosure,
71 const char *aFromSegment,
72 PRUint32 aToOffset,
73 PRUint32 aCount,
74 PRUint32 *aWriteCount);
77 native nsWriteSegmentFun(nsWriteSegmentFun);
79 /**
80 * nsIInputStream
82 * An interface describing a readable stream of data. An input stream may be
83 * "blocking" or "non-blocking" (see the IsNonBlocking method). A blocking
84 * input stream may suspend the calling thread in order to satisfy a call to
85 * Close, Available, Read, or ReadSegments. A non-blocking input stream, on
86 * the other hand, must not block the calling thread of execution.
88 * NOTE: blocking input streams are often read on a background thread to avoid
89 * locking up the main application thread. For this reason, it is generally
90 * the case that a blocking input stream should be implemented using thread-
91 * safe AddRef and Release.
93 [scriptable, uuid(fa9c7f6c-61b3-11d4-9877-00c04fa0cf4a)]
94 interface nsIInputStream : nsISupports
96 /**
97 * Close the stream. This method causes subsequent calls to Read and
98 * ReadSegments to return 0 bytes read to indicate end-of-file. Any
99 * subsequent calls to Available should throw NS_BASE_STREAM_CLOSED.
101 void close();
104 * Determine number of bytes available in the stream. A non-blocking
105 * stream that does not yet have any data to read should return 0 bytes
106 * from this method (i.e., it must not throw the NS_BASE_STREAM_WOULD_BLOCK
107 * exception).
109 * In addition to the number of bytes available in the stream, this method
110 * also informs the caller of the current status of the stream. A stream
111 * that is closed will throw an exception when this method is called. That
112 * enables the caller to know the condition of the stream before attempting
113 * to read from it. If a stream is at end-of-file, but not closed, then
114 * this method returns 0 bytes available. (Note: some nsIInputStream
115 * implementations automatically close when eof is reached; some do not).
117 * @return number of bytes currently available in the stream, or
118 * PR_UINT32_MAX if the size of the stream exceeds PR_UINT32_MAX.
120 * @throws NS_BASE_STREAM_CLOSED if the stream is closed normally.
121 * @throws <other-error> if the stream is closed due to some error
122 * condition
124 unsigned long available();
126 /**
127 * Read data from the stream.
129 * @param aBuf the buffer into which the data is to be read
130 * @param aCount the maximum number of bytes to be read
132 * @return number of bytes read (may be less than aCount).
133 * @return 0 if reached end-of-file
135 * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
136 * block the calling thread (non-blocking mode only)
137 * @throws <other-error> on failure
139 * NOTE: this method should not throw NS_BASE_STREAM_CLOSED.
141 [noscript] unsigned long read(in charPtr aBuf, in unsigned long aCount);
144 * Low-level read method that provides access to the stream's underlying
145 * buffer. The writer function may be called multiple times for segmented
146 * buffers. ReadSegments is expected to keep calling the writer until
147 * either there is nothing left to read or the writer returns an error.
148 * ReadSegments should not call the writer with zero bytes to consume.
150 * @param aWriter the "consumer" of the data to be read
151 * @param aClosure opaque parameter passed to writer
152 * @param aCount the maximum number of bytes to be read
154 * @return number of bytes read (may be less than aCount)
155 * @return 0 if reached end-of-file (or if aWriter refused to consume data)
157 * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
158 * block the calling thread (non-blocking mode only)
159 * @throws NS_ERROR_NOT_IMPLEMENTED if the stream has no underlying buffer
160 * @throws <other-error> on failure
162 * NOTE: this function may be unimplemented if a stream has no underlying
163 * buffer (e.g., socket input stream).
165 * NOTE: this method should not throw NS_BASE_STREAM_CLOSED.
167 [noscript] unsigned long readSegments(in nsWriteSegmentFun aWriter,
168 in voidPtr aClosure,
169 in unsigned long aCount);
172 * @return true if stream is non-blocking
174 * NOTE: reading from a blocking input stream will block the calling thread
175 * until at least one byte of data can be extracted from the stream.
177 * NOTE: a non-blocking input stream may implement nsIAsyncInputStream to
178 * provide consumers with a way to wait for the stream to have more data
179 * once its read method is unable to return any data without blocking.
181 boolean isNonBlocking();