1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <ucbhelper/interceptedinteraction.hxx>
22 #include <osl/diagnose.h>
26 InterceptedInteraction::InterceptedInteraction()
30 void InterceptedInteraction::setInterceptedHandler(const css::uno::Reference
< css::task::XInteractionHandler
>& xInterceptedHandler
)
32 m_xInterceptedHandler
= xInterceptedHandler
;
35 void InterceptedInteraction::setInterceptions(::std::vector
< InterceptedRequest
>&& lInterceptions
)
37 m_lInterceptions
= std::move(lInterceptions
);
40 InterceptedInteraction::EInterceptionState
InterceptedInteraction::intercepted(
41 const InterceptedRequest
&,
42 const css::uno::Reference
< css::task::XInteractionRequest
>&)
44 // default behaviour! see impl_interceptRequest() for further information ...
45 return E_NOT_INTERCEPTED
;
48 css::uno::Reference
< css::task::XInteractionContinuation
> InterceptedInteraction::extractContinuation(const css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> >& lContinuations
,
49 const css::uno::Type
& aType
)
51 const css::uno::Reference
< css::task::XInteractionContinuation
>* pContinuations
= std::find_if(lContinuations
.begin(), lContinuations
.end(),
52 [&aType
](const css::uno::Reference
< css::task::XInteractionContinuation
>& rContinuation
) {
53 css::uno::Reference
< css::uno::XInterface
> xCheck(rContinuation
, css::uno::UNO_QUERY
);
54 return xCheck
->queryInterface(aType
).hasValue();
56 if (pContinuations
!= lContinuations
.end())
57 return *pContinuations
;
59 return css::uno::Reference
< css::task::XInteractionContinuation
>();
62 void SAL_CALL
InterceptedInteraction::handle(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
64 impl_handleDefault(xRequest
);
67 void InterceptedInteraction::impl_handleDefault(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
69 EInterceptionState eState
= impl_interceptRequest(xRequest
);
73 case E_NOT_INTERCEPTED
:
75 // Non of the intercepted requests match to the given one.
76 // => forward request to the internal wrapped handler - if there is one.
77 if (m_xInterceptedHandler
.is())
78 m_xInterceptedHandler
->handle(xRequest
);
82 case E_NO_CONTINUATION_FOUND
:
84 // Runtime error! The defined continuation could not be located
85 // inside the set of available continuations of the incoming request.
86 // What's wrong - the interception list or the request?
87 OSL_FAIL("InterceptedInteraction::handle()\nCould intercept this interaction request - but can't locate the right continuation!");
96 InterceptedInteraction::EInterceptionState
InterceptedInteraction::impl_interceptRequest(const css::uno::Reference
< css::task::XInteractionRequest
>& xRequest
)
98 css::uno::Any aRequest
= xRequest
->getRequest();
99 const css::uno::Type
& aRequestType
= aRequest
.getValueType();
100 css::uno::Sequence
< css::uno::Reference
< css::task::XInteractionContinuation
> > lContinuations
= xRequest
->getContinuations();
102 // check against the list of static requests
103 auto pIt
= std::find_if(m_lInterceptions
.begin(), m_lInterceptions
.end(),
104 [&aRequestType
](const InterceptedRequest
& rInterception
) {
106 // don't change intercepted and request type here -> it will check the wrong direction!
107 return rInterception
.Request
.getValueType().isAssignableFrom(aRequestType
);
110 if (pIt
!= m_lInterceptions
.end()) // intercepted ...
112 const InterceptedRequest
& rInterception
= *pIt
;
114 // Call they might existing derived class, so they can handle that by its own.
115 // If it's not interested on that (maybe it's not overwritten and the default implementation
116 // returns E_NOT_INTERCEPTED as default) -> search required continuation
117 EInterceptionState eState
= intercepted(rInterception
, xRequest
);
118 if (eState
!= E_NOT_INTERCEPTED
)
121 css::uno::Reference
< css::task::XInteractionContinuation
> xContinuation
= InterceptedInteraction::extractContinuation(lContinuations
, rInterception
.Continuation
);
122 if (xContinuation
.is())
124 xContinuation
->select();
125 return E_INTERCEPTED
;
128 // Can be reached only, if the request does not support the given continuation!
130 return E_NO_CONTINUATION_FOUND
;
133 return E_NOT_INTERCEPTED
;
136 } // namespace ucbhelper
138 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */