LCOV - code coverage report
Current view: top level - libreoffice/comphelper/source/misc - officerestartmanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 14 66 21.2 %
Date: 2012-12-27 Functions: 5 12 41.7 %
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             : 
      21             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      22             : #include <com/sun/star/awt/XRequestCallback.hpp>
      23             : #include <com/sun/star/frame/Desktop.hpp>
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : 
      26             : #include <comphelper_module.hxx>
      27             : #include "officerestartmanager.hxx"
      28             : 
      29             : using namespace ::com::sun::star;
      30             : 
      31             : namespace comphelper
      32             : {
      33             : 
      34             : // ----------------------------------------------------------
      35          28 : uno::Sequence< ::rtl::OUString > SAL_CALL OOfficeRestartManager::getSupportedServiceNames_static()
      36             : {
      37          28 :     uno::Sequence< rtl::OUString > aResult( 1 );
      38          28 :     aResult[0] = getServiceName_static();
      39          28 :     return aResult;
      40             : }
      41             : 
      42             : // ----------------------------------------------------------
      43          28 : ::rtl::OUString SAL_CALL OOfficeRestartManager::getImplementationName_static()
      44             : {
      45          28 :     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.task.OfficeRestartManager" ) );
      46             : }
      47             : 
      48             : // ----------------------------------------------------------
      49          14 : ::rtl::OUString SAL_CALL OOfficeRestartManager::getSingletonName_static()
      50             : {
      51          14 :     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.task.OfficeRestartManager" ) );
      52             : }
      53             : 
      54             : // ----------------------------------------------------------
      55          28 : ::rtl::OUString SAL_CALL OOfficeRestartManager::getServiceName_static()
      56             : {
      57          28 :     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.task.OfficeRestartManager" ) );
      58             : }
      59             : 
      60             : // ----------------------------------------------------------
      61           0 : uno::Reference< uno::XInterface > SAL_CALL OOfficeRestartManager::Create( const uno::Reference< uno::XComponentContext >& rxContext )
      62             : {
      63           0 :     return static_cast< cppu::OWeakObject* >( new OOfficeRestartManager( rxContext ) );
      64             : }
      65             : 
      66             : // XRestartManager
      67             : // ----------------------------------------------------------
      68           0 : void SAL_CALL OOfficeRestartManager::requestRestart( const uno::Reference< task::XInteractionHandler >& /* xInteractionHandler */ )
      69             :     throw (uno::Exception, uno::RuntimeException)
      70             : {
      71           0 :     if ( !m_xContext.is() )
      72           0 :         throw uno::RuntimeException();
      73             : 
      74             :     {
      75           0 :         ::osl::MutexGuard aGuard( m_aMutex );
      76             : 
      77             :         // if the restart already running there is no need to trigger it again
      78           0 :         if ( m_bRestartRequested )
      79             :             return;
      80             : 
      81           0 :         m_bRestartRequested = sal_True;
      82             : 
      83             :         // the office is still not initialized, no need to terminate, changing the state is enough
      84           0 :         if ( !m_bOfficeInitialized )
      85           0 :             return;
      86             :     }
      87             : 
      88             :     // TODO: use InteractionHandler to report errors
      89             :     try
      90             :     {
      91             :         // register itself as a job that should be executed asynchronously
      92           0 :         uno::Reference< lang::XMultiComponentFactory > xFactory( m_xContext->getServiceManager(), uno::UNO_SET_THROW );
      93             : 
      94             :         uno::Reference< awt::XRequestCallback > xRequestCallback(
      95           0 :             xFactory->createInstanceWithContext(
      96             :                  ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.AsyncCallback" )),
      97           0 :                  m_xContext ),
      98           0 :              uno::UNO_QUERY_THROW );
      99             : 
     100           0 :         xRequestCallback->addCallback( this, uno::Any() );
     101             :     }
     102           0 :     catch ( uno::Exception& )
     103             :     {
     104             :         // the try to request restart has failed
     105           0 :         m_bRestartRequested = sal_False;
     106             :     }
     107             : }
     108             : 
     109             : // ----------------------------------------------------------
     110           0 : ::sal_Bool SAL_CALL OOfficeRestartManager::isRestartRequested( ::sal_Bool bOfficeInitialized )
     111             :     throw (uno::Exception, uno::RuntimeException)
     112             : {
     113           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     114             : 
     115           0 :     if ( bOfficeInitialized && !m_bOfficeInitialized )
     116           0 :         m_bOfficeInitialized = bOfficeInitialized;
     117             : 
     118           0 :     return m_bRestartRequested;
     119             : }
     120             : 
     121             : // XCallback
     122             : // ----------------------------------------------------------
     123           0 : void SAL_CALL OOfficeRestartManager::notify( const uno::Any& /* aData */ )
     124             :     throw ( uno::RuntimeException )
     125             : {
     126             :     try
     127             :     {
     128           0 :         sal_Bool bSuccess = sal_False;
     129             : 
     130           0 :         if ( m_xContext.is() )
     131             :         {
     132           0 :             uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(m_xContext);
     133             : 
     134             :             // Turn Quickstarter veto off
     135           0 :             uno::Reference< beans::XPropertySet > xPropertySet( xDesktop, uno::UNO_QUERY_THROW );
     136           0 :             ::rtl::OUString aVetoPropName( RTL_CONSTASCII_USTRINGPARAM( "SuspendQuickstartVeto" ) );
     137           0 :             uno::Any aValue;
     138           0 :             aValue <<= (sal_Bool)sal_True;
     139           0 :             xPropertySet->setPropertyValue( aVetoPropName, aValue );
     140             : 
     141             :             try
     142             :             {
     143           0 :                 bSuccess = xDesktop->terminate();
     144           0 :             } catch( uno::Exception& )
     145             :             {}
     146             : 
     147           0 :             if ( !bSuccess )
     148             :             {
     149           0 :                 aValue <<= (sal_Bool)sal_False;
     150           0 :                 xPropertySet->setPropertyValue( aVetoPropName, aValue );
     151           0 :             }
     152             :         }
     153             : 
     154           0 :         if ( !bSuccess )
     155           0 :             m_bRestartRequested = sal_False;
     156             :     }
     157           0 :     catch( uno::Exception& )
     158             :     {
     159             :         // the try to restart has failed
     160           0 :         m_bRestartRequested = sal_False;
     161             :     }
     162           0 : }
     163             : 
     164             : // XServiceInfo
     165             : // ----------------------------------------------------------
     166           0 : ::rtl::OUString SAL_CALL OOfficeRestartManager::getImplementationName() throw (uno::RuntimeException)
     167             : {
     168           0 :     return getImplementationName_static();
     169             : }
     170             : 
     171             : // ----------------------------------------------------------
     172           0 : ::sal_Bool SAL_CALL OOfficeRestartManager::supportsService( const ::rtl::OUString& aServiceName ) throw (uno::RuntimeException)
     173             : {
     174           0 :     const uno::Sequence< rtl::OUString > & aSupportedNames = getSupportedServiceNames_static();
     175           0 :     for ( sal_Int32 nInd = 0; nInd < aSupportedNames.getLength(); nInd++ )
     176             :     {
     177           0 :         if ( aSupportedNames[ nInd ].equals( aServiceName ) )
     178           0 :             return sal_True;
     179             :     }
     180             : 
     181           0 :     return sal_False;
     182             : }
     183             : 
     184             : // ----------------------------------------------------------
     185           0 : uno::Sequence< ::rtl::OUString > SAL_CALL OOfficeRestartManager::getSupportedServiceNames() throw (uno::RuntimeException)
     186             : {
     187           0 :     return getSupportedServiceNames_static();
     188             : }
     189             : 
     190             : } // namespace comphelper
     191             : 
     192          14 : void createRegistryInfo_OOfficeRestartManager()
     193             : {
     194          14 :     static ::comphelper::module::OAutoRegistration< ::comphelper::OOfficeRestartManager > aAutoRegistration;
     195          14 :     static ::comphelper::module::OSingletonRegistration< ::comphelper::OOfficeRestartManager > aSingletonRegistration;
     196          14 : }
     197             : 
     198             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10