michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 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 nsIAsyncInputStream; michael@0: interface nsIAsyncOutputStream; michael@0: michael@0: /** michael@0: * nsIPipe represents an in-process buffer that can be read using nsIInputStream michael@0: * and written using nsIOutputStream. The reader and writer of a pipe do not michael@0: * have to be on the same thread. As a result, the pipe is an ideal mechanism michael@0: * to bridge data exchange between two threads. For example, a worker thread michael@0: * might write data to a pipe from which the main thread will read. michael@0: * michael@0: * Each end of the pipe can be either blocking or non-blocking. Recall that a michael@0: * non-blocking stream will return NS_BASE_STREAM_WOULD_BLOCK if it cannot be michael@0: * read or written to without blocking the calling thread. For example, if you michael@0: * try to read from an empty pipe that has not yet been closed, then if that michael@0: * pipe's input end is non-blocking, then the read call will fail immediately michael@0: * with NS_BASE_STREAM_WOULD_BLOCK as the error condition. However, if that michael@0: * pipe's input end is blocking, then the read call will not return until the michael@0: * pipe has data or until the pipe is closed. This example presumes that the michael@0: * pipe is being filled asynchronously on some background thread. michael@0: * michael@0: * The pipe supports nsIAsyncInputStream and nsIAsyncOutputStream, which give michael@0: * the user of a non-blocking pipe the ability to wait for the pipe to become michael@0: * ready again. For example, in the case of an empty non-blocking pipe, the michael@0: * user can call AsyncWait on the input end of the pipe to be notified when michael@0: * the pipe has data to read (or when the pipe becomes closed). michael@0: * michael@0: * NS_NewPipe2 and NS_NewPipe provide convenient pipe constructors. In most michael@0: * cases nsIPipe is not actually used. It is usually enough to just get michael@0: * references to the pipe's input and output end. In which case, the pipe is michael@0: * automatically closed when the respective pipe ends are released. michael@0: */ michael@0: [scriptable, uuid(25d0de93-685e-4ea4-95d3-d884e31df63c)] michael@0: interface nsIPipe : nsISupports michael@0: { michael@0: /** michael@0: * initialize this pipe michael@0: * michael@0: * @param nonBlockingInput michael@0: * true specifies non-blocking input stream behavior michael@0: * @param nonBlockingOutput michael@0: * true specifies non-blocking output stream behavior michael@0: * @param segmentSize michael@0: * specifies the segment size in bytes (pass 0 to use default value) michael@0: * @param segmentCount michael@0: * specifies the max number of segments (pass 0 to use default michael@0: * value). Passing UINT32_MAX here causes the pipe to have michael@0: * "infinite" space. This mode can be useful in some cases, but michael@0: * should always be used with caution. The default value for this michael@0: * parameter is a finite value. michael@0: */ michael@0: void init(in boolean nonBlockingInput, michael@0: in boolean nonBlockingOutput, michael@0: in unsigned long segmentSize, michael@0: in unsigned long segmentCount); michael@0: michael@0: /** michael@0: * The pipe's input end, which also implements nsISearchableInputStream. michael@0: */ michael@0: readonly attribute nsIAsyncInputStream inputStream; michael@0: michael@0: /** michael@0: * The pipe's output end. michael@0: */ michael@0: readonly attribute nsIAsyncOutputStream outputStream; michael@0: }; michael@0: michael@0: /** michael@0: * XXX this interface doesn't really belong in here. It is here because michael@0: * currently nsPipeInputStream is the only implementation of this interface. michael@0: */ michael@0: [scriptable, uuid(8C39EF62-F7C9-11d4-98F5-001083010E9B)] michael@0: interface nsISearchableInputStream : nsISupports michael@0: { michael@0: /** michael@0: * Searches for a string in the input stream. Since the stream has a notion michael@0: * of EOF, it is possible that the string may at some time be in the michael@0: * buffer, but is is not currently found up to some offset. Consequently, michael@0: * both the found and not found cases return an offset: michael@0: * if found, return offset where it was found michael@0: * if not found, return offset of the first byte not searched michael@0: * In the case the stream is at EOF and the string is not found, the first michael@0: * byte not searched will correspond to the length of the buffer. michael@0: */ michael@0: void search(in string forString, michael@0: in boolean ignoreCase, michael@0: out boolean found, michael@0: out unsigned long offsetSearchedTo); michael@0: }; michael@0: michael@0: %{C++ michael@0: michael@0: class nsIInputStream; michael@0: class nsIOutputStream; michael@0: michael@0: /** michael@0: * NS_NewPipe2 michael@0: * michael@0: * This function supersedes NS_NewPipe. It differs from NS_NewPipe in two michael@0: * major ways: michael@0: * (1) returns nsIAsyncInputStream and nsIAsyncOutputStream, so it is michael@0: * not necessary to QI in order to access these interfaces. michael@0: * (2) the size of the pipe is determined by the number of segments michael@0: * times the size of each segment. michael@0: * michael@0: * @param pipeIn michael@0: * resulting input end of the pipe michael@0: * @param pipeOut michael@0: * resulting output end of the pipe michael@0: * @param nonBlockingInput michael@0: * true specifies non-blocking input stream behavior michael@0: * @param nonBlockingOutput michael@0: * true specifies non-blocking output stream behavior michael@0: * @param segmentSize michael@0: * specifies the segment size in bytes (pass 0 to use default value) michael@0: * @param segmentCount michael@0: * specifies the max number of segments (pass 0 to use default value) michael@0: * passing UINT32_MAX here causes the pipe to have "infinite" space. michael@0: * this mode can be useful in some cases, but should always be used with michael@0: * caution. the default value for this parameter is a finite value. michael@0: */ michael@0: extern nsresult michael@0: NS_NewPipe2(nsIAsyncInputStream **pipeIn, michael@0: nsIAsyncOutputStream **pipeOut, michael@0: bool nonBlockingInput = false, michael@0: bool nonBlockingOutput = false, michael@0: uint32_t segmentSize = 0, michael@0: uint32_t segmentCount = 0); michael@0: michael@0: /** michael@0: * NS_NewPipe michael@0: * michael@0: * Preserved for backwards compatibility. Plus, this interface is more michael@0: * amiable in certain contexts (e.g., when you don't need the pipe's async michael@0: * capabilities). michael@0: * michael@0: * @param pipeIn michael@0: * resulting input end of the pipe michael@0: * @param pipeOut michael@0: * resulting output end of the pipe michael@0: * @param segmentSize michael@0: * specifies the segment size in bytes (pass 0 to use default value) michael@0: * @param maxSize michael@0: * specifies the max size of the pipe (pass 0 to use default value) michael@0: * number of segments is maxSize / segmentSize, and maxSize must be a michael@0: * multiple of segmentSize. passing UINT32_MAX here causes the michael@0: * pipe to have "infinite" space. this mode can be useful in some michael@0: * cases, but should always be used with caution. the default value michael@0: * for this parameter is a finite value. michael@0: * @param nonBlockingInput michael@0: * true specifies non-blocking input stream behavior michael@0: * @param nonBlockingOutput michael@0: * true specifies non-blocking output stream behavior michael@0: */ michael@0: extern nsresult michael@0: NS_NewPipe(nsIInputStream **pipeIn, michael@0: nsIOutputStream **pipeOut, michael@0: uint32_t segmentSize = 0, michael@0: uint32_t maxSize = 0, michael@0: bool nonBlockingInput = false, michael@0: bool nonBlockingOutput = false); michael@0: michael@0: %}