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 : : #include "ModuleHelper.hxx"
29 : : #include <comphelper/configurationhelper.hxx>
30 : : #include <comphelper/processfactory.hxx>
31 : : #include <osl/thread.h>
32 : : #include <com/sun/star/util/XMacroExpander.hpp>
33 : : #include <com/sun/star/beans/XPropertySet.hpp>
34 : : #include <com/sun/star/uno/XComponentContext.hpp>
35 : : #include <rtl/instance.hxx>
36 : : #include <rtl/uri.hxx>
37 : : #include <tools/debug.hxx>
38 : : #include <svl/solar.hrc>
39 : :
40 : : #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
41 : : #define ENTER_MOD_METHOD() \
42 : : ::osl::MutexGuard aGuard(theOModuleMutex::get()); \
43 : : ensureImpl()
44 : :
45 : : //.........................................................................
46 : : namespace rptui
47 : : {
48 : : //.........................................................................
49 : : using namespace ::com::sun::star;
50 : : //=========================================================================
51 : : //= OModuleImpl
52 : : //=========================================================================
53 : : /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
54 : : */
55 : : class OModuleImpl
56 : : {
57 : : ResMgr* m_pResources;
58 : :
59 : : public:
60 : : /// ctor
61 : : OModuleImpl();
62 : : ~OModuleImpl();
63 : :
64 : : /// get the manager for the resources of the module
65 : : ResMgr* getResManager();
66 : : };
67 : :
68 : : DBG_NAME( rpt_OModuleImpl )
69 : : //-------------------------------------------------------------------------
70 : 0 : OModuleImpl::OModuleImpl()
71 : 0 : :m_pResources(NULL)
72 : : {
73 : : DBG_CTOR( rpt_OModuleImpl,NULL);
74 : :
75 : 0 : }
76 : :
77 : : //-------------------------------------------------------------------------
78 : 0 : OModuleImpl::~OModuleImpl()
79 : : {
80 [ # # ]: 0 : if (m_pResources)
81 [ # # ]: 0 : delete m_pResources;
82 : :
83 : : DBG_DTOR( rpt_OModuleImpl,NULL);
84 : 0 : }
85 : :
86 : : //-------------------------------------------------------------------------
87 : 0 : ResMgr* OModuleImpl::getResManager()
88 : : {
89 : : // note that this method is not threadsafe, which counts for the whole class !
90 : :
91 [ # # ]: 0 : if (!m_pResources)
92 : : {
93 : : // create a manager with a fixed prefix
94 [ # # ]: 0 : m_pResources = ResMgr::CreateResMgr("rptui");
95 : : }
96 : 0 : return m_pResources;
97 : : }
98 : :
99 : : //=========================================================================
100 : : //= OModule
101 : : //=========================================================================
102 : :
103 : : namespace
104 : : {
105 : : // access safety
106 : : struct theOModuleMutex : public rtl::Static< osl::Mutex, theOModuleMutex > {};
107 : : }
108 : :
109 : : sal_Int32 OModule::s_nClients = 0;
110 : : OModuleImpl* OModule::s_pImpl = NULL;
111 : : //-------------------------------------------------------------------------
112 : 0 : ResMgr* OModule::getResManager()
113 : : {
114 [ # # ][ # # ]: 0 : ENTER_MOD_METHOD();
[ # # ]
115 [ # # ][ # # ]: 0 : return s_pImpl->getResManager();
116 : : }
117 : :
118 : : //-------------------------------------------------------------------------
119 : 0 : void OModule::registerClient()
120 : : {
121 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard(theOModuleMutex::get());
122 [ # # ]: 0 : ++s_nClients;
123 : 0 : }
124 : :
125 : : //-------------------------------------------------------------------------
126 : 0 : void OModule::revokeClient()
127 : : {
128 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard(theOModuleMutex::get());
129 [ # # ][ # # ]: 0 : if (!--s_nClients && s_pImpl)
[ # # ]
130 : : {
131 [ # # ][ # # ]: 0 : delete s_pImpl;
132 : 0 : s_pImpl = NULL;
133 [ # # ]: 0 : }
134 : 0 : }
135 : :
136 : : //-------------------------------------------------------------------------
137 : 0 : void OModule::ensureImpl()
138 : : {
139 [ # # ]: 0 : if (s_pImpl)
140 : 0 : return;
141 : 0 : s_pImpl = new OModuleImpl();
142 : : }
143 : :
144 : : //.........................................................................
145 : : } // namespace dbaui
146 : : //.........................................................................
147 : :
148 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|