1*228b4580SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*228b4580SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*228b4580SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*228b4580SAndrew Rist  * distributed with this work for additional information
6*228b4580SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*228b4580SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*228b4580SAndrew Rist  * "License"); you may not use this file except in compliance
9*228b4580SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*228b4580SAndrew Rist  *
11*228b4580SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*228b4580SAndrew Rist  *
13*228b4580SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*228b4580SAndrew Rist  * software distributed under the License is distributed on an
15*228b4580SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*228b4580SAndrew Rist  * KIND, either express or implied.  See the License for the
17*228b4580SAndrew Rist  * specific language governing permissions and limitations
18*228b4580SAndrew Rist  * under the License.
19*228b4580SAndrew Rist  *
20*228b4580SAndrew Rist  *************************************************************/
21*228b4580SAndrew Rist 
22*228b4580SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __FRAMEWORK_THREADHELP_ITRANSACTIONMANAGER_H_
25cdf0e10cSrcweir #define __FRAMEWORK_THREADHELP_ITRANSACTIONMANAGER_H_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir //	includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <general.h>
32cdf0e10cSrcweir #include <com/sun/star/uno/RuntimeException.hpp>
33cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //_________________________________________________________________________________________________________________
36cdf0e10cSrcweir //	namespace
37cdf0e10cSrcweir //_________________________________________________________________________________________________________________
38cdf0e10cSrcweir 
39cdf0e10cSrcweir namespace framework{
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //_________________________________________________________________________________________________________________
42cdf0e10cSrcweir //	declarations
43cdf0e10cSrcweir //_________________________________________________________________________________________________________________
44cdf0e10cSrcweir 
45cdf0e10cSrcweir /*-************************************************************************************************************//**
46cdf0e10cSrcweir 	@descr			Describe different states of a feature of following implementation.
47cdf0e10cSrcweir 					During live time of an object different working states occure:
48cdf0e10cSrcweir 						initialization - working - closing - closed
49cdf0e10cSrcweir 					If you whish to implement thread safe classes you should use these feature to protect
50cdf0e10cSrcweir 					your code against calls at wrong time. e.g. you are not full initialized but somewhere
51cdf0e10cSrcweir 					call an interface method (initialize phase means startup time from creating object till
52cdf0e10cSrcweir 					calling specified first method e.g. XInitialization::initialze()!) then you should refuse
53cdf0e10cSrcweir                     this call. The same for closing/disposing the object!
54cdf0e10cSrcweir *//*-*************************************************************************************************************/
55cdf0e10cSrcweir enum EWorkingMode
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     E_INIT       ,   // We stand in a init method   -> some calls are accepted - some one are rejected
58cdf0e10cSrcweir     E_WORK       ,   // Object is ready for working -> all calls are accepted
59cdf0e10cSrcweir     E_BEFORECLOSE,   // We stand in a close method  -> some calls are accepted - some one are rejected
60cdf0e10cSrcweir     E_CLOSE          // Object is dead!             -> all calls are rejected!
61cdf0e10cSrcweir };
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /*-************************************************************************************************************//**
64cdf0e10cSrcweir     @descr          If a request was refused by a transaction manager (internal state different E_WORK ...)
65cdf0e10cSrcweir                     user can check the reason by using this enum values.
66cdf0e10cSrcweir *//*-*************************************************************************************************************/
67cdf0e10cSrcweir enum ERejectReason
68cdf0e10cSrcweir {
69cdf0e10cSrcweir 	E_UNINITIALIZED	,
70cdf0e10cSrcweir 	E_NOREASON		,
71cdf0e10cSrcweir     E_INCLOSE       ,
72cdf0e10cSrcweir 	E_CLOSED
73cdf0e10cSrcweir };
74cdf0e10cSrcweir 
75cdf0e10cSrcweir /*-************************************************************************************************************//**
76cdf0e10cSrcweir     @descr          A transaction object should support throwing exceptions if user used it at wrong working mode.
77cdf0e10cSrcweir                     e.g. We can throw a DisposedException if user try to work and our mode is E_CLOSE!
78cdf0e10cSrcweir                     But sometimes he dont need this feature - will handle it by himself.
79cdf0e10cSrcweir                     Then we must differ between some exception-modi:
80cdf0e10cSrcweir 						E_NOEXCEPTIONS			We never throw any exceptions! User handle it private and looks for ERejectReason.
81cdf0e10cSrcweir 						E_HARDEXCEPTIONS		We throw exceptions for all working modes different from E_WORK!
82cdf0e10cSrcweir                         E_SOFTEXCEPTIONS        We throw exceptions for all working modes different from E_WORK AND E_INCLOSE!
83cdf0e10cSrcweir                                                 This mode is useful for impl-methods which should be callable from dispose() method!
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 												e.g.	void dispose()
86cdf0e10cSrcweir 														{
87cdf0e10cSrcweir                                                             m_aTransactionManager.setWorkingMode( E_BEFORECLOSE );
88cdf0e10cSrcweir 															...
89cdf0e10cSrcweir 															impl_setA( 0 );
90cdf0e10cSrcweir 															...
91cdf0e10cSrcweir                                                             m_aTransactionManager.setWorkingMode( E_CLOSE );
92cdf0e10cSrcweir 														}
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 														void impl_setA( int nA )
95cdf0e10cSrcweir 														{
96cdf0e10cSrcweir                                                             ERejectReason       EReason;
97cdf0e10cSrcweir                                                             TransactionGuard    aTransactionGuard( m_aTransactionManager, E_SOFTEXCEPTIONS, eReason );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 															m_nA = nA;
100cdf0e10cSrcweir 														}
101cdf0e10cSrcweir 
102cdf0e10cSrcweir                                                 Normaly (if E_HARDEXCEPTIONS was used!) creation of guard
103cdf0e10cSrcweir 												will throw an exception ... but using of E_SOFTEXCEPTIONS suppress it
104cdf0e10cSrcweir                                                 and member "A" can be set.
105cdf0e10cSrcweir *//*-*************************************************************************************************************/
106cdf0e10cSrcweir enum EExceptionMode
107cdf0e10cSrcweir {
108cdf0e10cSrcweir 	E_NOEXCEPTIONS	,
109cdf0e10cSrcweir 	E_HARDEXCEPTIONS,
110cdf0e10cSrcweir 	E_SOFTEXCEPTIONS
111cdf0e10cSrcweir };
112cdf0e10cSrcweir 
113cdf0e10cSrcweir /*-************************************************************************************************************//**
114cdf0e10cSrcweir     @descr          How can you use the transaction manager?
115cdf0e10cSrcweir                     Use it in combination with an TransactionGuard, which register your transaction in ctor
116cdf0e10cSrcweir                     and release in dtor automaticly! Follow interface class can be used to make using
117cdf0e10cSrcweir                     of different manager implmentations possible by using same guard.
118cdf0e10cSrcweir *//*-*************************************************************************************************************/
119cdf0e10cSrcweir class ITransactionManager
120cdf0e10cSrcweir {
121cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
122cdf0e10cSrcweir 	//	public methods
123cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
124cdf0e10cSrcweir 	public:
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 		/*-****************************************************************************************************//**
127cdf0e10cSrcweir 			@descr		These functions must be supported by a derived class!
128cdf0e10cSrcweir                             getWorkingMode()        -return current set working mode
129cdf0e10cSrcweir 							setWorkingMode()		-change working mode
130cdf0e10cSrcweir                                                      (This will block till all current transactions are finished!)
131cdf0e10cSrcweir 							isCallRejected()		-test method to check if a call will be rejected by wrong working mode or not
132cdf0e10cSrcweir                             registerTransaction()   -start new transaction (increase internal transaction count)
133cdf0e10cSrcweir                             unregisterTransaction() -finish transaction    (decrease internal transaction count)
134cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
135cdf0e10cSrcweir         virtual EWorkingMode getWorkingMode         (                                                ) const = 0;
136cdf0e10cSrcweir         virtual void         setWorkingMode         ( EWorkingMode   eMode                           )       = 0;
137cdf0e10cSrcweir         virtual sal_Bool     isCallRejected         ( ERejectReason& eReason                         ) const = 0;
138cdf0e10cSrcweir         virtual void         registerTransaction    ( EExceptionMode eMode  , ERejectReason& eReason ) throw( css::uno::RuntimeException, css::lang::DisposedException ) = 0;
139cdf0e10cSrcweir         virtual void         unregisterTransaction  (                                                ) throw( css::uno::RuntimeException, css::lang::DisposedException ) = 0;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir };      //  class ITransactionManager
142cdf0e10cSrcweir 
143cdf0e10cSrcweir }		//	namespace framework
144cdf0e10cSrcweir 
145cdf0e10cSrcweir #endif  //  #ifndef __FRAMEWORK_THREADHELP_ITRANSACTIONMANAGER_H_
146