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 #ifndef CHART2_CONTROLLERLOCKGUARD_HXX
28 #define CHART2_CONTROLLERLOCKGUARD_HXX
29 
30 #include <com/sun/star/frame/XModel.hpp>
31 #include "charttoolsdllapi.hxx"
32 
33 namespace chart
34 {
35 
36 /** This guard calls lockControllers at the given Model in the CTOR and
37     unlockControllers in the DTOR.  Using this ensures that controllers do not
38     remain locked when leaving a function even in case an exception is thrown.
39  */
40 class OOO_DLLPUBLIC_CHARTTOOLS ControllerLockGuard
41 {
42 public:
43 	explicit ControllerLockGuard(
44         const ::com::sun::star::uno::Reference<
45             ::com::sun::star::frame::XModel > & xModel );
46     ~ControllerLockGuard();
47 
48 private:
49     ::com::sun::star::uno::Reference<
50             ::com::sun::star::frame::XModel > m_xModel;
51 };
52 
53 /** This helper class can be used to pass a locking mechanism to other objects
54     without exposing the full XModel to it.
55 
56     Use the ControllerLockHelperGuard to lock/unlock the model during a block of
57     instructions.
58  */
59 class OOO_DLLPUBLIC_CHARTTOOLS ControllerLockHelper
60 {
61 public:
62     explicit ControllerLockHelper(
63         const ::com::sun::star::uno::Reference<
64             ::com::sun::star::frame::XModel > & xModel );
65     ~ControllerLockHelper();
66 
67     SAL_DLLPRIVATE void lockControllers();
68     SAL_DLLPRIVATE void unlockControllers();
69 
70 private:
71     ::com::sun::star::uno::Reference<
72             ::com::sun::star::frame::XModel > m_xModel;
73 };
74 
75 /** This guard calls lockControllers at the given ControllerLockHelper in the
76     CTOR and unlockControllers in the DTOR.  Using this ensures that controllers
77     do not remain locked when leaving a function even in case an exception is
78     thrown.
79  */
80 class OOO_DLLPUBLIC_CHARTTOOLS ControllerLockHelperGuard
81 {
82 public:
83 	explicit ControllerLockHelperGuard( ControllerLockHelper & rHelper );
84     ~ControllerLockHelperGuard();
85 
86 private:
87     ControllerLockHelper & m_rHelper;
88 };
89 
90 } //  namespace chart
91 
92 // CHART2_CONTROLLERLOCKGUARD_HXX
93 #endif
94