diff --git a/config/autoconf.mk.in b/config/autoconf.mk.in index 7391047531db..c50e74070748 100644 --- a/config/autoconf.mk.in +++ b/config/autoconf.mk.in @@ -37,7 +37,6 @@ USE_NSPR_AUTOCONF = @USE_NSPR_AUTOCONF@ ### XXX ### BROKEN MOZ_XLIBRGB_LDFLAGS = @MOZ_XLIBRGB_LDFLAGS@ ### XXX ### BROKEN MOZ_USING_XLIBRGB = @MOZ_USING_XLIBRGB@ -MOZ_TIMER_LIBS = @MOZ_TIMER_LIBS@ MOZ_JS_LIBS = @MOZ_JS_LIBS@ MOZ_REGISTRY_LIBS = $(DIST)/lib/libmozreg_s.$(LIB_SUFFIX) MOZ_WIDGET_SUPPORT_LIBS = $(DIST)/lib/libwidgetsupport_s.$(LIB_SUFFIX) diff --git a/configure.in b/configure.in index 02d353a25caa..6f22f1456836 100644 --- a/configure.in +++ b/configure.in @@ -352,7 +352,6 @@ MOZ_ZLIB_LIBS='$(DIST)/lib/libzlib.$(LIB_SUFFIX)' MOZ_PNG_CFLAGS= MOZ_PNG_LIBS='$(DIST)/lib/libpng.$(LIB_SUFFIX)' -MOZ_TIMER_LIBS='$(DIST)/lib/libtimer_s.$(LIB_SUFFIX)' MOZ_JS_LIBS='-lmozjs' XPCOM_LIBS='-L$(DIST)/bin -lxpcom' @@ -544,7 +543,6 @@ case "$target" in MKSHLIB='$(CXX) $(CXXFLAGS) $(DSO_LDOPTS) -o $@' DSO_LDOPTS='-nostart -Wl,-h -Wl,$@' TK_LIBS='-lbe -lroot' - MOZ_TIMER_LIBS='$(DIST)/lib/libtimer_beos.so' LIBS="$LIBS -lbe" _WARNINGS_CFLAGS="${_WARNINGS_CFLAGS} -Wno-multichar" _WARNINGS_CXXFLAGS="${_WARNINGS_CXXFLAGS} -Wno-multichar -Wno-ctor-dtor-privacy" @@ -782,7 +780,6 @@ case "$target" in MOZ_ZLIB_LIBS='$(DIST)/lib/zlib.$(LIB_SUFFIX)' MOZ_PNG_LIBS='$(DIST)/lib/png.$(LIB_SUFFIX)' MOZ_JS_LIBS='$(DIST)/lib/mozjs.lib' - MOZ_TIMER_LIBS='$(DIST)/lib/timer.lib' case "$target" in *-*-os2_emx) @@ -866,7 +863,6 @@ alpha*-*-osf*) AC_DEFINE(TARGET_CARBON) AC_DEFINE(TARGET_API_MAC_CARBON) ENABLE_TESTS= - MOZ_TIMER_LIBS='$(DIST)/lib/libtimer_mac.dylib' MOZ_WIDGET_TOOLKIT='mac' TK_LIBS='/System/Library/Frameworks/Carbon.framework/Carbon' CFLAGS="$CFLAGS -traditional-cpp -fno-common -I/System/Library/Frameworks/Carbon.framework/Headers" diff --git a/widget/timer/public/nsITimer.h b/widget/timer/public/nsITimer.h index 16fadd5bcad2..583294f43cbf 100644 --- a/widget/timer/public/nsITimer.h +++ b/widget/timer/public/nsITimer.h @@ -25,6 +25,8 @@ #include "nscore.h" #include "nsISupports.h" +#include "nsCOMPtr.h" +#include "nsIComponentManager.h" class nsITimer; class nsITimerCallback; @@ -143,7 +145,20 @@ public: // Warning: This function should NOT be defined with NS_TIMER because // the intention is that it be linked statically with the library/DLL // or app that uses it. - +#ifdef XP_UNIX +inline nsresult NS_NewTimer(nsITimer **aInstancePtrResult) +{ + nsresult rv; + nsCOMPtr timer = do_CreateInstance("component://netscape/timer", &rv); + if (NS_SUCCEEDED(rv)) { + *aInstancePtrResult = timer; + NS_ADDREF(*aInstancePtrResult); + } + return rv; +} +#else extern nsresult NS_NewTimer(nsITimer** aInstancePtrResult); +#endif + #endif // nsITimer_h___ diff --git a/widget/timer/src/unix/Makefile.in b/widget/timer/src/unix/Makefile.in index ee9376a2ac5b..aa87da3f281b 100644 --- a/widget/timer/src/unix/Makefile.in +++ b/widget/timer/src/unix/Makefile.in @@ -32,12 +32,6 @@ ifdef MOZ_MONOLITHIC_TOOLKIT DIRS = $(MOZ_WIDGET_TOOLKIT) else -LIBRARY_NAME = timer_s - -REQUIRES = xpcom - -CPPSRCS = nsNewTimer.cpp - ifdef MOZ_ENABLE_GTK DIRS += gtk endif @@ -58,11 +52,6 @@ ifdef MOZ_ENABLE_PHOTON DIRS += photon endif - -override NO_SHARED_LIB=1 -override NO_STATIC_LIB= - -endif - include $(topsrcdir)/config/rules.mk +endif diff --git a/widget/timer/src/unix/gtk/nsTimerGtk.cpp b/widget/timer/src/unix/gtk/nsTimerGtk.cpp index 16b8a7bdfa38..1ae6f6bf9e58 100644 --- a/widget/timer/src/unix/gtk/nsTimerGtk.cpp +++ b/widget/timer/src/unix/gtk/nsTimerGtk.cpp @@ -157,7 +157,7 @@ nsTimerGtk::Init(nsITimerCallback *aCallback, return NS_OK; } -NS_IMPL_ISUPPORTS(nsTimerGtk, kITimerIID) +NS_IMPL_ISUPPORTS1(nsTimerGtk, nsITimer) void nsTimerGtk::Cancel() diff --git a/widget/timer/src/unix/gtk/nsTimerGtkFactory.cpp b/widget/timer/src/unix/gtk/nsTimerGtkFactory.cpp index 499a000e5f87..5f84c8cd47d4 100644 --- a/widget/timer/src/unix/gtk/nsTimerGtkFactory.cpp +++ b/widget/timer/src/unix/gtk/nsTimerGtkFactory.cpp @@ -33,7 +33,7 @@ static nsModuleComponentInfo components[] = { { "GTK timer", NS_TIMER_GTK_CID, - "component://netscape/timer/unix/gtk", + "component://netscape/timer", nsTimerGtkConstructor } }; diff --git a/widget/timer/src/unix/nsNewTimer.cpp b/widget/timer/src/unix/nsNewTimer.cpp deleted file mode 100644 index 4648c8695948..000000000000 --- a/widget/timer/src/unix/nsNewTimer.cpp +++ /dev/null @@ -1,204 +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.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/NPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * - * The Initial Developer of the Original Code is Netscape - * Communications Corporation. Portions created by Netscape are - * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - * Pierre Phaneuf - */ -#include "nsITimer.h" -#include "nsUnixTimerCIID.h" -#include "nsIComponentManager.h" -#include "nsIUnixToolkitService.h" - -#include "nsCRT.h" -#include "prenv.h" - -// Cache the nsIFactory vs. nsComponentManager::CreateInstance() -// The CM is supposed to cache the factory itself, but hashing into -// that doubles the time NS_NewTimer() takes. -// -// With factory caching, the time used by this NS_NewTimer() compared -// to the monolithic ones, is very close. Theres only a few (2/3) ms -// difference in optimized builds. This is probably within the -// margin of error of PR_Now(). -#define CACHE_FACTORY - -#undef CHEAP_PERFORMANCE_MEASURMENT - -// Used to measure how long NS_NewTimer() and CreateInstance() takes. -#ifdef CHEAP_PERFORMANCE_MEASURMENT -#include "prinrval.h" -static PRTime sStartTime = 0; -static PRTime sEndTime = 0; -static PRTime sCreateInstanceStartTime = 0; -static PRTime sCreateInstanceEndTime = 0; -static PRInt32 sTimerCount = 0; -#endif /* CHEAP_PERFORMANCE_MEASURMENT */ - - -static NS_DEFINE_IID(kITimerIID, NS_ITIMER_IID); - -static nsresult FindFactory(const nsCID & aClass, - nsIFactory ** aFactoryOut); - -static nsresult NewTimer(const nsCID & aClass, - nsITimer ** aInstancePtrResult); - - -static nsresult NewTimer(const nsCID & aClass, - nsITimer ** aInstancePtrResult) -{ - NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); - - if (nsnull == aInstancePtrResult) - return NS_ERROR_NULL_POINTER; - - nsresult rv = NS_ERROR_FAILURE; - nsITimer * timer = nsnull; - -#ifdef CHEAP_PERFORMANCE_MEASURMENT - sCreateInstanceStartTime = PR_Now(); -#endif - -#ifdef CACHE_FACTORY - static nsIFactory * factory = nsnull; - - if (nsnull == factory) - { - nsresult frv = FindFactory(aClass,&factory); - - NS_ASSERTION(NS_SUCCEEDED(frv),"Could not find timer factory."); - NS_ASSERTION(nsnull != factory,"Could not instanciate timer factory."); - } - - if (nsnull != factory) - { - rv = factory->CreateInstance(NULL, - kITimerIID, - (void **)& timer); - - } -#else - - rv = nsComponentManager::CreateInstance(aClass, - nsnull, - kITimerIID, - (void **)& timer); -#endif - -#ifdef CHEAP_PERFORMANCE_MEASURMENT - sCreateInstanceEndTime = PR_Now(); -#endif - - NS_ASSERTION(NS_SUCCEEDED(rv),"Could not instanciate a timer."); - - - if (nsnull == timer) - return NS_ERROR_OUT_OF_MEMORY; - - *aInstancePtrResult = timer; - - return rv; - -// Dont QI() cause the factory above will do it for us. Otherwise -// the refcnt will be one too much and every single timer will leak. - -// return timer->QueryInterface(kITimerIID, (void **) aInstancePtrResult); -} -////////////////////////////////////////////////////////////////////////// -static const nsCID * -GetTimerCID() -{ - static const nsCID * sgTimerCID = nsnull; - - static NS_DEFINE_CID(kCUnixToolkitServiceCID, NS_UNIX_TOOLKIT_SERVICE_CID); - - // For obvious efficiency reasons, do this only once - if (nsnull == sgTimerCID) - { - nsIUnixToolkitService * unixToolkitService = nsnull; - - nsresult rv = - nsComponentManager::CreateInstance(kCUnixToolkitServiceCID, - nsnull, - NS_GET_IID(nsIUnixToolkitService), - (void **) &unixToolkitService); - - NS_ASSERTION(rv == NS_OK,"Cannot obtain unix toolkit service."); - - if (NS_OK == rv && nsnull != unixToolkitService) - { - nsresult rv2; - - rv2 = unixToolkitService->GetTimerCID((nsCID **) &sgTimerCID); - - NS_ASSERTION(rv2 == NS_OK,"Cannot get timer cid."); - - NS_RELEASE(unixToolkitService); - } - } - - return sgTimerCID; -} -////////////////////////////////////////////////////////////////////////// -static nsresult FindFactory(const nsCID & aClass, - nsIFactory ** aFactoryOut) -{ - - NS_ASSERTION(nsnull != aFactoryOut,"NULL out pointer."); - - static nsIFactory * factory = nsnull; - nsresult rv = NS_ERROR_FAILURE; - - *aFactoryOut = nsnull; - - if (nsnull == factory) - { - rv = nsComponentManager::FindFactory(aClass,&factory); - } - - *aFactoryOut = factory; - - return rv; -} -////////////////////////////////////////////////////////////////////////// - -////////////////////////////////////////////////////////////////////////// -nsresult NS_NewTimer(nsITimer ** aInstancePtrResult) -{ -#ifdef CHEAP_PERFORMANCE_MEASURMENT - sStartTime = PR_Now(); -#endif - - const nsCID * cid = GetTimerCID(); - - NS_ASSERTION(nsnull != cid,"Dude! Trying to make a timer with a null CID."); - - nsresult rv = NewTimer(*cid,aInstancePtrResult); - -#ifdef CHEAP_PERFORMANCE_MEASURMENT - sEndTime = PR_Now(); - - printf("NS_NewTimer(count=%-4d,time=%lld ms,CI time=%lld ms)\n", - sTimerCount++, - sEndTime - sStartTime, - sCreateInstanceEndTime - sCreateInstanceStartTime); -#endif - - return rv; -}