1*6df1ea1fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6df1ea1fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6df1ea1fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6df1ea1fSAndrew Rist * distributed with this work for additional information 6*6df1ea1fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6df1ea1fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6df1ea1fSAndrew Rist * "License"); you may not use this file except in compliance 9*6df1ea1fSAndrew Rist * with the License. You may obtain a copy of the License at 10*6df1ea1fSAndrew Rist * 11*6df1ea1fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*6df1ea1fSAndrew Rist * 13*6df1ea1fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6df1ea1fSAndrew Rist * software distributed under the License is distributed on an 15*6df1ea1fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6df1ea1fSAndrew Rist * KIND, either express or implied. See the License for the 17*6df1ea1fSAndrew Rist * specific language governing permissions and limitations 18*6df1ea1fSAndrew Rist * under the License. 19*6df1ea1fSAndrew Rist * 20*6df1ea1fSAndrew Rist *************************************************************/ 21*6df1ea1fSAndrew Rist 22*6df1ea1fSAndrew Rist 23cdf0e10cSrcweir #ifndef _FILTASK_HXX_ 24cdf0e10cSrcweir #define _FILTASK_HXX_ 25cdf0e10cSrcweir #endif 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <hash_map> 28cdf0e10cSrcweir #include <rtl/ustring.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #include "osl/mutex.hxx" 31cdf0e10cSrcweir #include <com/sun/star/ucb/DuplicateCommandIdentifierException.hpp> 32cdf0e10cSrcweir #include <com/sun/star/ucb/XCommandEnvironment.hpp> 33cdf0e10cSrcweir #include <com/sun/star/ucb/XProgressHandler.hpp> 34cdf0e10cSrcweir #include <com/sun/star/task/XInteractionHandler.hpp> 35cdf0e10cSrcweir #include <com/sun/star/task/XInteractionRequest.hpp> 36cdf0e10cSrcweir #include "filerror.hxx" 37cdf0e10cSrcweir 38cdf0e10cSrcweir 39cdf0e10cSrcweir namespace fileaccess 40cdf0e10cSrcweir { 41cdf0e10cSrcweir class BaseContent; 42cdf0e10cSrcweir 43cdf0e10cSrcweir /* 44cdf0e10cSrcweir * This implementation is inherited by class fileaccess::shell. 45cdf0e10cSrcweir * The relevant methods in this class all have as first argument the CommandId, 46cdf0e10cSrcweir * so if necessary, every method has access to its relevant XInteractionHandler and 47cdf0e10cSrcweir * XProgressHandler. 48cdf0e10cSrcweir */ 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir class TaskManager 52cdf0e10cSrcweir { 53cdf0e10cSrcweir protected: 54cdf0e10cSrcweir 55cdf0e10cSrcweir class TaskHandling 56cdf0e10cSrcweir { 57cdf0e10cSrcweir private: 58cdf0e10cSrcweir 59cdf0e10cSrcweir bool m_bAbort,m_bHandled; 60cdf0e10cSrcweir sal_Int32 m_nErrorCode,m_nMinorCode; 61cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > m_xInteractionHandler; 62cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > m_xProgressHandler; 63cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > m_xCommandEnvironment; 64cdf0e10cSrcweir 65cdf0e10cSrcweir 66cdf0e10cSrcweir public: 67cdf0e10cSrcweir TaskHandling(const com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> & xCommandEnv=com::sun::star::uno::Reference<com::sun::star::ucb::XCommandEnvironment> (0))68cdf0e10cSrcweir TaskHandling( 69cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv 70cdf0e10cSrcweir = com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >( 0 ) ) 71cdf0e10cSrcweir : m_bAbort( false ), 72cdf0e10cSrcweir m_bHandled( false ), 73cdf0e10cSrcweir m_nErrorCode( TASKHANDLER_NO_ERROR ), 74cdf0e10cSrcweir m_nMinorCode( TASKHANDLER_NO_ERROR ), 75cdf0e10cSrcweir m_xInteractionHandler( 0 ), 76cdf0e10cSrcweir m_xProgressHandler( 0 ), 77cdf0e10cSrcweir m_xCommandEnvironment( xCommandEnv ) 78cdf0e10cSrcweir { 79cdf0e10cSrcweir } 80cdf0e10cSrcweir abort()81cdf0e10cSrcweir void SAL_CALL abort() 82cdf0e10cSrcweir { 83cdf0e10cSrcweir m_bAbort = true; 84cdf0e10cSrcweir } 85cdf0e10cSrcweir setHandled()86cdf0e10cSrcweir void setHandled() 87cdf0e10cSrcweir { 88cdf0e10cSrcweir m_bHandled = true; 89cdf0e10cSrcweir } 90cdf0e10cSrcweir isHandled()91cdf0e10cSrcweir bool isHandled() 92cdf0e10cSrcweir { 93cdf0e10cSrcweir return true; 94cdf0e10cSrcweir } 95cdf0e10cSrcweir clearError()96cdf0e10cSrcweir void clearError() 97cdf0e10cSrcweir { 98cdf0e10cSrcweir m_nErrorCode = TASKHANDLER_NO_ERROR; 99cdf0e10cSrcweir m_nMinorCode = TASKHANDLER_NO_ERROR; 100cdf0e10cSrcweir } 101cdf0e10cSrcweir installError(sal_Int32 nErrorCode,sal_Int32 nMinorCode=TASKHANDLER_NO_ERROR)102cdf0e10cSrcweir void SAL_CALL installError( sal_Int32 nErrorCode, 103cdf0e10cSrcweir sal_Int32 nMinorCode = TASKHANDLER_NO_ERROR ) 104cdf0e10cSrcweir { 105cdf0e10cSrcweir m_nErrorCode = nErrorCode; 106cdf0e10cSrcweir m_nMinorCode = nMinorCode; 107cdf0e10cSrcweir } 108cdf0e10cSrcweir getInstalledError()109cdf0e10cSrcweir sal_Int32 SAL_CALL getInstalledError() 110cdf0e10cSrcweir { 111cdf0e10cSrcweir return m_nErrorCode; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir getMinorErrorCode()114cdf0e10cSrcweir sal_Int32 SAL_CALL getMinorErrorCode() 115cdf0e10cSrcweir { 116cdf0e10cSrcweir return m_nMinorCode; 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > SAL_CALL getProgressHandler()120cdf0e10cSrcweir getProgressHandler() 121cdf0e10cSrcweir { 122cdf0e10cSrcweir if( ! m_xProgressHandler.is() && m_xCommandEnvironment.is() ) 123cdf0e10cSrcweir m_xProgressHandler = m_xCommandEnvironment->getProgressHandler(); 124cdf0e10cSrcweir 125cdf0e10cSrcweir return m_xProgressHandler; 126cdf0e10cSrcweir } 127cdf0e10cSrcweir 128cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > SAL_CALL getInteractionHandler()129cdf0e10cSrcweir getInteractionHandler() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir if( ! m_xInteractionHandler.is() && m_xCommandEnvironment.is() ) 132cdf0e10cSrcweir m_xInteractionHandler = m_xCommandEnvironment->getInteractionHandler(); 133cdf0e10cSrcweir 134cdf0e10cSrcweir return m_xInteractionHandler; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > SAL_CALL getCommandEnvironment()138cdf0e10cSrcweir getCommandEnvironment() 139cdf0e10cSrcweir { 140cdf0e10cSrcweir return m_xCommandEnvironment; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir }; // end class TaskHandling 144cdf0e10cSrcweir 145cdf0e10cSrcweir 146cdf0e10cSrcweir typedef std::hash_map< sal_Int32,TaskHandling,std::hash< sal_Int32 > > TaskMap; 147cdf0e10cSrcweir 148cdf0e10cSrcweir 149cdf0e10cSrcweir private: 150cdf0e10cSrcweir 151cdf0e10cSrcweir osl::Mutex m_aMutex; 152cdf0e10cSrcweir sal_Int32 m_nCommandId; 153cdf0e10cSrcweir TaskMap m_aTaskMap; 154cdf0e10cSrcweir 155cdf0e10cSrcweir 156cdf0e10cSrcweir public: 157cdf0e10cSrcweir 158cdf0e10cSrcweir TaskManager(); 159cdf0e10cSrcweir virtual ~TaskManager(); 160cdf0e10cSrcweir 161cdf0e10cSrcweir void SAL_CALL startTask( 162cdf0e10cSrcweir sal_Int32 CommandId, 163cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment >& xCommandEnv ) 164cdf0e10cSrcweir throw( com::sun::star::ucb::DuplicateCommandIdentifierException ); 165cdf0e10cSrcweir 166cdf0e10cSrcweir sal_Int32 SAL_CALL getCommandId( void ); 167cdf0e10cSrcweir void SAL_CALL abort( sal_Int32 CommandId ); 168cdf0e10cSrcweir 169cdf0e10cSrcweir 170cdf0e10cSrcweir /** 171cdf0e10cSrcweir * The error code may be one of the error codes defined in 172cdf0e10cSrcweir * filerror.hxx. 173cdf0e10cSrcweir * The minor code refines the information given in ErrorCode. 174cdf0e10cSrcweir */ 175cdf0e10cSrcweir 176cdf0e10cSrcweir void SAL_CALL clearError(); 177cdf0e10cSrcweir 178cdf0e10cSrcweir void SAL_CALL installError( sal_Int32 CommandId, 179cdf0e10cSrcweir sal_Int32 ErrorCode, 180cdf0e10cSrcweir sal_Int32 minorCode = TASKHANDLER_NO_ERROR ); 181cdf0e10cSrcweir 182cdf0e10cSrcweir 183cdf0e10cSrcweir // void SAL_CALL installError( sal_Int32 CommandId, 184cdf0e10cSrcweir // sal_Int32 ErrorCode, 185cdf0e10cSrcweir // rtl::OUString message ); 186cdf0e10cSrcweir 187cdf0e10cSrcweir // void SAL_CALL installError( sal_Int32 CommandId, 188cdf0e10cSrcweir // sal_Int32 ErrorCode, 189cdf0e10cSrcweir // rtl::OUString message ); 190cdf0e10cSrcweir 191cdf0e10cSrcweir void SAL_CALL retrieveError( sal_Int32 CommandId, 192cdf0e10cSrcweir sal_Int32 &ErrorCode, 193cdf0e10cSrcweir sal_Int32 &minorCode); 194cdf0e10cSrcweir 195cdf0e10cSrcweir /** 196cdf0e10cSrcweir * Deinstalls the task and evaluates a possibly set error code. 197cdf0e10cSrcweir * "endTask" throws in case an error code is set the corresponding exception. 198cdf0e10cSrcweir */ 199cdf0e10cSrcweir 200cdf0e10cSrcweir void SAL_CALL endTask( sal_Int32 CommandId, 201cdf0e10cSrcweir // the physical URL of the object 202cdf0e10cSrcweir const rtl::OUString& aUnqPath, 203cdf0e10cSrcweir BaseContent* pContent); 204cdf0e10cSrcweir 205cdf0e10cSrcweir 206cdf0e10cSrcweir /** 207cdf0e10cSrcweir * Handles an interactionrequest 208cdf0e10cSrcweir */ 209cdf0e10cSrcweir 210cdf0e10cSrcweir void SAL_CALL handleTask( sal_Int32 CommandId, 211cdf0e10cSrcweir const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& request ); 212cdf0e10cSrcweir 213cdf0e10cSrcweir /** 214cdf0e10cSrcweir * Clears any error which are set on the commandid 215cdf0e10cSrcweir */ 216cdf0e10cSrcweir 217cdf0e10cSrcweir void SAL_CALL clearError( sal_Int32 ); 218cdf0e10cSrcweir 219cdf0e10cSrcweir }; 220cdf0e10cSrcweir 221cdf0e10cSrcweir } // end namespace TaskHandling 222