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