bump product version to 5.0.4.1
[LibreOffice.git] / ucb / source / ucp / file / filtask.hxx
blobacf67c6dffbf2f715dc1056727d4714f62991bf0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_UCB_SOURCE_UCP_FILE_FILTASK_HXX
20 #define INCLUDED_UCB_SOURCE_UCP_FILE_FILTASK_HXX
21 #endif
23 #include <rtl/ustring.hxx>
25 #include "osl/mutex.hxx"
26 #include <com/sun/star/ucb/DuplicateCommandIdentifierException.hpp>
27 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
28 #include <com/sun/star/ucb/XProgressHandler.hpp>
29 #include <com/sun/star/task/XInteractionHandler.hpp>
30 #include <com/sun/star/task/XInteractionRequest.hpp>
31 #include <boost/functional/hash.hpp>
32 #include "filerror.hxx"
33 #include <unordered_map>
35 namespace fileaccess
37 class BaseContent;
40 * This implementation is inherited by class fileaccess::shell.
41 * The relevant methods in this class all have as first argument the CommandId,
42 * so if necessary, every method has access to its relevant XInteractionHandler and
43 * XProgressHandler.
47 class TaskManager
49 protected:
51 class TaskHandling
53 private:
55 bool m_bAbort,m_bHandled;
56 sal_Int32 m_nErrorCode,m_nMinorCode;
57 com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInteractionHandler;
58 com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > m_xProgressHandler;
59 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xCommandEnvironment;
62 public:
64 TaskHandling(
65 const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv
66 = com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >( 0 ) )
67 : m_bAbort( false ),
68 m_bHandled( false ),
69 m_nErrorCode( TASKHANDLER_NO_ERROR ),
70 m_nMinorCode( TASKHANDLER_NO_ERROR ),
71 m_xInteractionHandler( 0 ),
72 m_xProgressHandler( 0 ),
73 m_xCommandEnvironment( xCommandEnv )
77 void SAL_CALL abort()
79 m_bAbort = true;
82 void setHandled()
84 m_bHandled = true;
87 bool isHandled() const
89 return m_bHandled;
92 void clearError()
94 m_nErrorCode = TASKHANDLER_NO_ERROR;
95 m_nMinorCode = TASKHANDLER_NO_ERROR;
98 void SAL_CALL installError( sal_Int32 nErrorCode,
99 sal_Int32 nMinorCode = TASKHANDLER_NO_ERROR )
101 m_nErrorCode = nErrorCode;
102 m_nMinorCode = nMinorCode;
105 sal_Int32 SAL_CALL getInstalledError()
107 return m_nErrorCode;
110 sal_Int32 SAL_CALL getMinorErrorCode()
112 return m_nMinorCode;
115 com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > SAL_CALL
116 getProgressHandler()
118 if( ! m_xProgressHandler.is() && m_xCommandEnvironment.is() )
119 m_xProgressHandler = m_xCommandEnvironment->getProgressHandler();
121 return m_xProgressHandler;
124 com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > SAL_CALL
125 getInteractionHandler()
127 if( ! m_xInteractionHandler.is() && m_xCommandEnvironment.is() )
128 m_xInteractionHandler = m_xCommandEnvironment->getInteractionHandler();
130 return m_xInteractionHandler;
133 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > SAL_CALL
134 getCommandEnvironment()
136 return m_xCommandEnvironment;
139 }; // end class TaskHandling
142 typedef std::unordered_map< sal_Int32,TaskHandling,boost::hash< sal_Int32 > > TaskMap;
143 private:
145 osl::Mutex m_aMutex;
146 sal_Int32 m_nCommandId;
147 TaskMap m_aTaskMap;
150 public:
152 TaskManager();
153 virtual ~TaskManager();
155 void SAL_CALL startTask(
156 sal_Int32 CommandId,
157 const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv )
158 throw( com::sun::star::ucb::DuplicateCommandIdentifierException );
160 sal_Int32 SAL_CALL getCommandId();
161 void SAL_CALL abort( sal_Int32 CommandId );
165 * The error code may be one of the error codes defined in
166 * filerror.hxx.
167 * The minor code refines the information given in ErrorCode.
170 void SAL_CALL clearError();
172 void SAL_CALL installError( sal_Int32 CommandId,
173 sal_Int32 ErrorCode,
174 sal_Int32 minorCode = TASKHANDLER_NO_ERROR );
176 void SAL_CALL retrieveError( sal_Int32 CommandId,
177 sal_Int32 &ErrorCode,
178 sal_Int32 &minorCode);
181 * Deinstalls the task and evaluates a possibly set error code.
182 * "endTask" throws in case an error code is set the corresponding exception.
185 void SAL_CALL endTask( sal_Int32 CommandId,
186 // the physical URL of the object
187 const OUString& aUnqPath,
188 BaseContent* pContent);
192 * Handles an interactionrequest
195 void SAL_CALL handleTask( sal_Int32 CommandId,
196 const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& request );
199 * Clears any error which are set on the commandid
202 void SAL_CALL clearError( sal_Int32 );
206 } // end namespace TaskHandling
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */