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 
32 namespace comphelper
33 {
34  //= AnyEvent
35 
39  {
40  public:
41  AnyEvent();
42 
43  protected:
44  virtual ~AnyEvent() override;
45 
46  private:
47  AnyEvent( AnyEvent const & ) = delete;
48  AnyEvent& operator=( AnyEvent const & ) = delete;
49  };
50 
51 
52  //= typedefs
53 
54  typedef ::rtl::Reference< AnyEvent > AnyEventRef;
55 
56 
57  //= IEventProcessor
58 
64  {
65  public:
68  virtual void processEvent( const AnyEvent& _rEvent ) = 0;
69 
70  virtual void SAL_CALL acquire() throw () = 0;
71  virtual void SAL_CALL release() throw () = 0;
72 
73  protected:
75  };
76 
77 
78  //= AsyncEventNotifier
79 
80  struct EventNotifierImpl;
81 
99  {
100  friend struct EventNotifierImpl;
101 
102  protected:
103  std::unique_ptr<EventNotifierImpl> m_xImpl;
104 
105  SAL_DLLPRIVATE virtual ~AsyncEventNotifierBase();
106 
107  // Thread
108  SAL_DLLPRIVATE virtual void execute();
109 
110  public:
112 
121  virtual void SAL_CALL terminate();
122 
134  void addEvent( const AnyEventRef& _rEvent, const ::rtl::Reference< IEventProcessor >& _xProcessor );
135 
138  void removeEventsForProcessor( const ::rtl::Reference< IEventProcessor >& _xProcessor );
139  };
140 
145  : public AsyncEventNotifierBase
146  , public salhelper::Thread
147  {
148 
149  private:
150  SAL_DLLPRIVATE virtual ~AsyncEventNotifier() override;
151 
152  SAL_DLLPRIVATE virtual void execute() override;
153 
154  public:
160  AsyncEventNotifier(char const* name);
161 
162  virtual void SAL_CALL terminate() override;
163  };
164 
169  : public AsyncEventNotifierBase
170  , private osl::Thread
171  {
172 
173  private:
174  SAL_DLLPRIVATE AsyncEventNotifierAutoJoin(char const* name);
175 
176  SAL_DLLPRIVATE virtual void SAL_CALL run() override;
177  SAL_DLLPRIVATE virtual void SAL_CALL onTerminated() override;
178 
179  public:
180  // only public so shared_ptr finds it
181  SAL_DLLPRIVATE virtual ~AsyncEventNotifierAutoJoin() override;
182 
183  static std::shared_ptr<AsyncEventNotifierAutoJoin>
184  newAsyncEventNotifierAutoJoin(char const* name);
185 
186  virtual void SAL_CALL terminate() override;
187 
188  using osl::Thread::join;
189  using osl::Thread::operator new;
190  using osl::Thread::operator delete; // clang really wants this?
191 
192  static void launch(std::shared_ptr<AsyncEventNotifierAutoJoin> const&);
193  };
194 
195 
196  //= EventHolder
197 
200  template < typename EVENT_OBJECT >
201  class SAL_DLLPUBLIC_RTTI EventHolder final : public AnyEvent
202  {
203  public:
204  typedef EVENT_OBJECT EventObjectType;
205 
206  private:
207  EventObjectType const m_aEvent;
208 
209  public:
210  EventHolder( const EventObjectType& _rEvent )
211  :m_aEvent( _rEvent )
212  {
213  }
214 
215  const EventObjectType& getEventObject() const { return m_aEvent; }
216  };
217 
219 
220 } // namespace comphelper
221 
222 
223 #endif // INCLUDED_COMPHELPER_ASYNCNOTIFICATION_HXX
224 
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This is a hack (when proper joining is not possible), use of which should be avoided by good design...
AnyEvent derivee holding a foreign event instance.
::rtl::Reference< AnyEvent > AnyEventRef
void JoinAsyncEventNotifiers()
a helper class for notifying events asynchronously
def run
const EventObjectType & getEventObject() const
EventObjectType const m_aEvent
const char * name
the very basic instance to hold a description of an event
#define SAL_NO_VTABLE
#define COMPHELPER_DLLPUBLIC
This class is usable with rtl::Reference.
std::unique_ptr< EventNotifierImpl > m_xImpl
EventHolder(const EventObjectType &_rEvent)