1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: filtask.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include "filtask.hxx"
34 #include "filglob.hxx"
36 /*********************************************************************************/
40 /*********************************************************************************/
43 using namespace fileaccess
;
44 using namespace com::sun::star
;
45 using namespace com::sun::star::uno
;
46 using namespace com::sun::star::ucb
;
50 TaskManager::TaskManager()
57 TaskManager::~TaskManager()
64 TaskManager::startTask(
66 const uno::Reference
< XCommandEnvironment
>& xCommandEnv
)
67 throw( DuplicateCommandIdentifierException
)
69 osl::MutexGuard
aGuard( m_aMutex
);
70 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
71 if( it
!= m_aTaskMap
.end() )
73 throw DuplicateCommandIdentifierException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( OSL_LOG_PREFIX
) ), uno::Reference
< uno::XInterface
>() );
75 m_aTaskMap
[ CommandId
] = TaskHandling( xCommandEnv
);
81 TaskManager::endTask( sal_Int32 CommandId
,
82 const rtl::OUString
& aUncPath
,
83 BaseContent
* pContent
)
85 osl::MutexGuard
aGuard( m_aMutex
);
86 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
87 if( it
== m_aTaskMap
.end() )
90 sal_Int32 ErrorCode
= it
->second
.getInstalledError();
91 sal_Int32 MinorCode
= it
->second
.getMinorErrorCode();
92 bool isHandled
= it
->second
.isHandled();
94 Reference
< XCommandEnvironment
> xComEnv
= it
->second
.getCommandEnvironment();
96 m_aTaskMap
.erase( it
);
98 if( ErrorCode
!= TASKHANDLER_NO_ERROR
)
111 TaskManager::abort( sal_Int32 CommandId
)
115 osl::MutexGuard
aGuard( m_aMutex
);
116 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
117 if( it
== m_aTaskMap
.end() )
125 bool SAL_CALL
TaskManager::isAborted( sal_Int32 CommandId
)
127 osl::MutexGuard
aGuard( m_aMutex
);
128 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
129 if( it
== m_aTaskMap
.end() || it
->second
.isAborted() )
136 void SAL_CALL
TaskManager::clearError( sal_Int32 CommandId
)
138 osl::MutexGuard
aGuard( m_aMutex
);
139 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
140 if( it
!= m_aTaskMap
.end() )
141 it
->second
.clearError();
145 void SAL_CALL
TaskManager::retrieveError( sal_Int32 CommandId
,
146 sal_Int32
&ErrorCode
,
147 sal_Int32
&minorCode
)
149 osl::MutexGuard
aGuard( m_aMutex
);
150 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
151 if( it
!= m_aTaskMap
.end() )
153 ErrorCode
= it
->second
.getInstalledError();
154 minorCode
= it
->second
. getMinorErrorCode();
160 void SAL_CALL
TaskManager::installError( sal_Int32 CommandId
,
162 sal_Int32 MinorCode
)
164 osl::MutexGuard
aGuard( m_aMutex
);
165 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
166 if( it
!= m_aTaskMap
.end() )
167 it
->second
.installError( ErrorCode
,MinorCode
);
173 TaskManager::getCommandId( void )
175 osl::MutexGuard
aGuard( m_aMutex
);
176 return ++m_nCommandId
;
181 uno::Reference
< task::XInteractionHandler
> SAL_CALL
182 TaskManager::getInteractionHandler( sal_Int32 CommandId
)
184 osl::MutexGuard
aGuard( m_aMutex
);
185 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
186 if( it
== m_aTaskMap
.end() )
187 return uno::Reference
< task::XInteractionHandler
>( 0 );
189 return it
->second
.getInteractionHandler();
194 uno::Reference
< XProgressHandler
> SAL_CALL
195 TaskManager::getProgressHandler( sal_Int32 CommandId
)
197 osl::MutexGuard
aGuard( m_aMutex
);
198 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
199 if( it
== m_aTaskMap
.end() )
200 return uno::Reference
< XProgressHandler
>( 0 );
202 return it
->second
.getProgressHandler();
206 uno::Reference
< XCommandEnvironment
> SAL_CALL
207 TaskManager::getCommandEnvironment( sal_Int32 CommandId
)
209 osl::MutexGuard
aGuard( m_aMutex
);
210 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
211 if( it
== m_aTaskMap
.end() )
212 return uno::Reference
< XCommandEnvironment
>( 0 );
214 return it
->second
.getCommandEnvironment();
218 void SAL_CALL
TaskManager::handleTask( sal_Int32 CommandId
,
219 const uno::Reference
< task::XInteractionRequest
>& request
)
221 osl::MutexGuard
aGuard( m_aMutex
);
222 TaskMap::iterator it
= m_aTaskMap
.find( CommandId
);
223 uno::Reference
< task::XInteractionHandler
> xInt
;
224 if( it
!= m_aTaskMap
.end() )
226 xInt
= it
->second
.getInteractionHandler();
228 xInt
->handle( request
);
229 it
->second
.setHandled();