1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _ASYNCEVENTNOTIFIER_HXX_
29 #define _ASYNCEVENTNOTIFIER_HXX_
30 
31 //------------------------------------------------------------------------
32 // includes
33 //------------------------------------------------------------------------
34 
35 #include <osl/mutex.hxx>
36 #include <osl/conditn.hxx>
37 #include <cppuhelper/interfacecontainer.h>
38 
39 #if defined _MSC_VER
40 #pragma warning(push, 1)
41 #endif
42 #include <windows.h>
43 #if defined _MSC_VER
44 #pragma warning(pop)
45 #endif
46 
47 #include <list>
48 #include <utility>
49 #include "eventnotification.hxx"
50 
51 //---------------------------------------------
52 //
53 //---------------------------------------------
54 
55 class CAsyncEventNotifier
56 {
57 public:
58     CAsyncEventNotifier(cppu::OBroadcastHelper& rBroadcastHelper);
59     ~CAsyncEventNotifier();
60 
61 	bool SAL_CALL startup(bool bCreateSuspended = true);
62 	void SAL_CALL shutdown();
63 
64     // notifications may be added the
65     // the event queue but will only
66     // be notified to the clients after
67     // resume was called
68     void suspend();
69 
70     // resume notifying events
71     void resume();
72 
73 	// this class is responsible for the memory management of
74 	// the CEventNotification instance
75     void SAL_CALL notifyEvent(CEventNotification* EventNotification);
76 
77     void SAL_CALL addListener   (const ::com::sun::star::uno::Type&                                           aType    ,
78                                  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xListener);
79     void SAL_CALL removeListener(const ::com::sun::star::uno::Type&                                           aType    ,
80                                  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xListener);
81 
82 private:
83 	size_t              SAL_CALL getEventListSize();
84 	void                SAL_CALL resetNotifyEvent();
85 	CEventNotification* SAL_CALL getNextEventRecord();
86 	void                SAL_CALL removeNextEventRecord();
87 
88     void SAL_CALL run( );
89 
90 	static unsigned int WINAPI ThreadProc(LPVOID pParam);
91 
92 private:
93     std::list<CEventNotification*>  m_EventList;
94     HANDLE							m_hThread;
95 	bool							m_bRun;
96 	unsigned						m_ThreadId;
97     ::cppu::OBroadcastHelper&		m_rBroadcastHelper;
98     HANDLE                          m_hEvents[2];
99     HANDLE&                         m_NotifyEvent;
100     HANDLE&                         m_ResumeNotifying;
101     osl::Mutex						m_Mutex;
102 
103 // prevent copy and assignment
104 private:
105     CAsyncEventNotifier( const CAsyncEventNotifier& );
106     CAsyncEventNotifier& operator=( const CAsyncEventNotifier& );
107 };
108 
109 #endif
110