LibreOffice Module comphelper (master)  1
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
comphelper::AsyncEventNotifierBase Class Reference

a helper class for notifying events asynchronously More...

#include <asyncnotification.hxx>

Inheritance diagram for comphelper::AsyncEventNotifierBase:
[legend]

Public Member Functions

 AsyncEventNotifierBase ()
 
virtual void SAL_CALL terminate ()
 terminates the thread More...
 
void addEvent (const AnyEventRef &_rEvent, const ::rtl::Reference< IEventProcessor > &_xProcessor)
 adds an event to the queue, together with the instance which is responsible for processing it More...
 
void removeEventsForProcessor (const ::rtl::Reference< IEventProcessor > &_xProcessor)
 removes all events for the given event processor from the queue More...
 

Protected Member Functions

virtual SAL_DLLPRIVATE ~AsyncEventNotifierBase ()
 
virtual SAL_DLLPRIVATE void execute ()
 

Protected Attributes

std::unique_ptr< EventNotifierImplm_xImpl
 

Friends

struct EventNotifierImpl
 

Detailed Description

a helper class for notifying events asynchronously

If you need to notify certain events to external components, you usually should not do this while you have mutexes locked, to prevent multi-threading issues.

However, you do not always have complete control over all mutex guards on the stack. If, in such a case, the listener notification is one-way, you can decide to do it asynchronously.

The ->AsyncEventNotifier helps you to process such events asynchronously. Every event is tied to an ->IEventProcessor which is responsible for processing it.

The AsyncEventNotifier is implemented as a thread itself, which sleeps as long as there are no events in the queue. As soon as you add an event, the thread is woken up, processes the event, and sleeps again.

Definition at line 98 of file asyncnotification.hxx.

Constructor & Destructor Documentation

comphelper::AsyncEventNotifierBase::~AsyncEventNotifierBase ( )
protectedvirtual

Definition at line 95 of file asyncnotification.cxx.

comphelper::AsyncEventNotifierBase::AsyncEventNotifierBase ( )

Definition at line 89 of file asyncnotification.cxx.

Member Function Documentation

void comphelper::AsyncEventNotifierBase::addEvent ( const AnyEventRef _rEvent,
const ::rtl::Reference< IEventProcessor > &  _xProcessor 
)

adds an event to the queue, together with the instance which is responsible for processing it

Parameters
_rEventthe event to add to the queue
_xProcessorthe processor for the event.
Beware of life time issues here. If your event processor dies or becomes otherwise nonfunctional, you are responsible for removing all respective events from the queue. You can do this by calling ->removeEventsForProcessor

Definition at line 121 of file asyncnotification.cxx.

References m_xImpl.

void comphelper::AsyncEventNotifierBase::execute ( )
protectedvirtual
void comphelper::AsyncEventNotifierBase::removeEventsForProcessor ( const ::rtl::Reference< IEventProcessor > &  _xProcessor)

removes all events for the given event processor from the queue

Definition at line 100 of file asyncnotification.cxx.

References m_xImpl.

void SAL_CALL comphelper::AsyncEventNotifierBase::terminate ( )
virtual

terminates the thread

Note that this is a cooperative termination - if you call this from a thread different from the notification thread itself, then it will block until the notification thread finished processing the current event. If you call it from the notification thread itself, it will return immediately, and the thread will be terminated as soon as the current notification is finished.

Reimplemented in comphelper::AsyncEventNotifierAutoJoin, and comphelper::AsyncEventNotifier.

Definition at line 109 of file asyncnotification.cxx.

References m_xImpl.

Referenced by comphelper::AsyncEventNotifier::terminate(), and comphelper::AsyncEventNotifierAutoJoin::terminate().

Friends And Related Function Documentation

friend struct EventNotifierImpl
friend

Definition at line 100 of file asyncnotification.hxx.

Member Data Documentation

std::unique_ptr<EventNotifierImpl> comphelper::AsyncEventNotifierBase::m_xImpl
protected

The documentation for this class was generated from the following files: