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