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