pjs/netwerk/base/public/nsIStreamIO.idl

184 строки
5.8 KiB
Plaintext

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.idl"
interface nsIInputStream;
interface nsIOutputStream;
interface nsIURI;
interface nsIFile;
/**
* nsIStreamIO is an abstract interface that gives access to input and output
* streams on an object. Perhaps the most interesting subclass of this is
* nsIFileIO which allows access to input and output streams to files.
*/
[scriptable, uuid(d6c01ab2-0d04-11d4-986e-00c04fa0cf4a)]
interface nsIStreamIO : nsISupports
{
/**
* Logically opens a stream I/O object, returning its content type
* and length. If either of these are unknown, the value -1 is returned.
*/
void open(out string contentType,
out long contentLength);
/**
* Logically closes a stream I/O object. A status value is passed in
* to indicate a successful close (NS_OK) or failure.
*/
void close(in nsresult status);
/**
* Gets an input stream from a stream I/O object.
*/
readonly attribute nsIInputStream inputStream;
/**
* Gets an output stream from a stream I/O object.
*/
readonly attribute nsIOutputStream outputStream;
/**
* Returns the 'name' of a stream I/O object. This name is often
* used for display purposes.
*/
readonly attribute string name;
};
////////////////////////////////////////////////////////////////////////////////
// nsIFileIO
/**
* nsIFileIO specializes nsIStreamIO to allow initialization from an nsIFile
* object. For this implementation, the name attribute will correspond to the
* path to the file.
*/
[scriptable, uuid(2a45fb42-0d06-11d4-986e-00c04fa0cf4a)]
interface nsIFileIO : nsIStreamIO
{
void init(in nsIFile file,
in long ioFlags,
in long perm);
readonly attribute nsIFile file;
};
%{C++
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#define NS_FILEIO_CLASSNAME "File I/O"
#define NS_FILEIO_PROGID "component://netscape/network/file-io"
#define NS_FILEIO_CID \
{ /* 0965ce3e-0d06-11d4-986e-00c04fa0cf4a */ \
0x0965ce3e, \
0x0d06, \
0x11d4, \
{0x98, 0x6e, 0x00, 0xc0, 0x4f, 0xa0, 0xcf, 0x4a} \
}
inline nsresult
NS_NewFileIO(nsIFileIO **result,
nsIFile* file,
PRInt32 ioFlags = -1,
PRInt32 perm = -1)
{
nsresult rv;
nsCOMPtr<nsIFileIO> fileIO;
static NS_DEFINE_CID(kFileIOCID, NS_FILEIO_CID);
rv = nsComponentManager::CreateInstance(kFileIOCID,
nsnull,
NS_GET_IID(nsIFileIO),
getter_AddRefs(fileIO));
if (NS_FAILED(rv)) return rv;
rv = fileIO->Init(file, ioFlags, perm);
if (NS_FAILED(rv)) return rv;
*result = fileIO;
NS_ADDREF(*result);
return NS_OK;
}
%}
////////////////////////////////////////////////////////////////////////////////
// nsIInputStreamIO
/**
* nsIInputStreamIO specializes nsIStreamIO to allow initialization from an
* input stream, name, content type and length. Note that attempts to access
* the output stream of an nsIInputStreamIO will fail. This implementation
* is provided as a convenience, to avoid the need to implement the complete
* nsIStreamIO interface, when all you need is the input stream part.
*/
[scriptable, uuid(2d64af08-0d06-11d4-986e-00c04fa0cf4a)]
interface nsIInputStreamIO : nsIStreamIO
{
void init(in string name,
in nsIInputStream input,
in string contentType,
in long contentLength);
};
%{C++
#define NS_INPUTSTREAMIO_CLASSNAME "Input Stream I/O"
#define NS_INPUTSTREAMIO_PROGID "component://netscape/network/input-stream-io"
#define NS_INPUTSTREAMIO_CID \
{ /* 0f5e1198-0d06-11d4-986e-00c04fa0cf4a */ \
0x0f5e1198, \
0x0d06, \
0x11d4, \
{0x98, 0x6e, 0x00, 0xc0, 0x4f, 0xa0, 0xcf, 0x4a} \
}
inline nsresult
NS_NewInputStreamIO(nsIInputStreamIO* *result,
const char* name,
nsIInputStream* inStr,
const char* contentType,
PRInt32 contentLength)
{
nsresult rv;
nsCOMPtr<nsIInputStreamIO> io;
static NS_DEFINE_CID(kInputStreamIOCID, NS_INPUTSTREAMIO_CID);
rv = nsComponentManager::CreateInstance(kInputStreamIOCID,
nsnull,
NS_GET_IID(nsIInputStreamIO),
getter_AddRefs(io));
if (NS_FAILED(rv)) return rv;
rv = io->Init(name, inStr, contentType, contentLength);
if (NS_FAILED(rv)) return rv;
*result = io;
NS_ADDREF(*result);
return NS_OK;
}
%}
////////////////////////////////////////////////////////////////////////////////