Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "dp_manager.h"
31 : : #include "dp_resource.h"
32 : : #include "cppuhelper/compbase1.hxx"
33 : : #include "comphelper/servicedecl.hxx"
34 : : #include "com/sun/star/deployment/thePackageManagerFactory.hpp"
35 : : #include <boost/unordered_map.hpp>
36 : :
37 : :
38 : : using namespace ::dp_misc;
39 : : using namespace ::com::sun::star;
40 : : using namespace ::com::sun::star::uno;
41 : : using ::rtl::OUString;
42 : :
43 : : namespace dp_manager {
44 : : namespace factory {
45 : :
46 : : typedef ::cppu::WeakComponentImplHelper1<
47 : : deployment::XPackageManagerFactory > t_pmfac_helper;
48 : :
49 : : //==============================================================================
50 : : class PackageManagerFactoryImpl : private MutexHolder, public t_pmfac_helper
51 : : {
52 : : Reference<XComponentContext> m_xComponentContext;
53 : :
54 : : Reference<deployment::XPackageManager> m_xUserMgr;
55 : : Reference<deployment::XPackageManager> m_xSharedMgr;
56 : : Reference<deployment::XPackageManager> m_xBundledMgr;
57 : : typedef ::boost::unordered_map<
58 : : OUString, WeakReference<deployment::XPackageManager>,
59 : : ::rtl::OUStringHash > t_string2weakref;
60 : : t_string2weakref m_managers;
61 : :
62 : : protected:
63 : : inline void check();
64 : : virtual void SAL_CALL disposing();
65 : :
66 : : public:
67 : : virtual ~PackageManagerFactoryImpl();
68 : : PackageManagerFactoryImpl(
69 : : Reference<XComponentContext> const & xComponentContext );
70 : :
71 : : // XPackageManagerFactory
72 : : virtual Reference<deployment::XPackageManager> SAL_CALL getPackageManager(
73 : : OUString const & context ) throw (RuntimeException);
74 : : };
75 : :
76 : : //==============================================================================
77 : : namespace sdecl = comphelper::service_decl;
78 : 124 : sdecl::class_<PackageManagerFactoryImpl> servicePMFI;
79 : 124 : extern sdecl::ServiceDecl const serviceDecl(
80 : : servicePMFI,
81 : : // a private one:
82 : : "com.sun.star.comp.deployment.PackageManagerFactory",
83 : : "com.sun.star.comp.deployment.PackageManagerFactory" );
84 : :
85 : : //______________________________________________________________________________
86 : 124 : PackageManagerFactoryImpl::PackageManagerFactoryImpl(
87 : : Reference<XComponentContext> const & xComponentContext )
88 : 124 : : t_pmfac_helper( getMutex() ),
89 [ + - ]: 248 : m_xComponentContext( xComponentContext )
90 : : {
91 : 124 : }
92 : :
93 : : //______________________________________________________________________________
94 [ + - ][ + - ]: 124 : PackageManagerFactoryImpl::~PackageManagerFactoryImpl()
95 : : {
96 [ - + ]: 124 : }
97 : :
98 : : //______________________________________________________________________________
99 : 1228 : inline void PackageManagerFactoryImpl::check()
100 : : {
101 [ + - ]: 1228 : ::osl::MutexGuard guard( getMutex() );
102 [ + - ][ - + ]: 1228 : if (rBHelper.bInDispose || rBHelper.bDisposed)
103 : : {
104 : : throw lang::DisposedException(
105 : : OUSTR("PackageManagerFactory instance has already been disposed!"),
106 [ # # ][ # # ]: 0 : static_cast<OWeakObject *>(this) );
[ # # ]
107 [ + - ]: 1228 : }
108 : 1228 : }
109 : :
110 : : //______________________________________________________________________________
111 : 124 : void PackageManagerFactoryImpl::disposing()
112 : : {
113 : : // dispose all managers:
114 [ + - ]: 124 : ::osl::MutexGuard guard( getMutex() );
115 [ + - ]: 124 : t_string2weakref::const_iterator iPos( m_managers.begin() );
116 [ + - ]: 124 : t_string2weakref::const_iterator const iEnd( m_managers.end() );
117 [ + + ]: 498 : for ( ; iPos != iEnd; ++iPos )
118 [ + - ][ + - ]: 374 : try_dispose( iPos->second );
[ + - ]
119 [ + - ][ + - ]: 124 : m_managers = t_string2weakref();
[ + - ]
120 : : // the below are already disposed:
121 : 124 : m_xUserMgr.clear();
122 : 124 : m_xSharedMgr.clear();
123 [ + - ]: 124 : m_xBundledMgr.clear();
124 : 124 : }
125 : :
126 : : // XPackageManagerFactory
127 : : //______________________________________________________________________________
128 : : Reference<deployment::XPackageManager>
129 : 1228 : PackageManagerFactoryImpl::getPackageManager( OUString const & context )
130 : : throw (RuntimeException)
131 : : {
132 : 1228 : Reference< deployment::XPackageManager > xRet;
133 [ + - ]: 1228 : ::osl::ResettableMutexGuard guard( getMutex() );
134 [ + - ]: 1228 : check();
135 [ + - ]: 1228 : t_string2weakref::const_iterator const iFind( m_managers.find( context ) );
136 [ + + ][ + - ]: 1228 : if (iFind != m_managers.end()) {
137 [ + - ][ + - ]: 854 : xRet = iFind->second;
[ + - ]
138 [ + + ]: 854 : if (xRet.is())
139 : : return xRet;
140 : : }
141 : :
142 [ + - ]: 380 : guard.clear();
143 [ + - ][ + - ]: 380 : xRet.set( PackageManagerImpl::create( m_xComponentContext, context ) );
144 [ + - ]: 380 : guard.reset();
145 : : ::std::pair< t_string2weakref::iterator, bool > insertion(
146 [ + - ][ + - ]: 380 : m_managers.insert( t_string2weakref::value_type( context, xRet ) ) );
[ + - ]
147 [ + + ]: 380 : if (insertion.second)
148 : : {
149 : : OSL_ASSERT( insertion.first->second.get() == xRet );
150 : : // hold user, shared mgrs for whole process: live deployment
151 [ + + ]: 374 : if ( context == "user" )
152 [ + - ]: 124 : m_xUserMgr = xRet;
153 [ + + ]: 250 : else if ( context == "shared" )
154 [ + - ]: 124 : m_xSharedMgr = xRet;
155 [ + + ]: 126 : else if ( context == "bundled" )
156 [ + - ]: 124 : m_xBundledMgr = xRet;
157 : : }
158 : : else
159 : : {
160 : : Reference< deployment::XPackageManager > xAlreadyIn(
161 [ + - ][ + - ]: 6 : insertion.first->second );
162 [ - + ]: 6 : if (xAlreadyIn.is())
163 : : {
164 [ # # ]: 0 : guard.clear();
165 [ # # ]: 0 : try_dispose( xRet );
166 [ # # ]: 0 : xRet = xAlreadyIn;
167 : : }
168 : : else
169 : : {
170 [ + - ][ + - ]: 6 : insertion.first->second = xRet;
171 : 6 : }
172 : : }
173 [ + - ]: 1228 : return xRet;
174 : : }
175 : :
176 : : } // namespace factory
177 [ + - ][ + - ]: 372 : } // namespace dp_manager
178 : :
179 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|