diff --git a/mozilla/gfx/public/nsITimer.h b/mozilla/gfx/public/nsITimer.h new file mode 100644 index 00000000000..38874809146 --- /dev/null +++ b/mozilla/gfx/public/nsITimer.h @@ -0,0 +1,96 @@ +/* -*- 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 nsITimer_h___ +#define nsITimer_h___ + +#include "nscore.h" +#include "nsISupports.h" + +class nsITimer; +class nsITimerCallback; + +// Implementations of nsITimer should be written such that there are no limitations +// on what can be called by the TimerCallbackFunc. On platforms like the Macintosh this +// means that callback functions must be called from the main event loop NOT from +// an interrupt. + +/// Signature of timer callback function +typedef void +(*nsTimerCallbackFunc) (nsITimer *aTimer, void *aClosure); + +/// Interface IID for nsITimer +#define NS_ITIMER_IID \ +{ 0x497eed20, 0xb740, 0x11d1, \ +{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +/** + * Timer class, used to invoke a function or method after a fixed + * millisecond interval. Note that this interface is subject to + * change! + */ +class nsITimer : public nsISupports { +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITIMER_IID) + + /** + * Initialize a timer to fire after the given millisecond interval. + * This version takes a function to call and a closure to pass to + * that function. + * + * @param aFunc - The function to invoke + * @param aClosure - an opaque pointer to pass to that function + * @param aRepeat - (Not yet implemented) One-shot or repeating + * @param aDelay - The millisecond interval + * @result - NS_OK if this operation was successful + */ + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay)=0; + + /** + * Initialize a timer to fire after the given millisecond interval. + * This version takes an interface of type nsITimerCallback. + * The Notify method of this method is invoked. + * + * @param aCallback - The interface to notify + * @param aRepeat - (Not yet implemented) One-shot or repeating + * @param aDelay - The millisecond interval + * @result - NS_OK if this operation was successful + */ + virtual nsresult Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay)=0; + + /// Cancels the timeout + virtual void Cancel()=0; + + /// @return the millisecond delay of the timeout + virtual PRUint32 GetDelay()=0; + + /// Change the millisecond interval for the timeout + virtual void SetDelay(PRUint32 aDelay)=0; + + /// @return the opaque pointer + virtual void* GetClosure()=0; +}; + +/** Factory method for creating an nsITimer */ +extern NS_GFX nsresult NS_NewTimer(nsITimer** aInstancePtrResult); + +#endif diff --git a/mozilla/gfx/public/nsITimerCallback.h b/mozilla/gfx/public/nsITimerCallback.h new file mode 100644 index 00000000000..80127210477 --- /dev/null +++ b/mozilla/gfx/public/nsITimerCallback.h @@ -0,0 +1,43 @@ +/* -*- 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 nsITimerCallback_h___ +#define nsITimerCallback_h___ + +#include "nscore.h" +#include "nsISupports.h" + +class nsITimer; + +/// Interface IID for nsITimerCallback +#define NS_ITIMERCALLBACK_IID \ +{ 0x5079b3a0, 0xb743, 0x11d1, \ +{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } } + +/** + * Interface implemented by users of the nsITimer class. An instance + * of this interface is passed in when creating a timer. The Notify() + * method of that instance is invoked after the specified delay. + */ +class nsITimerCallback : public nsISupports { +public: + NS_DEFINE_STATIC_IID_ACCESSOR(NS_ITIMERCALLBACK_IID) + + virtual void Notify(nsITimer *timer) = 0; +}; + +#endif diff --git a/mozilla/gfx/src/gtk/nsTimer.cpp b/mozilla/gfx/src/gtk/nsTimer.cpp new file mode 100644 index 00000000000..b8ba5c52597 --- /dev/null +++ b/mozilla/gfx/src/gtk/nsTimer.cpp @@ -0,0 +1,191 @@ +/* -*- 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. + */ +#include "nsITimer.h" +#include "nsITimerCallback.h" +#include "nsCRT.h" +#include "prlog.h" +#include +#include +#include + +static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); + +extern "C" gint nsTimerExpired(gpointer aCallData); + +/* + * Implementation of timers using Gtk timer facility + */ +class TimerImpl : public nsITimer { +public: + +public: + TimerImpl(); + virtual ~TimerImpl(); + + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay); + + virtual nsresult Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay); + + NS_DECL_ISUPPORTS + + virtual void Cancel(); + virtual PRUint32 GetDelay() { return mDelay; } + virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; }; + virtual void* GetClosure() { return mClosure; } + + void FireTimeout(); + +private: + nsresult Init(PRUint32 aDelay); + + PRUint32 mDelay; + nsTimerCallbackFunc mFunc; + void *mClosure; + nsITimerCallback *mCallback; + // PRBool mRepeat; + TimerImpl *mNext; + guint mTimerId; +}; + +void TimerImpl::FireTimeout() +{ + if (mFunc != NULL) { + (*mFunc)(this, mClosure); + } + else if (mCallback != NULL) { + mCallback->Notify(this); // Fire the timer + } + +// Always repeating here + +// if (mRepeat) +// mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this); +} + + +TimerImpl::TimerImpl() +{ + // printf("TimerImple::TimerImpl called for %p\n", this); + NS_INIT_REFCNT(); + mFunc = NULL; + mCallback = NULL; + mNext = NULL; + mTimerId = 0; + mDelay = 0; + mClosure = NULL; +} + +TimerImpl::~TimerImpl() +{ + //printf("TimerImpl::~TimerImpl called for %p\n", this); + Cancel(); + NS_IF_RELEASE(mCallback); +} + +nsresult +TimerImpl::Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay) +{ + //printf("TimerImpl::Init called with func + closure for %p\n", this); + mFunc = aFunc; + mClosure = aClosure; + // mRepeat = aRepeat; + + if ((aDelay > 10000) || (aDelay < 0)) { + printf("Timer::Init() called with bogus value \"%d\"! Not enabling timer.\n", + aDelay); + return Init(aDelay); + } + + mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this); + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay) +{ + //printf("TimerImpl::Init called with callback only for %p\n", this); + mCallback = aCallback; + NS_ADDREF(mCallback); + // mRepeat = aRepeat; + if ((aDelay > 10000) || (aDelay < 0)) { + printf("Timer::Init() called with bogus value \"%d\"! Not enabling timer.\n", + aDelay); + return Init(aDelay); + } + + mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this); + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(PRUint32 aDelay) +{ + //printf("TimerImpl::Init called with delay %d only for %p\n", aDelay, this); + + mDelay = aDelay; + // NS_ADDREF(this); + + return NS_OK; +} + +NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID) + + +void +TimerImpl::Cancel() +{ + //printf("TimerImpl::Cancel called for %p\n", this); + TimerImpl *me = this; + if (mTimerId) + gtk_timeout_remove(mTimerId); +} + +NS_GFX nsresult NS_NewTimer(nsITimer** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + + TimerImpl *timer = new TimerImpl(); + if (nsnull == timer) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); +} + +gint nsTimerExpired(gpointer aCallData) +{ + //printf("nsTimerExpired for %p\n", aCallData); + TimerImpl* timer = (TimerImpl *)aCallData; + timer->FireTimeout(); + return 0; +} diff --git a/mozilla/gfx/src/mac/nsTimer.cpp b/mozilla/gfx/src/mac/nsTimer.cpp new file mode 100644 index 00000000000..ab16b217fab --- /dev/null +++ b/mozilla/gfx/src/mac/nsTimer.cpp @@ -0,0 +1,357 @@ +/* -*- 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. + */ + +// +// Mac implementation of the nsITimer interface +// + + + +#include "nsITimer.h" +#include "nsITimerCallback.h" +#include "prlog.h" +#include "nsRepeater.h" + +#include +#include + + + +#pragma mark class TimerImpl + +//======================================================================================== +class TimerImpl : public nsITimer +// TimerImpl implements nsITimer API +//======================================================================================== +{ + friend class TimerPeriodical; + + private: + nsTimerCallbackFunc mCallbackFunc; + nsITimerCallback * mCallbackObject; + void * mClosure; + PRUint32 mDelay; + PRUint32 mFireTime; // Timer should fire when TickCount >= this number + TimerImpl * mPrev; + TimerImpl * mNext; + + public: + + // constructors + + TimerImpl(); + + virtual ~TimerImpl(); + + NS_DECL_ISUPPORTS + + PRUint32 GetFireTime() const { return mFireTime; } + + void Fire(); + + // nsITimer overrides + + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, + PRUint32 aDelay); + + virtual nsresult Init(nsITimerCallback *aCallback, + PRUint32 aDelay); + + virtual void Cancel(); + + virtual PRUint32 GetDelay(); + + virtual void SetDelay(PRUint32 aDelay); + + virtual void* GetClosure(); + +#if DEBUG + enum { + eGoodTimerSignature = 'Barf', + eDeletedTimerSignature = 'oops' + }; + + Boolean IsGoodTimer() const { return (mSignature == eGoodTimerSignature); } +#endif + + private: + // Calculates mFireTime too + void SetDelaySelf( PRUint32 aDelay ); + +#if DEBUG + UInt32 mSignature; +#endif + +}; + +#pragma mark class TimerPeriodical + +//======================================================================================== +class TimerPeriodical : public Repeater +// TimerPeriodical is a singleton Repeater subclass that fires +// off TimerImpl. The firing is done on idle. +//======================================================================================== +{ + static TimerPeriodical * gPeriodical; + + TimerImpl* mTimers; + + public: + // Returns the singleton instance + static TimerPeriodical * GetPeriodical(); + + TimerPeriodical(); + + virtual ~TimerPeriodical(); + + virtual void RepeatAction( const EventRecord &inMacEvent); + + nsresult AddTimer( TimerImpl * aTimer); + + nsresult RemoveTimer( TimerImpl * aTimer); + +}; + + +//======================================================================================== +// TimerImpl implementation +//======================================================================================== + +NS_IMPL_ISUPPORTS(TimerImpl, nsITimer::GetIID()) + +//---------------------------------------------------------------------------------------- +TimerImpl::TimerImpl() +//---------------------------------------------------------------------------------------- +: mCallbackFunc(nsnull) +, mCallbackObject(nsnull) +, mClosure(nsnull) +, mDelay(0) +, mFireTime(0) +, mPrev(nsnull) +, mNext(nsnull) +#if DEBUG +, mSignature(eGoodTimerSignature) +#endif +{ + NS_INIT_REFCNT(); +} + +//---------------------------------------------------------------------------------------- +TimerImpl::~TimerImpl() +//---------------------------------------------------------------------------------------- +{ + Cancel(); + NS_IF_RELEASE(mCallbackObject); +#if DEBUG + mSignature = eDeletedTimerSignature; +#endif +} + +//---------------------------------------------------------------------------------------- +nsresult TimerImpl::Init(nsTimerCallbackFunc aFunc, + void *aClosure, + PRUint32 aDelay) +//---------------------------------------------------------------------------------------- +{ + mCallbackFunc = aFunc; + mClosure = aClosure; + SetDelaySelf(aDelay); + return TimerPeriodical::GetPeriodical()->AddTimer(this); +} + +//---------------------------------------------------------------------------------------- +nsresult TimerImpl::Init(nsITimerCallback *aCallback, + PRUint32 aDelay) +//---------------------------------------------------------------------------------------- +{ + NS_ADDREF(aCallback); + mCallbackObject = aCallback; + SetDelaySelf(aDelay); + return TimerPeriodical::GetPeriodical()->AddTimer(this); +} + +//---------------------------------------------------------------------------------------- +void TimerImpl::Cancel() +//---------------------------------------------------------------------------------------- +{ + TimerPeriodical::GetPeriodical()->RemoveTimer(this); +} + +//---------------------------------------------------------------------------------------- +PRUint32 TimerImpl::GetDelay() +//---------------------------------------------------------------------------------------- +{ + return mDelay; +} + +//---------------------------------------------------------------------------------------- +void TimerImpl::SetDelay(PRUint32 aDelay) +//---------------------------------------------------------------------------------------- +{ + SetDelaySelf(aDelay); +} + +//---------------------------------------------------------------------------------------- +void* TimerImpl::GetClosure() +//---------------------------------------------------------------------------------------- +{ + return mClosure; +} + +//---------------------------------------------------------------------------------------- +void TimerImpl::Fire() +//---------------------------------------------------------------------------------------- +{ + NS_PRECONDITION(mRefCnt > 0, "Firing a disposed Timer!"); + if (mCallbackFunc != NULL) { + (*mCallbackFunc)(this, mClosure); + } + else if (mCallbackObject != NULL) { + mCallbackObject->Notify(this); // Fire the timer + } +} + +//---------------------------------------------------------------------------------------- +void TimerImpl::SetDelaySelf( PRUint32 aDelay ) +//---------------------------------------------------------------------------------------- +{ + + mDelay = aDelay; + mFireTime = TickCount() + (mDelay * 3) / 50; // We need mFireTime in ticks (1/60th) + // but aDelay is in 1000th (60/1000 = 3/50) +} + +TimerPeriodical * TimerPeriodical::gPeriodical = nsnull; + +TimerPeriodical * TimerPeriodical::GetPeriodical() +{ + if (gPeriodical == NULL) + gPeriodical = new TimerPeriodical(); + return gPeriodical; +} + +TimerPeriodical::TimerPeriodical() +{ + mTimers = nsnull; +} + +TimerPeriodical::~TimerPeriodical() +{ + PR_ASSERT(mTimers == 0); +} + +nsresult TimerPeriodical::AddTimer( TimerImpl * aTimer) +{ + // make sure it's not already there + RemoveTimer(aTimer); + // keep list sorted by fire time + if (mTimers) + { + if (aTimer->GetFireTime() < mTimers->GetFireTime()) + { + mTimers->mPrev = aTimer; + aTimer->mNext = mTimers; + mTimers = aTimer; + } + else + { + TimerImpl *t = mTimers; + TimerImpl *prevt; + // we know we will enter the while loop at least the first + // time, and thus prevt will be initialized + while (t && (t->GetFireTime() <= aTimer->GetFireTime())) + { + prevt = t; + t = t->mNext; + } + aTimer->mPrev = prevt; + aTimer->mNext = prevt->mNext; + prevt->mNext = aTimer; + if (aTimer->mNext) aTimer->mNext->mPrev = aTimer; + } + } + else mTimers = aTimer; + + StartRepeating(); + return NS_OK; +} + +nsresult TimerPeriodical::RemoveTimer( TimerImpl * aTimer) +{ + TimerImpl* t = mTimers; + TimerImpl* next_t = nsnull; + if (t) next_t = t->mNext; + while (t) + { + if (t == aTimer) + { + if (mTimers == t) mTimers = t->mNext; + if (t->mPrev) t->mPrev->mNext = t->mNext; + if (t->mNext) t->mNext->mPrev = t->mPrev; + t->mNext = nsnull; + t->mPrev = nsnull; + } + t = next_t; + if (t) next_t = t->mNext; + } + + if ( mTimers == nsnull ) + StopRepeating(); + return NS_OK; +} + +// Called through every event loop +// Loops through the list of available timers, and +// fires off the appropriate ones +void TimerPeriodical::RepeatAction( const EventRecord &inMacEvent) +{ + PRBool done = false; + while (!done) + { + TimerImpl* t = mTimers; + while (t) + { + NS_ASSERTION(t->IsGoodTimer(), "Bad timer!"); + + if (t->GetFireTime() <= inMacEvent.when) + { + RemoveTimer(t); + t->Fire(); + break; + } + t = t->mNext; + } + done = true; + } +} + + +NS_GFX nsresult NS_NewTimer(nsITimer** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + TimerImpl *timer = new TimerImpl(); + if (nsnull == timer) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return timer->QueryInterface(nsITimer::GetIID(), (void **) aInstancePtrResult); +} diff --git a/mozilla/gfx/src/motif/nsTimer.cpp b/mozilla/gfx/src/motif/nsTimer.cpp new file mode 100644 index 00000000000..418459ae54c --- /dev/null +++ b/mozilla/gfx/src/motif/nsTimer.cpp @@ -0,0 +1,173 @@ +/* -*- 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. + */ +#include "nsITimer.h" +#include "nsITimerCallback.h" +#include "nsCRT.h" +#include "prlog.h" +#include +#include +#include + +static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); + +// Hack for now. This is Bad because it creates a dependency between the widget +// library and this library. This needs to be replaced with having code +// to pass an interface which can be queried for the app context. +extern XtAppContext gAppContext; + +extern void nsTimerExpired(XtPointer aCallData); + + +/* + * Implementation of timers using Xt timer facility + */ +class TimerImpl : public nsITimer { +public: + +public: + TimerImpl(); + virtual ~TimerImpl(); + + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay); + + virtual nsresult Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay); + + NS_DECL_ISUPPORTS + + virtual void Cancel(); + virtual PRUint32 GetDelay() { return mDelay; } + virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; }; + virtual void* GetClosure() { return mClosure; } + + void FireTimeout(); + +private: + nsresult Init(PRUint32 aDelay); + + PRUint32 mDelay; + nsTimerCallbackFunc mFunc; + void *mClosure; + nsITimerCallback *mCallback; + // PRBool mRepeat; + TimerImpl *mNext; + XtIntervalId mTimerId; +}; + +void TimerImpl::FireTimeout() +{ + if (mFunc != NULL) { + (*mFunc)(this, mClosure); + } + else if (mCallback != NULL) { + mCallback->Notify(this); // Fire the timer + } + +// Always repeating here + +// if (mRepeat) +// mTimerId = XtAppAddTimeOut(gAppContext, GetDelay(),(XtTimerCallbackProc)nsTimerExpired, this); +} + + +TimerImpl::TimerImpl() +{ + NS_INIT_REFCNT(); + mFunc = NULL; + mCallback = NULL; + mNext = NULL; + mTimerId = 0; + mDelay = 0; + mClosure = NULL; +} + +TimerImpl::~TimerImpl() +{ +} + +nsresult +TimerImpl::Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay) +{ + mFunc = aFunc; + mClosure = aClosure; + // mRepeat = aRepeat; + + mTimerId = XtAppAddTimeOut(gAppContext, aDelay,(XtTimerCallbackProc)nsTimerExpired, this); + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay) +{ + mCallback = aCallback; + // mRepeat = aRepeat; + + mTimerId = XtAppAddTimeOut(gAppContext, aDelay, (XtTimerCallbackProc)nsTimerExpired, this); + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(PRUint32 aDelay) +{ + mDelay = aDelay; + NS_ADDREF(this); + + return NS_OK; +} + +NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID) + + +void +TimerImpl::Cancel() +{ + XtRemoveTimeOut(mTimerId); +} + +NS_GFX nsresult NS_NewTimer(nsITimer** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + + TimerImpl *timer = new TimerImpl(); + if (nsnull == timer) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); +} + + +void nsTimerExpired(XtPointer aCallData) +{ + TimerImpl* timer = (TimerImpl *)aCallData; + timer->FireTimeout(); +} diff --git a/mozilla/gfx/src/photon/nsTimer.cpp b/mozilla/gfx/src/photon/nsTimer.cpp new file mode 100644 index 00000000000..ccb32cfb25a --- /dev/null +++ b/mozilla/gfx/src/photon/nsTimer.cpp @@ -0,0 +1,261 @@ +/* -*- 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. + */ +#include "nsITimer.h" +#include "nsITimerCallback.h" +#include "nsCRT.h" +#include "prlog.h" +#include +#include +#include +#include +#include + +static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); + +extern "C" int nsTimerExpired(void *aCallData); + +/* + * Implementation of timers QNX/Neutrino timers. + */ + +class TimerImpl : public nsITimer { +public: + +public: + TimerImpl(); + virtual ~TimerImpl(); + + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, + PRUint32 aDelay); + + virtual nsresult Init(nsITimerCallback *aCallback, + PRUint32 aDelay); + + NS_DECL_ISUPPORTS + + virtual void Cancel(); + virtual PRUint32 GetDelay() { return mDelay; } + virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; }; + virtual void* GetClosure() { return mClosure; } + + void FireTimeout(); + +private: + nsresult Init(PRUint32 aDelay); + nsresult SetupTimer(PRUint32 aDelay); + + PRUint32 mDelay; + nsTimerCallbackFunc mFunc; + void *mClosure; + nsITimerCallback *mCallback; + TimerImpl *mNext; + timer_t mTimerId; +}; + +/* + * This method is called when the Delay/Duration expires + */ +void TimerImpl::FireTimeout() +{ + printf("TimerImpl::FireTimeout called for %p. mFunc=<%p> and mCallback=<%p>\n", this, mFunc, mCallback); + if (mFunc != NULL) + { + (*mFunc)(this, mClosure); + } + else if (mCallback != NULL) + { + mCallback->Notify(this); // Fire the timer + } +} + + +TimerImpl::TimerImpl() +{ + printf("TimerImpl::TimerImpl called for %p\n", this); + NS_INIT_REFCNT(); + mFunc = NULL; + mCallback = NULL; + mNext = NULL; + mTimerId = 0; + mDelay = 0; + mClosure = NULL; +} + +TimerImpl::~TimerImpl() +{ + printf("TimerImpl::~TimerImpl called for %p\n", this); + Cancel(); + NS_IF_RELEASE(mCallback); +} + +nsresult +TimerImpl::SetupTimer(PRUint32 aDelay) +{ +struct sigevent event; +struct itimerspec tv; +int err; + + printf("TimerImpl::SetupTimer called with func %p\n", this); + + event.sigev_notify=SIGEV_PULSE; + event.sigev_coid=0; /* REVISIT: Get the global Photon channel ID */ + event.sigev_priority=0; + event.sigev_code=0; + event.sigev_value.sival_int=0; + err = timer_create(CLOCK_SOFTTIME,&event,&mTimerId); + if (err!=0) + { + printf ("Timer::SetupTimer() timer_create error:%d\n",errno); + return NS_ERROR_FAILURE; + } + + printf ("Timer::Init() timer id: %d\n",mTimerId); + + tv.it_interval.tv_sec=0; + tv.it_interval.tv_nsec=0; + tv.it_value.tv_sec=aDelay; + tv.it_value.tv_nsec=0; + err=timer_settime(mTimerId,0,&tv,0); + if (err!=0) + { + printf ("Timer::Init() timer_settime error:%d\n",errno); + return NS_ERROR_FAILURE; + } + + return NS_OK; +} + + +nsresult +TimerImpl::Init(nsTimerCallbackFunc aFunc, + void *aClosure, + PRUint32 aDelay) +{ +nsresult err; + + printf("TimerImpl::Init called with func + closure for %p\n", this); + mFunc = aFunc; + mClosure = aClosure; + + if ((aDelay > 10000) || (aDelay < 0)) + { + printf("Timer::Init() called with bogus value \"%d\"! Not enabling timer.\n", aDelay); + return Init(aDelay); + } + +#if 0 + mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this); +#else + err = SetupTimer(aDelay); + if (err != NS_OK) + { + printf ("Timer::Init() timer_create error:%d\n",errno); + return NS_ERROR_FAILURE; + } +#endif + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(nsITimerCallback *aCallback, + PRUint32 aDelay) +{ +nsresult err; + + printf("TimerImpl::Init called with callback only for %p\n", this); + + mCallback = aCallback; + if ((aDelay > 10000) || (aDelay < 0)) + { + printf("Timer::Init() called with bogus value \"%d\"! Not enabling timer.\n", + aDelay); + return Init(aDelay); + } + +#if 0 + mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this); +#else + err = SetupTimer(aDelay); + if (err != NS_OK) + { + printf ("Timer::Init() timer_create error:%d\n",errno); + return NS_ERROR_FAILURE; + } +#endif + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(PRUint32 aDelay) +{ + printf("TimerImpl::Init called with delay %d only for %p\n", aDelay, this); + + mDelay = aDelay; + NS_ADDREF(this); + + return NS_OK; +} + +NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID) + + +void +TimerImpl::Cancel() +{ +int err; + + printf("TimerImpl::Cancel called for %p\n", this); + TimerImpl *me = this; + + if (mTimerId) + { +#if 0 + gtk_timeout_remove(mTimerId); +#else + err = timer_delete(mTimerId); +#endif + } +} + +NS_GFX nsresult NS_NewTimer(nsITimer** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); + if (nsnull == aInstancePtrResult) + { + return NS_ERROR_NULL_POINTER; + } + + TimerImpl *timer = new TimerImpl(); + if (nsnull == timer) + { + return NS_ERROR_OUT_OF_MEMORY; + } + + return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); +} + +int nsTimerExpired(void *aCallData) +{ + printf("nsTimerExpired for %p\n", aCallData); + TimerImpl* timer = (TimerImpl *)aCallData; + timer->FireTimeout(); + return 0; +} diff --git a/mozilla/gfx/src/rhapsody/nsTimer.cpp b/mozilla/gfx/src/rhapsody/nsTimer.cpp new file mode 100644 index 00000000000..d93a2bb2804 --- /dev/null +++ b/mozilla/gfx/src/rhapsody/nsTimer.cpp @@ -0,0 +1,200 @@ +/* -*- 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. + */ +#include "nsITimer.h" +#include "nsITimerCallback.h" +#include "nsCRT.h" +#include "prlog.h" +#include +#include + +// +// Copied from the unix version, Rhapsody needs to +// make this work. Stubs to compile things for now. +// + +#if 0 +Michael Hanni suggests: + + I understand that nsTimer.cpp in base/rhapsody/ needs to be completed, + yes? Wouldn't this code just use some NSTimers in the NSRunLoop? + + Timer = [NSTimer timerWithTimeInterval:0.02 //seconds + target:self + selector:@selector(doThis:) + userInfo:nil + repeats:YES]; + [[NSRunLoop currentRunLoop] addTimer:Timer + forMode:NSDefaultRunLoopMode]; + + I only looked at nsTimer.cpp briefly, but could something like this work + if imbedded in all that c++? ;-) + +#endif + +static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); + +extern void nsTimerExpired(void *aCallData); + +class TimerImpl : public nsITimer { +public: + +public: + TimerImpl(); + virtual ~TimerImpl(); + + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay); + + virtual nsresult Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay); + + NS_DECL_ISUPPORTS + + virtual void Cancel(); + virtual PRUint32 GetDelay() { return mDelay; } + virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; }; + virtual void* GetClosure() { return mClosure; } + + void FireTimeout(); + +private: + nsresult Init(PRUint32 aDelay); + + PRUint32 mDelay; + nsTimerCallbackFunc mFunc; + void *mClosure; + nsITimerCallback *mCallback; + // PRBool mRepeat; + TimerImpl *mNext; + int mTimerId; +}; + +void TimerImpl::FireTimeout() +{ + if (mFunc != NULL) { + (*mFunc)(this, mClosure); + } + else if (mCallback != NULL) { + mCallback->Notify(this); // Fire the timer + } + +// Always repeating here + +// if (mRepeat) +// mTimerId = XtAppAddTimeOut(gAppContext, GetDelay(),(XtTimerCallbackProc)nsTimerExpired, this); +} + + +TimerImpl::TimerImpl() +{ + NS_INIT_REFCNT(); + mFunc = NULL; + mCallback = NULL; + mNext = NULL; + mTimerId = 0; + mDelay = 0; + mClosure = NULL; +} + +TimerImpl::~TimerImpl() +{ +} + +nsresult +TimerImpl::Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay) +{ + mFunc = aFunc; + mClosure = aClosure; + // mRepeat = aRepeat; + + printf("TimerImpl::Init() not implemented\n"); + +#ifdef RHAPSODY_NEEDS_TO_IMPLEMENT_THIS + mTimerId = XtAppAddTimeOut(gAppContext, aDelay,(XtTimerCallbackProc)nsTimerExpired, this); +#endif + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay) +{ + mCallback = aCallback; + // mRepeat = aRepeat; + +printf("TimerImpl::Init() not implmented.\n"); + +#ifdef RHAPSODY_NEEDS_TO_IMPLEMENT_THIS + mTimerId = XtAppAddTimeOut(gAppContext, aDelay, (XtTimerCallbackProc)nsTimerExpired, this); +#endif + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(PRUint32 aDelay) +{ + mDelay = aDelay; + NS_ADDREF(this); + + return NS_OK; +} + +NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID) + + +void +TimerImpl::Cancel() +{ + + printf("TimerImpl::Cancel() not implemented.\n"); + +#ifdef RHAPSODY_NEEDS_TO_IMPLEMENT_THIS + XtRemoveTimeOut(mTimerId); +#endif +} + +NS_GFX nsresult NS_NewTimer(nsITimer** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + + TimerImpl *timer = new TimerImpl(); + if (nsnull == timer) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); +} + + +void nsTimerExpired(void *aCallData) +{ + TimerImpl* timer = (TimerImpl *)aCallData; + timer->FireTimeout(); +} diff --git a/mozilla/gfx/src/windows/nsTimer.cpp b/mozilla/gfx/src/windows/nsTimer.cpp new file mode 100644 index 00000000000..b652feecb70 --- /dev/null +++ b/mozilla/gfx/src/windows/nsTimer.cpp @@ -0,0 +1,362 @@ +/* -*- 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. + */ +#include "nsITimer.h" +#include "nsITimerCallback.h" +#include "nsCRT.h" +#include "prlog.h" +#include +#include +#include + +static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); + +/* + * Implementation of timers lifted from Windows front-end file timer.cpp + */ +class TimerImpl : public nsITimer { +public: + static TimerImpl *gTimerList; + static UINT gWindowsTimer; + static DWORD gNextFire; + + static void ProcessTimeouts(DWORD aNow); + static void SyncTimeoutPeriod(DWORD aTickCount); + +public: + TimerImpl(); + virtual ~TimerImpl(); + + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay); + + virtual nsresult Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay); + + NS_DECL_ISUPPORTS + + virtual void Cancel(); + void Fire(DWORD aNow); + + virtual PRUint32 GetDelay() { return mDelay; } + virtual void SetDelay(PRUint32 aDelay) {}; + + virtual void* GetClosure() { return mClosure; } + +private: + nsresult Init(PRUint32 aDelay); + + PRUint32 mDelay; + nsTimerCallbackFunc mFunc; + void *mClosure; + nsITimerCallback *mCallback; + DWORD mFireTime; + // PRBool mRepeat; + TimerImpl *mNext; +}; + +TimerImpl *TimerImpl::gTimerList = NULL; +UINT TimerImpl::gWindowsTimer = 0; +DWORD TimerImpl::gNextFire = (DWORD)-1; + +void CALLBACK FireTimeout(HWND aWindow, + UINT aMessage, + UINT aTimerID, + DWORD aTime) +{ + static BOOL bCanEnter = TRUE; + + // Don't allow old timer messages in here. + if(aMessage != WM_TIMER) { + PR_ASSERT(0); + return; + } + + if(aTimerID != TimerImpl::gWindowsTimer) { + return; + } + + // Block only one entry into this function, or else. + if(bCanEnter) { + bCanEnter = FALSE; + // see if we need to fork off any timeout functions + if(TimerImpl::gTimerList) { + TimerImpl::ProcessTimeouts(aTime); + } + bCanEnter = TRUE; + } +} + +// Function to correctly have the timer be set. +void +TimerImpl::SyncTimeoutPeriod(DWORD aTickCount) +{ + // May want us to set tick count ourselves. + if(aTickCount == 0) { + aTickCount = ::GetTickCount(); + } + + // If there's no list, we should clear the timer. + if(!gTimerList) { + if(gWindowsTimer) { + ::KillTimer(NULL, gWindowsTimer); + gWindowsTimer = 0; + gNextFire = (DWORD)-1; + } + } + else { + // See if we need to clear the current timer. + // Curcumstances are that if the timer will not + // fire on time for the next timeout. + BOOL bSetTimer = FALSE; + TimerImpl *pTimeout = gTimerList; + if(gWindowsTimer) { + if(pTimeout->mFireTime != gNextFire) { + ::KillTimer(NULL, gWindowsTimer); + gWindowsTimer = 0; + gNextFire = (DWORD)-1; + + // Set the timer. + bSetTimer = TRUE; + } + } + else { + // No timer set, attempt. + bSetTimer = TRUE; + } + + if(bSetTimer) { + DWORD dwFireWhen = pTimeout->mFireTime > aTickCount ? + pTimeout->mFireTime - aTickCount : 0; + if(dwFireWhen > UINT_MAX) { + dwFireWhen = UINT_MAX; + } + UINT uFireWhen = (UINT)dwFireWhen; + + PR_ASSERT(gWindowsTimer == 0); + gWindowsTimer = ::SetTimer(NULL, 0, uFireWhen, (TIMERPROC)FireTimeout); + + if(gWindowsTimer) { + // Set the fire time. + gNextFire = pTimeout->mFireTime; + } + } + } +} + +// Walk down the timeout list and launch anyone appropriate +void +TimerImpl::ProcessTimeouts(DWORD aNow) +{ + TimerImpl *p = gTimerList; + if(aNow == 0) { + aNow = ::GetTickCount(); + } + + BOOL bCalledSync = FALSE; + + // loop over all entries + while(p) { + // send it + if(p->mFireTime < aNow) { + // Make sure that the timer cannot be deleted during the + // Fire(...) call which may release *all* other references + // to p... + NS_ADDREF(p); + p->Fire(aNow); + + // Clear the timer. + // Period synced. + p->Cancel(); + bCalledSync = TRUE; + NS_RELEASE(p); + + // Reset the loop (can't look at p->pNext now, and called + // code may have added/cleared timers). + // (could do this by going recursive and returning). + p = gTimerList; + } else { + // Make sure we fire an timer. + // Also, we need to check to see if things are backing up (they + // may be asking to be fired long before we ever get to them, + // and we don't want to pass in negative values to the real + // timer code, or it takes days to fire.... + if(bCalledSync == FALSE) { + SyncTimeoutPeriod(aNow); + bCalledSync = TRUE; + } + // Get next timer. + p = p->mNext; + } + } +} + + +TimerImpl::TimerImpl() +{ + NS_INIT_REFCNT(); + mFunc = NULL; + mCallback = NULL; + mNext = NULL; + mClosure = nsnull; +} + +TimerImpl::~TimerImpl() +{ + Cancel(); + NS_IF_RELEASE(mCallback); +} + +nsresult +TimerImpl::Init(nsTimerCallbackFunc aFunc, + void *aClosure, +// PRBool aRepeat, + PRUint32 aDelay) +{ + mFunc = aFunc; + mClosure = aClosure; + // mRepeat = aRepeat; + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(nsITimerCallback *aCallback, +// PRBool aRepeat, + PRUint32 aDelay) +{ + mCallback = aCallback; + NS_ADDREF(mCallback); + // mRepeat = aRepeat; + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(PRUint32 aDelay) +{ + DWORD dwNow = ::GetTickCount(); + + mDelay = aDelay; + mFireTime = (DWORD) aDelay + dwNow; + mNext = NULL; + + // add it to the list + if(!gTimerList) { + // no list add it + gTimerList = this; + } + else { + + // is it before everything else on the list? + if(mFireTime < gTimerList->mFireTime) { + + mNext = gTimerList; + gTimerList = this; + + } else { + + TimerImpl * pPrev = gTimerList; + TimerImpl * pCurrent = gTimerList; + + while(pCurrent && (pCurrent->mFireTime <= mFireTime)) { + pPrev = pCurrent; + pCurrent = pCurrent->mNext; + } + + PR_ASSERT(pPrev); + + // insert it after pPrev (this could be at the end of the list) + mNext = pPrev->mNext; + pPrev->mNext = this; + + } + + } + + NS_ADDREF(this); + + // Sync the timer fire period. + SyncTimeoutPeriod(dwNow); + + return NS_OK; +} + +NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID) + +void +TimerImpl::Fire(DWORD aNow) +{ + if (mFunc != NULL) { + (*mFunc)(this, mClosure); + } + else if (mCallback != NULL) { + mCallback->Notify(this); + } +} + +void +TimerImpl::Cancel() +{ + TimerImpl *me = this; + + if(gTimerList == this) { + + // first element in the list lossage + gTimerList = mNext; + + } else { + + // walk until no next pointer + for(TimerImpl * p = gTimerList; p && p->mNext && (p->mNext != this); p = p->mNext) + ; + + // if we found something valid pull it out of the list + if(p && p->mNext && p->mNext == this) { + p->mNext = mNext; + + } else { + // get out before we delete something that looks bogus + return; + } + + } + + // if we got here it must have been a valid element so trash it + NS_RELEASE(me); + + // If there's now no be sure to clear the timer. + SyncTimeoutPeriod(0); +} + +NS_GFX nsresult NS_NewTimer(nsITimer** aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + + TimerImpl *timer = new TimerImpl(); + if (nsnull == timer) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); +} diff --git a/mozilla/gfx/src/xlib/nsTimer.cpp b/mozilla/gfx/src/xlib/nsTimer.cpp new file mode 100644 index 00000000000..2fab789ae23 --- /dev/null +++ b/mozilla/gfx/src/xlib/nsTimer.cpp @@ -0,0 +1,295 @@ +/* -*- 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. + */ + +#include +#include +#include +#include "nsITimer.h" +#include "nsITimerCallback.h" +#include "prlog.h" + +static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); + +extern "C" int NS_TimeToNextTimeout(struct timeval *aTimer); +extern "C" void NS_ProcessTimeouts(void); + +class TimerImpl : public nsITimer +{ +public: + static TimerImpl *gTimerList; + static struct timeval gTimer; + static struct timeval gNextFire; + static void ProcessTimeouts(struct timeval *aNow); + TimerImpl(); + ~TimerImpl(); + + virtual nsresult Init(nsTimerCallbackFunc aFunc, + void *aClosure, + PRUint32 aDelay); + + virtual nsresult Init(nsITimerCallback *aCallback, + PRUint32 aDelay); + + NS_DECL_ISUPPORTS + + virtual void Cancel(); + void Fire(struct timeval *aNow); + + virtual PRUint32 GetDelay() { return 0; }; + virtual void SetDelay(PRUint32 aDelay) {}; + virtual void *GetClosure() { return mClosure; } + + // this needs to be public so that the mainloop can + // find the next fire time... + struct timeval mFireTime; + TimerImpl *mNext; + +private: + nsresult Init(PRUint32 aDelay); + nsTimerCallbackFunc mFunc; + void *mClosure; + PRUint32 mDelay; + nsITimerCallback *mCallback; + +}; + + +TimerImpl *TimerImpl::gTimerList = NULL; +struct timeval TimerImpl::gTimer = {0, 0}; +struct timeval TimerImpl::gNextFire = {0, 0}; + +TimerImpl::TimerImpl() +{ + //printf("TimerImpl::TimerImpl (%p) called.\n", + //this); + NS_INIT_REFCNT(); + mFunc = NULL; + mCallback = NULL; + mNext = NULL; + mClosure = NULL; +} + +TimerImpl::~TimerImpl() +{ + //printf("TimerImpl::~TimerImpl (%p) called.\n", + // this); + Cancel(); + NS_IF_RELEASE(mCallback); +} + +NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID) + +nsresult +TimerImpl::Init(nsTimerCallbackFunc aFunc, + void *aClosure, + PRUint32 aDelay) +{ + mFunc = aFunc; + mClosure = aClosure; + return Init(aDelay); +} + +nsresult +TimerImpl::Init(nsITimerCallback *aCallback, + PRUint32 aDelay) +{ + mCallback = aCallback; + NS_ADDREF(mCallback); + + return Init(aDelay); +} + +nsresult +TimerImpl::Init(PRUint32 aDelay) +{ + struct timeval Now; + // printf("TimerImpl::Init (%p) called with delay %d\n", + //this, aDelay); + // get the cuurent time + gettimeofday(&Now, NULL); + mFireTime.tv_sec = Now.tv_sec + (aDelay / 1000); + mFireTime.tv_usec = Now.tv_usec + (aDelay * 1000); + //printf("fire set to %ld / %ld\n", + //mFireTime.tv_sec, mFireTime.tv_usec); + // set the next pointer to nothing. + mNext = NULL; + // add ourself to the list + if (!gTimerList) { + // no list here. I'm the start! + //printf("This is the beginning of the list..\n"); + gTimerList = this; + } + else { + // is it before everything else on the list? + if ((mFireTime.tv_sec < gTimerList->mFireTime.tv_sec) && + (mFireTime.tv_usec < gTimerList->mFireTime.tv_usec)) { + // printf("This is before the head of the list...\n"); + mNext = gTimerList; + gTimerList = this; + } + else { + TimerImpl *pPrev = gTimerList; + TimerImpl *pCurrent = gTimerList; + while (pCurrent && ((pCurrent->mFireTime.tv_sec <= mFireTime.tv_sec) && + (pCurrent->mFireTime.tv_usec <= mFireTime.tv_usec))) { + pPrev = pCurrent; + pCurrent = pCurrent->mNext; + } + PR_ASSERT(pPrev); + + // isnert it after pPrev ( this could be at the end of the list) + mNext = pPrev->mNext; + pPrev->mNext = this; + } + } + NS_ADDREF(this); + return NS_OK; +} + +void +TimerImpl::Fire(struct timeval *aNow) +{ + // printf("TimerImpl::Fire (%p) called at %ld / %ld\n", + // this, + //aNow->tv_sec, aNow->tv_usec); + if (mFunc != NULL) { + (*mFunc)(this, mClosure); + } + else if (mCallback != NULL) { + mCallback->Notify(this); + } +} + +void +TimerImpl::Cancel() +{ + TimerImpl *me = this; + TimerImpl *p; + // printf("TimerImpl::Cancel (%p) called.\n", + // this); + if (gTimerList == this) { + // first element in the list lossage... + gTimerList = mNext; + } + else { + // walk until there's no next pointer + for (p = gTimerList; p && p->mNext && (p->mNext != this); p = p->mNext) + ; + + // if we found something valid pull it out of the list + if (p && p->mNext && p->mNext == this) { + p->mNext = mNext; + } + else { + // get out before we delete something that looks bogus + return; + } + } + // if we got here it must have been a valid element so trash it + NS_RELEASE(me); + +} + +void +TimerImpl::ProcessTimeouts(struct timeval *aNow) +{ + TimerImpl *p = gTimerList; + if (aNow->tv_sec == 0 && + aNow->tv_usec == 0) { + gettimeofday(aNow, NULL); + } + // printf("TimerImpl::ProcessTimeouts called at %ld / %ld\n", + // aNow->tv_sec, aNow->tv_usec); + while (p) { + if ((p->mFireTime.tv_sec < aNow->tv_sec) || + ((p->mFireTime.tv_sec == aNow->tv_sec) && + (p->mFireTime.tv_usec <= aNow->tv_usec))) { + // Make sure that the timer cannot be deleted during the + // Fire(...) call which may release *all* other references + // to p... + //printf("Firing timeout for (%p)\n", + // p); + NS_ADDREF(p); + p->Fire(aNow); + // Clear the timer. + // Period synced. + p->Cancel(); + NS_RELEASE(p); + // Reset the loop (can't look at p->pNext now, and called + // code may have added/cleared timers). + // (could do this by going recursive and returning). + p = gTimerList; + } + else { + p = p->mNext; + } + } +} + +NS_GFX nsresult NS_NewTimer(nsITimer **aInstancePtrResult) +{ + NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); + if (nsnull == aInstancePtrResult) { + return NS_ERROR_NULL_POINTER; + } + + TimerImpl *timer = new TimerImpl(); + if (nsnull == timer) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); +} + +int NS_TimeToNextTimeout(struct timeval *aTimer) { + TimerImpl *timer; + timer = TimerImpl::gTimerList; + if (timer) { + if ((timer->mFireTime.tv_sec < aTimer->tv_sec) || + ((timer->mFireTime.tv_sec == aTimer->tv_sec) && + (timer->mFireTime.tv_usec <= aTimer->tv_usec))) { + aTimer->tv_sec = 0; + aTimer->tv_usec = 0; + return 1; + } + else { + aTimer->tv_sec -= timer->mFireTime.tv_sec; + // handle the overflow case + if (aTimer->tv_usec < timer->mFireTime.tv_usec) { + aTimer->tv_usec = timer->mFireTime.tv_usec - aTimer->tv_usec; + // make sure we don't go past zero when we decrement + if (aTimer->tv_sec) + aTimer->tv_sec--; + } + else { + aTimer->tv_usec -= timer->mFireTime.tv_usec; + } + return 1; + } + } + else { + return 0; + } +} + +void NS_ProcessTimeouts(void) { + struct timeval now; + now.tv_sec = 0; + now.tv_usec = 0; + TimerImpl::ProcessTimeouts(&now); +} diff --git a/mozilla/widget/public/nsRepeater.h b/mozilla/widget/public/nsRepeater.h deleted file mode 100644 index d72d45c1f2f..00000000000 --- a/mozilla/widget/public/nsRepeater.h +++ /dev/null @@ -1,60 +0,0 @@ -/* -*- 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 nsRepeater_h___ -#define nsRepeater_h___ - -#include "nscore.h" - -class EventRecord; - -class NS_BASE Repeater { - public: - - Repeater(); - virtual ~Repeater(); - - virtual void RepeatAction(const EventRecord &aMacEvent) = 0; - - void StartRepeating(); - void StopRepeating(); - void StartIdling(); - void StopIdling(); - - static void DoRepeaters(const EventRecord &aMacEvent); - static void DoIdlers(const EventRecord &aMacEvent); - - protected: - - void AddToRepeatList(); - void RemoveFromRepeatList(); - void AddToIdleList(); - void RemoveFromIdleList(); - - static Repeater* sRepeaters; - static Repeater* sIdlers; - - bool mRepeating; - bool mIdling; - Repeater* mPrevRptr; - Repeater* mNextRptr; - Repeater* mPrevIdlr; - Repeater* mNextIdlr; -}; - -#endif \ No newline at end of file diff --git a/mozilla/widget/src/mac/nsRepeater.cpp b/mozilla/widget/src/mac/nsRepeater.cpp deleted file mode 100644 index 5a93b4d2970..00000000000 --- a/mozilla/widget/src/mac/nsRepeater.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* -*- 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. - */ - -#include "nsRepeater.h" - -Repeater* Repeater::sRepeaters = 0; -Repeater* Repeater::sIdlers = 0; - -Repeater::Repeater() -{ - mRepeating = false; - mIdling = false; - mPrevRptr = 0; - mNextRptr = 0; - mPrevIdlr = 0; - mNextIdlr = 0; -} - -Repeater::~Repeater() -{ - if (mRepeating) RemoveFromRepeatList(); - if (mIdling) RemoveFromIdleList(); -} - -// protected helper functs - -//---------------------------------------------------------------------------- -void Repeater::AddToRepeatList() -{ - if (sRepeaters) - { - sRepeaters->mPrevRptr = this; - mNextRptr = sRepeaters; - } - sRepeaters = this; -} - -//---------------------------------------------------------------------------- -void Repeater::RemoveFromRepeatList() -{ - if (sRepeaters == this) sRepeaters = mNextRptr; - if (mPrevRptr) mPrevRptr->mNextRptr = mNextRptr; - if (mNextRptr) mNextRptr->mPrevRptr = mPrevRptr; - mPrevRptr = 0; - mNextRptr = 0; -} - -//---------------------------------------------------------------------------- -void Repeater::AddToIdleList() -{ - if (sIdlers) - { - sIdlers->mPrevIdlr = this; - mNextIdlr = sIdlers; - } - sIdlers = this; -} - -//---------------------------------------------------------------------------- -void Repeater::RemoveFromIdleList() -{ - if (sIdlers == this) sIdlers = mNextIdlr; - if (mPrevIdlr) mPrevIdlr->mNextIdlr = mNextIdlr; - if (mNextIdlr) mNextIdlr->mPrevIdlr = mPrevIdlr; - mPrevIdlr = 0; - mNextIdlr = 0; -} - -// repeater methods -//---------------------------------------------------------------------------- - -void Repeater::StartRepeating() -{ - if (!mRepeating) - { - AddToRepeatList(); - mRepeating = true; - } -} - -void Repeater::StopRepeating() -{ - if (mRepeating) - { - RemoveFromRepeatList(); - mRepeating = false; - } -} - -void Repeater::DoRepeaters(const EventRecord &aMacEvent) -{ - Repeater* theRepeater = sRepeaters; - while (theRepeater) - { - theRepeater->RepeatAction(aMacEvent); - theRepeater = theRepeater->mNextRptr; - } -} - -// idler methods - -void Repeater::StartIdling() -{ - if (!mIdling) - { - AddToIdleList(); - mIdling = true; - } -} - -void Repeater::StopIdling() -{ - if (mIdling) - { - RemoveFromIdleList(); - mIdling = false; - } -} - -void Repeater::DoIdlers(const EventRecord &aMacEvent) -{ - Repeater* theIdler = sIdlers; - while (theIdler) - { - theIdler->RepeatAction(aMacEvent); - theIdler = theIdler->mNextIdlr; - } -} - - - - diff --git a/mozilla/xpcom/base/MANIFEST b/mozilla/xpcom/base/MANIFEST deleted file mode 100644 index bdea888b0b6..00000000000 --- a/mozilla/xpcom/base/MANIFEST +++ /dev/null @@ -1,12 +0,0 @@ -nsAgg.h -nsIAllocator.h -nsCOMPtr.h -nsCom.h -nsDebug.h -nsError.h -nsID.h -nsIID.h -nsIPtr.h -nsISupportsUtils.h -nsTraceRefcnt.h -nscore.h diff --git a/mozilla/xpcom/components/MANIFEST b/mozilla/xpcom/components/MANIFEST deleted file mode 100644 index 7320b115b61..00000000000 --- a/mozilla/xpcom/components/MANIFEST +++ /dev/null @@ -1,8 +0,0 @@ -nsIComponentManager.h -nsIFactory.h -nsIGenericFactory.h -nsIRegistry.h -nsIServiceManager.h -nsIServiceProvider.h -nsRepository.h -nsXPComFactory.h diff --git a/mozilla/xpcom/ds/MANIFEST b/mozilla/xpcom/ds/MANIFEST deleted file mode 100644 index 19d7ace1828..00000000000 --- a/mozilla/xpcom/ds/MANIFEST +++ /dev/null @@ -1,32 +0,0 @@ -nsBTree.h -nsCRT.h -nsDeque.h -nsEnumeratorUtils.h -nsHashtable.h -nsIArena.h -nsIAtom.h -nsIBuffer.h -nsIByteBuffer.h -nsIObserver.h -nsIObserverList.h -nsIObserverService.h -nsIPageManager.h -nsIProperties.h -nsISimpleEnumerator.h -nsISizeOfHandler.h -nsIString.h -nsISupportsArray.h -nsIUnicharBuffer.h -nsIVariant.h -nsInt64.h -nsQuickSort.h -nsRBTree.h -nsStr.h -nsString.h -nsString2.h -nsTime.h -nsUnitConversion.h -nsVector.h -nsVoidArray.h -nsXPIDLString.h -plvector.h diff --git a/mozilla/xpcom/idl/nsIFileSpec.idl b/mozilla/xpcom/idl/nsIFileSpec.idl deleted file mode 100644 index f3101296473..00000000000 --- a/mozilla/xpcom/idl/nsIFileSpec.idl +++ /dev/null @@ -1,157 +0,0 @@ -/* -*- 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. - */ - -// This is the only correct cross-platform way to specify a file. -// Strings are not such a way. If you grew up on windows or unix, you -// may think they are. Welcome to reality. - -#include "nsISupports.idl" - -%{C++ -#include "nscore.h" // for NS_BASE - -// Start commenting out the C++ versions of the below in the output header -#if 0 -%} -[ref] native nsStringRef(nsString); -native StandardFilterMask(nsIFileSpec::StandardFilterMask); -%{C++ -// End commenting out the C++ versions of the above in the output header -#endif -%} - -interface nsIFileURL; -interface nsIFilePath; - -[scriptable, uuid(d8c0a080-0868-11d3-915f-d9d889d48e3c)] -interface nsIFileSpec : nsISupports -{ - void fromFileSpec([const] in nsIFileSpec original); -%{C++ - // - // The "choose" functions present the file picker UI in order to set the - // value of the file spec. -%} - void chooseOutputFile(in string windowTitle, in string suggestedLeafName); - -%{C++ - // The mask for standard filters is given as follows: - enum StandardFilterMask - { - eAllReadable = (1<<0) - , eHTMLFiles = (1<<1) - , eXMLFiles = (1<<2) - , eImageFiles = (1<<3) - , eAllFiles = (1<<4) - - // Mask containing all the above default filters - , eAllStandardFilters = ( - eAllReadable - | eHTMLFiles - | eXMLFiles - | eImageFiles - | eAllFiles) - - // The "extra filter" bit should be set if the "extra filter" - // is passed in to chooseInputFile. - , eExtraFilter = (1<<31) - }; - enum { kNumStandardFilters = 5 }; -%} - void chooseInputFile( - in string title - , in StandardFilterMask standardFilterMask - , in string extraFilterTitle - , in string extraFilter - ); - void chooseDirectory(in string title); - - attribute string URLString; - attribute string UnixStyleFilePath; - attribute string PersistentDescriptorString; - attribute string NativePath; - - readonly attribute string NSPRPath; - - void error(); - - boolean isValid(); - boolean failed(); - - attribute string LeafName; - - readonly attribute nsIFileSpec Parent; - - void makeUnique(); - void makeUniqueWithSuggestedName(in string suggestedName); - - readonly attribute unsigned long ModDate; - boolean modDateChanged(in unsigned long oldStamp); - - boolean isDirectory(); - boolean isFile(); - boolean exists(); - - readonly attribute unsigned long FileSize; - readonly attribute unsigned long DiskSpaceAvailable; - - void AppendRelativeUnixPath(in string relativePath); - - void createDir(); - void rename([const] in string newLeafName); - void copyToDir([const] in nsIFileSpec newParentDir); - void moveToDir([const] in nsIFileSpec newParentDir); - void execute([const] in string args); - - void openStreamForReading(); - void openStreamForWriting(); - void openStreamForReadingAndWriting(); - void closeStream(); - boolean isStreamOpen(); - - boolean eof(); - long read(inout string buffer, in long requestedCount); - void readLine(inout string line, in long bufferSize, out boolean wasTruncated); -%{C++ - // Check eof() before each call. - // CAUTION: false result only indicates line was truncated - // to fit buffer, or an error occurred (OTHER THAN eof). -%} - long write(in string data, in long requestedCount); - void flush(); - - void seek(in long offset); - long tell(); - void endline(); - -}; - -[scriptable, uuid(d8c0a083-0868-11d3-915f-d9d889d48e3c)] -interface nsIDirectoryIterator : nsISupports -{ - void Init(in nsIFileSpec parent); - boolean exists(); - void next(); - readonly attribute nsIFileSpec currentSpec; -}; - -%{C++ -// Factory methods -NS_BASE nsresult NS_NewFileSpec(nsIFileSpec** result); -NS_BASE nsresult NS_NewDirectoryIterator(nsIDirectoryIterator** result); -%} diff --git a/mozilla/xpcom/io/MANIFEST b/mozilla/xpcom/io/MANIFEST deleted file mode 100644 index 700dbf1c768..00000000000 --- a/mozilla/xpcom/io/MANIFEST +++ /dev/null @@ -1,13 +0,0 @@ -nsEscape.h -nsFileSpec.h -nsFileSpecStreaming.h -nsFileStream.h -nsIFileWidget.h -nsIBaseStream.h -nsIByteBufferInputStream.h -nsIFileStream.h -nsIInputStream.h -nsIOutputStream.h -nsIStringStream.h -nsIUnicharInputStream.h -nsSpecialSystemDirectory.h diff --git a/mozilla/xpcom/io/nsIFileSpec.idl b/mozilla/xpcom/io/nsIFileSpec.idl deleted file mode 100644 index 8ad2278ab4e..00000000000 --- a/mozilla/xpcom/io/nsIFileSpec.idl +++ /dev/null @@ -1,166 +0,0 @@ -/* -*- 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. - */ - -// This is the only correct cross-platform way to specify a file. -// Strings are not such a way. If you grew up on windows or unix, you -// may think they are. Welcome to reality. - -#include "nsISupports.idl" - -%{C++ -#include "nscore.h" // for NS_BASE - -// Start commenting out the C++ versions of the below in the output header -#if 0 -%} -[ref] native nsStringRef(nsString); -native StandardFilterMask(nsIFileSpec::StandardFilterMask); -%{C++ -// End commenting out the C++ versions of the above in the output header -#endif -%} - -interface nsIFileURL; -interface nsIFilePath; - -[scriptable, uuid(d8c0a080-0868-11d3-915f-d9d889d48e3c)] -interface nsIFileSpec : nsISupports -{ - void fromFileSpec([const] in nsIFileSpec original); -%{C++ -// File Widget stuff depends on widget/public/nsIWidget.h -// Until the following is moved out of xpcom/ ifdeffing it -// out. -#ifdef FILE_WIDGET_DEPENDENCY -%} -%{C++ - // - // The "choose" functions present the file picker UI in order to set the - // value of the file spec. -%} - void chooseOutputFile(in string windowTitle, in string suggestedLeafName); - -%{C++ - // The mask for standard filters is given as follows: - enum StandardFilterMask - { - eAllReadable = (1<<0) - , eHTMLFiles = (1<<1) - , eXMLFiles = (1<<2) - , eImageFiles = (1<<3) - , eAllFiles = (1<<4) - - // Mask containing all the above default filters - , eAllStandardFilters = ( - eAllReadable - | eHTMLFiles - | eXMLFiles - | eImageFiles - | eAllFiles) - - // The "extra filter" bit should be set if the "extra filter" - // is passed in to chooseInputFile. - , eExtraFilter = (1<<31) - }; - enum { kNumStandardFilters = 5 }; -%} - void chooseInputFile( - in string title - , in StandardFilterMask standardFilterMask - , in string extraFilterTitle - , in string extraFilter - ); - void chooseDirectory(in string title); -%{C++ -#endif /* FILE_WIDGET_DEPENDENCY */ -%} - - attribute string URLString; - attribute string UnixStyleFilePath; - attribute string PersistentDescriptorString; - attribute string NativePath; - - readonly attribute string NSPRPath; - - void error(); - - boolean isValid(); - boolean failed(); - - attribute string LeafName; - - readonly attribute nsIFileSpec Parent; - - void makeUnique(); - void makeUniqueWithSuggestedName(in string suggestedName); - - readonly attribute unsigned long ModDate; - boolean modDateChanged(in unsigned long oldStamp); - - boolean isDirectory(); - boolean isFile(); - boolean exists(); - - readonly attribute unsigned long FileSize; - readonly attribute unsigned long DiskSpaceAvailable; - - void AppendRelativeUnixPath(in string relativePath); - - void createDir(); - void rename([const] in string newLeafName); - void copyToDir([const] in nsIFileSpec newParentDir); - void moveToDir([const] in nsIFileSpec newParentDir); - void execute([const] in string args); - - void openStreamForReading(); - void openStreamForWriting(); - void openStreamForReadingAndWriting(); - void closeStream(); - boolean isStreamOpen(); - - boolean eof(); - long read(inout string buffer, in long requestedCount); - void readLine(inout string line, in long bufferSize, out boolean wasTruncated); -%{C++ - // Check eof() before each call. - // CAUTION: false result only indicates line was truncated - // to fit buffer, or an error occurred (OTHER THAN eof). -%} - long write(in string data, in long requestedCount); - void flush(); - - void seek(in long offset); - long tell(); - void endline(); - -}; - -[scriptable, uuid(d8c0a083-0868-11d3-915f-d9d889d48e3c)] -interface nsIDirectoryIterator : nsISupports -{ - void Init(in nsIFileSpec parent); - boolean exists(); - void next(); - readonly attribute nsIFileSpec currentSpec; -}; - -%{C++ -// Factory methods -NS_BASE nsresult NS_NewFileSpec(nsIFileSpec** result); -NS_BASE nsresult NS_NewDirectoryIterator(nsIDirectoryIterator** result); -%} diff --git a/mozilla/xpcom/io/nsIFileWidget.h b/mozilla/xpcom/io/nsIFileWidget.h deleted file mode 100644 index 5f263eb8498..00000000000 --- a/mozilla/xpcom/io/nsIFileWidget.h +++ /dev/null @@ -1,162 +0,0 @@ -/* -*- 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 nsIFileWidget_h__ -#define nsIFileWidget_h__ - -#include "nsString.h" -#include "nsFileSpec.h" - -class nsIWidget; -class nsIDeviceContext; -class nsIAppShell; -class nsIToolkit; - -// {F8030015-C342-11d1-97F0-00609703C14E} -#define NS_IFILEWIDGET_IID \ -{ 0xf8030015, 0xc342, 0x11d1, { 0x97, 0xf0, 0x0, 0x60, 0x97, 0x3, 0xc1, 0x4e } } - - -/** - * File selector mode - */ - -enum nsFileDlgMode { - /// Load a file or directory - eMode_load, - /// Save a file or directory - eMode_save, - /// Select a fodler/directory - eMode_getfolder - }; - - -enum nsFileDlgResults { - nsFileDlgResults_Cancel, // User hit cancel, ignore selection - nsFileDlgResults_OK, // User hit Ok, process selection - nsFileDlgResults_Replace // User acknowledged file already exists so ok to replace, process selection -}; - -/** - * File selector widget. - * Modally selects files for loading or saving from a list. - */ - -class nsIFileWidget : public nsISupports -{ - -public: - - - NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFILEWIDGET_IID) - - /** - * Create the file filter. This differs from the standard - * widget Create method because it passes in the mode - * - * @param aParent the parent to place this widget into - * @param aTitle The title for the file widget - * @param aMode load or save - * @return void - * - */ - NS_IMETHOD Create(nsIWidget *aParent, - const nsString& aTitle, - nsFileDlgMode aMode, - nsIDeviceContext *aContext = nsnull, - nsIAppShell *aAppShell = nsnull, - nsIToolkit *aToolkit = nsnull, - void *aInitData = nsnull) = 0; - - - /** - * Set the list of file filters - * - * @param aNumberOfFilter number of filters. - * @param aTitle array of filter titles - * @param aFilter array of filters to associate with titles - * @return void - * - */ - - NS_IMETHOD SetFilterList(PRUint32 aNumberOfFilters,const nsString aTitles[],const nsString aFilters[]) = 0; - - /** - * Show File Dialog. The dialog is displayed modally. - * - * @return PR_TRUE if user selects OK, PR_FALSE if user selects CANCEL - * - */ - - virtual PRBool Show() = 0; - - /** - * Get the nsFileSpec for the file or directory. - * - * @param aFile on exit it contains the file or directory selected - */ - - NS_IMETHOD GetFile(nsFileSpec& aFile) = 0; - - - /** - * Set the default string that appears in file open/save dialog - * - * @param aString the name of the file - * @return void - * - */ - NS_IMETHOD SetDefaultString(const nsString& aString) = 0; - - /** - * Set the directory that the file open/save dialog initially displays - * - * @param aDirectory the name of the directory - * @return void - * - */ - NS_IMETHOD SetDisplayDirectory(const nsFileSpec& aDirectory) = 0; - - /** - * Get the directory that the file open/save dialog was last displaying - * - * @param aDirectory the name of the directory - * @return void - * - */ - NS_IMETHOD GetDisplayDirectory(nsFileSpec& aDirectory) = 0; - - - virtual nsFileDlgResults GetFile( - nsIWidget * aParent, - const nsString & promptString, // Window title for the dialog - nsFileSpec & theFileSpec) = 0; // Populate with initial path for file dialog - - virtual nsFileDlgResults GetFolder( - nsIWidget * aParent, - const nsString & promptString, // Window title for the dialog - nsFileSpec & theFileSpec) = 0; // Populate with initial path for file dialog - - virtual nsFileDlgResults PutFile( - nsIWidget * aParent, - const nsString & promptString, // Window title for the dialog - nsFileSpec & theFileSpec) = 0; // Populate with initial path for file dialog -}; - -#endif // nsIFileWidget_h__ - diff --git a/mozilla/xpcom/macbuild/FilesTest.mcp b/mozilla/xpcom/macbuild/FilesTest.mcp deleted file mode 100644 index a1cd54affd8..00000000000 Binary files a/mozilla/xpcom/macbuild/FilesTest.mcp and /dev/null differ diff --git a/mozilla/xpcom/macbuild/files.prefix b/mozilla/xpcom/macbuild/files.prefix deleted file mode 100644 index e5eda421547..00000000000 --- a/mozilla/xpcom/macbuild/files.prefix +++ /dev/null @@ -1,19 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; 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. - */ - -#include "MacPrefix_debug.h" diff --git a/mozilla/xpcom/macbuild/filesDebug.prefix b/mozilla/xpcom/macbuild/filesDebug.prefix deleted file mode 100644 index e5eda421547..00000000000 --- a/mozilla/xpcom/macbuild/filesDebug.prefix +++ /dev/null @@ -1,19 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; 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. - */ - -#include "MacPrefix_debug.h" diff --git a/mozilla/xpcom/reflect/Makefile.in b/mozilla/xpcom/reflect/Makefile.in deleted file mode 100644 index 65b7e455ff6..00000000000 --- a/mozilla/xpcom/reflect/Makefile.in +++ /dev/null @@ -1,30 +0,0 @@ -#!gmake -# 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 = ../.. -topsrcdir = @top_srcdir@ -VPATH = @srcdir@ -srcdir = @srcdir@ - -include $(DEPTH)/config/autoconf.mk - -DIRS = xptinfo xptcall - -ifdef ENABLE_TESTS -DIRS += tests -endif - -include $(topsrcdir)/config/rules.mk diff --git a/mozilla/xpcom/threads/MANIFEST b/mozilla/xpcom/threads/MANIFEST deleted file mode 100644 index bd7400d1eed..00000000000 --- a/mozilla/xpcom/threads/MANIFEST +++ /dev/null @@ -1,4 +0,0 @@ -nsAutoLock.h -nsIEventQueue.h -nsIEventQueueService.h -nsIThread.h