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 /** Schedule a task to be executed repeatedly. The task is executed the
74 first time after nFirst nano-seconds (1000000000 corresponds to one
75 second). After that task is executed in intervalls that are
76 nIntervall ns long until CancelTask is called.
78 static sal_Int32
ScheduleRepeatedTask (
80 const sal_Int64 nFirst
,
81 const sal_Int64 nIntervall
);
83 static void CancelTask (const sal_Int32 nTaskId
);
88 typedef cppu::WeakComponentImplHelper1
<
90 > PresenterClockTimerInterfaceBase
;
92 /** A timer that calls its listeners, typically clocks, every second to
93 update their current time value.
95 class PresenterClockTimer
96 : protected ::cppu::BaseMutex
,
97 public PresenterClockTimerInterfaceBase
100 class Listener
{ public:
101 virtual void TimeHasChanged (const oslDateTime
& rCurrentTime
) = 0;
103 typedef ::boost::shared_ptr
<Listener
> SharedListener
;
105 static ::rtl::Reference
<PresenterClockTimer
> Instance (
106 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
);
108 void AddListener (const SharedListener
& rListener
);
109 void RemoveListener (const SharedListener
& rListener
);
111 static oslDateTime
GetCurrentTime (void);
113 /** Return the difference between the two different times in
116 static sal_Int64
GetTimeDifference (const oslDateTime
& rNow
, const oslDateTime
& rThen
);
120 virtual void SAL_CALL
notify (const css::uno::Any
& rUserData
)
121 throw (css::uno::RuntimeException
);
124 static ::rtl::Reference
<PresenterClockTimer
> mpInstance
;
126 ::osl::Mutex maMutex
;
127 typedef ::std::vector
<SharedListener
> ListenerContainer
;
128 ListenerContainer maListeners
;
129 oslDateTime maDateTime
;
130 sal_Int32 mnTimerTaskId
;
131 bool mbIsCallbackPending
;
132 css::uno::Reference
<css::awt::XRequestCallback
> mxRequestCallback
;
134 PresenterClockTimer (
135 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
);
136 ~PresenterClockTimer (void);
138 void CheckCurrentTime (const TimeValue
& rCurrentTime
);
145 } } // end of namespace ::sdext::presenter