summaryrefslogtreecommitdiff
path: root/comphelper
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2006-03-14 10:39:18 +0000
committerVladimir Glazounov <vg@openoffice.org>2006-03-14 10:39:18 +0000
commit9f56e8f5561d386afaeac3f592cf661a5fdcee6e (patch)
tree5ea93e3050f529de86dbb1787b39bf9eebd41299 /comphelper
parent54c3d2ef0a94c32c0001fbfb03f0e86f8b0247c8 (diff)
INTEGRATION: CWS pbrwuno (1.4.14); FILE MERGED
2005/10/19 08:25:56 fs 1.4.14.2: #i53095# make IEventProcessor ref-counted 2005/10/07 12:19:53 fs 1.4.14.1: cleaned up this, so that it's much more generic now - and thus usable for #i53095#
Diffstat (limited to 'comphelper')
-rw-r--r--comphelper/inc/comphelper/asyncnotification.hxx205
1 files changed, 81 insertions, 124 deletions
diff --git a/comphelper/inc/comphelper/asyncnotification.hxx b/comphelper/inc/comphelper/asyncnotification.hxx
index 5d24c0ccf265..db932d592495 100644
--- a/comphelper/inc/comphelper/asyncnotification.hxx
+++ b/comphelper/inc/comphelper/asyncnotification.hxx
@@ -4,9 +4,9 @@
*
* $RCSfile: asyncnotification.hxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: rt $ $Date: 2005-09-08 02:27:30 $
+ * last change: $Author: vg $ $Date: 2006-03-14 11:39:18 $
*
* The Contents of this file are made available subject to
* the terms of GNU Lesser General Public License Version 2.1.
@@ -36,41 +36,21 @@
#ifndef COMPHELPER_ASYNCNOTIFICATION_HXX
#define COMPHELPER_ASYNCNOTIFICATION_HXX
-/** === begin UNO includes === **/
-#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_
-#include <com/sun/star/lang/XComponent.hpp>
-#endif
-#ifndef _COM_SUN_STAR_LANG_XEVENTLISTENER_HPP_
-#include <com/sun/star/lang/XEventListener.hpp>
-#endif
-#ifndef _COM_SUN_STAR_UNO_XADAPTER_HPP_
-#include <com/sun/star/uno/XAdapter.hpp>
-#endif
-/** === end UNO includes === **/
-
-#ifndef _VOS_THREAD_HXX_
-#include <vos/thread.hxx>
-#endif
-#ifndef _OSL_MUTEX_HXX_
-#include <osl/mutex.hxx>
-#endif
-#ifndef _OSL_CONDITN_HXX_
-#include <osl/conditn.hxx>
+#ifndef _THREAD_HXX_
+#include <osl/thread.hxx>
#endif
#ifndef _RTL_REF_HXX_
#include <rtl/ref.hxx>
#endif
-#ifndef _CPPUHELPER_IMPLBASE1_HXX_
-#include <cppuhelper/implbase1.hxx>
-#endif
-
#ifndef INCLUDED_COMPHELPERDLLAPI_H
-#include "comphelper/comphelperdllapi.h"
+#include <comphelper/comphelperdllapi.h>
+#endif
+#ifndef _RTL_ALLOC_H_
+#include <rtl/alloc.h>
#endif
-#include <deque>
#include <memory>
//........................................................................
@@ -79,71 +59,32 @@ namespace comphelper
//........................................................................
//====================================================================
- //= EventDescription
+ //= AnyEvent
//====================================================================
/** the very basic instance to hold a description of an event
-
- In this simple version, an event is described by an numeric value only, whose
- semantics is completely up to the user of this class.
-
- Normally, you won't use this description directly, but instead derive own
- classes which can hold more information.
*/
- class COMPHELPER_DLLPUBLIC EventDescription : ::rtl::IReference
+ class COMPHELPER_DLLPUBLIC AnyEvent : ::rtl::IReference
{
- public:
- typedef sal_uInt16 EventType;
-
private:
oslInterlockedCount m_refCount;
- EventType m_nType;
public:
- EventDescription( EventType nType );
-
- inline EventType getEventType() const { return m_nType; }
+ AnyEvent();
virtual oslInterlockedCount SAL_CALL acquire();
virtual oslInterlockedCount SAL_CALL release();
protected:
- EventDescription( const EventDescription& _rSource );
- EventDescription& operator=( const EventDescription& _rSource );
+ AnyEvent( const AnyEvent& _rSource );
+ AnyEvent& operator=( const AnyEvent& _rSource );
- virtual ~EventDescription();
-
- private:
- EventDescription( ); // never implemented
- };
-
- //====================================================================
- //= EventObjectHolder
- //====================================================================
- /** EventDescription derivee holding an UNO EventObject derivee
- */
- template <typename EVENT_OBJECT >
- class EventObjectHolder : public EventDescription
- {
- public:
- typedef EVENT_OBJECT EventObjectType;
-
- private:
- EventObjectType m_aEvent;
-
- public:
- inline EventObjectHolder( const EventObjectType& _rUnoEvent, EventType _nType )
- :EventDescription( _nType )
- ,m_aEvent( _rUnoEvent )
- {
- }
-
- inline const EventObjectType& getEventObject() const { return m_aEvent; }
+ virtual ~AnyEvent();
};
//====================================================================
//= typedefs
//====================================================================
- typedef ::rtl::Reference< EventDescription > EventDescriptionRef;
+ typedef ::rtl::Reference< AnyEvent > AnyEventRef;
//====================================================================
//= IEventProcessor
@@ -152,31 +93,21 @@ namespace comphelper
@see AsyncEventNotifier
*/
- class IEventProcessor
+ class SAL_NO_VTABLE IEventProcessor
{
public:
/** process a single event
*/
- virtual void processEvent( const EventDescription& _rEvent ) = 0;
-
- /** retrieve the component associated with the event processor
+ virtual void processEvent( const AnyEvent& _rEvent ) = 0;
- If this method returns a non-<NULL/> object, this can be used to signal
- the ending of the life time of the processor.
- Every instance which hols a pointer to the processor instance is then required
- to register as <type scope="com::sun::star::lang">XEventListener</type> at the
- component, and to <em>not</em> access the event processor anymore after the
- component has notified its disposal.
- */
- virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
- getComponent() = 0;
+ virtual void SAL_CALL acquire() = 0;
+ virtual void SAL_CALL release() = 0;
};
//====================================================================
//= AsyncEventNotifier
//====================================================================
- typedef ::vos::OThread AsyncEventNotifier_TBASE;
- typedef ::cppu::WeakImplHelper1< ::com::sun::star::lang::XEventListener > AsyncEventNotifier_BASE;
+ typedef ::osl::Thread AsyncEventNotifier_TBASE;
struct EventNotifierImpl;
/** a helper class for notifying events asynchronously
@@ -188,67 +119,93 @@ namespace comphelper
If, in such a case, the listener notification is one-way, you can decide to do it
asynchronously.
- For this, you need to
- <ul>
- <li>implement the <type>IEventProcessor</type> interface</li>
- <li>instantiate an <type>AsyncEventNotifier</type> instance, and <member>acquire</member>
- and <member>create</member> it</li>
- <li>derive a class from <type>EventDescription</type>, which is able to hold
- all the necessary information about your event</li>
- <li>pass an instance of this derived <type>EventDescription</type> to <member>processEvent</member>
- of your <type>AsyncEventNotifier</type></li>
- </ul>
-
- Your event processor's <member>IEventProcessor::processEvent</member> method will then be called
- with the given event, in a separate thread where definately no mutexes are locked.
+ 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.
*/
- class COMPHELPER_DLLPUBLIC AsyncEventNotifier
- :public AsyncEventNotifier_TBASE
- ,public AsyncEventNotifier_BASE
+ class COMPHELPER_DLLPUBLIC AsyncEventNotifier :protected AsyncEventNotifier_TBASE
+ ,public ::rtl::IReference
{
friend struct EventNotifierImpl;
private:
- typedef ::std::deque< EventDescriptionRef > Events;
-
- private:
::std::auto_ptr< EventNotifierImpl > m_pImpl;
protected:
- // OThread
+ // Thread
virtual void SAL_CALL run();
- virtual void SAL_CALL kill();
virtual void SAL_CALL onTerminated();
public:
/** constructs a notifier thread
-
- @param _pProcessor
- the instance processing the events
*/
- AsyncEventNotifier( IEventProcessor* _pProcessor );
+ AsyncEventNotifier();
- /** adds an event to the queue
- */
- void addEvent( const EventDescriptionRef& _rEvent );
+ // IReference implementations
+ virtual oslInterlockedCount SAL_CALL acquire();
+ virtual oslInterlockedCount SAL_CALL release();
+
+ /// creates (starts) the thread
+ AsyncEventNotifier_TBASE::create;
+
+ AsyncEventNotifier_TBASE::operator new;
+ AsyncEventNotifier_TBASE::operator delete;
- // XEventListener
- virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException);
+ /** terminates the thread
- /* resolve ambiguity : both OWeakObject and OObject have these memory operators */
- void* SAL_CALL operator new( size_t size ) throw() { return OThread::operator new( size ); }
- void SAL_CALL operator delete( void * p ) throw() { OThread::operator delete( p ); }
+ Note that this is a cooporative 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.
+ */
+ virtual void SAL_CALL terminate();
+
+ /** adds an event to the queue, together with the instance which is responsible for
+ processing it
+
+ @param _rEvent
+ the event to add to the queue
+ @param _xProcessor
+ the processor for the event.<br/>
+ 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
+ */
+ void addEvent( const AnyEventRef& _rEvent, const ::rtl::Reference< IEventProcessor >& _xProcessor );
+
+ /** removes all events for the given event processor from the queue
+ */
+ void removeEventsForProcessor( const ::rtl::Reference< IEventProcessor >& _xProcessor );
protected:
virtual ~AsyncEventNotifier();
+ };
+
+ //====================================================================
+ //= EventHolder
+ //====================================================================
+ /** AnyEvent derivee holding an foreign event instance
+ */
+ template < typename EVENT_OBJECT >
+ class EventHolder : public AnyEvent
+ {
+ public:
+ typedef EVENT_OBJECT EventObjectType;
private:
- void implStarted( );
- void implTerminated( );
+ EventObjectType m_aEvent;
+
+ public:
+ inline EventHolder( const EventObjectType& _rEvent )
+ :m_aEvent( _rEvent )
+ {
+ }
+
+ inline const EventObjectType& getEventObject() const { return m_aEvent; }
};
//........................................................................