xref: /AOO41X/main/ucbhelper/source/provider/commandenvironmentproxy.cxx (revision ac9096f48ddc8269a54878c5b102c19157b971bd)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_ucbhelper.hxx"
26 
27 /**************************************************************************
28                                 TODO
29  **************************************************************************
30 
31  *************************************************************************/
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <com/sun/star/ucb/XContentIdentifierFactory.hpp>
35 #include <com/sun/star/ucb/XContentProvider.hpp>
36 #include <com/sun/star/ucb/XContentProviderManager.hpp>
37 #include <osl/mutex.hxx>
38 #include <ucbhelper/commandenvironmentproxy.hxx>
39 
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::task;
42 using namespace com::sun::star::ucb;
43 using namespace com::sun::star::uno;
44 using namespace rtl;
45 
46 namespace ucbhelper
47 {
48 
49 //=========================================================================
50 //=========================================================================
51 //
52 // struct CommandEnvironmentProxy_Impl.
53 //
54 //=========================================================================
55 //=========================================================================
56 
57 struct CommandEnvironmentProxy_Impl
58 {
59     osl::Mutex                       m_aMutex;
60     Reference< XCommandEnvironment > m_xEnv;
61     Reference< XInteractionHandler > m_xInteractionHandler;
62     Reference< XProgressHandler >    m_xProgressHandler;
63     sal_Bool m_bGotInteractionHandler;
64     sal_Bool m_bGotProgressHandler;
65 
CommandEnvironmentProxy_Implucbhelper::CommandEnvironmentProxy_Impl66     CommandEnvironmentProxy_Impl(
67         const Reference< XCommandEnvironment >& rxEnv )
68     : m_xEnv( rxEnv ), m_bGotInteractionHandler( sal_False ),
69       m_bGotProgressHandler( sal_False ) {}
70 };
71 
72 //=========================================================================
73 //=========================================================================
74 //
75 // CommandEnvironmentProxy Implementation.
76 //
77 //=========================================================================
78 //=========================================================================
79 
CommandEnvironmentProxy(const Reference<XCommandEnvironment> & rxEnv)80 CommandEnvironmentProxy::CommandEnvironmentProxy(
81                         const Reference< XCommandEnvironment >& rxEnv )
82 {
83     m_pImpl = new CommandEnvironmentProxy_Impl( rxEnv );
84 }
85 
86 //=========================================================================
87 // virtual
~CommandEnvironmentProxy()88 CommandEnvironmentProxy::~CommandEnvironmentProxy()
89 {
90     delete m_pImpl;
91 }
92 
93 //=========================================================================
94 //
95 // XInterface methods
96 //
97 //=========================================================================
98 
99 XINTERFACE_IMPL_2( CommandEnvironmentProxy,
100                    XTypeProvider,
101                    XCommandEnvironment );
102 
103 //=========================================================================
104 //
105 // XTypeProvider methods
106 //
107 //=========================================================================
108 
109 XTYPEPROVIDER_IMPL_2( CommandEnvironmentProxy,
110                       XTypeProvider,
111                       XCommandEnvironment );
112 
113 //=========================================================================
114 //
115 // XCommandEnvironemnt methods.
116 //
117 //=========================================================================
118 
119 // virtual
120 Reference< XInteractionHandler > SAL_CALL
getInteractionHandler()121 CommandEnvironmentProxy::getInteractionHandler()
122     throw ( RuntimeException )
123 {
124     if ( m_pImpl->m_xEnv.is() )
125     {
126         if ( !m_pImpl->m_bGotInteractionHandler )
127         {
128             osl::MutexGuard aGuard( m_pImpl->m_aMutex );
129             if ( !m_pImpl->m_bGotInteractionHandler )
130             {
131                 m_pImpl->m_xInteractionHandler
132                                 = m_pImpl->m_xEnv->getInteractionHandler();
133                 m_pImpl->m_bGotInteractionHandler = sal_True;
134             }
135         }
136     }
137     return m_pImpl->m_xInteractionHandler;
138 }
139 
140 //=========================================================================
141 // virtual
142 Reference< XProgressHandler > SAL_CALL
getProgressHandler()143 CommandEnvironmentProxy::getProgressHandler()
144     throw ( RuntimeException )
145 {
146     if ( m_pImpl->m_xEnv.is() )
147     {
148         if ( !m_pImpl->m_bGotProgressHandler )
149         {
150             osl::MutexGuard aGuard( m_pImpl->m_aMutex );
151             if ( !m_pImpl->m_bGotProgressHandler )
152             {
153                 m_pImpl->m_xProgressHandler
154                                 = m_pImpl->m_xEnv->getProgressHandler();
155                 m_pImpl->m_bGotProgressHandler = sal_True;
156             }
157         }
158     }
159     return m_pImpl->m_xProgressHandler;
160 }
161 
162 } /* namespace ucbhelper */
163 
164