Remove obsolote files.
git-svn-id: svn://10.0.0.236/trunk@40885 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -1,198 +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 "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prlog.h"
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
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;
|
||||
|
||||
// This is ancient debug code that is making it impossible to have timeouts
|
||||
// greater than 10 seconds. -re
|
||||
|
||||
// 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;
|
||||
|
||||
// This is ancient debug code that is making it impossible to have timeouts
|
||||
// greater than 10 seconds. -re
|
||||
|
||||
// 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_GFXNONXP 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;
|
||||
}
|
||||
@@ -1,173 +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 "nsITimer.h"
|
||||
#include "nsITimerCallback.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prlog.h"
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include <X11/Intrinsic.h>
|
||||
|
||||
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.
|
||||
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();
|
||||
}
|
||||
@@ -1,295 +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 <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#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);
|
||||
}
|
||||
Reference in New Issue
Block a user