Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / ucb / source / ucp / file / filtask.hxx
blob4053583a01a9c0661c828557a68dbb507a66e5dc
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 _FILTASK_HXX_
20 #define _FILTASK_HXX_
21 #endif
23 #include <boost/unordered_map.hpp>
24 #include <rtl/ustring.hxx>
26 #include "osl/mutex.hxx"
27 #include <com/sun/star/ucb/DuplicateCommandIdentifierException.hpp>
28 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
29 #include <com/sun/star/ucb/XProgressHandler.hpp>
30 #include <com/sun/star/task/XInteractionHandler.hpp>
31 #include <com/sun/star/task/XInteractionRequest.hpp>
32 #include "filerror.hxx"
34 namespace fileaccess
36 class BaseContent;
39 * This implementation is inherited by class fileaccess::shell.
40 * The relevant methods in this class all have as first argument the CommandId,
41 * so if necessary, every method has access to its relevant XInteractionHandler and
42 * XProgressHandler.
46 class TaskManager
48 protected:
50 class TaskHandling
52 private:
54 bool m_bAbort,m_bHandled;
55 sal_Int32 m_nErrorCode,m_nMinorCode;
56 com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInteractionHandler;
57 com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > m_xProgressHandler;
58 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xCommandEnvironment;
61 public:
63 TaskHandling(
64 const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv
65 = com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >( 0 ) )
66 : m_bAbort( false ),
67 m_bHandled( false ),
68 m_nErrorCode( TASKHANDLER_NO_ERROR ),
69 m_nMinorCode( TASKHANDLER_NO_ERROR ),
70 m_xInteractionHandler( 0 ),
71 m_xProgressHandler( 0 ),
72 m_xCommandEnvironment( xCommandEnv )
76 void SAL_CALL abort()
78 m_bAbort = true;
81 void setHandled()
83 m_bHandled = true;
86 bool isHandled() const
88 return true;
91 void clearError()
93 m_nErrorCode = TASKHANDLER_NO_ERROR;
94 m_nMinorCode = TASKHANDLER_NO_ERROR;
97 void SAL_CALL installError( sal_Int32 nErrorCode,
98 sal_Int32 nMinorCode = TASKHANDLER_NO_ERROR )
100 m_nErrorCode = nErrorCode;
101 m_nMinorCode = nMinorCode;
104 sal_Int32 SAL_CALL getInstalledError()
106 return m_nErrorCode;
109 sal_Int32 SAL_CALL getMinorErrorCode()
111 return m_nMinorCode;
114 com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > SAL_CALL
115 getProgressHandler()
117 if( ! m_xProgressHandler.is() && m_xCommandEnvironment.is() )
118 m_xProgressHandler = m_xCommandEnvironment->getProgressHandler();
120 return m_xProgressHandler;
123 com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > SAL_CALL
124 getInteractionHandler()
126 if( ! m_xInteractionHandler.is() && m_xCommandEnvironment.is() )
127 m_xInteractionHandler = m_xCommandEnvironment->getInteractionHandler();
129 return m_xInteractionHandler;
132 com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > SAL_CALL
133 getCommandEnvironment()
135 return m_xCommandEnvironment;
138 }; // end class TaskHandling
141 typedef boost::unordered_map< sal_Int32,TaskHandling,boost::hash< sal_Int32 > > TaskMap;
144 private:
146 osl::Mutex m_aMutex;
147 sal_Int32 m_nCommandId;
148 TaskMap m_aTaskMap;
151 public:
153 TaskManager();
154 virtual ~TaskManager();
156 void SAL_CALL startTask(
157 sal_Int32 CommandId,
158 const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv )
159 throw( com::sun::star::ucb::DuplicateCommandIdentifierException );
161 sal_Int32 SAL_CALL getCommandId( void );
162 void SAL_CALL abort( sal_Int32 CommandId );
166 * The error code may be one of the error codes defined in
167 * filerror.hxx.
168 * The minor code refines the information given in ErrorCode.
171 void SAL_CALL clearError();
173 void SAL_CALL installError( sal_Int32 CommandId,
174 sal_Int32 ErrorCode,
175 sal_Int32 minorCode = TASKHANDLER_NO_ERROR );
177 void SAL_CALL retrieveError( sal_Int32 CommandId,
178 sal_Int32 &ErrorCode,
179 sal_Int32 &minorCode);
182 * Deinstalls the task and evaluates a possibly set error code.
183 * "endTask" throws in case an error code is set the corresponding exception.
186 void SAL_CALL endTask( sal_Int32 CommandId,
187 // the physical URL of the object
188 const rtl::OUString& aUnqPath,
189 BaseContent* pContent);
193 * Handles an interactionrequest
196 void SAL_CALL handleTask( sal_Int32 CommandId,
197 const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& request );
200 * Clears any error which are set on the commandid
203 void SAL_CALL clearError( sal_Int32 );
207 } // end namespace TaskHandling
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */