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

Generated by: LCOV version 1.10