LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/desktop/source/deployment/manager - dp_managerfac.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 60 83.3 %
Date: 2013-07-09 Functions: 7 8 87.5 %
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 "dp_manager.h"
      22             : #include "dp_resource.h"
      23             : #include "cppuhelper/compbase1.hxx"
      24             : #include "comphelper/servicedecl.hxx"
      25             : #include "com/sun/star/deployment/thePackageManagerFactory.hpp"
      26             : #include <boost/unordered_map.hpp>
      27             : 
      28             : 
      29             : using namespace ::dp_misc;
      30             : using namespace ::com::sun::star;
      31             : using namespace ::com::sun::star::uno;
      32             : 
      33             : namespace dp_manager {
      34             : namespace factory {
      35             : 
      36             : typedef ::cppu::WeakComponentImplHelper1<
      37             :     deployment::XPackageManagerFactory > t_pmfac_helper;
      38             : 
      39             : //==============================================================================
      40             : class PackageManagerFactoryImpl : private MutexHolder, public t_pmfac_helper
      41             : {
      42             :     Reference<XComponentContext> m_xComponentContext;
      43             : 
      44             :     Reference<deployment::XPackageManager> m_xUserMgr;
      45             :     Reference<deployment::XPackageManager> m_xSharedMgr;
      46             :     Reference<deployment::XPackageManager> m_xBundledMgr;
      47             :     Reference<deployment::XPackageManager> m_xTmpMgr;
      48             :     Reference<deployment::XPackageManager> m_xBakMgr;
      49             :     typedef ::boost::unordered_map<
      50             :         OUString, WeakReference<deployment::XPackageManager>,
      51             :         OUStringHash > t_string2weakref;
      52             :     t_string2weakref m_managers;
      53             : 
      54             : protected:
      55             :     inline void check();
      56             :     virtual void SAL_CALL disposing();
      57             : 
      58             : public:
      59             :     virtual ~PackageManagerFactoryImpl();
      60             :     PackageManagerFactoryImpl(
      61             :         Reference<XComponentContext> const & xComponentContext );
      62             : 
      63             :     // XPackageManagerFactory
      64             :     virtual Reference<deployment::XPackageManager> SAL_CALL getPackageManager(
      65             :         OUString const & context ) throw (RuntimeException);
      66             : };
      67             : 
      68             : //==============================================================================
      69             : namespace sdecl = comphelper::service_decl;
      70          65 : sdecl::class_<PackageManagerFactoryImpl> servicePMFI;
      71          65 : extern sdecl::ServiceDecl const serviceDecl(
      72             :     servicePMFI,
      73             :     // a private one:
      74             :     "com.sun.star.comp.deployment.PackageManagerFactory",
      75             :     "com.sun.star.comp.deployment.PackageManagerFactory" );
      76             : 
      77             : //______________________________________________________________________________
      78          65 : PackageManagerFactoryImpl::PackageManagerFactoryImpl(
      79             :     Reference<XComponentContext> const & xComponentContext )
      80          65 :     : t_pmfac_helper( getMutex() ),
      81         130 :       m_xComponentContext( xComponentContext )
      82             : {
      83          65 : }
      84             : 
      85             : //______________________________________________________________________________
      86          64 : PackageManagerFactoryImpl::~PackageManagerFactoryImpl()
      87             : {
      88          64 : }
      89             : 
      90             : //______________________________________________________________________________
      91        1404 : inline void PackageManagerFactoryImpl::check()
      92             : {
      93        1404 :     ::osl::MutexGuard guard( getMutex() );
      94        1404 :     if (rBHelper.bInDispose || rBHelper.bDisposed)
      95             :     {
      96             :         throw lang::DisposedException(
      97             :             "PackageManagerFactory instance has already been disposed!",
      98           0 :             static_cast<OWeakObject *>(this) );
      99        1404 :     }
     100        1404 : }
     101             : 
     102             : //______________________________________________________________________________
     103          64 : void PackageManagerFactoryImpl::disposing()
     104             : {
     105             :     // dispose all managers:
     106          64 :     ::osl::MutexGuard guard( getMutex() );
     107          64 :     t_string2weakref::const_iterator iPos( m_managers.begin() );
     108          64 :     t_string2weakref::const_iterator const iEnd( m_managers.end() );
     109         286 :     for ( ; iPos != iEnd; ++iPos )
     110         222 :         try_dispose( iPos->second );
     111          64 :     m_managers = t_string2weakref();
     112             :     // the below are already disposed:
     113          64 :     m_xUserMgr.clear();
     114          64 :     m_xSharedMgr.clear();
     115          64 :     m_xBundledMgr.clear();
     116          64 :     m_xTmpMgr.clear();
     117          64 :     m_xBakMgr.clear();
     118          64 : }
     119             : 
     120             : // XPackageManagerFactory
     121             : //______________________________________________________________________________
     122             : Reference<deployment::XPackageManager>
     123        1404 : PackageManagerFactoryImpl::getPackageManager( OUString const & context )
     124             :     throw (RuntimeException)
     125             : {
     126        1404 :     Reference< deployment::XPackageManager > xRet;
     127        2808 :     ::osl::ResettableMutexGuard guard( getMutex() );
     128        1404 :     check();
     129        1404 :     t_string2weakref::const_iterator const iFind( m_managers.find( context ) );
     130        1404 :     if (iFind != m_managers.end()) {
     131        1180 :         xRet = iFind->second;
     132        1180 :         if (xRet.is())
     133        1180 :             return xRet;
     134             :     }
     135             : 
     136         224 :     guard.clear();
     137         224 :     xRet.set( PackageManagerImpl::create( m_xComponentContext, context ) );
     138         222 :     guard.reset();
     139             :     ::std::pair< t_string2weakref::iterator, bool > insertion(
     140         222 :         m_managers.insert( t_string2weakref::value_type( context, xRet ) ) );
     141         222 :     if (insertion.second)
     142             :     {
     143             :         OSL_ASSERT( insertion.first->second.get() == xRet );
     144             :         // hold user, shared mgrs for whole process: live deployment
     145         222 :         if ( context == "user" )
     146          63 :             m_xUserMgr = xRet;
     147         159 :         else if ( context == "shared" )
     148          63 :             m_xSharedMgr = xRet;
     149          96 :         else if ( context == "bundled" )
     150          63 :             m_xBundledMgr = xRet;
     151          33 :         else if ( context == "tmp" )
     152          33 :             m_xTmpMgr = xRet;
     153           0 :         else if ( context == "bak" )
     154           0 :             m_xBakMgr = xRet;
     155             :     }
     156             :     else
     157             :     {
     158             :         Reference< deployment::XPackageManager > xAlreadyIn(
     159           0 :             insertion.first->second );
     160           0 :         if (xAlreadyIn.is())
     161             :         {
     162           0 :             guard.clear();
     163           0 :             try_dispose( xRet );
     164           0 :             xRet = xAlreadyIn;
     165             :         }
     166             :         else
     167             :         {
     168           0 :             insertion.first->second = xRet;
     169           0 :         }
     170             :     }
     171         222 :     return xRet;
     172             : }
     173             : 
     174             : } // namespace factory
     175         195 : } // namespace dp_manager
     176             : 
     177             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10