/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* If you need additional object safety for your class, and want to ensure that your own
mutex is locked before the mutex this class provides is, than use this ctor. Beware that this is a hack. Unfortunately, OpenOffice.org has two different mutex hierarchies,
which are not compatible. In addition, wide parts of the code (especially VCL) is not thread-safe,
but instead relies on a single global mutex. As a consequence, components using
directly or indirectly such code need to care for this global mutex. Yes, this is as ugly as
anything. Note that the external lock is used as additional lock, not as the only one. The own mutex of the
instance is used for internal actions, and every action which potentially involves external code
(for instance every call to a virtual method overridden by derivees) is additionally and
first guarded by with the external lock. Beware of the lifetime of the lock - you must ensure that the lock exists at least as long as
the context does. A good approach to implement the lock may be to derive you own context
not only from OAccessibleContextHelper, but also from IMutex. One more note. This lock is definately not used once the dtor is reached. Means whatever
the dtor implementation does, it does not guard the external lock. See this as a contract.
If your derived implementation implements the XAccessible (and does not follow the proposed
separation of XAccessible from XAccessibleContext), you may pass The object is hold weak, so it's life time is not affected. The object is needed for performance reasons: for This means any further locking will not be guard the external lock anymore, never. To be used in derived classes which do not supply the external lock themself, but instead get
them passed from own derivees (or clients). This basic implementation here returns the index This basic implementation returns the locale of the parent context,
as retrieved via getAccessibleParent()->getAccessibleContext. The class has two responsibilities:
You should ensure the same thing for own derivees which do not supply the lock themself,
but get them from yet another derivee.this
here.i
of the child for which
<parent>.getAccessibleChild( i )
equals our creator.
This makes it your first choice (hopefully :) for guarding any interface method implementations of
you derived class.
The given context (it's mutex, respectively) is locked, and an exception is thrown if the context is not alive anymore. In the latter case, of course, the mutex is freed, again.
@param _pContext the context which shall be guarded @precondThe context (it's mutex, respectively) is unlocked.
*/ inline ~OContextEntryGuard(); }; //..................................................................... inline OContextEntryGuard::OContextEntryGuard( OAccessibleContextHelper* _pContext ) :OContextEntryGuard_Base( _pContext->GetMutex( OAccessibleContextHelper::OAccessControl() ) ) { _pContext->ensureAlive( OAccessibleContextHelper::OAccessControl() ); } //..................................................................... inline OContextEntryGuard::~OContextEntryGuard() { } //===================================================================== //= OExternalLockGuard //===================================================================== class OExternalLockGuard :public OMutexGuard ,public OContextEntryGuard { public: inline OExternalLockGuard( OAccessibleContextHelper* _pContext ); inline ~OExternalLockGuard( ); }; //..................................................................... inline OExternalLockGuard::OExternalLockGuard( OAccessibleContextHelper* _pContext ) :OMutexGuard( _pContext->getExternalLock( OAccessibleContextHelper::OAccessControl() ) ) ,OContextEntryGuard( _pContext ) { // #102438# // Only lock the external mutex, // release the ::osl::Mutex of the OAccessibleContextHelper instance. // If you call into another UNO object with locked ::osl::Mutex, // this may lead to dead locks. clear(); } //..................................................................... inline OExternalLockGuard::~OExternalLockGuard( ) { } //......................................................................... } // namespace comphelper //......................................................................... #endif // COMPHELPER_ACCESSIBLE_CONTEXT_HELPER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */