xpcom/io/nsIPipe.idl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/xpcom/io/nsIPipe.idl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,169 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     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 nsIAsyncInputStream;
    1.12 +interface nsIAsyncOutputStream;
    1.13 +
    1.14 +/**
    1.15 + * nsIPipe represents an in-process buffer that can be read using nsIInputStream
    1.16 + * and written using nsIOutputStream.  The reader and writer of a pipe do not
    1.17 + * have to be on the same thread.  As a result, the pipe is an ideal mechanism
    1.18 + * to bridge data exchange between two threads.  For example, a worker thread
    1.19 + * might write data to a pipe from which the main thread will read.
    1.20 + *
    1.21 + * Each end of the pipe can be either blocking or non-blocking.  Recall that a
    1.22 + * non-blocking stream will return NS_BASE_STREAM_WOULD_BLOCK if it cannot be
    1.23 + * read or written to without blocking the calling thread.  For example, if you
    1.24 + * try to read from an empty pipe that has not yet been closed, then if that
    1.25 + * pipe's input end is non-blocking, then the read call will fail immediately
    1.26 + * with NS_BASE_STREAM_WOULD_BLOCK as the error condition.  However, if that
    1.27 + * pipe's input end is blocking, then the read call will not return until the
    1.28 + * pipe has data or until the pipe is closed.  This example presumes that the
    1.29 + * pipe is being filled asynchronously on some background thread.
    1.30 + *
    1.31 + * The pipe supports nsIAsyncInputStream and nsIAsyncOutputStream, which give
    1.32 + * the user of a non-blocking pipe the ability to wait for the pipe to become
    1.33 + * ready again.  For example, in the case of an empty non-blocking pipe, the
    1.34 + * user can call AsyncWait on the input end of the pipe to be notified when 
    1.35 + * the pipe has data to read (or when the pipe becomes closed).
    1.36 + *
    1.37 + * NS_NewPipe2 and NS_NewPipe provide convenient pipe constructors.  In most
    1.38 + * cases nsIPipe is not actually used.  It is usually enough to just get
    1.39 + * references to the pipe's input and output end.  In which case, the pipe is
    1.40 + * automatically closed when the respective pipe ends are released.
    1.41 + */
    1.42 +[scriptable, uuid(25d0de93-685e-4ea4-95d3-d884e31df63c)]
    1.43 +interface nsIPipe : nsISupports
    1.44 +{
    1.45 +    /**
    1.46 +     * initialize this pipe
    1.47 +     *
    1.48 +     * @param nonBlockingInput
    1.49 +     *        true specifies non-blocking input stream behavior
    1.50 +     * @param nonBlockingOutput
    1.51 +     *        true specifies non-blocking output stream behavior
    1.52 +     * @param segmentSize
    1.53 +     *        specifies the segment size in bytes (pass 0 to use default value)
    1.54 +     * @param segmentCount
    1.55 +     *        specifies the max number of segments (pass 0 to use default
    1.56 +     *        value).   Passing UINT32_MAX here causes the pipe to have
    1.57 +     *        "infinite" space.  This mode can be useful in some cases, but
    1.58 +     *        should always be used with caution.  The default value for this
    1.59 +     *        parameter is a finite value.
    1.60 +     */
    1.61 +    void init(in boolean nonBlockingInput,
    1.62 +              in boolean nonBlockingOutput,
    1.63 +              in unsigned long segmentSize,
    1.64 +              in unsigned long segmentCount);
    1.65 +
    1.66 +    /**
    1.67 +     * The pipe's input end, which also implements nsISearchableInputStream.
    1.68 +     */
    1.69 +    readonly attribute nsIAsyncInputStream inputStream;
    1.70 +
    1.71 +    /**
    1.72 +     * The pipe's output end.
    1.73 +     */
    1.74 +    readonly attribute nsIAsyncOutputStream outputStream;
    1.75 +};
    1.76 +
    1.77 +/**
    1.78 + * XXX this interface doesn't really belong in here.  It is here because
    1.79 + * currently nsPipeInputStream is the only implementation of this interface.
    1.80 + */
    1.81 +[scriptable, uuid(8C39EF62-F7C9-11d4-98F5-001083010E9B)] 
    1.82 +interface nsISearchableInputStream : nsISupports
    1.83 +{
    1.84 +    /**
    1.85 +     * Searches for a string in the input stream. Since the stream has a notion
    1.86 +     * of EOF, it is possible that the string may at some time be in the 
    1.87 +     * buffer, but is is not currently found up to some offset. Consequently,
    1.88 +     * both the found and not found cases return an offset:
    1.89 +     *    if found, return offset where it was found
    1.90 +     *    if not found, return offset of the first byte not searched
    1.91 +     * In the case the stream is at EOF and the string is not found, the first
    1.92 +     * byte not searched will correspond to the length of the buffer.
    1.93 +     */
    1.94 +    void search(in string forString, 
    1.95 +                in boolean ignoreCase, 
    1.96 +                out boolean found,
    1.97 +                out unsigned long offsetSearchedTo);
    1.98 +};
    1.99 +
   1.100 +%{C++
   1.101 +
   1.102 +class nsIInputStream;
   1.103 +class nsIOutputStream;
   1.104 +
   1.105 +/**
   1.106 + * NS_NewPipe2
   1.107 + *
   1.108 + * This function supersedes NS_NewPipe.  It differs from NS_NewPipe in two
   1.109 + * major ways:
   1.110 + *  (1) returns nsIAsyncInputStream and nsIAsyncOutputStream, so it is
   1.111 + *      not necessary to QI in order to access these interfaces.
   1.112 + *  (2) the size of the pipe is determined by the number of segments
   1.113 + *      times the size of each segment.
   1.114 + *
   1.115 + * @param pipeIn
   1.116 + *        resulting input end of the pipe
   1.117 + * @param pipeOut
   1.118 + *        resulting output end of the pipe
   1.119 + * @param nonBlockingInput
   1.120 + *        true specifies non-blocking input stream behavior
   1.121 + * @param nonBlockingOutput
   1.122 + *        true specifies non-blocking output stream behavior
   1.123 + * @param segmentSize
   1.124 + *        specifies the segment size in bytes (pass 0 to use default value)
   1.125 + * @param segmentCount
   1.126 + *        specifies the max number of segments (pass 0 to use default value)
   1.127 + *        passing UINT32_MAX here causes the pipe to have "infinite" space.
   1.128 + *        this mode can be useful in some cases, but should always be used with
   1.129 + *        caution.  the default value for this parameter is a finite value.
   1.130 + */
   1.131 +extern nsresult
   1.132 +NS_NewPipe2(nsIAsyncInputStream **pipeIn,
   1.133 +            nsIAsyncOutputStream **pipeOut,
   1.134 +            bool nonBlockingInput = false,
   1.135 +            bool nonBlockingOutput = false,
   1.136 +            uint32_t segmentSize = 0,
   1.137 +            uint32_t segmentCount = 0);
   1.138 +
   1.139 +/**
   1.140 + * NS_NewPipe
   1.141 + *
   1.142 + * Preserved for backwards compatibility.  Plus, this interface is more
   1.143 + * amiable in certain contexts (e.g., when you don't need the pipe's async
   1.144 + * capabilities).
   1.145 + *
   1.146 + * @param pipeIn
   1.147 + *        resulting input end of the pipe
   1.148 + * @param pipeOut
   1.149 + *        resulting output end of the pipe
   1.150 + * @param segmentSize
   1.151 + *        specifies the segment size in bytes (pass 0 to use default value)
   1.152 + * @param maxSize
   1.153 + *        specifies the max size of the pipe (pass 0 to use default value)
   1.154 + *        number of segments is maxSize / segmentSize, and maxSize must be a
   1.155 + *        multiple of segmentSize.  passing UINT32_MAX here causes the
   1.156 + *        pipe to have "infinite" space.  this mode can be useful in some
   1.157 + *        cases, but should always be used with caution.  the default value
   1.158 + *        for this parameter is a finite value.
   1.159 + * @param nonBlockingInput
   1.160 + *        true specifies non-blocking input stream behavior
   1.161 + * @param nonBlockingOutput
   1.162 + *        true specifies non-blocking output stream behavior
   1.163 + */
   1.164 +extern nsresult
   1.165 +NS_NewPipe(nsIInputStream **pipeIn,
   1.166 +           nsIOutputStream **pipeOut,
   1.167 +           uint32_t segmentSize = 0,
   1.168 +           uint32_t maxSize = 0,
   1.169 +           bool nonBlockingInput = false,
   1.170 +           bool nonBlockingOutput = false);
   1.171 +
   1.172 +%}

mercurial