1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterTimer.hxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #ifndef SDEXT_PRESENTER_TIMER_HXX
33 #define SDEXT_PRESENTER_TIMER_HXX
35 #include <com/sun/star/awt/XCallback.hpp>
36 #include <com/sun/star/awt/XRequestCallback.hpp>
37 #include <cppuhelper/basemutex.hxx>
38 #include <cppuhelper/compbase1.hxx>
39 #include <osl/mutex.hxx>
41 #include <rtl/ref.hxx>
42 #include <sal/types.h>
43 #include <boost/enable_shared_from_this.hpp>
44 #include <boost/function.hpp>
47 namespace css
= ::com::sun::star
;
49 namespace sdext
{ namespace presenter
{
51 class PresenterClockInternalTimer
;
53 /** The timer allows tasks to be scheduled for execution at a specified time
59 /** A task is called with the current time.
61 typedef ::boost::function
<void(const TimeValue
&)> Task
;
63 static const sal_Int32 NotAValidTaskId
= 0;
65 static sal_Int32
ScheduleSingleTaskRelative (
67 const sal_Int64 nDelay
);
69 static sal_Int32
ScheduleSingleTaskAbsolute (
71 const TimeValue
& rDueTime
);
73 static sal_Int32
ScheduleRepeatedTask (
75 const sal_Int64 nFirst
,
76 const sal_Int64 nIntervall
);
78 static void CancelTask (const sal_Int32 nTaskId
);
83 typedef cppu::WeakComponentImplHelper1
<
85 > PresenterClockTimerInterfaceBase
;
87 /** A timer that calls its listeners, typically clocks, every second to
88 update their current time value.
90 class PresenterClockTimer
91 : protected ::cppu::BaseMutex
,
92 public PresenterClockTimerInterfaceBase
95 class Listener
{ public:
96 virtual void TimeHasChanged (const oslDateTime
& rCurrentTime
) = 0;
98 typedef ::boost::shared_ptr
<Listener
> SharedListener
;
100 static ::rtl::Reference
<PresenterClockTimer
> Instance (
101 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
);
103 void AddListener (const SharedListener
& rListener
);
104 void RemoveListener (const SharedListener
& rListener
);
106 static oslDateTime
GetCurrentTime (void);
108 /** Return the difference between the two different times in
111 static sal_Int64
GetTimeDifference (const oslDateTime
& rNow
, const oslDateTime
& rThen
);
115 virtual void SAL_CALL
notify (const css::uno::Any
& rUserData
)
116 throw (css::uno::RuntimeException
);
119 static ::rtl::Reference
<PresenterClockTimer
> mpInstance
;
121 ::osl::Mutex maMutex
;
122 typedef ::std::vector
<SharedListener
> ListenerContainer
;
123 ListenerContainer maListeners
;
124 oslDateTime maDateTime
;
125 sal_Int32 mnTimerTaskId
;
126 bool mbIsCallbackPending
;
127 css::uno::Reference
<css::awt::XRequestCallback
> mxRequestCallback
;
129 PresenterClockTimer (
130 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
);
131 ~PresenterClockTimer (void);
133 void CheckCurrentTime (const TimeValue
& rCurrentTime
);
140 } } // end of namespace ::sdext::presenter