1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
21 #define INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
23 #include <comphelper/accessiblecomponenthelper.hxx>
24 #include <comphelper/solarmutex.hxx>
31 //= OContextEntryGuard
33 /** helper class for guarding the entry into OCommonAccessibleComponent methods.
35 <p>The class has two responsibilities:
36 <ul><li>it locks the mutex of an OCommonAccessibleComponent instance, as long as the guard lives</li>
37 <li>it checks if a given OCommonAccessibleComponent instance is alive, else an exception is thrown
38 our of the constructor of the guard</li>
41 This makes it your first choice (hopefully :) for guarding any interface method implementations of
45 class OContextEntryGuard
: public ::osl::ClearableMutexGuard
48 /** constructs the guard
50 <p>The given context (it's mutex, respectively) is locked, and an exception is thrown if the context
51 is not alive anymore. In the latter case, of course, the mutex is freed, again.</p>
54 the context which shall be guarded
55 @precond <arg>_pContext</arg> != NULL
57 inline OContextEntryGuard( OCommonAccessibleComponent
* _pContext
);
61 inline OContextEntryGuard::OContextEntryGuard( OCommonAccessibleComponent
* _pContext
)
62 : ::osl::ClearableMutexGuard( _pContext
->GetMutex() )
64 _pContext
->ensureAlive();
68 //= OExternalLockGuard
70 class OExternalLockGuard
71 :public osl::Guard
<SolarMutex
>
72 ,public OContextEntryGuard
75 inline OExternalLockGuard( OCommonAccessibleComponent
* _pContext
);
79 inline OExternalLockGuard::OExternalLockGuard( OCommonAccessibleComponent
* _pContext
)
80 :osl::Guard
<SolarMutex
>( SolarMutex::get() )
81 ,OContextEntryGuard( _pContext
)
83 // Only lock the external mutex,
84 // release the ::osl::Mutex of the OCommonAccessibleComponent instance.
85 // If you call into another UNO object with locked ::osl::Mutex,
86 // this may lead to dead locks.
91 } // namespace comphelper
94 #endif // INCLUDED_COMPHELPER_ACCESSIBLECONTEXTHELPER_HXX
97 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */