LibreOffice Module comphelper (master) 1
|
a helper class for notifying events asynchronously More...
#include <asyncnotification.hxx>
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< EventNotifierImpl > | m_xImpl |
Friends | |
struct | EventNotifierImpl |
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 99 of file asyncnotification.hxx.
|
protectedvirtual |
Definition at line 84 of file asyncnotification.cxx.
comphelper::AsyncEventNotifierBase::AsyncEventNotifierBase | ( | ) |
Definition at line 78 of file asyncnotification.cxx.
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
_rEvent | the event to add to the queue |
_xProcessor | the 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 110 of file asyncnotification.cxx.
References m_xImpl.
|
protectedvirtual |
Reimplemented in comphelper::AsyncEventNotifier.
Definition at line 122 of file asyncnotification.cxx.
References m_xImpl.
Referenced by comphelper::AsyncEventNotifier::execute(), and comphelper::AsyncEventNotifierAutoJoin::run().
void comphelper::AsyncEventNotifierBase::removeEventsForProcessor | ( | const ::rtl::Reference< IEventProcessor > & | _xProcessor | ) |
removes all events for the given event processor from the queue
Definition at line 89 of file asyncnotification.cxx.
References m_xImpl.
|
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::AsyncEventNotifier, and comphelper::AsyncEventNotifierAutoJoin.
Definition at line 98 of file asyncnotification.cxx.
References m_xImpl.
Referenced by comphelper::AsyncEventNotifier::terminate(), and comphelper::AsyncEventNotifierAutoJoin::terminate().
|
friend |
Definition at line 101 of file asyncnotification.hxx.
|
protected |
Definition at line 104 of file asyncnotification.hxx.
Referenced by addEvent(), comphelper::AsyncEventNotifierAutoJoin::AsyncEventNotifierAutoJoin(), execute(), comphelper::AsyncEventNotifierAutoJoin::onTerminated(), removeEventsForProcessor(), comphelper::AsyncEventNotifierAutoJoin::run(), and terminate().