1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONMANAGER_HXX_
29 #define __FRAMEWORK_THREADHELP_TRANSACTIONMANAGER_HXX_
30 
31 //_________________________________________________________________________________________________________________
32 //	my own includes
33 //_________________________________________________________________________________________________________________
34 
35 #include <threadhelp/inoncopyable.h>
36 #include <threadhelp/itransactionmanager.h>
37 #include <threadhelp/gate.hxx>
38 #include <macros/debug.hxx>
39 
40 //_________________________________________________________________________________________________________________
41 //	interface includes
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/uno/Reference.hxx>
44 #include <com/sun/star/uno/XInterface.hpp>
45 #include <com/sun/star/uno/RuntimeException.hpp>
46 #include <com/sun/star/lang/DisposedException.hpp>
47 
48 //_________________________________________________________________________________________________________________
49 //	other includes
50 //_________________________________________________________________________________________________________________
51 #include <osl/mutex.hxx>
52 #include <fwidllapi.h>
53 
54 //_________________________________________________________________________________________________________________
55 //	namespace
56 //_________________________________________________________________________________________________________________
57 
58 namespace framework{
59 
60 //_________________________________________________________________________________________________________________
61 //	const
62 //_________________________________________________________________________________________________________________
63 
64 //_________________________________________________________________________________________________________________
65 //	declarations
66 //_________________________________________________________________________________________________________________
67 
68 /*-************************************************************************************************************//**
69     @short          implement a transaction manager to support non breakable interface methods
70     @descr          Use it to support non breakable interface methods without using any thread
71                     synchronization like e.g. mutex, rw-lock!
72                     That protect your code against wrong calls at wrong time ... e.g. calls after disposing an object!
73                     Use combination of EExceptionMode and ERejectReason to detect rejected requests
74                     and react for it. You can enable automaticly throwing of exceptions too.
75 
76     @implements     ITransactionManager
77     @base           INonCopyable
78                     ITransactionManager
79 
80     @devstatus      draft
81 *//*-*************************************************************************************************************/
82 class FWI_DLLPUBLIC TransactionManager : public  ITransactionManager
83                          , private INonCopyable
84 {
85 	//-------------------------------------------------------------------------------------------------------------
86 	//	public methods
87 	//-------------------------------------------------------------------------------------------------------------
88 	public:
89 
90                                    TransactionManager           (                                              );
91         virtual                    ~TransactionManager          (                                              );
92         virtual void               setWorkingMode               ( EWorkingMode eMode                           );
93         virtual EWorkingMode       getWorkingMode               (                                              ) const;
94         virtual sal_Bool           isCallRejected               ( ERejectReason& eReason                       ) const;
95         virtual void               registerTransaction          ( EExceptionMode eMode, ERejectReason& eReason ) throw( css::uno::RuntimeException, css::lang::DisposedException );
96         virtual void               unregisterTransaction        (                                              ) throw( css::uno::RuntimeException, css::lang::DisposedException );
97 
98 	//-------------------------------------------------------------------------------------------------------------
99 	//	private methods
100 	//-------------------------------------------------------------------------------------------------------------
101 	private:
102 
103         void impl_throwExceptions( EExceptionMode eMode, ERejectReason eReason ) const throw( css::uno::RuntimeException, css::lang::DisposedException );
104 
105 	//-------------------------------------------------------------------------------------------------------------
106 	//	private member
107 	//-------------------------------------------------------------------------------------------------------------
108 	private:
109 
110         mutable ::osl::Mutex    m_aAccessLock           ;   /// regulate access on internal member of this instance
111         Gate                    m_aBarrier              ;   /// used to block transactions requests during change or work mode
112         EWorkingMode            m_eWorkingMode          ;   /// current working mode of object which use this manager (used to reject calls at wrong time)
113         sal_Int32               m_nTransactionCount     ;   /// every transaction request is registered by this counter
114 
115 };      //  class TransactionManager
116 
117 }		//	namespace framework
118 
119 #endif  //  #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONMANAGER_HXX_
120