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