1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef SDEXT_PRESENTER_TIMER_HXX 29*cdf0e10cSrcweir #define SDEXT_PRESENTER_TIMER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <com/sun/star/awt/XCallback.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/awt/XRequestCallback.hpp> 33*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx> 34*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx> 35*cdf0e10cSrcweir #include <osl/mutex.hxx> 36*cdf0e10cSrcweir #include <osl/time.h> 37*cdf0e10cSrcweir #include <rtl/ref.hxx> 38*cdf0e10cSrcweir #include <sal/types.h> 39*cdf0e10cSrcweir #include <boost/enable_shared_from_this.hpp> 40*cdf0e10cSrcweir #include <boost/function.hpp> 41*cdf0e10cSrcweir #include <vector> 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir namespace css = ::com::sun::star; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir namespace sdext { namespace presenter { 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir class PresenterClockInternalTimer; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir /** The timer allows tasks to be scheduled for execution at a specified time 50*cdf0e10cSrcweir in the future. 51*cdf0e10cSrcweir */ 52*cdf0e10cSrcweir class PresenterTimer 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir public: 55*cdf0e10cSrcweir /** A task is called with the current time. 56*cdf0e10cSrcweir */ 57*cdf0e10cSrcweir typedef ::boost::function<void(const TimeValue&)> Task; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir static const sal_Int32 NotAValidTaskId = 0; 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir static sal_Int32 ScheduleSingleTaskRelative ( 62*cdf0e10cSrcweir const Task& rTask, 63*cdf0e10cSrcweir const sal_Int64 nDelay); 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir static sal_Int32 ScheduleSingleTaskAbsolute ( 66*cdf0e10cSrcweir const Task& rTask, 67*cdf0e10cSrcweir const TimeValue& rDueTime); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir /** Schedule a task to be executed repeatedly. The task is executed the 70*cdf0e10cSrcweir first time after nFirst nano-seconds (1000000000 corresponds to one 71*cdf0e10cSrcweir second). After that task is executed in intervalls that are 72*cdf0e10cSrcweir nIntervall ns long until CancelTask is called. 73*cdf0e10cSrcweir */ 74*cdf0e10cSrcweir static sal_Int32 ScheduleRepeatedTask ( 75*cdf0e10cSrcweir const Task& rTask, 76*cdf0e10cSrcweir const sal_Int64 nFirst, 77*cdf0e10cSrcweir const sal_Int64 nIntervall); 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir static void CancelTask (const sal_Int32 nTaskId); 80*cdf0e10cSrcweir }; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir typedef cppu::WeakComponentImplHelper1< 85*cdf0e10cSrcweir css::awt::XCallback 86*cdf0e10cSrcweir > PresenterClockTimerInterfaceBase; 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir /** A timer that calls its listeners, typically clocks, every second to 89*cdf0e10cSrcweir update their current time value. 90*cdf0e10cSrcweir */ 91*cdf0e10cSrcweir class PresenterClockTimer 92*cdf0e10cSrcweir : protected ::cppu::BaseMutex, 93*cdf0e10cSrcweir public PresenterClockTimerInterfaceBase 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir public: 96*cdf0e10cSrcweir class Listener { public: 97*cdf0e10cSrcweir virtual void TimeHasChanged (const oslDateTime& rCurrentTime) = 0; 98*cdf0e10cSrcweir }; 99*cdf0e10cSrcweir typedef ::boost::shared_ptr<Listener> SharedListener; 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir static ::rtl::Reference<PresenterClockTimer> Instance ( 102*cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxContext); 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void AddListener (const SharedListener& rListener); 105*cdf0e10cSrcweir void RemoveListener (const SharedListener& rListener); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir static oslDateTime GetCurrentTime (void); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /** Return the difference between the two different times in 110*cdf0e10cSrcweir nanoseconds. 111*cdf0e10cSrcweir */ 112*cdf0e10cSrcweir static sal_Int64 GetTimeDifference (const oslDateTime& rNow, const oslDateTime& rThen); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir // XCallback 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir virtual void SAL_CALL notify (const css::uno::Any& rUserData) 117*cdf0e10cSrcweir throw (css::uno::RuntimeException); 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir private: 120*cdf0e10cSrcweir static ::rtl::Reference<PresenterClockTimer> mpInstance; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir ::osl::Mutex maMutex; 123*cdf0e10cSrcweir typedef ::std::vector<SharedListener> ListenerContainer; 124*cdf0e10cSrcweir ListenerContainer maListeners; 125*cdf0e10cSrcweir oslDateTime maDateTime; 126*cdf0e10cSrcweir sal_Int32 mnTimerTaskId; 127*cdf0e10cSrcweir bool mbIsCallbackPending; 128*cdf0e10cSrcweir css::uno::Reference<css::awt::XRequestCallback> mxRequestCallback; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir PresenterClockTimer ( 131*cdf0e10cSrcweir const css::uno::Reference<css::uno::XComponentContext>& rxContext); 132*cdf0e10cSrcweir ~PresenterClockTimer (void); 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir void CheckCurrentTime (const TimeValue& rCurrentTime); 135*cdf0e10cSrcweir }; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir } } // end of namespace ::sdext::presenter 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir #endif 144