git-svn-id: svn://10.0.0.236/trunk@129037 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
dougt%netscape.com
2002-09-07 05:38:16 +00:00
parent 7f7e6c6d70
commit db8cc9c7ec
100 changed files with 680 additions and 671 deletions

View File

@@ -1,5 +1,4 @@
nsAutoLock.h
plevent.h
nsProcess.h
nsITimer.h
nsITimerCallback.h

View File

@@ -1,7 +1,8 @@
nsIRunnable.idl
nsIThread.idl
nsIThreadPool.idl
nsITimer.idl
nsITimerManager.idl
nsIEventQueue.idl
nsIEventQueueService.idl
nsIScriptableTimer.idl

View File

@@ -55,19 +55,18 @@ EXPORTS = \
nsAutoLock.h \
plevent.h \
nsProcess.h \
nsITimer.h \
nsITimerCallback.h \
$(NULL)
XPIDLSRCS = \
nsIThread.idl \
nsIThreadPool.idl \
nsITimer.idl \
nsITimerInternal.idl \
nsITimerManager.idl \
nsIRunnable.idl \
nsIEventQueue.idl \
nsIEventQueueService.idl \
nsIProcess.idl \
nsIScriptableTimer.idl \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

View File

@@ -1,94 +0,0 @@
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 2002
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Samir Gehani <sgehani@netscape.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsISupports.idl"
#include "nsIObserver.idl"
/* -----
* NOTE:
* -----
*
* This interface is a temporary measure till nsITimer is converted
* to IDL. The hope is that nsITimer will be converted by mozilla1.0.
* See: <http://bugzilla.mozilla.org/show_bug.cgi?id=120201#c18>
*/
[scriptable,uuid(84271f22-c023-4b01-8050-d71c0c6a6235)]
interface nsIScriptableTimer : nsISupports
{
/* Timer types */
const short TYPE_ONE_SHOT = 0;
const short TYPE_REPEATING_SLACK = 1;
const short TYPE_REPEATING_PRECISE = 2;
/**
* Initialize a timer that will fire after the said delay.
* A user must keep a reference to this timer till it is
* is no longer needed or has been cancelled.
*
* @param aObserver the callback object that observes the
* ``timer-callback'' topic with the subject being
* the timer itself when the timer fires:
*
* observe(nsISupports aSubject, => nsIScriptableTimer
* string aTopic, => ``timer-callback''
* wstring data => null
*
* @param aDelay delay in milliseconds for timer to fire
* @param aIdle whether the timer is an idle timer
* @param aType timer type per TYPE* consts defined above
*/
void init(in nsIObserver aObserver, in unsigned long aDelay,
in boolean aIdle, in unsigned long aType);
/**
* Cancellation of timers applies to repeating timers
* (i.e., init()ed with aType=TYPE_REPEATING*).
*/
void cancel();
};
%{C++
#ifndef NS_TIMER_CONTRACTID
#define NS_TIMER_CONTRACTID "@mozilla.org/timer;1"
#endif
#define NS_TIMER_CALLBACK_TOPIC "timer-callback"
%}

View File

