LCOV - code coverage report
Current view: top level - libreoffice/framework/inc/threadhelp - transactionguard.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 13 14 92.9 %
Date: 2012-12-27 Functions: 3 3 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONGUARD_HXX_
      21             : #define __FRAMEWORK_THREADHELP_TRANSACTIONGUARD_HXX_
      22             : 
      23             : #include <threadhelp/inoncopyable.h>
      24             : #include <threadhelp/itransactionmanager.h>
      25             : 
      26             : namespace framework{
      27             : 
      28             : /*-************************************************************************************************************//**
      29             :     @short          implement a guard to support non breakable transactions
      30             :     @descr          If you whish to support non breakable method calls without lockingf any mutex, rw-lock or
      31             :                     something like that - you should use this guard implementation.
      32             :                     Initialize it at first in your method and don't release it till end of your function!
      33             :                     Your "transaction" is registered in ctor and automaticly released in dtor.
      34             :                     Use set/get of working mode to enable/disable further transactions.
      35             :                     It's possible too, to enable automaticly throwing of some exceptions for illegal
      36             :                     transaction requests ... e.g. interface call for already disposed objects.
      37             : 
      38             :     @attention      To prevent us against wrong using, the default ctor, copy ctor and the =operator are maked private!
      39             : 
      40             :     @implements     -
      41             :     @base           INonCopyable
      42             : 
      43             :     @devstatus      draft
      44             : *//*-*************************************************************************************************************/
      45             : class TransactionGuard : private INonCopyable
      46             : {
      47             :     //-------------------------------------------------------------------------------------------------------------
      48             :     //  public methods
      49             :     //-------------------------------------------------------------------------------------------------------------
      50             :     public:
      51             : 
      52             :         /*-****************************************************************************************************//**
      53             :             @short      ctors
      54             :             @descr      Use these ctor methods to initialize the guard right.
      55             :                         Given reference must be valid - otherwise crashes could occure!
      56             : 
      57             :             @attention  It's not neccessary to lock any mutex here! Because a ctor should not be called
      58             :                         from different threads at the same time ... this class use no refcount mechanism!
      59             : 
      60             :             @seealso    -
      61             : 
      62             :             @param      "rManager"  reference to transaction manager for using to register a request
      63             :             @param      "eMode"     enable/disable throwing of exceptions for rejected calls
      64             :             @param      "eReason"   returns reason for rejected calls if "eMode=E_NOEXCEPTIONS"!
      65             :             @return     -
      66             : 
      67             :             @onerror    -
      68             :         *//*-*****************************************************************************************************/
      69       78373 :         inline TransactionGuard( ITransactionManager& rManager, EExceptionMode eMode, ERejectReason* eReason = NULL )
      70       78373 :             : m_pManager( &rManager )
      71             :         {
      72             :             // If exception mode is set to E_HARDEXCETIONS we don't need a buffer to return reason!
      73             :             // We handle it private. If a call is rejected, our manager throw some exceptions ... and the reason
      74             :             // could be ignorable ...
      75       78373 :             if( eReason == NULL )
      76             :             {
      77             :                 ERejectReason eMyReason;
      78       78373 :                 m_pManager->registerTransaction( eMode, eMyReason );
      79             :             }
      80             :             else
      81             :             {
      82           0 :                 m_pManager->registerTransaction( eMode, *eReason );
      83             :             }
      84       78373 :         }
      85             : 
      86             :         /*-************************************************************************************************************//**
      87             :             @short      dtor
      88             :             @descr      We must release the transaction manager and can forget his pointer.
      89             : 
      90             :             @seealso    -
      91             : 
      92             :             @param      -
      93             :             @return     -
      94             : 
      95             :             @onerror    -
      96             :         *//*-*************************************************************************************************************/
      97       78373 :         inline ~TransactionGuard()
      98             :         {
      99       78373 :             stop();
     100       78373 :         }
     101             : 
     102             :         /*-************************************************************************************************************//**
     103             :             @short      stop current transaction
     104             :             @descr      We must release the transaction manager and can forget his pointer.
     105             : 
     106             :             @attention  We don't support any start() method here - because it is not easy to
     107             :                         detect if a transaction already started or not!
     108             :                         (combination of EExceptionMode and ERejectReason)
     109             : 
     110             :             @seealso    -
     111             : 
     112             :             @param      -
     113             :             @return     -
     114             : 
     115             :             @onerror    -
     116             :         *//*-*************************************************************************************************************/
     117       78456 :         inline void stop()
     118             :         {
     119       78456 :             if( m_pManager != NULL )
     120             :             {
     121       78373 :                 m_pManager->unregisterTransaction();
     122       78373 :                 m_pManager = NULL;
     123             :             }
     124       78456 :         }
     125             : 
     126             :     //-------------------------------------------------------------------------------------------------------------
     127             :     //  private methods
     128             :     //-------------------------------------------------------------------------------------------------------------
     129             :     private:
     130             : 
     131             :         /*-****************************************************************************************************//**
     132             :             @short      disable using of these functions!
     133             :             @descr      It's not allowed to use this methods. Different problem can occure otherwise.
     134             :                         Thats why we disable it by make it private.
     135             : 
     136             :             @seealso    other ctor
     137             : 
     138             :             @param      -
     139             :             @return     -
     140             : 
     141             :             @onerror    -
     142             :         *//*-*****************************************************************************************************/
     143             :         TransactionGuard();
     144             : 
     145             :     //-------------------------------------------------------------------------------------------------------------
     146             :     //  private member
     147             :     //-------------------------------------------------------------------------------------------------------------
     148             :     private:
     149             : 
     150             :         ITransactionManager*   m_pManager   ;   /// pointer to safed transaction manager
     151             : 
     152             : };      //  class TransactionGuard
     153             : 
     154             : }       //  namespace framework
     155             : 
     156             : #endif  //  #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONGUARD_HXX_
     157             : 
     158             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10