LCOV - code coverage report
Current view: top level - desktop/source/deployment/manager - dp_managerfac.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 60 0.0 %
Date: 2014-04-14 Functions: 0 8 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 "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() SAL_OVERRIDE;
      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, std::exception) SAL_OVERRIDE;
      66             : };
      67             : 
      68             : 
      69             : namespace sdecl = comphelper::service_decl;
      70           0 : sdecl::class_<PackageManagerFactoryImpl> servicePMFI;
      71           0 : 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           0 : PackageManagerFactoryImpl::PackageManagerFactoryImpl(
      79             :     Reference<XComponentContext> const & xComponentContext )
      80           0 :     : t_pmfac_helper( getMutex() ),
      81           0 :       m_xComponentContext( xComponentContext )
      82             : {
      83           0 : }
      84             : 
      85             : 
      86           0 : PackageManagerFactoryImpl::~PackageManagerFactoryImpl()
      87             : {
      88           0 : }
      89             : 
      90             : 
      91           0 : inline void PackageManagerFactoryImpl::check()
      92             : {
      93           0 :     ::osl::MutexGuard guard( getMutex() );
      94           0 :     if (rBHelper.bInDispose || rBHelper.bDisposed)
      95             :     {
      96             :         throw lang::DisposedException(
      97             :             "PackageManagerFactory instance has already been disposed!",
      98           0 :             static_cast<OWeakObject *>(this) );
      99           0 :     }
     100           0 : }
     101             : 
     102             : 
     103           0 : void PackageManagerFactoryImpl::disposing()
     104             : {
     105             :     // dispose all managers:
     106           0 :     ::osl::MutexGuard guard( getMutex() );
     107           0 :     t_string2weakref::const_iterator iPos( m_managers.begin() );
     108           0 :     t_string2weakref::const_iterator const iEnd( m_managers.end() );
     109           0 :     for ( ; iPos != iEnd; ++iPos )
     110           0 :         try_dispose( iPos->second );
     111           0 :     m_managers = t_string2weakref();
     112             :     // the below are already disposed:
     113           0 :     m_xUserMgr.clear();
     114           0 :     m_xSharedMgr.clear();
     115           0 :     m_xBundledMgr.clear();
     116           0 :     m_xTmpMgr.clear();
     117           0 :     m_xBakMgr.clear();
     118           0 : }
     119             : 
     120             : // XPackageManagerFactory
     121             : 
     122             : Reference<deployment::XPackageManager>
     123           0 : PackageManagerFactoryImpl::getPackageManager( OUString const & context )
     124             :     throw (RuntimeException, std::exception)
     125             : {
     126           0 :     Reference< deployment::XPackageManager > xRet;
     127           0 :     ::osl::ResettableMutexGuard guard( getMutex() );
     128           0 :     check();
     129           0 :     t_string2weakref::const_iterator const iFind( m_managers.find( context ) );
     130           0 :     if (iFind != m_managers.end()) {
     131           0 :         xRet = iFind->second;
     132           0 :         if (xRet.is())
     133           0 :             return xRet;
     134             :     }
     135             : 
     136           0 :     guard.clear();
     137           0 :     xRet.set( PackageManagerImpl::create( m_xComponentContext, context ) );
     138           0 :     guard.reset();
     139             :     ::std::pair< t_string2weakref::iterator, bool > insertion(
     140           0 :         m_managers.insert( t_string2weakref::value_type( context, xRet ) ) );
     141           0 :     if (insertion.second)
     142             :     {
     143             :         OSL_ASSERT( insertion.first->second.get() == xRet );
     144             :         // hold user, shared mgrs for whole process: live deployment
     145           0 :         if ( context == "user" )
     146           0 :             m_xUserMgr = xRet;
     147           0 :         else if ( context == "shared" )
     148           0 :             m_xSharedMgr = xRet;
     149           0 :         else if ( context == "bundled" )
     150           0 :             m_xBundledMgr = xRet;
     151           0 :         else if ( context == "tmp" )
     152           0 :             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           0 :     return xRet;
     172             : }
     173             : 
     174             : } // namespace factory
     175           0 : } // namespace dp_manager
     176             : 
     177             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10