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

Generated by: LCOV version 1.10