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 :
20 : #include <comphelper/stillreadwriteinteraction.hxx>
21 :
22 : #include <com/sun/star/ucb/InteractiveIOException.hpp>
23 :
24 : #include <com/sun/star/task/XInteractionAbort.hpp>
25 :
26 : #include <com/sun/star/ucb/UnsupportedDataSinkException.hpp>
27 :
28 : namespace comphelper{
29 :
30 4055 : StillReadWriteInteraction::StillReadWriteInteraction(const css::uno::Reference< css::task::XInteractionHandler >& xHandler)
31 : : m_bUsed (false)
32 : , m_bHandledByMySelf (false)
33 4055 : , m_bHandledByInternalHandler(false)
34 : {
35 4055 : ::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest > lInterceptions;
36 8110 : ::ucbhelper::InterceptedInteraction::InterceptedRequest aInterceptedRequest;
37 :
38 4055 : aInterceptedRequest.Handle = HANDLE_INTERACTIVEIOEXCEPTION;
39 4055 : aInterceptedRequest.Request <<= css::ucb::InteractiveIOException();
40 4055 : aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
41 4055 : aInterceptedRequest.MatchExact = false;
42 4055 : lInterceptions.push_back(aInterceptedRequest);
43 :
44 4055 : aInterceptedRequest.Handle = HANDLE_UNSUPPORTEDDATASINKEXCEPTION;
45 4055 : aInterceptedRequest.Request <<= css::ucb::UnsupportedDataSinkException();
46 4055 : aInterceptedRequest.Continuation = ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0));
47 4055 : aInterceptedRequest.MatchExact = false;
48 4055 : lInterceptions.push_back(aInterceptedRequest);
49 :
50 4055 : setInterceptedHandler(xHandler);
51 8110 : setInterceptions(lInterceptions);
52 4055 : }
53 :
54 2420 : void StillReadWriteInteraction::resetInterceptions()
55 : {
56 2420 : setInterceptions(::std::vector< ::ucbhelper::InterceptedInteraction::InterceptedRequest >());
57 2420 : }
58 :
59 2420 : void StillReadWriteInteraction::resetErrorStates()
60 : {
61 2420 : m_bUsed = false;
62 2420 : m_bHandledByMySelf = false;
63 2420 : m_bHandledByInternalHandler = false;
64 2420 : }
65 :
66 12 : bool StillReadWriteInteraction::wasWriteError()
67 : {
68 12 : return (m_bUsed && m_bHandledByMySelf);
69 : }
70 :
71 114 : ucbhelper::InterceptedInteraction::EInterceptionState StillReadWriteInteraction::intercepted(const ::ucbhelper::InterceptedInteraction::InterceptedRequest& aRequest,
72 : const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionRequest >& xRequest)
73 : {
74 : // we are used!
75 114 : m_bUsed = true;
76 :
77 : // check if it's a real interception - might some parameters are not the right ones ...
78 114 : bool bAbort = false;
79 114 : switch(aRequest.Handle)
80 : {
81 : case HANDLE_INTERACTIVEIOEXCEPTION:
82 : {
83 114 : css::ucb::InteractiveIOException exIO;
84 114 : xRequest->getRequest() >>= exIO;
85 : bAbort = (
86 114 : (exIO.Code == css::ucb::IOErrorCode_ACCESS_DENIED )
87 114 : || (exIO.Code == css::ucb::IOErrorCode_LOCKING_VIOLATION )
88 228 : || (exIO.Code == css::ucb::IOErrorCode_NOT_EXISTING )
89 : #ifdef MACOSX
90 : // this is a workaround for MAC, on this platform if the file is locked
91 : // the returned error code looks to be wrong
92 : || (exIO.Code == css::ucb::IOErrorCode_GENERAL )
93 : #endif
94 114 : );
95 : }
96 114 : break;
97 :
98 : case HANDLE_UNSUPPORTEDDATASINKEXCEPTION:
99 : {
100 0 : bAbort = true;
101 : }
102 0 : break;
103 : }
104 :
105 : // handle interaction by ourself
106 114 : if (bAbort)
107 : {
108 114 : m_bHandledByMySelf = true;
109 : css::uno::Reference< css::task::XInteractionContinuation > xAbort = ::ucbhelper::InterceptedInteraction::extractContinuation(
110 114 : xRequest->getContinuations(),
111 228 : ::getCppuType(static_cast< css::uno::Reference< css::task::XInteractionAbort >* >(0)));
112 114 : if (!xAbort.is())
113 0 : return ::ucbhelper::InterceptedInteraction::E_NO_CONTINUATION_FOUND;
114 114 : xAbort->select();
115 114 : return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
116 : }
117 :
118 : // Otherwhise use internal handler.
119 0 : if (m_xInterceptedHandler.is())
120 : {
121 0 : m_bHandledByInternalHandler = true;
122 0 : m_xInterceptedHandler->handle(xRequest);
123 : }
124 0 : return ::ucbhelper::InterceptedInteraction::E_INTERCEPTED;
125 : }
126 : }
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|