Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <dispatch/loaddispatcher.hxx>
30 : : #include <threadhelp/readguard.hxx>
31 : : #include <threadhelp/writeguard.hxx>
32 : :
33 : : #include <com/sun/star/frame/DispatchResultState.hpp>
34 : :
35 : : namespace framework{
36 : :
37 : : namespace css = ::com::sun::star;
38 : :
39 : 2 : LoadDispatcher::LoadDispatcher(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR ,
40 : : const css::uno::Reference< css::frame::XFrame >& xOwnerFrame ,
41 : : const ::rtl::OUString sTargetName ,
42 : : sal_Int32 nSearchFlags)
43 : : : ThreadHelpBase( )
44 : : , m_xSMGR (xSMGR )
45 : : , m_xOwnerFrame (xOwnerFrame )
46 : : , m_sTarget (sTargetName )
47 : : , m_nSearchFlags(nSearchFlags)
48 [ + - ][ + - ]: 2 : , m_aLoader (xSMGR )
[ + - ]
49 : : {
50 : 2 : }
51 : :
52 [ + - ][ + - ]: 2 : LoadDispatcher::~LoadDispatcher()
[ + - ]
53 : : {
54 : 2 : m_xSMGR.clear();
55 [ - + ]: 4 : }
56 : :
57 : 0 : void SAL_CALL LoadDispatcher::dispatchWithNotification(const css::util::URL& aURL ,
58 : : const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
59 : : const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
60 : : throw(css::uno::RuntimeException)
61 : : {
62 : 0 : impl_dispatch( aURL, lArguments, xListener );
63 : 0 : }
64 : :
65 : 2 : void SAL_CALL LoadDispatcher::dispatch(const css::util::URL& aURL ,
66 : : const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
67 : : throw(css::uno::RuntimeException)
68 : : {
69 [ + - ]: 2 : impl_dispatch( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() );
70 : 2 : }
71 : :
72 : 0 : css::uno::Any SAL_CALL LoadDispatcher::dispatchWithReturnValue( const css::util::URL& rURL,
73 : : const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
74 : : throw( css::uno::RuntimeException )
75 : : {
76 [ # # ]: 0 : return impl_dispatch( rURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
77 : : }
78 : :
79 : 0 : void SAL_CALL LoadDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
80 : : const css::util::URL& /*aURL*/ )
81 : : throw(css::uno::RuntimeException)
82 : : {
83 : 0 : }
84 : :
85 : 0 : void SAL_CALL LoadDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
86 : : const css::util::URL& /*aURL*/ )
87 : : throw(css::uno::RuntimeException)
88 : : {
89 : 0 : }
90 : :
91 : 2 : css::uno::Any LoadDispatcher::impl_dispatch( const css::util::URL& rURL,
92 : : const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
93 : : const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
94 : : {
95 : : // Attention: May be nobody outside hold such temp. dispatch object alive (because
96 : : // the container in which we resists isnt implemented threadsafe but updated by a timer
97 : : // and clear our reference ...) we should hold us self alive!
98 [ + - ]: 2 : css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::frame::XNotifyingDispatch* >(this), css::uno::UNO_QUERY);
99 : :
100 : : // SAFE -> ----------------------------------
101 [ + - ]: 2 : ReadGuard aReadLock(m_aLock);
102 : :
103 : : // We are the only client of this load env object ... but
104 : : // may a dispatch request before is still in progress (?!).
105 : : // Then we should wait a little bit and block this new request.
106 : : // In case we run into the timeout, we should reject this new request
107 : : // and return "FAILED" as result. Otherwhise we can start this new operation.
108 [ + - ][ - + ]: 2 : if (!m_aLoader.waitWhileLoading(2000)) // => 2 sec.
109 : : {
110 [ # # ]: 0 : if (xListener.is())
111 [ # # ]: 0 : xListener->dispatchFinished(
112 [ # # ][ # # ]: 0 : css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::DONTKNOW, css::uno::Any())); // DONTKNOW? ... not realy started ... not realy failed :-)
[ # # ]
113 : : }
114 : :
115 [ + - ][ + - ]: 2 : css::uno::Reference< css::frame::XFrame > xBaseFrame(m_xOwnerFrame.get(), css::uno::UNO_QUERY);
116 [ - + ]: 2 : if (!xBaseFrame.is())
117 : : {
118 [ # # ]: 0 : if (xListener.is())
119 [ # # ]: 0 : xListener->dispatchFinished(
120 [ # # ][ # # ]: 0 : css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::FAILURE, css::uno::Any()));
[ # # ]
121 : : }
122 : :
123 : : // OK ... now the internal loader seems to be useable for new requests
124 : : // and our owner frame seems to be valid for such operations.
125 : : // Initialize it with all new but needed properties and start the loading.
126 : 2 : css::uno::Reference< css::lang::XComponent > xComponent;
127 : : try
128 : : {
129 [ + - ]: 2 : m_aLoader.initializeLoading( rURL.Complete, lArguments, xBaseFrame, m_sTarget, m_nSearchFlags, (LoadEnv::EFeature)(LoadEnv::E_ALLOW_CONTENTHANDLER | LoadEnv::E_WORK_WITH_UI));
130 [ + - ]: 2 : m_aLoader.startLoading();
131 [ + - ]: 2 : m_aLoader.waitWhileLoading(); // wait for ever!
132 [ + - ][ + - ]: 2 : xComponent = m_aLoader.getTargetComponent();
[ # # ]
133 : :
134 : : // TODO thinking about asynchronous operations and listener support
135 : : }
136 : 0 : catch(const LoadEnvException&)
137 : 0 : { xComponent.clear(); }
138 : :
139 [ - + ]: 2 : if (xListener.is())
140 : : {
141 [ # # ]: 0 : if (xComponent.is())
142 [ # # ]: 0 : xListener->dispatchFinished(
143 [ # # ][ # # ]: 0 : css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::SUCCESS, css::uno::Any()));
[ # # ]
144 : : else
145 [ # # ]: 0 : xListener->dispatchFinished(
146 [ # # ][ # # ]: 0 : css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::FAILURE, css::uno::Any()));
[ # # ]
147 : : }
148 : :
149 : : // return the model - like loadComponentFromURL()
150 : 2 : css::uno::Any aRet;
151 [ + - ]: 2 : if ( xComponent.is () )
152 [ + - ]: 2 : aRet = css::uno::makeAny( xComponent );
153 : :
154 [ + - ]: 2 : aReadLock.unlock();
155 : : // <- SAFE ----------------------------------
156 [ + - ]: 2 : return aRet;
157 : : }
158 : :
159 : : } // namespace framework
160 : :
161 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|