PageRenderTime 35ms CodeModel.GetById 20ms RepoModel.GetById 0ms 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. #include "nsISupports.idl"
  40. interface nsIInputStream;
  41. %{C++
  42. /**
  43. * The signature of the writer function passed to ReadSegments. This
  44. * is the "consumer" of data that gets read from the stream's buffer.
  45. *
  46. * @param aInStream stream being read
  47. * @param aClosure opaque parameter passed to ReadSegments
  48. * @param aFromSegment pointer to memory owned by the input stream. This is
  49. * where the writer function should start consuming data.
  50. * @param aToOffset amount of data already consumed by this writer during this
  51. * ReadSegments call. This is also the sum of the aWriteCount
  52. * returns from this writer over the previous invocations of
  53. * the writer by this ReadSegments call.
  54. * @param aCount Number of bytes available to be read starting at aFromSegment
  55. * @param [out] aWriteCount number of bytes read by this writer function call
  56. *
  57. * Implementers should return the following:
  58. *
  59. * @return NS_OK and (*aWriteCount > 0) if consumed some data
  60. * @return <any-error> if not interested in consuming any data
  61. *
  62. * Errors are never passed to the caller of ReadSegments.
  63. *
  64. * NOTE: returning NS_OK and (*aWriteCount = 0) has undefined behavior.
  65. *
  66. * @status FROZEN
  67. */
  68. typedef NS_CALLBACK(nsWriteSegmentFun)(nsIInputStream *aInStream,
  69. void *aClosure,
  70. const char *aFromSegment,
  71. PRUint32 aToOffset,
  72. PRUint32 aCount,
  73. PRUint32 *aWriteCount);
  74. %}
  75. native nsWriteSegmentFun(nsWriteSegmentFun);
  76. /**
  77. * nsIInputStream
  78. *
  79. * An interface describing a readable stream of data. An input stream may be
  80. * "blocking" or "non-blocking" (see the IsNonBlocking method). A blocking
  81. * input stream may suspend the calling thread in order to satisfy a call to
  82. * Close, Available, Read, or ReadSegments. A non-blocking input stream, on
  83. * the other hand, must not block the calling thread of execution.
  84. *
  85. * NOTE: blocking input streams are often read on a background thread to avoid
  86. * locking up the main application thread. For this reason, it is generally
  87. * the case that a blocking input stream should be implemented using thread-
  88. * safe AddRef and Release.
  89. *
  90. * @status FROZEN
  91. */
  92. [scriptable, uuid(fa9c7f6c-61b3-11d4-9877-00c04fa0cf4a)]
  93. interface nsIInputStream : nsISupports
  94. {
  95. /**
  96. * Close the stream. This method causes subsequent calls to Read and
  97. * ReadSegments to return 0 bytes read to indicate end-of-file. Any
  98. * subsequent calls to Available should throw NS_BASE_STREAM_CLOSED.
  99. */
  100. void close();
  101. /**
  102. * Determine number of bytes available in the stream. A non-blocking
  103. * stream that does not yet have any data to read should return 0 bytes
  104. * from this method (i.e., it must not throw the NS_BASE_STREAM_WOULD_BLOCK
  105. * exception).
  106. *
  107. * In addition to the number of bytes available in the stream, this method
  108. * also informs the caller of the current status of the stream. A stream
  109. * that is closed will throw an exception when this method is called. That
  110. * enables the caller to know the condition of the stream before attempting
  111. * to read from it. If a stream is at end-of-file, but not closed, then
  112. * this method should return 0 bytes available.
  113. *
  114. * @return number of bytes currently available in the stream, or
  115. * PR_UINT32_MAX if the size of the stream exceeds PR_UINT32_MAX.
  116. *
  117. * @throws NS_BASE_STREAM_CLOSED if the stream is closed normally or at
  118. * end-of-file
  119. * @throws <other-error> if the stream is closed due to some error
  120. * condition
  121. */
  122. unsigned long available();
  123. /**
  124. * Read data from the stream.
  125. *
  126. * @param aBuf the buffer into which the data is to be read
  127. * @param aCount the maximum number of bytes to be read
  128. *
  129. * @return number of bytes read (may be less than aCount).
  130. * @return 0 if reached end-of-file
  131. *
  132. * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
  133. * block the calling thread (non-blocking mode only)
  134. * @throws <other-error> on failure
  135. *
  136. * NOTE: this method should not throw NS_BASE_STREAM_CLOSED.
  137. */
  138. [noscript] unsigned long read(in charPtr aBuf, in unsigned long aCount);
  139. /**
  140. * Low-level read method that provides access to the stream's underlying
  141. * buffer. The writer function may be called multiple times for segmented
  142. * buffers. ReadSegments is expected to keep calling the writer until
  143. * either there is nothing left to read or the writer returns an error.
  144. * ReadSegments should not call the writer with zero bytes to consume.
  145. *
  146. * @param aWriter the "consumer" of the data to be read
  147. * @param aClosure opaque parameter passed to writer
  148. * @param aCount the maximum number of bytes to be read
  149. *
  150. * @return number of bytes read (may be less than aCount)
  151. * @return 0 if reached end-of-file (or if aWriter refused to consume data)
  152. *
  153. * @throws NS_BASE_STREAM_WOULD_BLOCK if reading from the input stream would
  154. * block the calling thread (non-blocking mode only)
  155. * @throws NS_ERROR_NOT_IMPLEMENTED if the stream has no underlying buffer
  156. * @throws <other-error> on failure
  157. *
  158. * NOTE: this function may be unimplemented if a stream has no underlying
  159. * buffer (e.g., socket input stream).
  160. *
  161. * NOTE: this method should not throw NS_BASE_STREAM_CLOSED.
  162. */
  163. [noscript] unsigned long readSegments(in nsWriteSegmentFun aWriter,
  164. in voidPtr aClosure,
  165. in unsigned long aCount);
  166. /**
  167. * @return true if stream is non-blocking
  168. *
  169. * NOTE: reading from a blocking input stream will block the calling thread
  170. * until at least one byte of data can be extracted from the stream.
  171. *
  172. * NOTE: a non-blocking input stream may implement nsIAsyncInputStream to
  173. * provide consumers with a way to wait for the stream to have more data
  174. * once its read method is unable to return any data without blocking.
  175. */
  176. boolean isNonBlocking();
  177. };