LCOV - code coverage report
Current view: top level - libreoffice/framework/source/dispatch - loaddispatcher.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 48 0.0 %
Date: 2012-12-27 Functions: 0 9 0.0 %
Legend: Lines: hit not hit

          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 <dispatch/loaddispatcher.hxx>
      21             : #include <threadhelp/readguard.hxx>
      22             : #include <threadhelp/writeguard.hxx>
      23             : 
      24             : #include <com/sun/star/frame/DispatchResultState.hpp>
      25             : 
      26             : namespace framework{
      27             : 
      28           0 : LoadDispatcher::LoadDispatcher(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR       ,
      29             :                                const css::uno::Reference< css::frame::XFrame >&              xOwnerFrame ,
      30             :                                const ::rtl::OUString                                         sTargetName ,
      31             :                                      sal_Int32                                               nSearchFlags)
      32             :     : ThreadHelpBase(            )
      33             :     , m_xSMGR       (xSMGR       )
      34             :     , m_xOwnerFrame (xOwnerFrame )
      35             :     , m_sTarget     (sTargetName )
      36             :     , m_nSearchFlags(nSearchFlags)
      37           0 :     , m_aLoader     (xSMGR       )
      38             : {
      39           0 : }
      40             : 
      41           0 : LoadDispatcher::~LoadDispatcher()
      42             : {
      43           0 :     m_xSMGR.clear();
      44           0 : }
      45             : 
      46           0 : void SAL_CALL LoadDispatcher::dispatchWithNotification(const css::util::URL&                                             aURL      ,
      47             :                                                        const css::uno::Sequence< css::beans::PropertyValue >&            lArguments,
      48             :                                                        const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
      49             :     throw(css::uno::RuntimeException)
      50             : {
      51           0 :     impl_dispatch( aURL, lArguments, xListener );
      52           0 : }
      53             : 
      54           0 : void SAL_CALL LoadDispatcher::dispatch(const css::util::URL&                                  aURL      ,
      55             :                                        const css::uno::Sequence< css::beans::PropertyValue >& lArguments)
      56             :     throw(css::uno::RuntimeException)
      57             : {
      58           0 :     impl_dispatch( aURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >() );
      59           0 : }
      60             : 
      61           0 : css::uno::Any SAL_CALL LoadDispatcher::dispatchWithReturnValue( const css::util::URL& rURL,
      62             :                                                                 const css::uno::Sequence< css::beans::PropertyValue >& lArguments )
      63             :     throw( css::uno::RuntimeException )
      64             : {
      65           0 :     return impl_dispatch( rURL, lArguments, css::uno::Reference< css::frame::XDispatchResultListener >());
      66             : }
      67             : 
      68           0 : void SAL_CALL LoadDispatcher::addStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
      69             :                                                 const css::util::URL&                                     /*aURL*/     )
      70             :     throw(css::uno::RuntimeException)
      71             : {
      72           0 : }
      73             : 
      74           0 : void SAL_CALL LoadDispatcher::removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >& /*xListener*/,
      75             :                                                    const css::util::URL&                                     /*aURL*/     )
      76             :     throw(css::uno::RuntimeException)
      77             : {
      78           0 : }
      79             : 
      80           0 : css::uno::Any LoadDispatcher::impl_dispatch( const css::util::URL& rURL,
      81             :                                              const css::uno::Sequence< css::beans::PropertyValue >& lArguments,
      82             :                                              const css::uno::Reference< css::frame::XDispatchResultListener >& xListener )
      83             : {
      84             :     // Attention: May be nobody outside hold such temp. dispatch object alive (because
      85             :     // the container in which we resists isnt implemented threadsafe but updated by a timer
      86             :     // and clear our reference ...) we should hold us self alive!
      87           0 :     css::uno::Reference< css::uno::XInterface > xThis(static_cast< css::frame::XNotifyingDispatch* >(this), css::uno::UNO_QUERY);
      88             : 
      89             :     // SAFE -> ----------------------------------
      90           0 :     ReadGuard aReadLock(m_aLock);
      91             : 
      92             :     // We are the only client of this load env object ... but
      93             :     // may a dispatch request before is still in progress (?!).
      94             :     // Then we should wait a little bit and block this new request.
      95             :     // In case we run into the timeout, we should reject this new request
      96             :     // and return "FAILED" as result. Otherwhise we can start this new operation.
      97           0 :     if (!m_aLoader.waitWhileLoading(2000)) // => 2 sec.
      98             :     {
      99           0 :         if (xListener.is())
     100           0 :             xListener->dispatchFinished(
     101           0 :                 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::DONTKNOW, css::uno::Any())); // DONTKNOW? ... not realy started ... not realy failed :-)
     102             :     }
     103             : 
     104           0 :     css::uno::Reference< css::frame::XFrame > xBaseFrame(m_xOwnerFrame.get(), css::uno::UNO_QUERY);
     105           0 :     if (!xBaseFrame.is())
     106             :     {
     107           0 :         if (xListener.is())
     108           0 :             xListener->dispatchFinished(
     109           0 :                 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::FAILURE, css::uno::Any()));
     110             :     }
     111             : 
     112             :     // OK ... now the internal loader seems to be useable for new requests
     113             :     // and our owner frame seems to be valid for such operations.
     114             :     // Initialize it with all new but needed properties and start the loading.
     115           0 :     css::uno::Reference< css::lang::XComponent > xComponent;
     116             :     try
     117             :     {
     118           0 :         m_aLoader.initializeLoading( rURL.Complete, lArguments, xBaseFrame, m_sTarget, m_nSearchFlags, (LoadEnv::EFeature)(LoadEnv::E_ALLOW_CONTENTHANDLER | LoadEnv::E_WORK_WITH_UI));
     119           0 :         m_aLoader.startLoading();
     120           0 :         m_aLoader.waitWhileLoading(); // wait for ever!
     121           0 :         xComponent = m_aLoader.getTargetComponent();
     122             : 
     123             :         // TODO thinking about asynchronous operations and listener support
     124             :     }
     125           0 :     catch(const LoadEnvException&)
     126           0 :         { xComponent.clear(); }
     127             : 
     128           0 :     if (xListener.is())
     129             :     {
     130           0 :         if (xComponent.is())
     131           0 :             xListener->dispatchFinished(
     132           0 :                 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::SUCCESS, css::uno::Any()));
     133             :         else
     134           0 :             xListener->dispatchFinished(
     135           0 :                 css::frame::DispatchResultEvent(xThis, css::frame::DispatchResultState::FAILURE, css::uno::Any()));
     136             :     }
     137             : 
     138             :     // return the model - like loadComponentFromURL()
     139           0 :     css::uno::Any aRet;
     140           0 :     if ( xComponent.is () )
     141           0 :         aRet = css::uno::makeAny( xComponent );
     142             : 
     143           0 :     aReadLock.unlock();
     144             :     // <- SAFE ----------------------------------
     145           0 :     return aRet;
     146             : }
     147             : 
     148             : } // namespace framework
     149             : 
     150             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10