Kaydet (Commit) e9e61809 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Simplify TransactionManager

Change-Id: I51d1969f9f88d9e29fc081fd54df365578900126
üst fc44b710
......@@ -51,18 +51,6 @@ enum EWorkingMode
E_CLOSE // Object is dead! -> all calls are rejected!
};
/*-************************************************************************************************************
@descr If a request was refused by a transaction manager (internal state different E_WORK ...)
user can check the reason by using this enum values.
*//*-*************************************************************************************************************/
enum ERejectReason
{
E_UNINITIALIZED ,
E_NOREASON ,
E_INCLOSE ,
E_CLOSED
};
/*-************************************************************************************************************
@descr A transaction object should support throwing exceptions if user used it at wrong working mode.
e.g. We can throw a DisposedException if user try to work and our mode is E_CLOSE!
......@@ -120,18 +108,9 @@ class FWI_DLLPUBLIC TransactionManager: private boost::noncopyable
~TransactionManager ( );
void setWorkingMode ( EWorkingMode eMode );
EWorkingMode getWorkingMode ( ) const;
bool isCallRejected ( ERejectReason& eReason ) const;
void registerTransaction ( EExceptionMode eMode ) throw( css::uno::RuntimeException, css::lang::DisposedException );
void unregisterTransaction ( ) throw( css::uno::RuntimeException, css::lang::DisposedException );
// private methods
private:
void impl_throwExceptions( EExceptionMode eMode, ERejectReason eReason ) const throw( css::uno::RuntimeException, css::lang::DisposedException );
// private member
private:
mutable ::osl::Mutex m_aAccessLock; /// regulate access on internal member of this instance
......
......@@ -155,22 +155,34 @@ EWorkingMode TransactionManager::getWorkingMode() const
*//*-*****************************************************************************************************/
void TransactionManager::registerTransaction( EExceptionMode eMode ) 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.
ERejectReason eReason;
if( isCallRejected( eReason ) )
::osl::MutexGuard aAccessGuard( m_aAccessLock );
switch( m_eWorkingMode )
{
impl_throwExceptions( eMode, eReason );
case E_INIT:
if( eMode == E_HARDEXCEPTIONS )
{
// Help programmer to find out, why this exception is thrown!
SAL_WARN( "fwk", "TransactionManager...: Owner instance not correctly initialized yet. Call was rejected! Normally it's an algorithm error ... wrong use of class!" );
//ATTENTION: temp. disabled - till all bad code positions are detected and changed! */
// throw css::uno::RuntimeException( "TransactionManager...\nOwner instance not right initialized yet. Call was rejected! Normally it's an algorithm error... wrong using of class!\n", css::uno::Reference< css::uno::XInterface >() );
}
break;
case E_WORK:
break;
case E_BEFORECLOSE:
if( eMode == E_HARDEXCEPTIONS )
{
// Help programmer to find out, why this exception is thrown!
SAL_WARN( "fwk", "TransactionManager...: Owner instance stand in close method. Call was rejected!" );
throw css::lang::DisposedException( "TransactionManager...\nOwner instance stand in close method. Call was rejected!" );
}
break;
case E_CLOSE:
// Help programmer to find out, why this exception is thrown!
SAL_WARN( "fwk", "TransactionManager...: Owner instance already closed. Call was rejected!" );
throw css::lang::DisposedException( "TransactionManager...\nOwner instance already closed. Call was rejected!" );
}
// 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 );
// Register this new transaction.
// If it is the first one .. close gate to disable changing of working mode.
++m_nTransactionCount;
......@@ -203,82 +215,6 @@ void TransactionManager::unregisterTransaction() throw( css::uno::RuntimeExcept
}
}
/*-****************************************************************************************************
@short look for rejected calls
@descr Sometimes user need a possibility to get information about rejected calls
without starting a transaction!
@param "eReason" returns reason of a rejected call
@return true if call was rejected, false otherwise
@onerror We return false.
*//*-*****************************************************************************************************/
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 a user wishes to use our automatic exception mode we use this impl-method.
We check all combinations of eReason and eExceptionMode and throw correct exception with some
descriptions for the recipient.
@seealso method registerTransaction()
@seealso enum ERejectReason
@seealso enum EExceptionMode
@param "eReason" , reason for rejected call
@param "eMode" , exception mode - set by user
*//*-*****************************************************************************************************/
void TransactionManager::impl_throwExceptions( EExceptionMode eMode, ERejectReason eReason ) const throw( css::uno::RuntimeException, css::lang::DisposedException )
{
switch( eReason )
{
case E_UNINITIALIZED : if( eMode == E_HARDEXCEPTIONS )
{
// Help programmer to find out, why this exception is thrown!
SAL_WARN( "fwk", "TransactionManager...: Owner instance not correctly initialized yet. Call was rejected! Normally it's an algorithm error ... wrong use of class!" );
//ATTENTION: temp. disabled - till all bad code positions are detected and changed! */
// throw css::uno::RuntimeException( "TransactionManager...\nOwner instance not right initialized yet. Call was rejected! Normally it's an algorithm error... wrong using 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!
SAL_WARN( "fwk", "TransactionManager...: Owner instance stand in close method. Call was rejected!" );
throw css::lang::DisposedException( "TransactionManager...\nOwner instance stand in close method. Call was rejected!" );
}
break;
case E_CLOSED : {
// Help programmer to find out, why this exception is thrown!
SAL_WARN( "fwk", "TransactionManager...: Owner instance already closed. Call was rejected!" );
throw css::lang::DisposedException( "TransactionManager...\nOwner instance already closed. Call was rejected!" );
}
case E_NOREASON : {
// Help programmer to find out
SAL_WARN( "fwk", "TransactionManager...: Impossible case E_NOREASON!" );
}
break;
default:
assert(false);
}
}
} // namespace framework
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment