git-svn-id: svn://10.0.0.236/trunk@32093 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
warren%netscape.com 1999-05-18 21:43:13 +00:00
parent e4b72ea23c
commit a89e09d70c
12 changed files with 1033 additions and 0 deletions

164
mozilla/xpcom/base/nscore.h Normal file
View File

@ -0,0 +1,164 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nscore_h___
#define nscore_h___
#ifdef _WIN32
#define NS_WIN32 1
#endif
#if defined(__unix)
#define NS_UNIX 1
#endif
#include "prtypes.h"
#ifdef __cplusplus
#include "nsDebug.h"
#endif
#ifndef __PRUNICHAR__
#define __PRUNICHAR__
typedef PRUint16 PRUnichar;
#endif
/// The preferred symbol for null.
#define nsnull 0
/* Define brackets for protecting C code from C++ */
#ifdef __cplusplus
#define NS_BEGIN_EXTERN_C extern "C" {
#define NS_END_EXTERN_C }
#else
#define NS_BEGIN_EXTERN_C
#define NS_END_EXTERN_C
#endif
/*----------------------------------------------------------------------*/
/* Import/export defines */
#ifdef NS_WIN32
#define NS_IMPORT _declspec(dllimport)
#define NS_IMPORT_(type) type _declspec(dllimport) __stdcall
#define NS_EXPORT _declspec(dllexport)
// XXX NS_EXPORT_ defined in nsCOm.h (xpcom) differs in where the __declspec
// is placed. It needs to be done this way to make the 4.x compiler happy...
#undef NS_EXPORT_
#define NS_EXPORT_(type) type _declspec(dllexport) __stdcall
#elif defined(XP_MAC)
#define NS_IMPORT
#define NS_IMPORT_(type) type
// XXX NS_EXPORT_ defined in nsCom.h actually does an export. Here it's just sugar.
#undef NS_EXPORT
#undef NS_EXPORT_
#define NS_EXPORT __declspec(export)
#define NS_EXPORT_(type) __declspec(export) type
#else
/* XXX do something useful? */
#define NS_IMPORT
#define NS_IMPORT_(type) type
#define NS_EXPORT
#define NS_EXPORT_(type) type
#endif
#ifdef _IMPL_NS_BASE
#define NS_BASE NS_EXPORT
#else
#define NS_BASE NS_IMPORT
#endif
#ifdef _IMPL_NS_NET
#define NS_NET NS_EXPORT
#else
#define NS_NET NS_IMPORT
#endif
#ifdef _IMPL_NS_DOM
#define NS_DOM NS_EXPORT
#else
#define NS_DOM NS_IMPORT
#endif
#ifdef _IMPL_NS_WIDGET
#define NS_WIDGET NS_EXPORT
#else
#define NS_WIDGET NS_IMPORT
#endif
#ifdef _IMPL_NS_VIEW
#define NS_VIEW NS_EXPORT
#else
#define NS_VIEW NS_IMPORT
#endif
#ifdef _IMPL_NS_GFXNONXP
#define NS_GFXNONXP NS_EXPORT
#define NS_GFXNONXP_(type) NS_EXPORT_(type)
#else
#define NS_GFXNONXP NS_IMPORT
#define NS_GFXNONXP_(type) NS_IMPORT_(type)
#endif
#ifdef _IMPL_NS_GFX
#define NS_GFX NS_EXPORT
#define NS_GFX_(type) NS_EXPORT_(type)
#else
#define NS_GFX NS_IMPORT
#define NS_GFX_(type) NS_IMPORT_(type)
#endif
#ifdef _IMPL_NS_PLUGIN
#define NS_PLUGIN NS_EXPORT
#else
#define NS_PLUGIN NS_IMPORT
#endif
#ifdef _IMPL_NS_APPSHELL
#define NS_APPSHELL NS_EXPORT
#else
#define NS_APPSHELL NS_IMPORT
#endif
/* ------------------------------------------------------------------------ */
// Casting macros for hiding C++ features from older compilers
// unix now determines this automatically
#ifndef XP_UNIX
#define HAVE_CPP_NEW_CASTS // we'll be optimistic.
#endif
#if defined(HAVE_CPP_NEW_CASTS)
#define NS_STATIC_CAST(__type, __ptr) static_cast<__type>(__ptr)
#define NS_CONST_CAST(__type, __ptr) const_cast<__type>(__ptr)
#define NS_REINTERPRET_CAST(__type, __ptr) reinterpret_cast<__type>(__ptr)
#else
#define NS_STATIC_CAST(__type, __ptr) ((__type)(__ptr))
#define NS_CONST_CAST(__type, __ptr) ((__type)(__ptr))
#define NS_REINTERPRET_CAST(__type, __ptr) ((__type)(__ptr))
#endif
// No sense in making an NS_DYNAMIC_CAST() macro: you can't duplicate
// the semantics. So if you want to dynamic_cast, then just use it
// "straight", no macro.
#endif /* nscore_h___ */

View File

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
// Force references to all of the symbols that we want exported from
// the dll that are located in the .lib files we link with
#include "nsVoidArray.h"
#include "nsIAtom.h"
#include "nsFileSpec.h"
#include "nsIBuffer.h"
#include "nsIByteBufferInputStream.h"
#include "nsFileStream.h"
#include "nsFileSpecStreaming.h"
#include "nsSpecialSystemDirectory.h"
#include "nsIThread.h"
#include "nsDeque.h"
#include "nsIObserver.h"
#include "nsTraceRefcnt.h"
#include "nsXPIDLString.h"
#include "nsIEnumerator.h"
#include "nsEnumeratorUtils.h"
#include "nsQuickSort.h"
#include "nsString2.h"
void XXXNeverCalled()
{
nsVoidArray();
NS_GetNumberOfAtoms();
nsFileURL(NULL);
NS_NewPipe(NULL, NULL);
NS_NewPipe2(NULL, NULL, 0, 0);
nsFileSpec s;
NS_NewIOFileStream(NULL, s, 0, 0);
nsInputFileStream(s, 0, 0);
nsPersistentFileDescriptor d;
ReadDescriptor(NULL, d);
new nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_DriveDirectory);
nsIThread::GetCurrent(NULL);
nsDeque(NULL);
NS_NewObserver(NULL, NULL);
nsTraceRefcnt::AddRef(NULL, 0, NULL, 0);
nsXPIDLCString::Copy(NULL);
NS_NewEmptyEnumerator(NULL);
nsArrayEnumerator(NULL);
NS_NewIntersectionEnumerator(NULL, NULL, NULL);
NS_QuickSort(NULL, 0, 0, NULL, NULL);
nsString2();
}

View File

