r=mcafee. 20677 assistance. We now have a scriptable input stream implementation and interface for js. Hurray!

This commit is contained in:
valeski%netscape.com 1999-12-04 20:29:42 +00:00
Родитель 6b0e23a664
Коммит 7f46457968
5 изменённых файлов: 198 добавлений и 4 удалений

Просмотреть файл

@ -47,6 +47,7 @@ CPPSRCS = \
nsUnicharInputStream.cpp \
nsBinaryStream.cpp \
nsStorageStream.cpp \
nsScriptableInputStream.cpp \
$(NULL)
EXPORTS = \
@ -59,6 +60,7 @@ EXPORTS = \
nsIStringStream.h \
nsIUnicharInputStream.h \
nsSpecialSystemDirectory.h \
nsScriptableInputStream.h \
$(NULL)
XPIDLSRCS = \
@ -72,6 +74,7 @@ XPIDLSRCS = \
nsIBinaryInputStream.idl \
nsIBinaryOutputStream.idl \
nsIStorageStream.idl \
nsIScriptableInputStream.idl \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

Просмотреть файл

@ -38,7 +38,8 @@ EXPORTS = \
nsIUnicharInputStream.h \
nsSpecialSystemDirectory.h \
nsStorageStream.h \
$(NULL)
nsScriptableInputStream.h \
$(NULL)
NO_XPT_GEN=1
XPIDL_MODULE = xpcom_io
@ -53,6 +54,7 @@ XPIDLSRCS = \
.\nsIOutputStream.idl \
.\nsIBufferInputStream.idl \
.\nsIBufferOutputStream.idl \
.\nsIScriptableInputStream.idl \
.\nsIStorageStream.idl \
$(NULL)
@ -62,10 +64,10 @@ XPIDLSRCS = \
LIBRARY_NAME=xpcomio_s
LINCS = \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\uconv \
-I$(PUBLIC)\unicharutil \
$(NULL)
$(NULL)
LINCS = $(LINCS) -I$(PUBLIC)\raptor # until we sort out the filespec/widgets dependency
@ -86,12 +88,12 @@ CPP_OBJS = \
.\$(OBJDIR)\nsSpecialSystemDirectory.obj \
.\$(OBJDIR)\nsStorageStream.obj \
.\$(OBJDIR)\nsUnicharInputStream.obj \
.\$(OBJDIR)\nsScriptableInputStream.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

Просмотреть файл

@ -0,0 +1,45 @@
/* -*- Mode: IDL; tab-width: 4; 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 Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
*/
#include "nsIBaseStream.idl"
interface nsIInputStream;
[scriptable, uuid(a2a32f90-9b90-11d3-a189-0050041caf44)]
interface nsIScriptableInputStream : nsIBaseStream
{
/** Wrap the given nsIInputStream with this nsIScriptableInputStream.
* @param aInputStream [in] parameter providing the stream to wrap
*/
void init(in nsIInputStream aInputStream);
/** Return the number of bytes currently available in the stream
* @param _retval [out] parameter to hold the number of bytes
* if an error occurs, the parameter will be undefined
* @return error status
*/
unsigned long available();
/** Read data from the stream.
* @param aCount [in] the maximum number of bytes to read
* @param _retval [out] the data
*/
string read(in unsigned long aCount);
};

Просмотреть файл

@ -0,0 +1,87 @@
/* -*- Mode: IDL; tab-width: 4; 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): Jud Valeski & Brendan Eich
*/
#include "nsScriptableInputStream.h"
#include "nsIAllocator.h"
NS_IMPL_ISUPPORTS2(nsScriptableInputStream, nsIBaseStream, nsIScriptableInputStream);
// nsIBaseStream methods
NS_IMETHODIMP
nsScriptableInputStream::Close(void) {
if (mInputStream) return NS_ERROR_NOT_INITIALIZED;
return mInputStream->Close();
}
// nsIScriptableInputStream methods
NS_IMETHODIMP
nsScriptableInputStream::Init(nsIInputStream *aInputStream) {
if (!aInputStream) return NS_ERROR_NULL_POINTER;
mInputStream = aInputStream;
return NS_OK;
}
NS_IMETHODIMP
nsScriptableInputStream::Available(PRUint32 *_retval) {
if (mInputStream) return NS_ERROR_NOT_INITIALIZED;
return mInputStream->Available(_retval);
}
NS_IMETHODIMP
nsScriptableInputStream::Read(PRUint32 aCount, char **_retval) {
nsresult rv = NS_OK;
PRUint32 count = 0;
char *buffer = nsnull;
if (!mInputStream) return NS_ERROR_NOT_INITIALIZED;
rv = mInputStream->Available(&count);
if (NS_FAILED(rv)) return rv;
count = PR_MIN(count, aCount);
buffer = (char*)nsAllocator::Alloc(count+1); // make room for '\0'
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
PRUint32 amtRead = 0;
rv = mInputStream->Read(buffer, count, &amtRead);
if (NS_FAILED(rv)) {
nsAllocator::Free(buffer);
return rv;
}
buffer[amtRead] = '\0';
*_retval = buffer;
return NS_OK;
}
NS_METHOD
nsScriptableInputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) {
if (aOuter) return NS_ERROR_NO_AGGREGATION;
nsScriptableInputStream *sis = new nsScriptableInputStream();
if (!sis) return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(sis);
nsresult rv = sis->QueryInterface(aIID, aResult);
NS_RELEASE(sis);
return rv;
}

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: IDL; tab-width: 4; 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): Jud Valeski & Brendan Eich
*/
#ifndef ___nsscriptableinputstream___h_
#define ___nsscriptableinputstream___h_
#include "nsIScriptableInputStream.h"
#include "nsIInputStream.h"
#include "nsCOMPtr.h"
#define NS_SCRIPTABLEINPUTSTREAM_CID \
{ 0x7225c040, 0xa9bf, 0x11d3, { 0xa1, 0x97, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } }
#define NS_SCRIPTABLEINPUTSTREAM_PROGID "component://netscape/scriptableinputstream"
#define NS_SCRIPTABLEINPUTSTREAM_CLASSNAME "Scriptable Input Stream"
class nsScriptableInputStream : public nsIScriptableInputStream {
public:
// nsISupports methods
NS_DECL_ISUPPORTS
// nsIBaseStream methods
NS_DECL_NSIBASESTREAM
// nsIScriptableInputStream methods
NS_DECL_NSISCRIPTABLEINPUTSTREAM
// nsScriptableInputStream methods
nsScriptableInputStream() { NS_INIT_REFCNT(); };
virtual ~nsScriptableInputStream() {};
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
private:
nsCOMPtr<nsIInputStream> mInputStream;
};
#endif // ___nsscriptableinputstream___h_