Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SDEXT_PRESENTER_TIMER_HXX
21 : #define SDEXT_PRESENTER_TIMER_HXX
22 :
23 : #include <com/sun/star/awt/XCallback.hpp>
24 : #include <com/sun/star/awt/XRequestCallback.hpp>
25 : #include <cppuhelper/basemutex.hxx>
26 : #include <cppuhelper/compbase1.hxx>
27 : #include <osl/mutex.hxx>
28 : #include <osl/time.h>
29 : #include <rtl/ref.hxx>
30 : #include <sal/types.h>
31 : #include <boost/enable_shared_from_this.hpp>
32 : #include <boost/function.hpp>
33 : #include <vector>
34 :
35 : namespace sdext { namespace presenter {
36 :
37 : /** The timer allows tasks to be scheduled for execution at a specified time
38 : in the future.
39 : */
40 : class PresenterTimer
41 : {
42 : public:
43 : /** A task is called with the current time.
44 : */
45 : typedef ::boost::function<void(const TimeValue&)> Task;
46 :
47 : static const sal_Int32 NotAValidTaskId = 0;
48 :
49 : /** Schedule a task to be executed repeatedly. The task is executed the
50 : first time after nFirst nano-seconds (1000000000 corresponds to one
51 : second). After that task is executed in intervalls that are
52 : nIntervall ns long until CancelTask is called.
53 : */
54 : static sal_Int32 ScheduleRepeatedTask (
55 : const Task& rTask,
56 : const sal_Int64 nFirst,
57 : const sal_Int64 nIntervall);
58 :
59 : static void CancelTask (const sal_Int32 nTaskId);
60 : };
61 :
62 : typedef cppu::WeakComponentImplHelper1<
63 : css::awt::XCallback
64 : > PresenterClockTimerInterfaceBase;
65 :
66 : /** A timer that calls its listeners, typically clocks, every second to
67 : update their current time value.
68 : */
69 : class PresenterClockTimer
70 : : protected ::cppu::BaseMutex,
71 : public PresenterClockTimerInterfaceBase
72 : {
73 : public:
74 0 : class Listener {
75 : public:
76 : virtual void TimeHasChanged (const oslDateTime& rCurrentTime) = 0;
77 :
78 : protected:
79 0 : ~Listener() {}
80 : };
81 : typedef ::boost::shared_ptr<Listener> SharedListener;
82 :
83 : static ::rtl::Reference<PresenterClockTimer> Instance (
84 : const css::uno::Reference<css::uno::XComponentContext>& rxContext);
85 :
86 : void AddListener (const SharedListener& rListener);
87 : void RemoveListener (const SharedListener& rListener);
88 :
89 : static oslDateTime GetCurrentTime (void);
90 :
91 : // XCallback
92 :
93 : virtual void SAL_CALL notify (const css::uno::Any& rUserData)
94 : throw (css::uno::RuntimeException);
95 :
96 : private:
97 : static ::rtl::Reference<PresenterClockTimer> mpInstance;
98 :
99 : ::osl::Mutex maMutex;
100 : typedef ::std::vector<SharedListener> ListenerContainer;
101 : ListenerContainer maListeners;
102 : oslDateTime maDateTime;
103 : sal_Int32 mnTimerTaskId;
104 : bool mbIsCallbackPending;
105 : css::uno::Reference<css::awt::XRequestCallback> mxRequestCallback;
106 :
107 : PresenterClockTimer (
108 : const css::uno::Reference<css::uno::XComponentContext>& rxContext);
109 : ~PresenterClockTimer (void);
110 :
111 : void CheckCurrentTime (const TimeValue& rCurrentTime);
112 : };
113 :
114 : } } // end of namespace ::sdext::presenter
115 :
116 : #endif
117 :
118 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|