@ -0,0 +1,209 @@
/* -*- Mode: C++; 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsIRegistry.h"
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsObserverService.h"
#include "nsObserver.h"
#include "nsProperties.h"
#include "nsAllocator.h"
#include "nsArena.h"
#include "nsBuffer.h"
#include "nsByteBuffer.h"
#include "nsPageMgr.h"
#include "nsSupportsArray.h"
#include "nsUnicharBuffer.h"
#include "nsByteBufferInputStream.h"
#include "nsComponentManager.h"
#include "nsIServiceManager.h"
#include "nsGenericFactory.h"
#include "nsEventQueueService.h"
#include "nsEventQueue.h"
// base
static NS_DEFINE_CID(kAllocatorCID, NS_ALLOCATOR_CID);
// ds
static NS_DEFINE_CID(kArenaCID, NS_ARENA_CID);
static NS_DEFINE_CID(kBufferCID, NS_BUFFER_CID);
static NS_DEFINE_CID(kByteBufferCID, NS_BYTEBUFFER_CID);
static NS_DEFINE_CID(kPageManagerCID, NS_PAGEMANAGER_CID);
static NS_DEFINE_CID(kObserverCID, NS_OBSERVER_CID);
static NS_DEFINE_CID(kObserverServiceCID, NS_OBSERVERSERVICE_CID);
static NS_DEFINE_CID(kPropertiesCID, NS_PROPERTIES_CID);
static NS_DEFINE_CID(kSupportsArrayCID, NS_SUPPORTSARRAY_CID);
static NS_DEFINE_CID(kUnicharBufferCID, NS_UNICHARBUFFER_CID);
// io
static NS_DEFINE_CID(kByteBufferInputStreamCID, NS_BYTEBUFFERINPUTSTREAM_CID);
// components
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
static NS_DEFINE_CID(kGenericFactoryCID, NS_GENERICFACTORY_CID);
// threads
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kEventQueueCID, NS_EVENTQUEUE_CID);
////////////////////////////////////////////////////////////////////////////////
// XPCOM initialization
//
// To Control the order of initialization of these key components I am putting
// this function.
//
// - nsServiceManager
// - nsComponentManager
// - nsRegistry
//
// Here are key points to remember:
// - A global of all these need to exist. nsServiceManager is an independent object.
// nsComponentManager uses both the globalServiceManager and its own registry.
//
// - A static object of both the nsComponentManager and nsServiceManager
// are in use. Hence InitXPCOM() gets triggered from both
// NS_GetGlobale{Service/Component}Manager() calls.
//
// - There exists no global Registry. Registry can be created from the component manager.
//
nsresult
RegisterGenericFactory(nsIComponentManager* compMgr, const nsCID& cid, const char* descr,
nsIGenericFactory::ConstructorProcPtr constr)
{
nsresult rv;
nsIGenericFactory* fact;
rv = NS_NewGenericFactory(&fact, constr);
if (NS_FAILED(rv)) return rv;
rv = compMgr->RegisterFactory(cid, descr, NULL, fact, PR_TRUE);
NS_RELEASE(fact);
return rv;
}
extern "C" NS_EXPORT nsresult
NS_RegistryGetFactory(nsISupports* servMgr, nsIFactory** aFactory);
nsIServiceManager* nsServiceManager::mGlobalServiceManager = NULL;
nsComponentManagerImpl* nsComponentManagerImpl::gComponentManager = NULL;
nsresult NS_InitXPCOM(nsIServiceManager* *result)
{
nsresult rv = NS_OK;
// 1. Create the Global Service Manager
nsIServiceManager* servMgr = NULL;
if (nsServiceManager::mGlobalServiceManager == NULL)
{
rv = NS_NewServiceManager(&servMgr);
if (NS_FAILED(rv)) return rv;
nsServiceManager::mGlobalServiceManager = servMgr;
NS_ADDREF(servMgr);
if (result) *result = servMgr;
}
// 2. Create the Component Manager and register with global service manager
// It is understood that the component manager can use the global service manager.
nsComponentManagerImpl *compMgr = NULL;
if (nsComponentManagerImpl::gComponentManager == NULL)
{
compMgr = new nsComponentManagerImpl();
if (compMgr == NULL)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(compMgr);
nsresult rv = compMgr->Init();
if (NS_FAILED(rv))
{
NS_RELEASE(compMgr);
return rv;
}
nsComponentManagerImpl::gComponentManager = compMgr;
}
rv = servMgr->RegisterService(kComponentManagerCID, compMgr);
if (NS_FAILED(rv)) return rv;
// 3. Register the global services with the component manager so that
// clients can create new objects.
// Registry
nsIFactory *registryFactory = NULL;
rv = NS_RegistryGetFactory(servMgr, &registryFactory);
if (NS_FAILED(rv)) return rv;
NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID);
rv = compMgr->RegisterFactory(kRegistryCID, NS_REGISTRY_CLASSNAME,
NS_REGISTRY_PROGID, registryFactory,
PR_TRUE);
NS_RELEASE(registryFactory);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kAllocatorCID, "Allocator",
nsAllocatorImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kArenaCID, "Arena",
ArenaImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kBufferCID, "Buffer",
nsBuffer::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kByteBufferCID, "ByteBuffer",
ByteBufferImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kPageManagerCID, "PageManager",
nsPageMgr::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kPropertiesCID, "Properties",
nsProperties::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kPersistentPropertiesCID, "PersistentProperties",
nsPersistentProperties::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kSupportsArrayCID, "ISupportsArray",
nsSupportsArray::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kObserverCID, "Observer",
nsObserver::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kObserverServiceCID, "ObserverService",
nsObserverService::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kGenericFactoryCID, "GenericFactory",
nsGenericFactory::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kEventQueueServiceCID, "EventQueueService",
nsEventQueueServiceImpl::Create);
if (NS_FAILED(rv)) return rv;
rv = RegisterGenericFactory(compMgr, kEventQueueCID, "EventQueue",
nsEventQueueImpl::Create);
return rv;
}
////////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsArena_h__
#define nsArena_h__
#include "nsIArena.h"
#define PL_ARENA_CONST_ALIGN_MASK 7
#include "plarena.h"
// Simple arena implementation layered on plarena
class ArenaImpl : public nsIArena {
public:
ArenaImpl(void) { NS_INIT_REFCNT(); }
virtual ~ArenaImpl();
NS_DECL_ISUPPORTS
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
NS_IMETHOD Init(PRUint32 arenaBlockSize);
NS_IMETHOD_(void*) Alloc(PRUint32 size);
protected:
PLArenaPool mPool;
PRUint32 mBlockSize;
};
#endif // nsArena_h__

View File

@ -0,0 +1,48 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsAtomTable_h__
#define nsAtomTable_h__
#include "nsIAtom.h"
class AtomImpl : public nsIAtom {
public:
AtomImpl();
virtual ~AtomImpl();
NS_DECL_ISUPPORTS
void* operator new(size_t size, const PRUnichar* us, PRInt32 uslen);
void operator delete(void* ptr) {
::operator delete(ptr);
}
virtual void ToString(nsString& aBuf) const;
virtual const PRUnichar* GetUnicode() const;
NS_IMETHOD SizeOf(nsISizeOfHandler* aHandler) const;
// Actually more; 0 terminated. This slot is reserved for the
// terminating zero.
PRUnichar mString[1];
};
#endif // nsAtomTable_h__

View File

@ -0,0 +1,40 @@
/* -*- Mode: C++; 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsBufferPoolService_h___
#define nsBufferPoolService_h___
#include "nsIBufferPoolService.h"
class nsBufferPoolService : public nsIBufferPoolService {
public:
NS_DECL_ISUPPORTS
// nsIBufferPoolService methods:
NS_IMETHOD NewBuffer(PRUint32 minSize, PRUint32 maxSize,
nsIByteBuffer* *result);
// nsBufferPoolService methods:
nsBufferPoolService();
virtual ~nsBufferPoolService();
protected:
};
#endif // nsBufferPoolService_h___

View File

@ -0,0 +1,47 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsByteBuffer_h__
#define nsByteBuffer_h__
#include "nsIByteBuffer.h"
class ByteBufferImpl : public nsIByteBuffer {
public:
ByteBufferImpl(void);
virtual ~ByteBufferImpl();
NS_DECL_ISUPPORTS
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
NS_IMETHOD Init(PRUint32 aBufferSize);
NS_IMETHOD_(PRUint32) GetLength(void) const;
NS_IMETHOD_(PRUint32) GetBufferSize(void) const;
NS_IMETHOD_(char*) GetBuffer() const;
NS_IMETHOD_(PRBool) Grow(PRUint32 aNewSize);
NS_IMETHOD_(PRInt32) Fill(nsresult* aErrorCode, nsIInputStream* aStream,
PRUint32 aKeep);
char* mBuffer;
PRUint32 mSpace;
PRUint32 mLength;
};
#endif // nsByteBuffer_h__

View File

@ -0,0 +1,46 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsUnicharBuffer_h__
#define nsUnicharBuffer_h__
#include "nsIUnicharBuffer.h"
class UnicharBufferImpl : public nsIUnicharBuffer {
public:
UnicharBufferImpl();
virtual ~UnicharBufferImpl();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
NS_DECL_ISUPPORTS
NS_IMETHOD Init(PRUint32 aBufferSize);
NS_IMETHOD_(PRInt32) GetLength() const;
NS_IMETHOD_(PRInt32) GetBufferSize() const;
NS_IMETHOD_(PRUnichar*) GetBuffer() const;
NS_IMETHOD_(PRBool) Grow(PRInt32 aNewSize);
NS_IMETHOD_(PRInt32) Fill(nsresult* aErrorCode, nsIUnicharInputStream* aStream,
PRInt32 aKeep);
PRUnichar* mBuffer;
PRUint32 mSpace;
PRUint32 mLength;
};
#endif // nsUnicharBuffer_h__

View File

@ -0,0 +1,179 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsByteBufferInputStream_h__
#define nsByteBufferInputStream_h__
#include "nsIByteBufferInputStream.h"
#include "nsCRT.h"
class nsByteBufferInputStream;
////////////////////////////////////////////////////////////////////////////////
class nsByteBufferOutputStream : public nsIOutputStream
{
public:
NS_DECL_ISUPPORTS
// nsIBaseStream methods:
NS_IMETHOD Close(void);
// nsIOutputStream methods:
NS_IMETHOD Write(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
NS_IMETHOD Write(nsIInputStream* fromStream, PRUint32 *aWriteCount);
NS_IMETHOD Flush(void);
// nsByteBufferOutputStream methods:
nsByteBufferOutputStream(nsByteBufferInputStream* in);
virtual ~nsByteBufferOutputStream();
protected:
nsByteBufferInputStream* mInputStream;
};
////////////////////////////////////////////////////////////////////////////////
class nsByteBufferInputStream : public nsIByteBufferInputStream
{
public:
NS_DECL_ISUPPORTS
// nsIBaseStream methods:
NS_IMETHOD Close(void);
// nsIInputStream methods:
NS_IMETHOD GetLength(PRUint32 *aLength);
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount);
// nsIByteBufferInputStream methods:
NS_IMETHOD Fill(nsIInputStream* stream, PRUint32 *aWriteCount);
NS_IMETHOD Fill(const char* aBuf, PRUint32 aCount, PRUint32 *aWriteCount);
// nsByteBufferInputStream methods:
nsByteBufferInputStream(PRBool blocking, PRUint32 size);
virtual ~nsByteBufferInputStream();
friend class nsByteBufferOutputStream;
nsresult Init(void);
nsresult SetEOF(void);
nsresult Drain(void);
PRBool AtEOF() { return mEOF && (mReadCursor == mWriteCursor) && !mFull; }
PRUint32 ReadableAmount() {
if (mReadCursor < mWriteCursor)
return mWriteCursor - mReadCursor;
else if (mReadCursor == mWriteCursor && !mFull)
return 0;
else
return (mLength - mReadCursor) + mWriteCursor;
}
PRUint32 WritableAmount() {
if (mWriteCursor < mReadCursor)
return mWriteCursor - mReadCursor;
else if (mReadCursor == mWriteCursor && mFull)
return 0;
else
return (mLength - mWriteCursor) + mReadCursor;
}
void ReadChunk(char* toBuf, PRUint32 max,
PRUint32 end, PRUint32 *totalRef)
{
NS_ASSERTION(mReadCursor <= end, "bad range");
PRUint32 diff = end - mReadCursor;
PRInt32 amt = PR_MIN(max, diff);
if (amt > 0) {
nsCRT::memcpy(toBuf, &mBuffer[mReadCursor], amt);
#ifdef DEBUG_warren
// nsCRT::memset(&mBuffer[mReadCursor], 0xDD, amt);
#endif
mReadCursor += amt;
*totalRef += amt;
}
}
nsresult WriteChunk(nsIInputStream* in,
PRUint32 end, PRUint32 *totalRef)
{
NS_ASSERTION(mWriteCursor <= end, "bad range");
PRUint32 amt = end - mWriteCursor;
if (amt > 0) {
PRUint32 readAmt;
nsresult rv = in->Read(&mBuffer[mWriteCursor], amt, &readAmt);
if (NS_FAILED(rv)) return rv;
mWriteCursor += readAmt;
*totalRef += readAmt;
}
return NS_OK;
}
protected:
char* mBuffer;
PRUint32 mLength;
PRUint32 mReadCursor;
PRUint32 mWriteCursor;
PRBool mFull;
PRBool mClosed;
PRBool mEOF;
PRBool mBlocking;
};
////////////////////////////////////////////////////////////////////////////////
class nsDummyBufferStream : public nsIInputStream
{
public:
NS_DECL_ISUPPORTS
// nsIBaseStream methods:
NS_IMETHOD Close(void) {
NS_NOTREACHED("nsDummyBufferStream::Close");
return NS_ERROR_FAILURE;
}
// nsIInputStream methods:
NS_IMETHOD GetLength(PRUint32 *aLength) {
*aLength = mLength;
return NS_OK;
}
NS_IMETHOD Read(char* aBuf, PRUint32 aCount, PRUint32 *aReadCount) {
PRUint32 amt = PR_MIN(aCount, mLength);
if (amt > 0) {
nsCRT::memcpy(aBuf, mBuffer, amt);
mBuffer += amt;
mLength -= amt;
}
*aReadCount = amt;
return NS_OK;
}
// nsDummyBufferStream methods:
nsDummyBufferStream(const char* buffer, PRUint32 length)
: mBuffer(buffer), mLength(length) {}
virtual ~nsDummyBufferStream() {}
protected:
const char* mBuffer;
PRUint32 mLength;
};
#endif // nsByteBufferInputStream_h__

View File

@ -0,0 +1,28 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..
IGNORE_MANIFEST=1
DIRS = xptinfo \
xptcall \
$(NULL)
# removed !ifdef BUILD_XPIDL above...
include <$(DEPTH)\config\rules.mak>

View File

@ -0,0 +1,134 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (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.
*
* 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.
*/
#ifndef nsEventQueueService_h__
#define nsEventQueueService_h__
#include "nsIEventQueueService.h"
#include "nsHashtable.h"
class nsIEventQueue;
////////////////////////////////////////////////////////////////////////////////
// XXX move to nsID.h or nsHashtable.h? (copied from nsComponentManager.cpp)
class ThreadKey: public nsHashKey {
private:
const PRThread* id;
public:
ThreadKey(const PRThread* aID) {
id = aID;
}
PRUint32 HashValue(void) const {
return (PRUint32)id;
}
PRBool Equals(const nsHashKey *aKey) const {
return (id == ((const ThreadKey *) aKey)->id);
}
nsHashKey *Clone(void) const {
return new ThreadKey(id);
}
};
////////////////////////////////////////////////////////////////////////////////
/* This class is used with the EventQueueEntries to allow us to nest
event queues */
class EventQueueStack
{
public:
EventQueueStack(EventQueueStack* next = NULL);
~EventQueueStack();
nsIEventQueue* GetEventQueue();
EventQueueStack* GetNext();
void SetNext(EventQueueStack* aStack);
private:
nsIEventQueue* mEventQueue;
EventQueueStack* mNextQueue;
};
////////////////////////////////////////////////////////////////////////////////
/*
* This class maintains the data associated with each entry in the EventQueue
* service's hash table...
*
* It derives from nsISupports merely as a convienence since the entries are
* reference counted...
*/
class EventQueueEntry : public nsISupports
{
public:
EventQueueEntry();
virtual ~EventQueueEntry();
// nsISupports interface...
NS_DECL_ISUPPORTS
nsIEventQueue* GetEventQueue(void);
void PushQueue(void);
void PopQueue(void);
private:
EventQueueStack* mQueueStack;
};
////////////////////////////////////////////////////////////////////////////////
class nsEventQueueServiceImpl : public nsIEventQueueService
{
public:
nsEventQueueServiceImpl();
virtual ~nsEventQueueServiceImpl();
static NS_METHOD
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
// nsISupports interface...
NS_DECL_ISUPPORTS
// nsIEventQueueService interface...
NS_IMETHOD CreateThreadEventQueue(void);
NS_IMETHOD DestroyThreadEventQueue(void);
NS_IMETHOD GetThreadEventQueue(PRThread* aThread, nsIEventQueue** aResult);
NS_IMETHOD CreateFromPLEventQueue(PLEventQueue* aPLEventQueue, nsIEventQueue** aResult);
NS_IMETHOD PushThreadEventQueue(void);
NS_IMETHOD PopThreadEventQueue(void);
#ifdef XP_MAC
NS_IMETHOD ProcessEvents();
#endif // XP_MAC
private:
nsHashtable* mEventQTable;
PRMonitor* mEventQMonitor;
};
////////////////////////////////////////////////////////////////////////////////
#endif // nsEventQueueService_h__

View File

@ -0,0 +1,28 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..
IGNORE_MANIFEST=1
# Build xpidl first, so it's available to process idl.
# Explicitly recur into libxpt/xptinfo and libxpt/xptcall,
# as they depend on xpidl and can't be in the DIRS for libxpt.
DIRS= xpt \
xpidl
include <$(DEPTH)\config\rules.mak>