Initial version of qt timer files. Did just enough work to get it to work.

git-svn-id: svn://10.0.0.236/trunk@43217 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
shawnp%earthling.net 1999-08-12 02:33:43 +00:00
parent 736f86d880
commit eeb33fbc83
3 changed files with 316 additions and 0 deletions

View File

@ -0,0 +1,47 @@
#!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@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
LIBRARY_NAME = $(TIMER_LIB_NAME)
### XXX ### IS_COMPONENT=1
REQUIRES=xpcom
DEFINES += -D_IMPL_NS_TIMER
CXXFLAGS += $(TK_CFLAGS)
INCLUDES += $(TK_CFLAGS) -I$(srcdir)/..
CPPSRCS = \
nsTimerQT.cpp \
moc_nsTimerQT.cpp \
$(NULL)
### XXX ### EXTRA_DSO_LDOPTS += $(TK_LIBS)
MKSHLIB =
override NO_SHARED_LIB=1
override NO_STATIC_LIB=
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,180 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsCRT.h"
#include "prlog.h"
#include <stdio.h>
#include <limits.h>
#include "nsTimerQT.h"
#include <qtimer.h>
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
nsTimerEventHandler::nsTimerEventHandler(nsITimer * aTimer,
nsTimerCallbackFunc aFunc,
void *aClosure,
nsITimerCallback *aCallback)
{
mTimer = aTimer;
mFunc = aFunc;
mClosure = aClosure;
mCallback = aCallback;
}
void nsTimerEventHandler::FireTimeout()
{
//debug("nsTimerEventHandler::FireTimeout called");
if (mFunc != NULL)
{
(*mFunc)(mTimer, mClosure);
}
else if (mCallback != NULL)
{
mCallback->Notify(mTimer); // Fire the timer
}
// Always repeating here
// if (mRepeat)
// mTimerId = gtk_timeout_add(aDelay, nsTimerExpired, this);
}
TimerImpl::TimerImpl() //: QObject()
{
//debug("TimerImpl::TimerImpl called for %p", this);
NS_INIT_REFCNT();
mFunc = nsnull;
mCallback = nsnull;
mNext = nsnull;
mTimer = nsnull;
mDelay = 0;
mClosure = nsnull;
mEventHandler = nsnull;
}
TimerImpl::~TimerImpl()
{
//debug("TimerImpl::~TimerImpl called for %p", this);
Cancel();
NS_IF_RELEASE(mCallback);
if (mEventHandler);
{
delete mEventHandler;
}
if (mTimer)
{
delete mTimer;
}
}
nsresult
TimerImpl::Init(nsTimerCallbackFunc aFunc,
void *aClosure,
// PRBool aRepeat,
PRUint32 aDelay)
{
//debug("TimerImpl::Init called with func + closure with %u delay", aDelay);
mFunc = aFunc;
mClosure = aClosure;
// mRepeat = aRepeat;
if ((aDelay > 10000) || (aDelay < 0))
{
printf("Timer::Init() called with bogus value \"%d\"! Not enabling timer.",
aDelay);
return Init(aDelay);
}
return Init(aDelay);
}
nsresult
TimerImpl::Init(nsITimerCallback *aCallback,
// PRBool aRepeat,
PRUint32 aDelay)
{
//debug("TimerImpl::Init called with callback only with %u delay", aDelay);
mCallback = aCallback;
NS_ADDREF(mCallback);
// mRepeat = aRepeat;
if ((aDelay > 10000) || (aDelay < 0))
{
printf("Timer::Init() called with bogus value \"%d\"! Not enabling timer.",
aDelay);
return NS_OK;
//return Init(aDelay);
}
return Init(aDelay);
}
nsresult
TimerImpl::Init(PRUint32 aDelay)
{
//debug("TimerImpl::Init called with delay %d only for %p", aDelay, this);
mEventHandler = new nsTimerEventHandler(this, mFunc, mClosure, mCallback);
mTimer = new QTimer();
if (!mTimer)
{
return NS_ERROR_NOT_INITIALIZED;
}
QObject::connect((QTimer *)mTimer,
SIGNAL(timeout()),
mEventHandler,
SLOT(FireTimeout()));
mTimer->start(aDelay);
mDelay = aDelay;
//NS_ADDREF(this);
return NS_OK;
}
NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID)
void
TimerImpl::Cancel()
{
//debug("TimerImpl::Cancel called for %p", this);
if (mTimer)
{
mTimer->stop();
}
}
NS_BASE 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);
}

View File

@ -0,0 +1,89 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include <qobject.h>
class nsTimerEventHandler : public QObject
{
Q_OBJECT
public:
nsTimerEventHandler(nsITimer * aTimer,
nsTimerCallbackFunc aFunc,
void *aClosure,
nsITimerCallback *aCallback);
public slots:
void FireTimeout();
private:
nsTimerCallbackFunc mFunc;
void * mClosure;
nsITimerCallback * mCallback;
nsITimer * mTimer;
};
/*
* Implementation of timers using Qt QTimer class
*/
class TimerImpl : //public QObject,
public nsITimer
{
// Q_OBJECT
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; }
//public slots:
void FireTimeout();
private:
nsresult Init(PRUint32 aDelay);
private:
PRUint32 mDelay;
nsTimerCallbackFunc mFunc;
void * mClosure;
nsITimerCallback * mCallback;
PRBool mRepeat;
TimerImpl * mNext;
QTimer * mTimer;
nsTimerEventHandler * mEventHandler;
};