LCOV - code coverage report
Current view: top level - framework/inc/threadhelp - itransactionmanager.h (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 2 100.0 %
Date: 2012-08-25 Functions: 2 2 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #ifndef __FRAMEWORK_THREADHELP_ITRANSACTIONMANAGER_H_
      30                 :            : #define __FRAMEWORK_THREADHELP_ITRANSACTIONMANAGER_H_
      31                 :            : 
      32                 :            : #include <general.h>
      33                 :            : #include <com/sun/star/uno/RuntimeException.hpp>
      34                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      35                 :            : 
      36                 :            : namespace framework{
      37                 :            : 
      38                 :            : /*-************************************************************************************************************//**
      39                 :            :     @descr          Describe different states of a feature of following implementation.
      40                 :            :                     During live time of an object different working states occure:
      41                 :            :                         initialization - working - closing - closed
      42                 :            :                     If you whish to implement thread safe classes you should use these feature to protect
      43                 :            :                     your code against calls at wrong time. e.g. you are not full initialized but somewhere
      44                 :            :                     call an interface method (initialize phase means startup time from creating object till
      45                 :            :                     calling specified first method e.g. XInitialization::initialze()!) then you should refuse
      46                 :            :                     this call. The same for closing/disposing the object!
      47                 :            : *//*-*************************************************************************************************************/
      48                 :            : enum EWorkingMode
      49                 :            : {
      50                 :            :     E_INIT       ,   // We stand in a init method   -> some calls are accepted - some one are rejected
      51                 :            :     E_WORK       ,   // Object is ready for working -> all calls are accepted
      52                 :            :     E_BEFORECLOSE,   // We stand in a close method  -> some calls are accepted - some one are rejected
      53                 :            :     E_CLOSE          // Object is dead!             -> all calls are rejected!
      54                 :            : };
      55                 :            : 
      56                 :            : /*-************************************************************************************************************//**
      57                 :            :     @descr          If a request was refused by a transaction manager (internal state different E_WORK ...)
      58                 :            :                     user can check the reason by using this enum values.
      59                 :            : *//*-*************************************************************************************************************/
      60                 :            : enum ERejectReason
      61                 :            : {
      62                 :            :     E_UNINITIALIZED ,
      63                 :            :     E_NOREASON      ,
      64                 :            :     E_INCLOSE       ,
      65                 :            :     E_CLOSED
      66                 :            : };
      67                 :            : 
      68                 :            : /*-************************************************************************************************************//**
      69                 :            :     @descr          A transaction object should support throwing exceptions if user used it at wrong working mode.
      70                 :            :                     e.g. We can throw a DisposedException if user try to work and our mode is E_CLOSE!
      71                 :            :                     But sometimes he dont need this feature - will handle it by himself.
      72                 :            :                     Then we must differ between some exception-modi:
      73                 :            :                         E_NOEXCEPTIONS          We never throw any exceptions! User handle it private and looks for ERejectReason.
      74                 :            :                         E_HARDEXCEPTIONS        We throw exceptions for all working modes different from E_WORK!
      75                 :            :                         E_SOFTEXCEPTIONS        We throw exceptions for all working modes different from E_WORK AND E_INCLOSE!
      76                 :            :                                                 This mode is useful for impl-methods which should be callable from dispose() method!
      77                 :            : 
      78                 :            :                                                 e.g.    void dispose()
      79                 :            :                                                         {
      80                 :            :                                                             m_aTransactionManager.setWorkingMode( E_BEFORECLOSE );
      81                 :            :                                                             ...
      82                 :            :                                                             impl_setA( 0 );
      83                 :            :                                                             ...
      84                 :            :                                                             m_aTransactionManager.setWorkingMode( E_CLOSE );
      85                 :            :                                                         }
      86                 :            : 
      87                 :            :                                                         void impl_setA( int nA )
      88                 :            :                                                         {
      89                 :            :                                                             ERejectReason       EReason;
      90                 :            :                                                             TransactionGuard    aTransactionGuard( m_aTransactionManager, E_SOFTEXCEPTIONS, eReason );
      91                 :            : 
      92                 :            :                                                             m_nA = nA;
      93                 :            :                                                         }
      94                 :            : 
      95                 :            :                                                 Normaly (if E_HARDEXCEPTIONS was used!) creation of guard
      96                 :            :                                                 will throw an exception ... but using of E_SOFTEXCEPTIONS suppress it
      97                 :            :                                                 and member "A" can be set.
      98                 :            : *//*-*************************************************************************************************************/
      99                 :            : enum EExceptionMode
     100                 :            : {
     101                 :            :     E_NOEXCEPTIONS  ,
     102                 :            :     E_HARDEXCEPTIONS,
     103                 :            :     E_SOFTEXCEPTIONS
     104                 :            : };
     105                 :            : 
     106                 :            : /*-************************************************************************************************************//**
     107                 :            :     @descr          How can you use the transaction manager?
     108                 :            :                     Use it in combination with an TransactionGuard, which register your transaction in ctor
     109                 :            :                     and release in dtor automaticly! Follow interface class can be used to make using
     110                 :            :                     of different manager implmentations possible by using same guard.
     111                 :            : *//*-*************************************************************************************************************/
     112                 :       4634 : class ITransactionManager
     113                 :            : {
     114                 :            :     //-------------------------------------------------------------------------------------------------------------
     115                 :            :     //  public methods
     116                 :            :     //-------------------------------------------------------------------------------------------------------------
     117                 :            :     public:
     118                 :            : 
     119                 :            :         /*-****************************************************************************************************//**
     120                 :            :             @descr      These functions must be supported by a derived class!
     121                 :            :                             getWorkingMode()        -return current set working mode
     122                 :            :                             setWorkingMode()        -change working mode
     123                 :            :                                                      (This will block till all current transactions are finished!)
     124                 :            :                             isCallRejected()        -test method to check if a call will be rejected by wrong working mode or not
     125                 :            :                             registerTransaction()   -start new transaction (increase internal transaction count)
     126                 :            :                             unregisterTransaction() -finish transaction    (decrease internal transaction count)
     127                 :            :         *//*-*****************************************************************************************************/
     128                 :            :         virtual EWorkingMode getWorkingMode         (                                                ) const = 0;
     129                 :            :         virtual void         setWorkingMode         ( EWorkingMode   eMode                           )       = 0;
     130                 :            :         virtual sal_Bool     isCallRejected         ( ERejectReason& eReason                         ) const = 0;
     131                 :            :         virtual void         registerTransaction    ( EExceptionMode eMode  , ERejectReason& eReason ) throw( css::uno::RuntimeException, css::lang::DisposedException ) = 0;
     132                 :            :         virtual void         unregisterTransaction  (                                                ) throw( css::uno::RuntimeException, css::lang::DisposedException ) = 0;
     133                 :            : 
     134                 :            :     protected:
     135                 :       4252 :         ~ITransactionManager() {}
     136                 :            : };      //  class ITransactionManager
     137                 :            : 
     138                 :            : }       //  namespace framework
     139                 :            : 
     140                 :            : #endif  //  #ifndef __FRAMEWORK_THREADHELP_ITRANSACTIONMANAGER_H_
     141                 :            : 
     142                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10