/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#ifndef INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
#define INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
#include 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 definitely 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 its 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 ) { // 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 // INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */