bump product version to 4.1.6.2
[LibreOffice.git] / desktop / source / deployment / manager / dp_managerfac.cxx
blobe2d1259fd3cc77a491c3357f259d68c37870beef
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
29 using namespace ::dp_misc;
30 using namespace ::com::sun::star;
31 using namespace ::com::sun::star::uno;
33 namespace dp_manager {
34 namespace factory {
36 typedef ::cppu::WeakComponentImplHelper1<
37 deployment::XPackageManagerFactory > t_pmfac_helper;
39 //==============================================================================
40 class PackageManagerFactoryImpl : private MutexHolder, public t_pmfac_helper
42 Reference<XComponentContext> m_xComponentContext;
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;
54 protected:
55 inline void check();
56 virtual void SAL_CALL disposing();
58 public:
59 virtual ~PackageManagerFactoryImpl();
60 PackageManagerFactoryImpl(
61 Reference<XComponentContext> const & xComponentContext );
63 // XPackageManagerFactory
64 virtual Reference<deployment::XPackageManager> SAL_CALL getPackageManager(
65 OUString const & context ) throw (RuntimeException);
68 //==============================================================================
69 namespace sdecl = comphelper::service_decl;
70 sdecl::class_<PackageManagerFactoryImpl> servicePMFI;
71 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" );
77 //______________________________________________________________________________
78 PackageManagerFactoryImpl::PackageManagerFactoryImpl(
79 Reference<XComponentContext> const & xComponentContext )
80 : t_pmfac_helper( getMutex() ),
81 m_xComponentContext( xComponentContext )
85 //______________________________________________________________________________
86 PackageManagerFactoryImpl::~PackageManagerFactoryImpl()
90 //______________________________________________________________________________
91 inline void PackageManagerFactoryImpl::check()
93 ::osl::MutexGuard guard( getMutex() );
94 if (rBHelper.bInDispose || rBHelper.bDisposed)
96 throw lang::DisposedException(
97 "PackageManagerFactory instance has already been disposed!",
98 static_cast<OWeakObject *>(this) );
102 //______________________________________________________________________________
103 void PackageManagerFactoryImpl::disposing()
105 // dispose all managers:
106 ::osl::MutexGuard guard( getMutex() );
107 t_string2weakref::const_iterator iPos( m_managers.begin() );
108 t_string2weakref::const_iterator const iEnd( m_managers.end() );
109 for ( ; iPos != iEnd; ++iPos )
110 try_dispose( iPos->second );
111 m_managers = t_string2weakref();
112 // the below are already disposed:
113 m_xUserMgr.clear();
114 m_xSharedMgr.clear();
115 m_xBundledMgr.clear();
116 m_xTmpMgr.clear();
117 m_xBakMgr.clear();
120 // XPackageManagerFactory
121 //______________________________________________________________________________
122 Reference<deployment::XPackageManager>
123 PackageManagerFactoryImpl::getPackageManager( OUString const & context )
124 throw (RuntimeException)
126 Reference< deployment::XPackageManager > xRet;
127 ::osl::ResettableMutexGuard guard( getMutex() );
128 check();
129 t_string2weakref::const_iterator const iFind( m_managers.find( context ) );
130 if (iFind != m_managers.end()) {
131 xRet = iFind->second;
132 if (xRet.is())
133 return xRet;
136 guard.clear();
137 xRet.set( PackageManagerImpl::create( m_xComponentContext, context ) );
138 guard.reset();
139 ::std::pair< t_string2weakref::iterator, bool > insertion(
140 m_managers.insert( t_string2weakref::value_type( context, xRet ) ) );
141 if (insertion.second)
143 OSL_ASSERT( insertion.first->second.get() == xRet );
144 // hold user, shared mgrs for whole process: live deployment
145 if ( context == "user" )
146 m_xUserMgr = xRet;
147 else if ( context == "shared" )
148 m_xSharedMgr = xRet;
149 else if ( context == "bundled" )
150 m_xBundledMgr = xRet;
151 else if ( context == "tmp" )
152 m_xTmpMgr = xRet;
153 else if ( context == "bak" )
154 m_xBakMgr = xRet;
156 else
158 Reference< deployment::XPackageManager > xAlreadyIn(
159 insertion.first->second );
160 if (xAlreadyIn.is())
162 guard.clear();
163 try_dispose( xRet );
164 xRet = xAlreadyIn;
166 else
168 insertion.first->second = xRet;
171 return xRet;
174 } // namespace factory
175 } // namespace dp_manager
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */