1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONMANAGER_HXX_
25 #define __FRAMEWORK_THREADHELP_TRANSACTIONMANAGER_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //	my own includes
29 //_________________________________________________________________________________________________________________
30 
31 #include <threadhelp/inoncopyable.h>
32 #include <threadhelp/itransactionmanager.h>
33 #include <threadhelp/gate.hxx>
34 #include <macros/debug.hxx>
35 
36 //_________________________________________________________________________________________________________________
37 //	interface includes
38 //_________________________________________________________________________________________________________________
39 #include <com/sun/star/uno/Reference.hxx>
40 #include <com/sun/star/uno/XInterface.hpp>
41 #include <com/sun/star/uno/RuntimeException.hpp>
42 #include <com/sun/star/lang/DisposedException.hpp>
43 
44 //_________________________________________________________________________________________________________________
45 //	other includes
46 //_________________________________________________________________________________________________________________
47 #include <osl/mutex.hxx>
48 #include <fwidllapi.h>
49 
50 //_________________________________________________________________________________________________________________
51 //	namespace
52 //_________________________________________________________________________________________________________________
53 
54 namespace framework{
55 
56 //_________________________________________________________________________________________________________________
57 //	const
58 //_________________________________________________________________________________________________________________
59 
60 //_________________________________________________________________________________________________________________
61 //	declarations
62 //_________________________________________________________________________________________________________________
63 
64 /*-************************************************************************************************************//**
65     @short          implement a transaction manager to support non breakable interface methods
66     @descr          Use it to support non breakable interface methods without using any thread
67                     synchronization like e.g. mutex, rw-lock!
68                     That protect your code against wrong calls at wrong time ... e.g. calls after disposing an object!
69                     Use combination of EExceptionMode and ERejectReason to detect rejected requests
70                     and react for it. You can enable automatically throwing of exceptions too.
71 
72     @implements     ITransactionManager
73     @base           INonCopyable
74                     ITransactionManager
75 
76     @devstatus      draft
77 *//*-*************************************************************************************************************/
78 class FWI_DLLPUBLIC TransactionManager : public  ITransactionManager
79                          , private INonCopyable
80 {
81 	//-------------------------------------------------------------------------------------------------------------
82 	//	public methods
83 	//-------------------------------------------------------------------------------------------------------------
84 	public:
85 
86                                    TransactionManager           (                                              );
87         virtual                    ~TransactionManager          (                                              );
88         virtual void               setWorkingMode               ( EWorkingMode eMode                           );
89         virtual EWorkingMode       getWorkingMode               (                                              ) const;
90         virtual sal_Bool           isCallRejected               ( ERejectReason& eReason                       ) const;
91         virtual void               registerTransaction          ( EExceptionMode eMode, ERejectReason& eReason ) throw( css::uno::RuntimeException, css::lang::DisposedException );
92         virtual void               unregisterTransaction        (                                              ) throw( css::uno::RuntimeException, css::lang::DisposedException );
93 
94 	//-------------------------------------------------------------------------------------------------------------
95 	//	private methods
96 	//-------------------------------------------------------------------------------------------------------------
97 	private:
98 
99         void impl_throwExceptions( EExceptionMode eMode, ERejectReason eReason ) const throw( css::uno::RuntimeException, css::lang::DisposedException );
100 
101 	//-------------------------------------------------------------------------------------------------------------
102 	//	private member
103 	//-------------------------------------------------------------------------------------------------------------
104 	private:
105 
106         mutable ::osl::Mutex    m_aAccessLock           ;   /// regulate access on internal member of this instance
107         Gate                    m_aBarrier              ;   /// used to block transactions requests during change or work mode
108         EWorkingMode            m_eWorkingMode          ;   /// current working mode of object which use this manager (used to reject calls at wrong time)
109         sal_Int32               m_nTransactionCount     ;   /// every transaction request is registered by this counter
110 
111 };      //  class TransactionManager
112 
113 }		//	namespace framework
114 
115 #endif  //  #ifndef __FRAMEWORK_THREADHELP_TRANSACTIONMANAGER_HXX_
116