Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "filtask.hxx"
21 : #include "filglob.hxx"
22 :
23 : /******************************************************************************/
24 : /* */
25 : /* TaskHandling */
26 : /* */
27 : /******************************************************************************/
28 :
29 :
30 : using namespace fileaccess;
31 : using namespace com::sun::star;
32 : using namespace com::sun::star::uno;
33 : using namespace com::sun::star::ucb;
34 :
35 :
36 :
37 0 : TaskManager::TaskManager()
38 0 : : m_nCommandId( 0 )
39 : {
40 0 : }
41 :
42 :
43 :
44 0 : TaskManager::~TaskManager()
45 : {
46 0 : }
47 :
48 :
49 :
50 : void SAL_CALL
51 0 : TaskManager::startTask(
52 : sal_Int32 CommandId,
53 : const uno::Reference< XCommandEnvironment >& xCommandEnv )
54 : throw( DuplicateCommandIdentifierException )
55 : {
56 0 : osl::MutexGuard aGuard( m_aMutex );
57 0 : TaskMap::iterator it = m_aTaskMap.find( CommandId );
58 0 : if( it != m_aTaskMap.end() )
59 : {
60 : throw DuplicateCommandIdentifierException(
61 : OUString( OSL_LOG_PREFIX ),
62 0 : uno::Reference< uno::XInterface >() );
63 : }
64 0 : m_aTaskMap[ CommandId ] = TaskHandling( xCommandEnv );
65 0 : }
66 :
67 :
68 :
69 : void SAL_CALL
70 0 : TaskManager::endTask( sal_Int32 CommandId,
71 : const OUString& aUncPath,
72 : BaseContent* pContent)
73 : {
74 0 : osl::MutexGuard aGuard( m_aMutex );
75 0 : TaskMap::iterator it = m_aTaskMap.find( CommandId );
76 0 : if( it == m_aTaskMap.end() )
77 0 : return;
78 :
79 0 : sal_Int32 ErrorCode = it->second.getInstalledError();
80 0 : sal_Int32 MinorCode = it->second.getMinorErrorCode();
81 0 : bool isHandled = it->second.isHandled();
82 :
83 : Reference< XCommandEnvironment > xComEnv
84 0 : = it->second.getCommandEnvironment();
85 :
86 0 : m_aTaskMap.erase( it );
87 :
88 0 : if( ErrorCode != TASKHANDLER_NO_ERROR )
89 : throw_handler(
90 : ErrorCode,
91 : MinorCode,
92 : xComEnv,
93 : aUncPath,
94 : pContent,
95 0 : isHandled);
96 : }
97 :
98 :
99 :
100 : void SAL_CALL
101 0 : TaskManager::abort( sal_Int32 CommandId )
102 : {
103 0 : if( CommandId )
104 : {
105 0 : osl::MutexGuard aGuard( m_aMutex );
106 0 : TaskMap::iterator it = m_aTaskMap.find( CommandId );
107 0 : if( it == m_aTaskMap.end() )
108 0 : return;
109 : else
110 0 : it->second.abort();
111 : }
112 : }
113 :
114 :
115 0 : void SAL_CALL TaskManager::clearError( sal_Int32 CommandId )
116 : {
117 0 : osl::MutexGuard aGuard( m_aMutex );
118 0 : TaskMap::iterator it = m_aTaskMap.find( CommandId );
119 0 : if( it != m_aTaskMap.end() )
120 0 : it->second.clearError();
121 0 : }
122 :
123 :
124 0 : void SAL_CALL TaskManager::retrieveError( sal_Int32 CommandId,
125 : sal_Int32 &ErrorCode,
126 : sal_Int32 &minorCode)
127 : {
128 0 : osl::MutexGuard aGuard( m_aMutex );
129 0 : TaskMap::iterator it = m_aTaskMap.find( CommandId );
130 0 : if( it != m_aTaskMap.end() )
131 : {
132 0 : ErrorCode = it->second.getInstalledError();
133 0 : minorCode = it->second. getMinorErrorCode();
134 0 : }
135 0 : }
136 :
137 :
138 :
139 0 : void SAL_CALL TaskManager::installError( sal_Int32 CommandId,
140 : sal_Int32 ErrorCode,
141 : sal_Int32 MinorCode )
142 : {
143 0 : osl::MutexGuard aGuard( m_aMutex );
144 0 : TaskMap::iterator it = m_aTaskMap.find( CommandId );
145 0 : if( it != m_aTaskMap.end() )
146 0 : it->second.installError( ErrorCode,MinorCode );
147 0 : }
148 :
149 :
150 :
151 : sal_Int32 SAL_CALL
152 0 : TaskManager::getCommandId( void )
153 : {
154 0 : osl::MutexGuard aGuard( m_aMutex );
155 0 : return ++m_nCommandId;
156 : }
157 :
158 :
159 :
160 0 : void SAL_CALL TaskManager::handleTask(
161 : sal_Int32 CommandId,
162 : const uno::Reference< task::XInteractionRequest >& request )
163 : {
164 0 : osl::MutexGuard aGuard( m_aMutex );
165 0 : TaskMap::iterator it = m_aTaskMap.find( CommandId );
166 0 : uno::Reference< task::XInteractionHandler > xInt;
167 0 : if( it != m_aTaskMap.end() )
168 : {
169 0 : xInt = it->second.getInteractionHandler();
170 0 : if( xInt.is() )
171 0 : xInt->handle( request );
172 0 : it->second.setHandled();
173 0 : }
174 0 : }
175 :
176 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|