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 DBAUI_ASYNCRONOUSLINK_HXX
25 #define DBAUI_ASYNCRONOUSLINK_HXX
26 
27 #include <tools/link.hxx>
28 #include <osl/mutex.hxx>
29 
30 namespace dbaui
31 {
32 	// =========================================================================
33 	// a helper for multi-threaded handling of async events
34 	// -------------------------------------------------------------------------
35 	/** handles asynchronous links which may be called in multi-threaded environments
36 		If you use an instance of this class as member of your own class, it will handle
37 		several crucial points for you (for instance the case that somebody posts the
38 		event while another thread tries to delete this event in the _destructor_ of the
39 		class).
40 	*/
41 	class OAsyncronousLink
42 	{
43         Link                m_aHandler;
44 
45 	protected:
46 		::osl::Mutex        m_aEventSafety;
47 		::osl::Mutex        m_aDestructionSafety;
48 		sal_uLong				m_nEventId;
49 
50 	public:
51 		/** constructs the object
52 			@param		_rHandler			The link to be called asyncronously
53 		*/
54 		OAsyncronousLink( const Link& _rHandler );
55 		virtual ~OAsyncronousLink();
56 
IsRunning() const57         bool    IsRunning() const { return m_nEventId != 0; }
58 
59 		void Call( void* _pArgument = NULL );
60 		void CancelCall();
61 
62 	protected:
63 		DECL_LINK(OnAsyncCall, void*);
64 	};
65 }
66 #endif // DBAUI_ASYNCRONOUSLINK_HXX
67 
68