diff options
Diffstat (limited to 'framework/source/threadhelp')
-rw-r--r-- | framework/source/threadhelp/lockhelper.cxx | 549 | ||||
-rw-r--r-- | framework/source/threadhelp/makefile.mk | 45 | ||||
-rw-r--r-- | framework/source/threadhelp/transactionmanager.cxx | 373 |
3 files changed, 0 insertions, 967 deletions
diff --git a/framework/source/threadhelp/lockhelper.cxx b/framework/source/threadhelp/lockhelper.cxx deleted file mode 100644 index 4c5ebb7a5d91..000000000000 --- a/framework/source/threadhelp/lockhelper.cxx +++ /dev/null @@ -1,549 +0,0 @@ -/************************************************************************* - * - * 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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_framework.hxx" - -//_________________________________________________________________________________________________________________ -// my own includes -//_________________________________________________________________________________________________________________ -#include <threadhelp/lockhelper.hxx> -#include <general.h> -#include <macros/debug.hxx> - -#include <macros/generic.hxx> - -//_________________________________________________________________________________________________________________ -// interface includes -//_________________________________________________________________________________________________________________ - -//_________________________________________________________________________________________________________________ -// other includes -//_________________________________________________________________________________________________________________ -#include <vos/process.hxx> - -//_________________________________________________________________________________________________________________ -// namespace -//_________________________________________________________________________________________________________________ - -namespace framework{ - -//_________________________________________________________________________________________________________________ -// const -//_________________________________________________________________________________________________________________ - -//_________________________________________________________________________________________________________________ -// declarations -//_________________________________________________________________________________________________________________ - -/*-************************************************************************************************************//** - @short use ctor to initialize instance - @descr We must initialize our member "m_eLockType". This value specify handling of locking. - User use this helper as parameter for a guard creation. - These guard use "m_eLockType" to set lock in the right way by using right mutex or rw-lock. - - @seealso enum ELockType - @seealso class ReadGuard - @seealso class WriteGuard - - @param "rSolarMutex", for some components we must be "vcl-free"! So we can't work with our solar mutex - directly. User must set his reference at this instance - so we can work with it! - @return - - - @onerror - -*//*-*************************************************************************************************************/ -LockHelper::LockHelper( ::vos::IMutex* pSolarMutex ) - : m_pFairRWLock ( NULL ) - , m_pOwnMutex ( NULL ) - , m_pSolarMutex ( NULL ) - , m_pShareableOslMutex( NULL ) - , m_bDummySolarMutex ( sal_False ) -{ - m_eLockType = implts_getLockType(); - switch( m_eLockType ) - { - case E_NOTHING : break; // There is nothing to do ... - case E_OWNMUTEX : { - m_pOwnMutex = new ::osl::Mutex; - } - break; - case E_SOLARMUTEX : { - if( pSolarMutex == NULL ) - { - m_pSolarMutex = new ::vos::OMutex; - m_bDummySolarMutex = sal_True; - } - else - { - m_pSolarMutex = pSolarMutex; - } - } - break; - case E_FAIRRWLOCK : { - m_pFairRWLock = new FairRWLock; - } - break; - #ifdef ENABLE_ASSERTIONS - default : LOG_ASSERT2( m_eLockType!=E_NOTHING, "LockHelper::ctor()", "Invalid lock type found .. so code will not be threadsafe!" ) - #endif - } -} - -/*-************************************************************************************************************//** - @short default dtor to release safed pointer - @descr We have created dynamical mutex- or lock-member ... or we hold a pointer to external objects. - We must release it! - - @seealso ctor() - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -LockHelper::~LockHelper() -{ - if( m_pShareableOslMutex != NULL ) - { - // Sometimes we hold two pointer to same object! - // (e.g. if m_eLockType==E_OWNMUTEX!) - // So we should forget it ... but don't delete it twice! - if( m_pShareableOslMutex != m_pOwnMutex ) - { - delete m_pShareableOslMutex; - } - m_pShareableOslMutex = NULL; - } - if( m_pOwnMutex != NULL ) - { - delete m_pOwnMutex; - m_pOwnMutex = NULL; - } - if( m_pSolarMutex != NULL ) - { - if (m_bDummySolarMutex) - { - delete static_cast<vos::OMutex*>(m_pSolarMutex); - m_bDummySolarMutex = sal_False; - } - m_pSolarMutex = NULL; - } - if( m_pFairRWLock != NULL ) - { - delete m_pFairRWLock; - m_pFairRWLock = NULL; - } -} - -/*-************************************************************************************************************//** - @interface IMutex - @short set an exclusiv lock - @descr We must match this lock call with current set lock type and used lock member. - If a mutex should be used - it will be easy ... but if a rw-lock should be used - we must simulate it as a write access! - - @attention If a shareable osl mutex exist, he must be used as twice! - It's neccessary for some cppu-helper classes ... - - @seealso method acquireWriteAccess() - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -void LockHelper::acquire() -{ - switch( m_eLockType ) - { - case E_NOTHING : break; // There is nothing to do ... - case E_OWNMUTEX : { - m_pOwnMutex->acquire(); - } - break; - case E_SOLARMUTEX : { - m_pSolarMutex->acquire(); - } - break; - case E_FAIRRWLOCK : { - m_pFairRWLock->acquireWriteAccess(); - } - break; - } -} - -/*-************************************************************************************************************//** - @interface IMutex - @short release exclusiv lock - @descr We must match this unlock call with current set lock type and used lock member. - If a mutex should be used - it will be easy ... but if a rw-lock should be used - we must simulate it as a write access! - - @attention If a shareable osl mutex exist, he must be used as twice! - It's neccessary for some cppu-helper classes ... - - @seealso method releaseWriteAccess() - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -void LockHelper::release() -{ - switch( m_eLockType ) - { - case E_NOTHING : break; // There is nothing to do ... - case E_OWNMUTEX : { - m_pOwnMutex->release(); - } - break; - case E_SOLARMUTEX : { - m_pSolarMutex->release(); - } - break; - case E_FAIRRWLOCK : { - m_pFairRWLock->releaseWriteAccess(); - } - break; - } -} - -/*-************************************************************************************************************//** - @interface IRWLock - @short set lock for reading - @descr A guard should call this method to acquire read access on your member. - Writing isn't allowed then - but nobody could check it for you! - We use m_eLockType to differ between all possible "lock-member"!!! - - @attention If a shareable osl mutex exist, he must be used as twice! - It's neccessary for some cppu-helper classes ... - - @seealso method releaseReadAccess() - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -void LockHelper::acquireReadAccess() -{ - switch( m_eLockType ) - { - case E_NOTHING : break; // There is nothing to do ... - case E_OWNMUTEX : { - m_pOwnMutex->acquire(); - } - break; - case E_SOLARMUTEX : { - m_pSolarMutex->acquire(); - } - break; - case E_FAIRRWLOCK : { - m_pFairRWLock->acquireReadAccess(); - } - break; - } -} - -/*-************************************************************************************************************//** - @interface IRWLock - @short reset lock for reading - @descr A guard should call this method to release read access on your member. - We use m_eLockType to differ between all possible "lock-member"!!! - - @attention If a shareable osl mutex exist, he must be used as twice! - It's neccessary for some cppu-helper classes ... - - @seealso method acquireReadAccess() - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -void LockHelper::releaseReadAccess() -{ - switch( m_eLockType ) - { - case E_NOTHING : break; // There is nothing to do ... - case E_OWNMUTEX : { - m_pOwnMutex->release(); - } - break; - case E_SOLARMUTEX : { - m_pSolarMutex->release(); - } - break; - case E_FAIRRWLOCK : { - m_pFairRWLock->releaseReadAccess(); - } - break; - } -} - -/*-************************************************************************************************************//** - @interface IRWLock - @short set lock for writing - @descr A guard should call this method to acquire write access on your member. - Reading is allowed too - of course. - After successfully calling of this method you are the only writer. - We use m_eLockType to differ between all possible "lock-member"!!! - - @attention If a shareable osl mutex exist, he must be used as twice! - It's neccessary for some cppu-helper classes ... - - @seealso method releaseWriteAccess() - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -void LockHelper::acquireWriteAccess() -{ - switch( m_eLockType ) - { - case E_NOTHING : break; // There is nothing to do ... - case E_OWNMUTEX : { - m_pOwnMutex->acquire(); - } - break; - case E_SOLARMUTEX : { - m_pSolarMutex->acquire(); - } - break; - case E_FAIRRWLOCK : { - m_pFairRWLock->acquireWriteAccess(); - } - break; - } -} - -/*-************************************************************************************************************//** - @interface IRWLock - @short reset lock for writing - @descr A guard should call this method to release write access on your member. - We use m_eLockType to differ between all possible "lock-member"!!! - - @attention If a shareable osl mutex exist, he must be used as twice! - It's neccessary for some cppu-helper classes ... - - @seealso method acquireWriteAccess() - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -void LockHelper::releaseWriteAccess() -{ - switch( m_eLockType ) - { - case E_NOTHING : break; // There is nothing to do ... - case E_OWNMUTEX : { - m_pOwnMutex->release(); - } - break; - case E_SOLARMUTEX : { - m_pSolarMutex->release(); - } - break; - case E_FAIRRWLOCK : { - m_pFairRWLock->releaseWriteAccess(); - } - break; - } -} - -/*-************************************************************************************************************//** - @interface IRWLock - @short downgrade a write access to a read access - @descr A guard should call this method to change a write to a read access. - New readers can work too - new writer are blocked! - We use m_eLockType to differ between all possible "lock-member"!!! - - @attention Ignore shareable mutex(!) - because this call never should release a lock completly! - We change a write access to a read access only. - - @attention a) Don't call this method if you are not a writer! - Results are not defined then ... - An upgrade can't be implemented realy ... because acquiring new access - will be the same - there no differences! - b) Without function if m_eLockTyp is different from E_FAIRRWLOCK(!) ... - because, a mutex don't support it realy. - - @seealso - - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -void LockHelper::downgradeWriteAccess() -{ - switch( m_eLockType ) - { - case E_NOTHING : break; // There is nothing to do ... - case E_OWNMUTEX : break; // Not supported for mutex! - case E_SOLARMUTEX : break; // Not supported for mutex! - case E_FAIRRWLOCK : m_pFairRWLock->downgradeWriteAccess(); - break; - } -} - -/*-************************************************************************************************************//** - @short return a reference to a static lock helper - @descr Sometimes we need the global mutex or rw-lock! (e.g. in our own static methods) - But it's not a good idea to use these global one very often ... - Thats why we use this little helper method. - We create our own "class global static" lock. - It will be created at first call only! - All other requests use these created one then directly. - - @seealso - - - @param - - @return A reference to a static mutex/lock member. - - @onerror No error should occure. -*//*-*************************************************************************************************************/ -LockHelper& LockHelper::getGlobalLock( ::vos::IMutex* pSolarMutex ) -{ - // Initialize static "member" only for one time! - // Algorithm: - // a) Start with an invalid lock (NULL pointer) - // b) If these method first called (lock not already exist!) ... - // c) ... we must create a new one. Protect follow code with the global mutex - - // (It must be - we create a static variable!) - // d) Check pointer again - because ... another instance of our class could be faster then these one! - // e) Create the new lock and set it for return on static variable. - // f) Return new created or already existing lock object. - static LockHelper* pLock = NULL; - if( pLock == NULL ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if( pLock == NULL ) - { - static LockHelper aLock( pSolarMutex ); - pLock = &aLock; - } - } - return *pLock; -} - -/*-************************************************************************************************************//** - @short return a reference to shared mutex member - @descr Sometimes we need a osl-mutex for sharing with our uno helper ... - What can we do? - a) If we have an initialized "own mutex" ... we can use it! - b) Otherwhise we must use a different mutex member :-( - I HOPE IT WORKS! - - @seealso - - - @param - - @return A reference to a shared mutex. - - @onerror No error should occure. -*//*-*************************************************************************************************************/ -::osl::Mutex& LockHelper::getShareableOslMutex() -{ - if( m_pShareableOslMutex == NULL ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if( m_pShareableOslMutex == NULL ) - { - switch( m_eLockType ) - { - case E_OWNMUTEX : { - m_pShareableOslMutex = m_pOwnMutex; - } - break; - default : { - m_pShareableOslMutex = new ::osl::Mutex; - } - break; - } - } - } - return *m_pShareableOslMutex; -} - -/*-************************************************************************************************************//** - @short search for right lock type, which should be used by an instance of this struct - @descr We must initialize our member "m_eLockType". This value specify handling of locking. - How we can do that? We search for an environment variable. We do it only for one time .... - because the environment is fix. So we safe this value and use it for all further requests. - If no variable could be found - we use a fallback! - - @attention We have numbered all our enum values for ELockType. So we can use it as value of searched - environment variable too! - - @seealso enum ELockType - @seealso environment LOCKTYPE - - @param - - @return A reference to a created and right initialized lock type! - - @onerror We use a fallback! -*//*-*************************************************************************************************************/ -ELockType& LockHelper::implts_getLockType() -{ - // Initialize static "member" only for one time! - // Algorithm: - // a) Start with an invalid variable (NULL pointer) - // b) If these method first called (value not already exist!) ... - // c) ... we must create a new one. Protect follow code with the global mutex - - // (It must be - we create a static variable!) - // d) Check pointer again - because ... another instance of our class could be faster then these one! - // e) Create the new static variable, get value from the environment and set it - // f) Return new created or already existing static variable. - static ELockType* pType = NULL; - if( pType == NULL ) - { - ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); - if( pType == NULL ) - { - static ELockType eType = FALLBACK_LOCKTYPE; - - ::vos::OStartupInfo aEnvironment; - ::rtl::OUString sValue ; - if( aEnvironment.getEnvironment( ENVVAR_LOCKTYPE, sValue ) == ::vos::OStartupInfo::E_None ) - { - eType = (ELockType)(sValue.toInt32()); - } - - LOG_LOCKTYPE( FALLBACK_LOCKTYPE, eType ) - - pType = &eType; - } - } - return *pType; -} - -} // namespace framework diff --git a/framework/source/threadhelp/makefile.mk b/framework/source/threadhelp/makefile.mk deleted file mode 100644 index be4d71137925..000000000000 --- a/framework/source/threadhelp/makefile.mk +++ /dev/null @@ -1,45 +0,0 @@ -#************************************************************************* -# -# 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 -# <http://www.openoffice.org/license.html> -# for a copy of the LGPLv3 License. -# -#************************************************************************* -PRJ=..$/.. - -PRJNAME= framework -TARGET= fwk_threadhelp -USE_DEFFILE= TRUE -ENABLE_EXCEPTIONS= TRUE - -# --- Settings ----------------------------------------------------- - -.INCLUDE : settings.mk - -# --- Generate ----------------------------------------------------- - -SLOFILES= $(SLO)$/lockhelper.obj \ - $(SLO)$/transactionmanager.obj - -# --- Targets ------------------------------------------------------ - -.INCLUDE : target.mk diff --git a/framework/source/threadhelp/transactionmanager.cxx b/framework/source/threadhelp/transactionmanager.cxx deleted file mode 100644 index a42c871c176e..000000000000 --- a/framework/source/threadhelp/transactionmanager.cxx +++ /dev/null @@ -1,373 +0,0 @@ -/************************************************************************* - * - * 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 - * <http://www.openoffice.org/license.html> - * for a copy of the LGPLv3 License. - * - ************************************************************************/ - -// MARKER(update_precomp.py): autogen include statement, do not remove -#include "precompiled_framework.hxx" - -//_________________________________________________________________________________________________________________ -// my own includes -//_________________________________________________________________________________________________________________ -#include <threadhelp/transactionmanager.hxx> -#include <threadhelp/resetableguard.hxx> -#include <macros/debug.hxx> - -#include <macros/generic.hxx> - -//_________________________________________________________________________________________________________________ -// interface includes -//_________________________________________________________________________________________________________________ -#include <com/sun/star/lang/DisposedException.hpp> -//_________________________________________________________________________________________________________________ -// other includes -//_________________________________________________________________________________________________________________ - -//_________________________________________________________________________________________________________________ -// const -//_________________________________________________________________________________________________________________ - -//_________________________________________________________________________________________________________________ -// namespace -//_________________________________________________________________________________________________________________ - -namespace framework{ - -//_________________________________________________________________________________________________________________ -// non exported const -//_________________________________________________________________________________________________________________ - -//_________________________________________________________________________________________________________________ -// non exported declarations -//_________________________________________________________________________________________________________________ - -//_________________________________________________________________________________________________________________ -// definitions -//_________________________________________________________________________________________________________________ - -/*-************************************************************************************************************//** - @short standard ctor - @descr Initialize instance with right start values for correct working. - - @seealso - - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -TransactionManager::TransactionManager() - : m_eWorkingMode ( E_INIT ) - , m_nTransactionCount ( 0 ) -{ - m_aBarrier.open(); -} - -/*-************************************************************************************************************//** - @short standard dtor - @descr - - - @seealso - - - @param - - @return - - - @onerror - -*//*-*************************************************************************************************************/ -TransactionManager::~TransactionManager() -{ -} - -/*-****************************************************************************************************//** - @interface ITransactionManager - @short set new working mode - @descr These implementation knows for states of working: E_INIT, E_WORK, E_CLOSING, E_CLOSE - You can step during this ones only from the left to the right side and start at left side again! - (This is neccessary e.g. for refcounted objects!) - This call will block till all current existing transactions was finished. - Follow results occure: - E_INIT : All requests on this implementation are refused. - It's your decision to react in a right way. - - E_WORK : The object can work now. The full functionality is available. - - E_BEFORECLOSE : The object start the closing mechanism ... but sometimes - e.g. the dispose() method need to call some private methods. - These some special methods should use E_SOFTEXCEPTIONS or ignore - E_INCLOSE as returned reason for E_NOEXCEPTIONS to detect this special case! - - E_CLOSE : Object is already dead! All further requests will be refused. - It's your decision to react in a right way. - - @seealso - - - @param "eMode", is the new mode - but we don't accept setting mode in wrong order! - @return - - - @onerror We do nothing. -*//*-*****************************************************************************************************/ -void TransactionManager::setWorkingMode( EWorkingMode eMode ) -{ - // Safe member access. - ::osl::ClearableMutexGuard aAccessGuard( m_aAccessLock ); - sal_Bool bWaitFor = sal_False ; - // Change working mode first! - if ( - ( m_eWorkingMode == E_INIT && eMode == E_WORK ) || - ( m_eWorkingMode == E_WORK && eMode == E_BEFORECLOSE ) || - ( m_eWorkingMode == E_BEFORECLOSE && eMode == E_CLOSE ) || - ( m_eWorkingMode == E_CLOSE && eMode == E_INIT ) - ) - { - m_eWorkingMode = eMode; - if( m_eWorkingMode == E_BEFORECLOSE || m_eWorkingMode == E_CLOSE ) - { - bWaitFor = sal_True; - } - } - - // Wait for current existing transactions then! - // (Only neccessary for changing to E_BEFORECLOSE or E_CLOSE! ... - // otherwise; if you wait at setting E_WORK another thrad could finish a acquire-call during our unlock() and wait() call - // ... and we will wait forever here!!!) - // Don't forget to release access mutex before. - aAccessGuard.clear(); - if( bWaitFor == sal_True ) - { - m_aBarrier.wait(); - } -} - -/*-****************************************************************************************************//** - @interface ITransactionManager - @short get current working mode - @descr If you stand in your close() or init() method ... but don't know - if you called more then ones(!) ... you can use this function to get - right information. - e.g: You have a method init() which is used to change working mode from - E_INIT to E_WORK and should be used to initialize some member too ... - What should you do: - - void init( sal_Int32 nValue ) - { - // Reject this call if our transaction manager say: "Object already initialized!" - // Otherwise initialize your member. - if( m_aTransactionManager.getWorkingMode() == E_INIT ) - { - // Object is uninitialized ... - // Make member access threadsafe! - ResetableGuard aGuard( m_aMutex ); - - // Check working mode again .. because anoz�ther instance could be faster. - // (It's possible to set this guard at first of this method too!) - if( m_aTransactionManager.getWorkingMode() == E_INIT ) - { - m_aMember = nValue; - - // Object is initialized now ... set working mode to E_WORK! - m_aTransactionManager.setWorkingMode( E_WORK ); - } - } - } - - @seealso method setWorkingMode() - - @param - - @return Current set mode. - - @onerror No error should occure. -*//*-*****************************************************************************************************/ -EWorkingMode TransactionManager::getWorkingMode() const -{ - // Synchronize access to internal member! - ::osl::MutexGuard aAccessLock( m_aAccessLock ); - return m_eWorkingMode; -} - -/*-****************************************************************************************************//** - @interface ITransactionManager - @short start new transaction - @descr A guard should use this method to start a new transaction. He should looks for rejected - calls to by using parameter eMode and eReason. - If call was not rejected your transaction will be non breakable during releasing your transaction - guard! BUT ... your code isn't threadsafe then! It's a transaction manager only .... - - @seealso method unregisterTransaction() - - @param "eMode" ,used to enable/disable throwing exceptions automaticly for rejected calls - @param "eReason" ,reason for rejected calls if eMode=E_NOEXCEPTIONS - @return - - - @onerror - -*//*-*****************************************************************************************************/ -void TransactionManager::registerTransaction( EExceptionMode eMode, ERejectReason& eReason ) throw( css::uno::RuntimeException, css::lang::DisposedException ) -{ - // Look for rejected calls first. - // If call was refused we throw some exceptions or do nothing! - // It depends from given parameter eMode. - if( isCallRejected( eReason ) == sal_True ) - { - impl_throwExceptions( eMode, eReason ); - } - - // BUT if no exception was thrown ... (may be eMode = E_SOFTEXCEPTIONS!) - // we must register this transaction too! - // Don't use "else" or a new scope here!!! - - // Safe access to internal member. - ::osl::MutexGuard aAccessGuard( m_aAccessLock ); - - #ifdef ENABLE_MUTEXDEBUG - LOG_ASSERT2( m_nTransactionCount<0, "TransactionManager::acquire()", "Wrong ref count detected!" ) - #endif - - // Register this new transaction. - // If it is the first one .. close gate to disable changing of working mode. - ++m_nTransactionCount; - if( m_nTransactionCount == 1 ) - { - m_aBarrier.close(); - } -} - -/*-****************************************************************************************************//** - @interface ITransactionManager - @short finish transaction - @descr A guard should call this method to release current transaction. - - @seealso method registerTransaction() - - @param - - @return - - - @onerror - -*//*-*****************************************************************************************************/ -void TransactionManager::unregisterTransaction() throw( css::uno::RuntimeException, css::lang::DisposedException ) -{ - // This call could not rejected! - // Safe access to internal member. - ::osl::MutexGuard aAccessGuard( m_aAccessLock ); - - #ifdef ENABLE_MUTEXDEBUG - LOG_ASSERT2( m_nTransactionCount<=0, "TransactionManager::release()", "Wrong ref count detected!" ) - #endif - - // Deregister this transaction. - // If it was the last one ... open gate to enable changing of working mode! - // (see setWorkingMode()) - - --m_nTransactionCount; - if( m_nTransactionCount == 0 ) - { - m_aBarrier.open(); - } -} - -/*-****************************************************************************************************//** - @interface ITransactionManager - @short look for rejected calls - @descr Sometimes user need a possibility to get information about rejected calls - without starting a transaction! - - @seealso - - - @param "eReason" returns reason of a rejected call - @return true if call was rejected, false otherwise - - @onerror We return false. -*//*-*****************************************************************************************************/ -sal_Bool TransactionManager::isCallRejected( ERejectReason& eReason ) const -{ - // This call must safe access to internal member only. - // Set "possible reason" for return and check reject-state then! - // User should look for return value first - reason then ... - ::osl::MutexGuard aAccessGuard( m_aAccessLock ); - switch( m_eWorkingMode ) - { - case E_INIT : eReason = E_UNINITIALIZED ; - break; - case E_WORK : eReason = E_NOREASON ; - break; - case E_BEFORECLOSE : eReason = E_INCLOSE ; - break; - case E_CLOSE : eReason = E_CLOSED ; - break; - } - return( eReason!=E_NOREASON ); -} - -/*-****************************************************************************************************//** - @short throw any exceptions for rejected calls - @descr If user whish to use our automaticly exception mode we use this impl-method. - We check all combinations of eReason and eExceptionMode and throw right exception with some - descriptions for recipient of it. - - @seealso method registerTransaction() - @seealso enum ERejectReason - @seealso enum EExceptionMode - - @param "eReason" , reason for rejected call - @param "eMode" , exception mode - set by user - @return - - - @onerror - -*//*-*****************************************************************************************************/ -void TransactionManager::impl_throwExceptions( EExceptionMode eMode, ERejectReason eReason ) const throw( css::uno::RuntimeException, css::lang::DisposedException ) -{ - if( eMode != E_NOEXCEPTIONS ) - { - switch( eReason ) - { - case E_UNINITIALIZED : if( eMode == E_HARDEXCEPTIONS ) - { - // Help programmer to find out, why this exception is thrown! - LOG_ERROR( "TransactionManager...", "Owner instance not right initialized yet. Call was rejected! Normaly it's an algorithm error ... wrong usin of class!" ) - //ATTENTION: temp. disabled - till all bad code positions are detected and changed! */ - // throw css::uno::RuntimeException( DECLARE_ASCII("TransactionManager...\nOwner instance not right initialized yet. Call was rejected! Normaly it's an algorithm error ... wrong usin of class!\n" ), css::uno::Reference< css::uno::XInterface >() ); - } - break; - case E_INCLOSE : if( eMode == E_HARDEXCEPTIONS ) - { - // Help programmer to find out, why this exception is thrown! - LOG_ERROR( "TransactionManager...", "Owner instance stand in close method. Call was rejected!" ) - throw css::lang::DisposedException( DECLARE_ASCII("TransactionManager...\nOwner instance stand in close method. Call was rejected!\n" ), css::uno::Reference< css::uno::XInterface >() ); - } - break; - case E_CLOSED : { - // Help programmer to find out, why this exception is thrown! - LOG_ERROR( "TransactionManager...", "Owner instance already closed. Call was rejected!" ) - throw css::lang::DisposedException( DECLARE_ASCII("TransactionManager...\nOwner instance already closed. Call was rejected!\n" ), css::uno::Reference< css::uno::XInterface >() ); - } - case E_NOREASON : { - // Help programmer to find out - LOG_ERROR( "TransactionManager...", "Impossible case E_NOREASON!" ) - } - break; - default: break; // nothing to do - } - } -} - -} // namespace framework |