From 9b64a66483b2776f3e283c70a9a53ae6d70a0730 Mon Sep 17 00:00:00 2001 From: "ramiro%netscape.com" Date: Tue, 17 Aug 1999 06:56:13 +0000 Subject: [PATCH] Fix the qt timers. --- widget/timer/src/unix/qt/.cvsignore | 2 + widget/timer/src/unix/qt/Makefile.in | 39 ++-- .../timer/src/unix/qt/nsTimerEventHandler.cpp | 50 ++++++ .../timer/src/unix/qt/nsTimerEventHandler.h | 48 +++++ .../unix/qt/{nsTimerQT.cpp => nsTimerQt.cpp} | 81 ++++----- .../src/unix/qt/{nsTimerQT.h => nsTimerQt.h} | 42 ++--- widget/timer/src/unix/qt/nsTimerQtFactory.cpp | 167 ++++++++++++++++++ 7 files changed, 335 insertions(+), 94 deletions(-) create mode 100644 widget/timer/src/unix/qt/.cvsignore create mode 100644 widget/timer/src/unix/qt/nsTimerEventHandler.cpp create mode 100644 widget/timer/src/unix/qt/nsTimerEventHandler.h rename widget/timer/src/unix/qt/{nsTimerQT.cpp => nsTimerQt.cpp} (65%) rename widget/timer/src/unix/qt/{nsTimerQT.h => nsTimerQt.h} (71%) create mode 100644 widget/timer/src/unix/qt/nsTimerQtFactory.cpp diff --git a/widget/timer/src/unix/qt/.cvsignore b/widget/timer/src/unix/qt/.cvsignore new file mode 100644 index 000000000000..2c5d631a3d96 --- /dev/null +++ b/widget/timer/src/unix/qt/.cvsignore @@ -0,0 +1,2 @@ +Makefile +moc_nsTimerEventHandler.cpp diff --git a/widget/timer/src/unix/qt/Makefile.in b/widget/timer/src/unix/qt/Makefile.in index 8a6809aa453b..ac323cc1a3e6 100644 --- a/widget/timer/src/unix/qt/Makefile.in +++ b/widget/timer/src/unix/qt/Makefile.in @@ -24,24 +24,37 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/config.mk +ifndef MOZ_MONOLITHIC_TOOLKIT + +LIBRARY_NAME = timer_qt +IS_COMPONENT = 1 +REQUIRES = xpcom +INCLUDES += $(MOZ_QT_CFLAGS) -I$(srcdir)/.. + +CPPSRCS = \ + moc_nsTimerEventHandler.cpp \ + nsTimerEventHandler.cpp \ + nsTimerQt.cpp \ + nsTimerQtFactory.cpp \ + $(NULL) + +EXTRA_DSO_LDOPTS += $(MOZ_QT_LDFLAGS) + +else + LIBRARY_NAME = $(TIMER_LIB_NAME) -### XXX ### IS_COMPONENT=1 - -REQUIRES=xpcom - -DEFINES += -D_IMPL_NS_TIMER +REQUIRES = xpcom CXXFLAGS += $(TK_CFLAGS) INCLUDES += $(TK_CFLAGS) -I$(srcdir)/.. - -CPPSRCS = \ - nsTimerQT.cpp \ - moc_nsTimerQT.cpp \ - $(NULL) - -### XXX ### EXTRA_DSO_LDOPTS += $(TK_LIBS) - +CPPSRCS =\ + moc_nsTimerEventHandler.cpp \ + nsTimerEventHandler.cpp \ + nsTimerQt.cpp \ + $(NULL) MKSHLIB = override NO_SHARED_LIB=1 override NO_STATIC_LIB= +endif # !MOZ_MONOLITHIC_TOOLKIT + include $(topsrcdir)/config/rules.mk diff --git a/widget/timer/src/unix/qt/nsTimerEventHandler.cpp b/widget/timer/src/unix/qt/nsTimerEventHandler.cpp new file mode 100644 index 000000000000..5bd0f4fe81f3 --- /dev/null +++ b/widget/timer/src/unix/qt/nsTimerEventHandler.cpp @@ -0,0 +1,50 @@ +/* -*- 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 "nsTimerEventHandler.h" + +#include + +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); +} diff --git a/widget/timer/src/unix/qt/nsTimerEventHandler.h b/widget/timer/src/unix/qt/nsTimerEventHandler.h new file mode 100644 index 000000000000..44d510affbb5 --- /dev/null +++ b/widget/timer/src/unix/qt/nsTimerEventHandler.h @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef __nsTimerEventHandler_h__ +#define __nsTimerEventHandler_h__ + +#include "nsITimer.h" +#include "nsITimerCallback.h" + +#include + +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; +}; + +#endif // __nsTimerEventHandler_h__ + diff --git a/widget/timer/src/unix/qt/nsTimerQT.cpp b/widget/timer/src/unix/qt/nsTimerQt.cpp similarity index 65% rename from widget/timer/src/unix/qt/nsTimerQT.cpp rename to widget/timer/src/unix/qt/nsTimerQt.cpp index 34b9942fbfd1..0501fdb328d7 100644 --- a/widget/timer/src/unix/qt/nsTimerQT.cpp +++ b/widget/timer/src/unix/qt/nsTimerQt.cpp @@ -16,47 +16,17 @@ * Reserved. */ -#include "nsCRT.h" -#include "prlog.h" -#include -#include -#include "nsTimerQT.h" +#include "nsTimerQt.h" + #include +#include + static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); -nsTimerEventHandler::nsTimerEventHandler(nsITimer * aTimer, - nsTimerCallbackFunc aFunc, - void *aClosure, - nsITimerCallback *aCallback) +nsTimerQt::nsTimerQt() { - 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); + //debug("nsTimerQt::nsTimerQt called for %p", this); NS_INIT_REFCNT(); mFunc = nsnull; mCallback = nsnull; @@ -67,9 +37,9 @@ TimerImpl::TimerImpl() //: QObject() mEventHandler = nsnull; } -TimerImpl::~TimerImpl() +nsTimerQt::~nsTimerQt() { - //debug("TimerImpl::~TimerImpl called for %p", this); + //debug("nsTimerQt::~nsTimerQt called for %p", this); Cancel(); NS_IF_RELEASE(mCallback); if (mEventHandler); @@ -84,12 +54,12 @@ TimerImpl::~TimerImpl() } nsresult -TimerImpl::Init(nsTimerCallbackFunc aFunc, +nsTimerQt::Init(nsTimerCallbackFunc aFunc, void *aClosure, // PRBool aRepeat, PRUint32 aDelay) { - //debug("TimerImpl::Init called with func + closure with %u delay", aDelay); + //debug("nsTimerQt::Init called with func + closure with %u delay", aDelay); mFunc = aFunc; mClosure = aClosure; // mRepeat = aRepeat; @@ -105,11 +75,11 @@ TimerImpl::Init(nsTimerCallbackFunc aFunc, } nsresult -TimerImpl::Init(nsITimerCallback *aCallback, +nsTimerQt::Init(nsITimerCallback *aCallback, // PRBool aRepeat, PRUint32 aDelay) { - //debug("TimerImpl::Init called with callback only with %u delay", aDelay); + //debug("nsTimerQt::Init called with callback only with %u delay", aDelay); mCallback = aCallback; NS_ADDREF(mCallback); // mRepeat = aRepeat; @@ -125,9 +95,9 @@ TimerImpl::Init(nsITimerCallback *aCallback, } nsresult -TimerImpl::Init(PRUint32 aDelay) +nsTimerQt::Init(PRUint32 aDelay) { - //debug("TimerImpl::Init called with delay %d only for %p", aDelay, this); + //debug("nsTimerQt::Init called with delay %d only for %p", aDelay, this); mEventHandler = new nsTimerEventHandler(this, mFunc, mClosure, mCallback); @@ -144,25 +114,26 @@ TimerImpl::Init(PRUint32 aDelay) mTimer->start(aDelay); mDelay = aDelay; - //NS_ADDREF(this); + NS_ADDREF(this); return NS_OK; } -NS_IMPL_ISUPPORTS(TimerImpl, kITimerIID) +NS_IMPL_ISUPPORTS(nsTimerQt, kITimerIID) void -TimerImpl::Cancel() +nsTimerQt::Cancel() { - //debug("TimerImpl::Cancel called for %p", this); + //debug("nsTimerQt::Cancel called for %p", this); if (mTimer) { mTimer->stop(); } } -NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult) +#ifdef MOZ_MONOLITHIC_TOOLKIT +nsresult NS_NewTimer(nsITimer** aInstancePtrResult) { NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); if (nsnull == aInstancePtrResult) @@ -170,7 +141,7 @@ NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult) return NS_ERROR_NULL_POINTER; } - TimerImpl *timer = new TimerImpl(); + nsTimerQt *timer = new nsTimerQt(); if (nsnull == timer) { return NS_ERROR_OUT_OF_MEMORY; @@ -178,3 +149,13 @@ NS_BASE nsresult NS_NewTimer(nsITimer** aInstancePtrResult) return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); } + +int NS_TimeToNextTimeout(struct timeval *aTimer) +{ + return 0; +} + +void NS_ProcessTimeouts(void) +{ +} +#endif /* MOZ_MONOLITHIC_TOOLKIT */ diff --git a/widget/timer/src/unix/qt/nsTimerQT.h b/widget/timer/src/unix/qt/nsTimerQt.h similarity index 71% rename from widget/timer/src/unix/qt/nsTimerQT.h rename to widget/timer/src/unix/qt/nsTimerQt.h index 77a70b51c871..be808a3f1f5c 100644 --- a/widget/timer/src/unix/qt/nsTimerQT.h +++ b/widget/timer/src/unix/qt/nsTimerQt.h @@ -16,44 +16,22 @@ * Reserved. */ -#include "nsITimer.h" -#include "nsITimerCallback.h" +#ifndef __nsTimerQt_h__ +#define __nsTimerQt_h__ - -#include - -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; -}; +#include "nsTimerEventHandler.h" /* * Implementation of timers using Qt QTimer class */ -class TimerImpl : //public QObject, - public nsITimer +class nsTimerQt : public nsITimer { -// Q_OBJECT public: -public: - TimerImpl(); - virtual ~TimerImpl(); + + nsTimerQt(); + virtual ~nsTimerQt(); virtual nsresult Init(nsTimerCallbackFunc aFunc, void *aClosure, @@ -71,7 +49,6 @@ public: virtual void SetDelay(PRUint32 aDelay) { mDelay=aDelay; }; virtual void* GetClosure() { return mClosure; } -//public slots: void FireTimeout(); private: @@ -83,7 +60,10 @@ private: void * mClosure; nsITimerCallback * mCallback; PRBool mRepeat; - TimerImpl * mNext; + nsTimerQt * mNext; QTimer * mTimer; nsTimerEventHandler * mEventHandler; }; + +#endif // __nsTimerQt_h__ + diff --git a/widget/timer/src/unix/qt/nsTimerQtFactory.cpp b/widget/timer/src/unix/qt/nsTimerQtFactory.cpp new file mode 100644 index 000000000000..e0f0ceb2f626 --- /dev/null +++ b/widget/timer/src/unix/qt/nsTimerQtFactory.cpp @@ -0,0 +1,167 @@ +/* -*- Mode: C++; tab-width: 2; indentT-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 "nsTimerQt.h" + +#include "nsUnixTimerCIID.h" + +#include "nsIFactory.h" +#include "nsIComponentManager.h" +#include "nsIServiceManager.h" +#include "nsCOMPtr.h" + +static NS_DEFINE_CID(kCTimerQt, NS_TIMER_QT_CID); +static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); + +class nsTimerQtFactory : public nsIFactory +{ +public: + NS_DECL_ISUPPORTS + + NS_IMETHOD CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult); + + NS_IMETHOD LockFactory(PRBool aLock); + + nsTimerQtFactory(const nsCID &aClass); + virtual ~nsTimerQtFactory(); + +private: + nsCID mClassID; + +}; + +nsTimerQtFactory::nsTimerQtFactory(const nsCID &aClass) : + mRefCnt(0), + mClassID(aClass) +{ +} + +nsTimerQtFactory::~nsTimerQtFactory() +{ + NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction"); +} + +NS_IMPL_ISUPPORTS(nsTimerQtFactory, nsIFactory::GetIID()) + + +NS_IMETHODIMP +nsTimerQtFactory::CreateInstance(nsISupports *aOuter, + const nsIID &aIID, + void **aResult) +{ + if (aResult == nsnull) + return NS_ERROR_NULL_POINTER; + + *aResult = nsnull; + + nsISupports *inst = nsnull; + + if (mClassID.Equals(kCTimerQt)) + { + inst = (nsISupports *)(nsTimerQt *) new nsTimerQt(); + } + + if (inst == nsnull) + return NS_ERROR_OUT_OF_MEMORY; + + nsresult rv = inst->QueryInterface(aIID, aResult); + + if (rv != NS_OK) + delete inst; + + return rv; +} + +nsresult nsTimerQtFactory::LockFactory(PRBool aLock) +{ + // Not implemented in simplest case. + return NS_OK; +} + +nsresult +NSGetFactory(nsISupports* servMgr, + const nsCID &aClass, + const char *aClassName, + const char *aProgID, + nsIFactory **aFactory) +{ + if (nsnull == aFactory) { + return NS_ERROR_NULL_POINTER; + } + + *aFactory = new nsTimerQtFactory(aClass); + + if (nsnull == aFactory) { + return NS_ERROR_OUT_OF_MEMORY; + } + + return (*aFactory)->QueryInterface(nsIFactory::GetIID(), (void**)aFactory); + +} + +PRBool +NSCanUnload(nsISupports* aServMgr) +{ + return PR_FALSE; +} + +nsresult +NSRegisterSelf(nsISupports* aServMgr, const char *fullpath) +{ + nsresult rv; + +#ifdef NS_DEBUG + printf("*** Registering QT timer\n"); +#endif + + nsCOMPtr + serviceManager(do_QueryInterface(aServMgr, &rv)); + if (NS_FAILED(rv)) return rv; + + NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv); + if (NS_FAILED(rv)) return rv; + + rv = compMgr->RegisterComponent(kCTimerQt, + "QT timer", + "component://netscape/timer/unix/qt", + fullpath, + PR_TRUE, + PR_TRUE); + + return rv; +} + +nsresult +NSUnregisterSelf(nsISupports* aServMgr, const char *fullpath) +{ + + nsresult rv; + nsCOMPtr + serviceManager(do_QueryInterface(aServMgr, &rv)); + if (NS_FAILED(rv)) return rv; + + NS_WITH_SERVICE(nsIComponentManager, compMgr, kComponentManagerCID, &rv); + if (NS_FAILED(rv)) return rv; + + compMgr->UnregisterComponent(kCTimerQt, fullpath); + + return NS_OK; +}