LibreOffice Module framework (master) 1
loaddispatcher.cxx
Go to the documentation of this file.
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
22#include <sal/log.hxx>
23
24#include <com/sun/star/frame/DispatchResultState.hpp>
25#include <utility>
26
27namespace framework{
28
29LoadDispatcher::LoadDispatcher(const css::uno::Reference< css::uno::XComponentContext >& xContext ,
30 const css::uno::Reference< css::frame::XFrame >& xOwnerFrame ,
31 OUString sTargetName ,
32 sal_Int32 nSearchFlags)
33 : m_xOwnerFrame (xOwnerFrame )
34 , m_sTarget (std::move(sTargetName ))
35 , m_nSearchFlags(nSearchFlags)
36 , m_aLoader (xContext )
37{
38}
39
41{
42}
43
44void SAL_CALL LoadDispatcher::dispatchWithNotification(const css::util::URL& aURL ,
45 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
46 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
47{
48 impl_dispatch( aURL, lArguments, xListener );
49}
50
51void SAL_CALL LoadDispatcher::dispatch(const css::util::URL& aURL ,
52 const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
53{
54 impl_dispatch( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() );
55}
56
57css::uno::Any SAL_CALL LoadDispatcher::dispatchWithReturnValue( const css::util::URL& rURL,
58 const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
59{
60 return impl_dispatch( rURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
61}
62
63void SAL_CALL LoadDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
64 const css::util::URL& /*aURL*/ )
65{
66}
67
68void SAL_CALL LoadDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
69 const css::util::URL& /*aURL*/ )
70{
71}
72
73css::uno::Any LoadDispatcher::impl_dispatch( const css::util::URL& rURL,
74 const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
75 const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
76{
77 // Attention: May be nobody outside hold such temp. dispatch object alive (because
78 // the container in which we resist isn't implemented threadsafe but updated by a timer
79 // and clear our reference...) we should hold us self alive!
80 css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::frame::XNotifyingDispatch* >(this), css::uno::UNO_QUERY);
81
82 osl::MutexGuard g(m_mutex);
83
84 // We are the only client of this load env object... but
85 // may a dispatch request before is still in progress (?!).
86 // Then we should wait a little bit and block this new request.
87 // In case we run into the timeout, we should reject this new request
88 // and return "FAILED" as result. Otherwise we can start this new operation.
89 if (!m_aLoader.waitWhileLoading(2000)) // => 2 sec.
90 {
91 if (xListener.is())
92 xListener->dispatchFinished(
93 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::DONTKNOW, css::uno::Any())); // DONTKNOW? ... not really started ... not really failed :-)
94 }
95
96 css::uno::Reference< css::frame::XFrame > xBaseFrame(m_xOwnerFrame.get(), css::uno::UNO_QUERY);
97 if (!xBaseFrame.is() && xListener.is())
98 xListener->dispatchFinished(
99 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::FAILURE, css::uno::Any()));
100
101 // OK ... now the internal loader seems to be usable for new requests
102 // and our owner frame seems to be valid for such operations.
103 // Initialize it with all new but needed properties and start the loading.
104 css::uno::Reference< css::lang::XComponent > xComponent;
105 try
106 {
108 m_aLoader.waitWhileLoading(); // wait for ever!
109 xComponent = m_aLoader.getTargetComponent();
110
111 // TODO thinking about asynchronous operations and listener support
112 }
113 catch(const LoadEnvException& e)
114 {
115 SAL_WARN(
116 "fwk.dispatch",
117 "caught LoadEnvException " << +e.m_nID << " \"" << e.m_sMessage
118 << "\""
119 << (e.m_exOriginal.has<css::uno::Exception>()
120 ? (", " + e.m_exOriginal.getValueTypeName() + " \""
121 + e.m_exOriginal.get<css::uno::Exception>().Message
122 + "\"")
123 : OUString())
124 << " while dispatching <" << rURL.Complete << ">");
125 xComponent.clear();
126 }
127
128 if (xListener.is())
129 {
130 if (xComponent.is())
131 xListener->dispatchFinished(
132 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::SUCCESS, css::uno::Any()));
133 else
134 xListener->dispatchFinished(
135 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::FAILURE, css::uno::Any()));
136 }
137
138 // return the model - like loadComponentFromURL()
139 css::uno::Any aRet;
140 if ( xComponent.is () )
141 aRet <<= xComponent;
142
143 return aRet;
144}
145
146} // namespace framework
147
148/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~LoadDispatcher() override
used to free internal resources.
css::uno::WeakReference< css::frame::XFrame > m_xOwnerFrame
TODO document me.
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
css::uno::Any impl_dispatch(const css::util::URL &rURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Reference< css::frame::XDispatchResultListener > &xListener)
virtual css::uno::Any SAL_CALL dispatchWithReturnValue(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments) override
LoadEnv m_aLoader
TODO document me.
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &xListener, const css::util::URL &aURL) override
virtual void SAL_CALL dispatch(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments) override
LoadDispatcher(const css::uno::Reference< css::uno::XComponentContext > &xContext, const css::uno::Reference< css::frame::XFrame > &xOwnerFrame, OUString sTargetName, sal_Int32 nSearchFlags)
creates a new instance and initialize it with all necessary parameters.
sal_Int32 m_nSearchFlags
TODO document me.
OUString m_sTarget
TODO document me.
virtual void SAL_CALL dispatchWithNotification(const css::util::URL &aURL, const css::uno::Sequence< css::beans::PropertyValue > &lArguments, const css::uno::Reference< css::frame::XDispatchResultListener > &xListener) override
specify an exception, which can be used inside the load environment only.
void startLoading(const OUString &sURL, const css::uno::Sequence< css::beans::PropertyValue > &lMediaDescriptor, const css::uno::Reference< css::frame::XFrame > &xBaseFrame, const OUString &sTarget, sal_Int32 nSearchFlags, LoadEnvFeatures eFeature=LoadEnvFeatures::NONE)
start loading of a resource
Definition: loadenv.cxx:231
bool waitWhileLoading(sal_uInt32 nTimeout=0)
wait for an already running load request (started by calling startLoading() before).
Definition: loadenv.cxx:426
css::uno::Reference< css::lang::XComponent > getTargetComponent() const
TODO document me ...
Definition: loadenv.cxx:460
URL aURL
@ WorkWithUI
enable using of UI elements during loading (means progress, interaction handler etcpp....
@ AllowContentHandler
enable loading of resources, which are not related to a target frame! (see concept of ContentHandler)
#define SAL_WARN(area, stream)