LibreOffice Module sdext (master)  1
PresenterTimer.hxx
Go to the documentation of this file.
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 INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTIMER_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERTIMER_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/compbase.hxx>
27 #include <osl/mutex.hxx>
28 #include <osl/time.h>
29 #include <rtl/ref.hxx>
30 #include <sal/types.h>
31 
32 #include <functional>
33 #include <memory>
34 #include <vector>
35 
36 namespace com { namespace sun { namespace star { namespace uno {
37  class XComponentContext;
38 } } } }
39 
40 namespace sdext { namespace presenter {
41 
46 {
47 public:
50  typedef ::std::function<void (const TimeValue&)> Task;
51 
52  static const sal_Int32 NotAValidTaskId = 0;
53 
59  static sal_Int32 ScheduleRepeatedTask (
60  const css::uno::Reference<css::uno::XComponentContext>& xContext,
61  const Task& rTask,
62  const sal_Int64 nFirst,
63  const sal_Int64 nInterval);
64 
65  static void CancelTask (const sal_Int32 nTaskId);
66 };
67 
68 typedef cppu::WeakComponentImplHelper<
69  css::awt::XCallback
71 
76  : protected ::cppu::BaseMutex,
78 {
79 public:
80  class Listener {
81  public:
82  virtual void TimeHasChanged (const oslDateTime& rCurrentTime) = 0;
83 
84  protected:
85  ~Listener() {}
86  };
87  typedef std::shared_ptr<Listener> SharedListener;
88 
89  static ::rtl::Reference<PresenterClockTimer> Instance (
90  const css::uno::Reference<css::uno::XComponentContext>& rxContext);
91 
92  void AddListener (const SharedListener& rListener);
93  void RemoveListener (const SharedListener& rListener);
94 
95  static oslDateTime GetCurrentTime();
96 
97  // XCallback
98 
99  virtual void SAL_CALL notify (const css::uno::Any& rUserData) override;
100 
101 private:
102  static ::rtl::Reference<PresenterClockTimer> mpInstance;
103 
104  ::osl::Mutex maMutex;
105  typedef ::std::vector<SharedListener> ListenerContainer;
106  ListenerContainer maListeners;
107  oslDateTime maDateTime;
108  sal_Int32 mnTimerTaskId;
110  css::uno::Reference<css::awt::XRequestCallback> mxRequestCallback;
111  const css::uno::Reference<css::uno::XComponentContext> m_xContext;
112 
114  const css::uno::Reference<css::uno::XComponentContext>& rxContext);
115  virtual ~PresenterClockTimer() override;
116 
117  void CheckCurrentTime (const TimeValue& rCurrentTime);
118 };
119 
120 } } // end of namespace ::sdext::presenter
121 
122 #endif
123 
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static sal_Int32 ScheduleRepeatedTask(const css::uno::Reference< css::uno::XComponentContext > &xContext, const Task &rTask, const sal_Int64 nFirst, const sal_Int64 nInterval)
Schedule a task to be executed repeatedly.
A timer that calls its listeners, typically clocks, every second to update their current time value...
void AddListener(const SharedListener &rListener)
void CheckCurrentTime(const TimeValue &rCurrentTime)
virtual void SAL_CALL notify(const css::uno::Any &rUserData) override
static::rtl::Reference< PresenterClockTimer > Instance(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
const css::uno::Reference< css::uno::XComponentContext > m_xContext
PresenterClockTimer(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
static void CancelTask(const sal_Int32 nTaskId)
virtual void TimeHasChanged(const oslDateTime &rCurrentTime)=0
css::uno::Reference< css::awt::XRequestCallback > mxRequestCallback
std::shared_ptr< Listener > SharedListener
::std::vector< SharedListener > ListenerContainer
void RemoveListener(const SharedListener &rListener)
static const sal_Int32 NotAValidTaskId
cppu::WeakComponentImplHelper< css::awt::XCallback > PresenterClockTimerInterfaceBase
The timer allows tasks to be scheduled for execution at a specified time in the future.
::std::function< void(const TimeValue &)> Task
A task is called with the current time.
static::rtl::Reference< PresenterClockTimer > mpInstance