@@ -1,164 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Stuart Parmenter <pavlov@netscape.com>
* Michael Lowe <michael.lowe@bigfoot.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef nsITimer_h___
#define nsITimer_h___
#include "nscore.h"
#include "nsISupports.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.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
* such as the Macintosh this means that callback functions must be called
* from the main event loop, NOT from an interrupt.
*/
// See nsITimerScriptable.idl for access to timer functionality from scripts.
// 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 types ---
enum nsTimerType {
/**
* Type of a timer that fires once only.
*/
NS_TYPE_ONE_SHOT = 0,
/**
* After firing, a NS_REPEATING_SLACK timer is stopped and not restarted
* until its callback completes. Specified timer period will be at least
* the time between when processing for last firing the callback completes
* and when the next firing occurs.
*
* This is the preferable repeating type for most situations.
*/
NS_TYPE_REPEATING_SLACK = 1,
/**
* An NS_REPEATING_PRECISE repeating timer aims to have constant period
* between firings. The processing time for each timer callback should not
* influence the timer period. However, if the processing for the last
* timer firing could not be completed until just before the next firing
* occurs, then you could have two timer notification routines being
* executed in quick succession.
*/
NS_TYPE_REPEATING_PRECISE = 2
};
#define REPEATING_TIMERS 1
/**
* Timer class, used to invoke a function or method after a fixed
* millisecond interval.
*/
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 aDelay - The millisecond interval
* @param aIdle - Whether this is an idle timer
* @param aType - The timer type : one shot or repeating
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD Init(nsTimerCallbackFunc aFunc,
void *aClosure,
PRUint32 aDelay,
PRBool aIdle = PR_TRUE,
PRUint32 aType = NS_TYPE_ONE_SHOT) = 0;
/**
* Initialize a timer to fire after the given millisecond interval.
* This version takes an interface of type <code>nsITimerCallback</code>.
* The <code>Notify</code> method of this method is invoked.
*
* @param aCallback - The interface to notify
* @param aDelay - The millisecond interval
* @param aIdle - Whether this is an idle timer
* @param aType - The timer type : one shot or repeating
* @result - NS_OK if this operation was successful
*/
NS_IMETHOD Init(nsITimerCallback *aCallback,
PRUint32 aDelay,
PRBool aIdle = PR_TRUE,
PRUint32 aType = NS_TYPE_ONE_SHOT) = 0;
/// Cancels the timeout
NS_IMETHOD Cancel() = 0;
/// @return true if the timer is an idle timer, false otherwise
NS_IMETHOD_(PRBool) IsIdle() const = 0;
/// @return the millisecond delay of the timeout
NS_IMETHOD_(PRUint32) GetDelay() const = 0;
/// Change the millisecond interval for the timeout
NS_IMETHOD_(void) SetDelay(PRUint32 aDelay) = 0;
NS_IMETHOD_(PRUint32) GetType() const = 0;
NS_IMETHOD_(void) SetType(PRUint32 aType) = 0;
/// @return the opaque pointer
NS_IMETHOD_(void*) GetClosure() const = 0;
};
extern NS_COM nsresult
NS_NewTimer(nsITimer* *aResult, nsTimerCallbackFunc aCallback, void *aClosure,
PRUint32 aDelay, PRBool aIdle, PRUint32 aType);
#endif // nsITimer_h___

View File

@@ -0,0 +1,178 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by the Initial Developer are
* Copyright (C) 2002 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*/
#include "nsISupports.idl"
interface nsIObserver;
%{C++
/**
* The signature of the timer callback function passed to initWithCallback. This
* is the function that will get called when the timer expires if the timer is
* initialized via initWithCallback.
*
* @param aTimer the timer which has expired
* @param aClosure opaque parameter passed to initWithCallback
*
* Implementers should return the following:
*
* @return NS_OK
*
*/
class nsITimer;
typedef void (*nsTimerCallbackFunc) (nsITimer *aTimer, void *aClosure);
%}
native nsTimerCallbackFunc(nsTimerCallbackFunc);
/**
* The callback interface for timers.
*/
interface nsITimer;
[scriptable, uuid(a796816d-7d47-4348-9ab8-c7aeb3216a7d)]
interface nsITimerCallback : nsISupports
{
/**
* @param aTimer the timer which has expired
*/
void notify(in nsITimer timer);
};
[scriptable, uuid(29ee628e-a3ea-471f-965d-dc9f11d1c183)]
interface nsITimer : nsISupports
{
/* Timer types */
/**
* Type of a timer that fires once only.
*/
const short TYPE_ONE_SHOT = 0;
/**
* After firing, a TYPE_REPEATING_SLACK timer is stopped and not restarted
* until its callback completes. Specified timer period will be at least
* the time between when processing for last firing the callback completes
* and when the next firing occurs.
*
* This is the preferable repeating type for most situations.
*/
const short TYPE_REPEATING_SLACK = 1;
/**
* An TYPE_REPEATING_PRECISE repeating timer aims to have constant period
* between firings. The processing time for each timer callback should not
* influence the timer period. However, if the processing for the last
* timer firing could not be completed until just before the next firing
* occurs, then you could have two timer notification routines being
* executed in quick succession.
*/
const short TYPE_REPEATING_PRECISE = 2;
/**
* Initialize a timer that will fire after the said delay.
* A user must keep a reference to this timer till it is
* is no longer needed or has been cancelled.
*
* @param aObserver the callback object that observes the
* ``timer-callback'' topic with the subject being
* the timer itself when the timer fires:
*
* observe(nsISupports aSubject, => nsITimer
* string aTopic, => ``timer-callback''
* wstring data => null
*
* @param aDelay delay in milliseconds for timer to fire
* @param aType timer type per TYPE* consts defined above
*/
void init(in nsIObserver aObserver, in unsigned long aDelay,
in unsigned long aType);
/**
* 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 aDelay The millisecond interval
* @param aType Timer type per TYPE* consts defined above
*/
[noscript] void initWithFuncCallback(in nsTimerCallbackFunc aCallback,
in voidPtr aClosure,
in unsigned long aDelay,
in unsigned long aType);
/**
* 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 nsITimerCallback interface to call when timer expires
* @param aDelay The millisecond interval
* @param aType Timer type per TYPE* consts defined above
*/
void initWithCallback(in nsITimerCallback aCallback,
in unsigned long aDelay,
in unsigned long aType);
/**
* Cancellation of timers applies to repeating timers
* (i.e., init()ed with aType=TYPE_REPEATING*).
*/
void cancel();
/**
* The millisecond delay of the timeout
*/
attribute unsigned long delay;
/**
* The timer type : one shot or repeating
*/
attribute unsigned long type;
/**
* The opaque pointer pass to initWithCallback.
*/
[noscript] readonly attribute voidPtr closure;
};
%{C++
#define NS_TIMER_CONTRACTID "@mozilla.org/timer;1"
#define NS_TIMER_CALLBACK_TOPIC "timer-callback"
%}

View File

@@ -1,63 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#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)
NS_IMETHOD_(void) Notify(nsITimer *timer) = 0;
};
#endif

View File

@@ -0,0 +1,43 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by the Initial Developer are
* Copyright (C) 2002 the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*/
#include "nsISupports.idl"
[scriptable, uuid(6dd8f185-ceb8-4878-8e38-2d13edc2d079)]
interface nsITimerInternal : nsISupports
{
attribute boolean idle;
};

View File

@@ -76,7 +76,7 @@ myNS_MeanAndStdDev(double n, double sumOfValues, double sumOfSquaredValues,
}
#endif
NS_IMPL_THREADSAFE_QUERY_INTERFACE2(nsTimerImpl, nsITimer, nsIScriptableTimer)
NS_IMPL_THREADSAFE_QUERY_INTERFACE2(nsTimerImpl, nsITimer, nsITimerInternal)
NS_IMPL_THREADSAFE_ADDREF(nsTimerImpl)
NS_IMETHODIMP_(nsrefcnt) nsTimerImpl::Release(void)
@@ -157,7 +157,8 @@ nsTimerImpl::nsTimerImpl() :
mFiring(PR_FALSE),
mArmed(PR_FALSE),
mCanceled(PR_FALSE),
mTimeout(0)
mTimeout(0),
mIdle(PR_TRUE)
{
NS_INIT_REFCNT();
nsIThread::GetCurrent(getter_AddRefs(mCallingThread));
@@ -204,11 +205,10 @@ void nsTimerImpl::Shutdown()
}
NS_IMETHODIMP nsTimerImpl::Init(nsTimerCallbackFunc aFunc,
void *aClosure,
PRUint32 aDelay,
PRBool aIdle,
PRUint32 aType)
NS_IMETHODIMP nsTimerImpl::InitWithFuncCallback(nsTimerCallbackFunc aFunc,
void *aClosure,
PRUint32 aDelay,
PRUint32 aType)
{
if (!gThread)
return NS_ERROR_FAILURE;
@@ -218,7 +218,6 @@ NS_IMETHODIMP nsTimerImpl::Init(nsTimerCallbackFunc aFunc,
mClosure = aClosure;
mIdle = aIdle;
mType = (PRUint8)aType;
SetDelayInternal(aDelay);
@@ -226,10 +225,9 @@ NS_IMETHODIMP nsTimerImpl::Init(nsTimerCallbackFunc aFunc,
return gThread->AddTimer(this);
}
NS_IMETHODIMP nsTimerImpl::Init(nsITimerCallback *aCallback,
PRUint32 aDelay,
PRBool aIdle,
PRUint32 aType)
NS_IMETHODIMP nsTimerImpl::InitWithCallback(nsITimerCallback *aCallback,
PRUint32 aDelay,
PRUint32 aType)
{
if (!gThread)
return NS_ERROR_FAILURE;
@@ -238,7 +236,6 @@ NS_IMETHODIMP nsTimerImpl::Init(nsITimerCallback *aCallback,
NS_ADDREF(mCallback.i);
mCallbackType = CALLBACK_TYPE_INTERFACE;
mIdle = aIdle;
mType = (PRUint8)aType;
SetDelayInternal(aDelay);
@@ -248,7 +245,6 @@ NS_IMETHODIMP nsTimerImpl::Init(nsITimerCallback *aCallback,
NS_IMETHODIMP nsTimerImpl::Init(nsIObserver *aObserver,
PRUint32 aDelay,
PRBool aIdle,
PRUint32 aType)
{
if (!gThread)
@@ -260,7 +256,6 @@ NS_IMETHODIMP nsTimerImpl::Init(nsIObserver *aObserver,
NS_ADDREF(mCallback.o);
mCallbackType = CALLBACK_TYPE_OBSERVER;
mIdle = aIdle;
mType = (PRUint8)aType;
return gThread->AddTimer(this);
@@ -276,25 +271,60 @@ NS_IMETHODIMP nsTimerImpl::Cancel()
return NS_OK;
}
NS_IMETHODIMP_(void) nsTimerImpl::SetDelay(PRUint32 aDelay)
NS_IMETHODIMP nsTimerImpl::SetDelay(PRUint32 aDelay)
{
// If we're already repeating precisely, update mTimeout now so that the
// new delay takes effect in the future.
if (mTimeout != 0 && mType == NS_TYPE_REPEATING_PRECISE)
if (mTimeout != 0 && mType == TYPE_REPEATING_PRECISE)
mTimeout = PR_IntervalNow();
SetDelayInternal(aDelay);
if (!mFiring && gThread)
gThread->TimerDelayChanged(this);
return NS_OK;
}
NS_IMETHODIMP_(void) nsTimerImpl::SetType(PRUint32 aType)
NS_IMETHODIMP nsTimerImpl::GetDelay(PRUint32* aDelay)
{
*aDelay = mDelay;
return NS_OK;
}
NS_IMETHODIMP nsTimerImpl::SetType(PRUint32 aType)
{
mType = (PRUint8)aType;
// XXX if this is called, we should change the actual type.. this could effect
// repeating timers. we need to ensure in Fire() that if mType has changed
// during the callback that we don't end up with the timer in the queue twice.
return NS_OK;
}
NS_IMETHODIMP nsTimerImpl::GetType(PRUint32* aType)
{
*aType = mType;
return NS_OK;
}
NS_IMETHODIMP nsTimerImpl::GetClosure(void** aClosure)
{
*aClosure = mClosure;
return NS_OK;
}
NS_IMETHODIMP nsTimerImpl::GetIdle(PRBool *aIdle)
{
*aIdle = mIdle;
return NS_OK;
}
NS_IMETHODIMP nsTimerImpl::SetIdle(PRBool aIdle)
{
mIdle = aIdle;
return NS_OK;
}
void nsTimerImpl::Fire()
@@ -323,7 +353,7 @@ void nsTimerImpl::Fire()
#endif
PRIntervalTime timeout = mTimeout;
if (mType == NS_TYPE_REPEATING_PRECISE) {
if (mType == TYPE_REPEATING_PRECISE) {
// Precise repeating timers advance mTimeout by mDelay without fail before
// calling Fire().
timeout -= PR_MillisecondsToInterval(mDelay);
@@ -340,7 +370,7 @@ void nsTimerImpl::Fire()
mCallback.i->Notify(this);
break;
case CALLBACK_TYPE_OBSERVER:
mCallback.o->Observe(NS_STATIC_CAST(nsIScriptableTimer *, this),
mCallback.o->Observe(NS_STATIC_CAST(nsITimer*,this),
NS_TIMER_CALLBACK_TOPIC,
nsnull);
break;
@@ -357,7 +387,7 @@ void nsTimerImpl::Fire()
}
#endif
if (mType == NS_TYPE_REPEATING_SLACK) {
if (mType == TYPE_REPEATING_SLACK) {
SetDelayInternal(mDelay); // force mTimeout to be recomputed.
if (gThread)
gThread->AddTimer(this);
@@ -386,7 +416,9 @@ void* handleTimerEvent(TimerEventType* event)
#endif
if (gFireOnIdle) {
if (NS_STATIC_CAST(nsTimerImpl*, event->e.owner)->IsIdle()) {
PRBool idle = PR_FALSE;
NS_STATIC_CAST(nsTimerImpl*, event->e.owner)->GetIdle(&idle);
if (idle) {
NS_ASSERTION(gManager, "Global Thread Manager is null!");
if (gManager)
gManager->AddIdleTimer(NS_STATIC_CAST(nsTimerImpl*, event->e.owner));
@@ -432,7 +464,7 @@ void nsTimerImpl::PostTimerEvent()
// If this is a repeating precise timer, we need to calculate the time for
// the next timer to fire before we make the callback.
if (mType == NS_TYPE_REPEATING_PRECISE) {
if (mType == TYPE_REPEATING_PRECISE) {
SetDelayInternal(mDelay);
if (gThread)
gThread->AddTimer(this);
@@ -459,7 +491,7 @@ void nsTimerImpl::SetDelayInternal(PRUint32 aDelay)
mDelay = aDelay;
PRIntervalTime now = PR_IntervalNow();
if (mTimeout == 0 || mType != NS_TYPE_REPEATING_PRECISE)
if (mTimeout == 0 || mType != TYPE_REPEATING_PRECISE)
mTimeout = now;
mTimeout += delayInterval;
@@ -474,26 +506,6 @@ void nsTimerImpl::SetDelayInternal(PRUint32 aDelay)
#endif
}
nsresult
NS_NewTimer(nsITimer* *aResult, nsTimerCallbackFunc aCallback, void *aClosure,
PRUint32 aDelay, PRBool aIdle, PRUint32 aType)
{
nsTimerImpl* timer = new nsTimerImpl();
if (timer == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(timer);
nsresult rv = timer->Init(aCallback, aClosure, aDelay, aIdle, aType);
if (NS_FAILED(rv)) {
NS_RELEASE(timer);
return rv;
}
*aResult = timer;
return NS_OK;
}
/**
* Timer Manager code
*/
@@ -580,3 +592,25 @@ NS_IMETHODIMP nsTimerManager::FireNextIdleTimer()
return NS_OK;
}
// NOT FOR PUBLIC CONSUMPTION!
nsresult
NS_NewTimer(nsITimer* *aResult, nsTimerCallbackFunc aCallback, void *aClosure,
PRUint32 aDelay, PRUint32 aType)
{
nsTimerImpl* timer = new nsTimerImpl();
if (timer == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(timer);
nsresult rv = timer->InitWithFuncCallback(aCallback, aClosure,
aDelay, aType);
if (NS_FAILED(rv)) {
NS_RELEASE(timer);
return rv;
}
*aResult = timer;
return NS_OK;
}

View File

@@ -36,15 +36,12 @@
#ifndef nsTimerImpl_h___
#define nsTimerImpl_h___
#define NS_TIMER_CONTRACTID "@mozilla.org/timer;1"
//#define FORCE_PR_LOG /* Allow logging in the release build */
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "nsIScriptableTimer.h"
#include "nsVoidArray.h"
#include "nsIThread.h"
#include "nsITimerInternal.h"
#include "nsCOMPtr.h"
@@ -82,7 +79,7 @@ enum {
// Is interval-time t less than u, even if t has wrapped PRIntervalTime?
#define TIMER_LESS_THAN(t, u) ((t) - (u) > DELAY_INTERVAL_LIMIT)
class nsTimerImpl : public nsITimer, public nsIScriptableTimer
class nsTimerImpl : public nsITimer, public nsITimerInternal
{
public:
@@ -97,29 +94,9 @@ public:
void PostTimerEvent();
void SetDelayInternal(PRUint32 aDelay);
NS_IMETHOD Init(nsTimerCallbackFunc aFunc,
void *aClosure,
PRUint32 aDelay,
PRBool aIdle,
PRUint32 aType);
NS_IMETHOD Init(nsITimerCallback *aCallback,
PRUint32 aDelay,
PRBool aIdle,
PRUint32 aType);
NS_DECL_ISUPPORTS
NS_DECL_NSISCRIPTABLETIMER
NS_IMETHOD_(PRBool) IsIdle() const { return mIdle; }
NS_IMETHOD_(PRUint32) GetDelay() const { return mDelay; }
NS_IMETHOD_(void) SetDelay(PRUint32 aDelay);
NS_IMETHOD_(PRUint32) GetType() const { return (PRUint32)mType; }
NS_IMETHOD_(void) SetType(PRUint32 aType);
NS_IMETHOD_(void*) GetClosure() const { return mClosure; }
NS_DECL_NSITIMER
NS_DECL_NSITIMERINTERNAL
private:
nsCOMPtr<nsIThread> mCallingThread;