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