1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _ASYNCEVENTNOTIFIER_HXX_
25 #define _ASYNCEVENTNOTIFIER_HXX_
26 
27 //------------------------------------------------------------------------
28 // includes
29 //------------------------------------------------------------------------
30 
31 #include <osl/mutex.hxx>
32 #include <osl/conditn.hxx>
33 #include <cppuhelper/interfacecontainer.h>
34 
35 #if defined _MSC_VER
36 #pragma warning(push, 1)
37 #endif
38 #include <windows.h>
39 #if defined _MSC_VER
40 #pragma warning(pop)
41 #endif
42 
43 #include <list>
44 #include <utility>
45 #include "eventnotification.hxx"
46 
47 //---------------------------------------------
48 //
49 //---------------------------------------------
50 
51 class CAsyncEventNotifier
52 {
53 public:
54     CAsyncEventNotifier(cppu::OBroadcastHelper& rBroadcastHelper);
55     ~CAsyncEventNotifier();
56 
57 	bool SAL_CALL startup(bool bCreateSuspended = true);
58 	void SAL_CALL shutdown();
59 
60     // notifications may be added the
61     // the event queue but will only
62     // be notified to the clients after
63     // resume was called
64     void suspend();
65 
66     // resume notifying events
67     void resume();
68 
69 	// this class is responsible for the memory management of
70 	// the CEventNotification instance
71     void SAL_CALL notifyEvent(CEventNotification* EventNotification);
72 
73     void SAL_CALL addListener   (const ::com::sun::star::uno::Type&                                           aType    ,
74                                  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xListener);
75     void SAL_CALL removeListener(const ::com::sun::star::uno::Type&                                           aType    ,
76                                  const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xListener);
77 
78 private:
79 	size_t              SAL_CALL getEventListSize();
80 	void                SAL_CALL resetNotifyEvent();
81 	CEventNotification* SAL_CALL getNextEventRecord();
82 	void                SAL_CALL removeNextEventRecord();
83 
84     void SAL_CALL run( );
85 
86 	static unsigned int WINAPI ThreadProc(LPVOID pParam);
87 
88 private:
89     std::list<CEventNotification*>  m_EventList;
90     HANDLE							m_hThread;
91 	bool							m_bRun;
92 	unsigned						m_ThreadId;
93     ::cppu::OBroadcastHelper&		m_rBroadcastHelper;
94     HANDLE                          m_hEvents[2];
95     HANDLE&                         m_NotifyEvent;
96     HANDLE&                         m_ResumeNotifying;
97     osl::Mutex						m_Mutex;
98 
99 // prevent copy and assignment
100 private:
101     CAsyncEventNotifier( const CAsyncEventNotifier& );
102     CAsyncEventNotifier& operator=( const CAsyncEventNotifier& );
103 };
104 
105 #endif
106