LibreOffice Module comphelper (master) 1
asyncnotification.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_COMPHELPER_ASYNCNOTIFICATION_HXX
21#define INCLUDED_COMPHELPER_ASYNCNOTIFICATION_HXX
22
23#include <sal/config.h>
24
26#include <rtl/ref.hxx>
27#include <sal/types.h>
28#include <salhelper/thread.hxx>
30#include <memory>
31#include <utility>
32
33namespace comphelper
34{
35 //= AnyEvent
36
40 {
41 public:
42 AnyEvent();
43
44 protected:
45 virtual ~AnyEvent() override;
46
47 private:
48 AnyEvent( AnyEvent const & ) = delete;
49 AnyEvent& operator=( AnyEvent const & ) = delete;
50 };
51
52
53 //= typedefs
54
55 typedef ::rtl::Reference< AnyEvent > AnyEventRef;
56
57
58 //= IEventProcessor
59
65 {
66 public:
69 virtual void processEvent( const AnyEvent& _rEvent ) = 0;
70
71 virtual void SAL_CALL acquire() noexcept = 0;
72 virtual void SAL_CALL release() noexcept = 0;
73
74 protected:
76 };
77
78
79 //= AsyncEventNotifier
80
81 struct EventNotifierImpl;
82
100 {
101 friend struct EventNotifierImpl;
102
103 protected:
104 std::unique_ptr<EventNotifierImpl> m_xImpl;
105
106 SAL_DLLPRIVATE virtual ~AsyncEventNotifierBase();
107
108 // Thread
109 SAL_DLLPRIVATE virtual void execute();
110
111 public:
113
122 virtual void SAL_CALL terminate();
123
135 void addEvent( const AnyEventRef& _rEvent, const ::rtl::Reference< IEventProcessor >& _xProcessor );
136
139 void removeEventsForProcessor( const ::rtl::Reference< IEventProcessor >& _xProcessor );
140 };
141
147 , public salhelper::Thread
148 {
149
150 private:
151 SAL_DLLPRIVATE virtual ~AsyncEventNotifier() override;
152
153 SAL_DLLPRIVATE virtual void execute() override;
154
155 public:
161 AsyncEventNotifier(char const* name);
162
163 virtual void SAL_CALL terminate() override;
164 };
165
171 , private osl::Thread
172 {
173
174 private:
175 SAL_DLLPRIVATE AsyncEventNotifierAutoJoin(char const* name);
176
177 SAL_DLLPRIVATE virtual void SAL_CALL run() override;
178 SAL_DLLPRIVATE virtual void SAL_CALL onTerminated() override;
179
180 public:
181 // only public so shared_ptr finds it
182 SAL_DLLPRIVATE virtual ~AsyncEventNotifierAutoJoin() override;
183
184 static std::shared_ptr<AsyncEventNotifierAutoJoin>
185 newAsyncEventNotifierAutoJoin(char const* name);
186
187 virtual void SAL_CALL terminate() override;
188
189 using osl::Thread::join;
190 using osl::Thread::operator new;
191 using osl::Thread::operator delete; // clang really wants this?
192
193 static void launch(std::shared_ptr<AsyncEventNotifierAutoJoin> const&);
194 };
195
196
197 //= EventHolder
198
201 template < typename EVENT_OBJECT >
202 class SAL_DLLPUBLIC_RTTI EventHolder final : public AnyEvent
203 {
204 public:
205 typedef EVENT_OBJECT EventObjectType;
206
207 private:
209
210 public:
212 :m_aEvent(std::move( _aEvent ))
213 {
214 }
215
216 const EventObjectType& getEventObject() const { return m_aEvent; }
217 };
218
220
221} // namespace comphelper
222
223
224#endif // INCLUDED_COMPHELPER_ASYNCNOTIFICATION_HXX
225
226/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
the very basic instance to hold a description of an event
AnyEvent(AnyEvent const &)=delete
AnyEvent & operator=(AnyEvent const &)=delete
This is a hack (when proper joining is not possible), use of which should be avoided by good design.
a helper class for notifying events asynchronously
std::unique_ptr< EventNotifierImpl > m_xImpl
This class is usable with rtl::Reference.
AnyEvent derivee holding a foreign event instance.
const EventObjectType & getEventObject() const
EventHolder(EventObjectType _aEvent)
EventObjectType const m_aEvent
virtual void SAL_CALL acquire() noexcept=0
virtual void processEvent(const AnyEvent &_rEvent)=0
process a single event
#define COMPHELPER_DLLPUBLIC
const char * name
def run(arg=None, arg2=-1)
void JoinAsyncEventNotifiers()
::rtl::Reference< AnyEvent > AnyEventRef
#define SAL_NO_VTABLE