1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTIMER_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTIMER_HXX
23 #include <com/sun/star/awt/XCallback.hpp>
24 #include <com/sun/star/awt/XRequestCallback.hpp>
25 #include <cppuhelper/basemutex.hxx>
26 #include <cppuhelper/compbase.hxx>
27 #include <osl/mutex.hxx>
29 #include <rtl/ref.hxx>
30 #include <sal/types.h>
36 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{
37 class XComponentContext
;
40 namespace sdext
{ namespace presenter
{
42 /** The timer allows tasks to be scheduled for execution at a specified time
48 /** A task is called with the current time.
50 typedef ::std::function
<void (const TimeValue
&)> Task
;
52 static const sal_Int32 NotAValidTaskId
= 0;
54 /** Schedule a task to be executed repeatedly. The task is executed the
55 first time after nFirst nano-seconds (1000000000 corresponds to one
56 second). After that task is executed in intervals that are
57 nInterval ns long until CancelTask is called.
59 static sal_Int32
ScheduleRepeatedTask (
60 const css::uno::Reference
<css::uno::XComponentContext
>& xContext
,
62 const sal_Int64 nFirst
,
63 const sal_Int64 nInterval
);
65 static void CancelTask (const sal_Int32 nTaskId
);
68 typedef cppu::WeakComponentImplHelper
<
70 > PresenterClockTimerInterfaceBase
;
72 /** A timer that calls its listeners, typically clocks, every second to
73 update their current time value.
75 class PresenterClockTimer
76 : protected ::cppu::BaseMutex
,
77 public PresenterClockTimerInterfaceBase
82 virtual void TimeHasChanged (const oslDateTime
& rCurrentTime
) = 0;
87 typedef std::shared_ptr
<Listener
> SharedListener
;
89 static ::rtl::Reference
<PresenterClockTimer
> Instance (
90 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
);
92 void AddListener (const SharedListener
& rListener
);
93 void RemoveListener (const SharedListener
& rListener
);
95 static oslDateTime
GetCurrentTime();
99 virtual void SAL_CALL
notify (const css::uno::Any
& rUserData
) override
;
102 static ::rtl::Reference
<PresenterClockTimer
> mpInstance
;
104 ::osl::Mutex maMutex
;
105 typedef ::std::vector
<SharedListener
> ListenerContainer
;
106 ListenerContainer maListeners
;
107 oslDateTime maDateTime
;
108 sal_Int32 mnTimerTaskId
;
109 bool mbIsCallbackPending
;
110 css::uno::Reference
<css::awt::XRequestCallback
> mxRequestCallback
;
111 const css::uno::Reference
<css::uno::XComponentContext
> m_xContext
;
113 PresenterClockTimer (
114 const css::uno::Reference
<css::uno::XComponentContext
>& rxContext
);
115 virtual ~PresenterClockTimer() override
;
117 void CheckCurrentTime (const TimeValue
& rCurrentTime
);
120 } } // end of namespace ::sdext::presenter
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */