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