This commit is contained in:
ramiro%netscape.com 1999-08-17 06:56:13 +00:00
Родитель 5adada7765
Коммит 9b64a66483
7 изменённых файлов: 335 добавлений и 94 удалений

Просмотреть файл

@ -0,0 +1,2 @@
Makefile
moc_nsTimerEventHandler.cpp

Просмотреть файл

@ -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__

Просмотреть файл

@ -16,47 +16,17 @@
* Reserved.
*/
#include "nsCRT.h"
#include "prlog.h"
#include <stdio.h>
#include <limits.h>
#include "nsTimerQT.h"
#include "nsTimerQt.h"
#include <qtimer.h>
#include <stdio.h>
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 */

Просмотреть файл

@ -16,44 +16,22 @@
* Reserved.
*/
#include "nsITimer.h"
#include "nsITimerCallback.h"
#ifndef __nsTimerQt_h__
#define __nsTimerQt_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;
};
#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__

Просмотреть файл

@ -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;
}