LCOV - code coverage report
Current view: top level - ucb/source/ucp/file - filtask.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 22 30 73.3 %
Date: 2015-06-13 12:38:46 Functions: 10 12 83.3 %
Legend: Lines: hit not hit

          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             : #ifndef INCLUDED_UCB_SOURCE_UCP_FILE_FILTASK_HXX
      20             : #define INCLUDED_UCB_SOURCE_UCP_FILE_FILTASK_HXX
      21             : #endif
      22             : 
      23             : #include <rtl/ustring.hxx>
      24             : 
      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>
      34             : 
      35             : namespace fileaccess
      36             : {
      37             :     class BaseContent;
      38             : 
      39             :     /*
      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.
      44             :      */
      45             : 
      46             : 
      47             :     class TaskManager
      48             :     {
      49             :     protected:
      50             : 
      51      585123 :         class TaskHandling
      52             :         {
      53             :         private:
      54             : 
      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;
      60             : 
      61             : 
      62             :         public:
      63             : 
      64      390082 :             explicit 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      390082 :                   m_xCommandEnvironment( xCommandEnv )
      74             :             {
      75      390082 :             }
      76             : 
      77           0 :             void SAL_CALL abort()
      78             :             {
      79           0 :                 m_bAbort = true;
      80           0 :             }
      81             : 
      82         980 :             void setHandled()
      83             :             {
      84         980 :                 m_bHandled = true;
      85         980 :             }
      86             : 
      87      195041 :             bool isHandled() const
      88             :             {
      89      195041 :                 return m_bHandled;
      90             :             }
      91             : 
      92           0 :             void clearError()
      93             :             {
      94           0 :                 m_nErrorCode = TASKHANDLER_NO_ERROR;
      95           0 :                 m_nMinorCode =  TASKHANDLER_NO_ERROR;
      96           0 :             }
      97             : 
      98       24014 :             void SAL_CALL installError( sal_Int32 nErrorCode,
      99             :                                         sal_Int32 nMinorCode = TASKHANDLER_NO_ERROR )
     100             :             {
     101       24014 :                 m_nErrorCode = nErrorCode;
     102       24014 :                 m_nMinorCode = nMinorCode;
     103       24014 :             }
     104             : 
     105      196021 :             sal_Int32 SAL_CALL getInstalledError()
     106             :             {
     107      196021 :                 return m_nErrorCode;
     108             :             }
     109             : 
     110      196021 :             sal_Int32 SAL_CALL getMinorErrorCode()
     111             :             {
     112      196021 :                 return m_nMinorCode;
     113             :             }
     114             : 
     115             :             com::sun::star::uno::Reference< com::sun::star::ucb::XProgressHandler > SAL_CALL
     116             :             getProgressHandler()
     117             :             {
     118             :                 if( ! m_xProgressHandler.is() && m_xCommandEnvironment.is() )
     119             :                     m_xProgressHandler = m_xCommandEnvironment->getProgressHandler();
     120             : 
     121             :                 return m_xProgressHandler;
     122             :             }
     123             : 
     124             :             com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler > SAL_CALL
     125         980 :             getInteractionHandler()
     126             :             {
     127         980 :                 if( ! m_xInteractionHandler.is() && m_xCommandEnvironment.is() )
     128           0 :                     m_xInteractionHandler = m_xCommandEnvironment->getInteractionHandler();
     129             : 
     130         980 :                 return m_xInteractionHandler;
     131             :             }
     132             : 
     133             :             com::sun::star::uno::Reference< com::sun::star::ucb::XCommandEnvironment > SAL_CALL
     134      195041 :             getCommandEnvironment()
     135             :             {
     136      195041 :                 return m_xCommandEnvironment;
     137             :             }
     138             : 
     139             :         };  // end class TaskHandling
     140             : 
     141             : 
     142             :         typedef std::unordered_map< sal_Int32,TaskHandling,boost::hash< sal_Int32 > > TaskMap;
     143             :     private:
     144             : 
     145             :         osl::Mutex                                                         m_aMutex;
     146             :         sal_Int32                                                           m_nCommandId;
     147             :         TaskMap                                                             m_aTaskMap;
     148             : 
     149             : 
     150             :     public:
     151             : 
     152             :         TaskManager();
     153             :         virtual ~TaskManager();
     154             : 
     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 );
     159             : 
     160             :         sal_Int32 SAL_CALL getCommandId();
     161             :         void SAL_CALL abort( sal_Int32 CommandId );
     162             : 
     163             : 
     164             :         /**
     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.
     168             :          */
     169             : 
     170             :         void SAL_CALL clearError();
     171             : 
     172             :         void SAL_CALL installError( sal_Int32 CommandId,
     173             :                                     sal_Int32 ErrorCode,
     174             :                                     sal_Int32 minorCode = TASKHANDLER_NO_ERROR );
     175             : 
     176             :         void SAL_CALL retrieveError( sal_Int32 CommandId,
     177             :                                      sal_Int32 &ErrorCode,
     178             :                                      sal_Int32 &minorCode);
     179             : 
     180             :         /**
     181             :          *  Deinstalls the task and evaluates a possibly set error code.
     182             :          *  "endTask" throws in case an error code is set the corresponding exception.
     183             :          */
     184             : 
     185             :         void SAL_CALL endTask( sal_Int32 CommandId,
     186             :                                // the physical URL of the object
     187             :                                const OUString& aUnqPath,
     188             :                                BaseContent* pContent);
     189             : 
     190             : 
     191             :         /**
     192             :          *  Handles an interactionrequest
     193             :          */
     194             : 
     195             :         void SAL_CALL handleTask( sal_Int32 CommandId,
     196             :                                   const com::sun::star::uno::Reference< com::sun::star::task::XInteractionRequest >& request );
     197             : 
     198             :         /**
     199             :          *  Clears any error which are set on the commandid
     200             :          */
     201             : 
     202             :         void SAL_CALL clearError( sal_Int32 );
     203             : 
     204             :     };
     205             : 
     206             : } // end namespace TaskHandling
     207             : 
     208             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11