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_file.hxx"
26 #include "filtask.hxx"
27 #include "filglob.hxx"
28
29 /******************************************************************************/
30 /* */
31 /* TaskHandling */
32 /* */
33 /******************************************************************************/
34
35
36 using namespace fileaccess;
37 using namespace com::sun::star;
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::ucb;
40
41
42
TaskManager()43 TaskManager::TaskManager()
44 : m_nCommandId( 0 )
45 {
46 }
47
48
49
~TaskManager()50 TaskManager::~TaskManager()
51 {
52 }
53
54
55
56 void SAL_CALL
startTask(sal_Int32 CommandId,const uno::Reference<XCommandEnvironment> & xCommandEnv)57 TaskManager::startTask(
58 sal_Int32 CommandId,
59 const uno::Reference< XCommandEnvironment >& xCommandEnv )
60 {
61 osl::MutexGuard aGuard( m_aMutex );
62 TaskMap::iterator it = m_aTaskMap.find( CommandId );
63 if( it != m_aTaskMap.end() )
64 {
65 throw DuplicateCommandIdentifierException(
66 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX ) ),
67 uno::Reference< uno::XInterface >() );
68 }
69 m_aTaskMap[ CommandId ] = TaskHandling( xCommandEnv );
70 }
71
72
73
74 void SAL_CALL
endTask(sal_Int32 CommandId,const rtl::OUString & aUncPath,BaseContent * pContent)75 TaskManager::endTask( sal_Int32 CommandId,
76 const rtl::OUString& aUncPath,
77 BaseContent* pContent)
78 {
79 osl::MutexGuard aGuard( m_aMutex );
80 TaskMap::iterator it = m_aTaskMap.find( CommandId );
81 if( it == m_aTaskMap.end() )
82 return;
83
84 sal_Int32 ErrorCode = it->second.getInstalledError();
85 sal_Int32 MinorCode = it->second.getMinorErrorCode();
86 bool isHandled = it->second.isHandled();
87
88 Reference< XCommandEnvironment > xComEnv
89 = it->second.getCommandEnvironment();
90
91 m_aTaskMap.erase( it );
92
93 if( ErrorCode != TASKHANDLER_NO_ERROR )
94 throw_handler(
95 ErrorCode,
96 MinorCode,
97 xComEnv,
98 aUncPath,
99 pContent,
100 isHandled);
101 }
102
103
104
105 void SAL_CALL
abort(sal_Int32 CommandId)106 TaskManager::abort( sal_Int32 CommandId )
107 {
108 if( CommandId )
109 {
110 osl::MutexGuard aGuard( m_aMutex );
111 TaskMap::iterator it = m_aTaskMap.find( CommandId );
112 if( it == m_aTaskMap.end() )
113 return;
114 else
115 it->second.abort();
116 }
117 }
118
119
clearError(sal_Int32 CommandId)120 void SAL_CALL TaskManager::clearError( sal_Int32 CommandId )
121 {
122 osl::MutexGuard aGuard( m_aMutex );
123 TaskMap::iterator it = m_aTaskMap.find( CommandId );
124 if( it != m_aTaskMap.end() )
125 it->second.clearError();
126 }
127
128
retrieveError(sal_Int32 CommandId,sal_Int32 & ErrorCode,sal_Int32 & minorCode)129 void SAL_CALL TaskManager::retrieveError( sal_Int32 CommandId,
130 sal_Int32 &ErrorCode,
131 sal_Int32 &minorCode)
132 {
133 osl::MutexGuard aGuard( m_aMutex );
134 TaskMap::iterator it = m_aTaskMap.find( CommandId );
135 if( it != m_aTaskMap.end() )
136 {
137 ErrorCode = it->second.getInstalledError();
138 minorCode = it->second. getMinorErrorCode();
139 }
140 }
141
142
143
installError(sal_Int32 CommandId,sal_Int32 ErrorCode,sal_Int32 MinorCode)144 void SAL_CALL TaskManager::installError( sal_Int32 CommandId,
145 sal_Int32 ErrorCode,
146 sal_Int32 MinorCode )
147 {
148 osl::MutexGuard aGuard( m_aMutex );
149 TaskMap::iterator it = m_aTaskMap.find( CommandId );
150 if( it != m_aTaskMap.end() )
151 it->second.installError( ErrorCode,MinorCode );
152 }
153
154
155
156 sal_Int32 SAL_CALL
getCommandId(void)157 TaskManager::getCommandId( void )
158 {
159 osl::MutexGuard aGuard( m_aMutex );
160 return ++m_nCommandId;
161 }
162
163
164
handleTask(sal_Int32 CommandId,const uno::Reference<task::XInteractionRequest> & request)165 void SAL_CALL TaskManager::handleTask(
166 sal_Int32 CommandId,
167 const uno::Reference< task::XInteractionRequest >& request )
168 {
169 osl::MutexGuard aGuard( m_aMutex );
170 TaskMap::iterator it = m_aTaskMap.find( CommandId );
171 uno::Reference< task::XInteractionHandler > xInt;
172 if( it != m_aTaskMap.end() )
173 {
174 xInt = it->second.getInteractionHandler();
175 if( xInt.is() )
176 xInt->handle( request );
177 it->second.setHandled();
178 }
179 }
180