зеркало из https://github.com/mozilla/pjs.git
Fix the qt timers.
This commit is contained in:
Родитель
4f5e4d5a8d
Коммит
d702007e37
|
@ -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
|
||||
|
|
|
@ -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 <qtimer.h>
|
||||
|
||||
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);
|
||||
}
|
|
@ -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 <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;
|
||||
};
|
||||
|
||||
#endif // __nsTimerEventHandler_h__
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/* -*- 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 "nsTimerQt.h"
|
||||
|
||||
#include <qtimer.h>
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID);
|
||||
|
||||
nsTimerQt::nsTimerQt()
|
||||
{
|
||||
//debug("nsTimerQt::nsTimerQt called for %p", this);
|
||||
NS_INIT_REFCNT();
|
||||
mFunc = nsnull;
|
||||
mCallback = nsnull;
|
||||
mNext = nsnull;
|
||||
mTimer = nsnull;
|
||||
mDelay = 0;
|
||||
mClosure = nsnull;
|
||||
mEventHandler = nsnull;
|
||||
}
|
||||
|
||||
nsTimerQt::~nsTimerQt()
|
||||
{
|
||||
//debug("nsTimerQt::~nsTimerQt called for %p", this);
|
||||
Cancel();
|
||||
NS_IF_RELEASE(mCallback);
|
||||
if (mEventHandler);
|
||||
{
|
||||
delete mEventHandler;
|
||||
}
|
||||
|
||||
if (mTimer)
|
||||
{
|
||||
delete mTimer;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsTimerQt::Init(nsTimerCallbackFunc aFunc,
|
||||
void *aClosure,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
//debug("nsTimerQt::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
|
||||
nsTimerQt::Init(nsITimerCallback *aCallback,
|
||||
// PRBool aRepeat,
|
||||
PRUint32 aDelay)
|
||||
{
|
||||
//debug("nsTimerQt::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
|
||||
nsTimerQt::Init(PRUint32 aDelay)
|
||||
{
|
||||
//debug("nsTimerQt::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(nsTimerQt, kITimerIID)
|
||||
|
||||
|
||||
void
|
||||
nsTimerQt::Cancel()
|
||||
{
|
||||
//debug("nsTimerQt::Cancel called for %p", this);
|
||||
if (mTimer)
|
||||
{
|
||||
mTimer->stop();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MOZ_MONOLITHIC_TOOLKIT
|
||||
nsresult NS_NewTimer(nsITimer** aInstancePtrResult)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
|
||||
if (nsnull == aInstancePtrResult)
|
||||
{
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
nsTimerQt *timer = new nsTimerQt();
|
||||
if (nsnull == timer)
|
||||
{
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult);
|
||||
}
|
||||
|
||||
int NS_TimeToNextTimeout(struct timeval *aTimer)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NS_ProcessTimeouts(void)
|
||||
{
|
||||
}
|
||||
#endif /* MOZ_MONOLITHIC_TOOLKIT */
|
|
@ -0,0 +1,69 @@
|
|||
/* -*- 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 __nsTimerQt_h__
|
||||
#define __nsTimerQt_h__
|
||||
|
||||
#include "nsTimerEventHandler.h"
|
||||
|
||||
/*
|
||||
* Implementation of timers using Qt QTimer class
|
||||
*/
|
||||
class nsTimerQt : public nsITimer
|
||||
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
nsTimerQt();
|
||||
virtual ~nsTimerQt();
|
||||
|
||||
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);
|
||||
|
||||
private:
|
||||
PRUint32 mDelay;
|
||||
nsTimerCallbackFunc mFunc;
|
||||
void * mClosure;
|
||||
nsITimerCallback * mCallback;
|
||||
PRBool mRepeat;
|
||||
nsTimerQt * mNext;
|
||||
QTimer * mTimer;
|
||||
nsTimerEventHandler * mEventHandler;
|
||||
};
|
||||
|
||||
#endif // __nsTimerQt_h__
|
||||
|
|
@ -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<nsIServiceManager>
|
||||
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<nsIServiceManager>
|
||||
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;
|
||||
}
|
Загрузка…
Ссылка в новой задаче