1c25918c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3c25918c1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c25918c1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c25918c1SAndrew Rist  * distributed with this work for additional information
6c25918c1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c25918c1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c25918c1SAndrew Rist  * "License"); you may not use this file except in compliance
9c25918c1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10c25918c1SAndrew Rist  *
11c25918c1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12c25918c1SAndrew Rist  *
13c25918c1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c25918c1SAndrew Rist  * software distributed under the License is distributed on an
15c25918c1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c25918c1SAndrew Rist  * KIND, either express or implied.  See the License for the
17c25918c1SAndrew Rist  * specific language governing permissions and limitations
18c25918c1SAndrew Rist  * under the License.
19c25918c1SAndrew Rist  *
20c25918c1SAndrew Rist  *************************************************************/
21c25918c1SAndrew Rist 
22c25918c1SAndrew Rist 
23*39ded6f8SDamjan Jovanovic #include "precompiled_formula.hxx"
24cdf0e10cSrcweir #include "ModuleHelper.hxx"
25cdf0e10cSrcweir #include <comphelper/configurationhelper.hxx>
26cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
27cdf0e10cSrcweir #include <osl/thread.h>
28cdf0e10cSrcweir #include <com/sun/star/util/XMacroExpander.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
30cdf0e10cSrcweir #include <com/sun/star/uno/XComponentContext.hpp>
31cdf0e10cSrcweir #include <rtl/uri.hxx>
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir #ifndef _SOLAR_HRC
34cdf0e10cSrcweir #include <svl/solar.hrc>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #define EXPAND_PROTOCOL     "vnd.sun.star.expand:"
38cdf0e10cSrcweir #define ENTER_MOD_METHOD()	\
39cdf0e10cSrcweir 	::osl::MutexGuard aGuard(s_aMutex);	\
40cdf0e10cSrcweir 	ensureImpl()
41cdf0e10cSrcweir 
42cdf0e10cSrcweir //.........................................................................
43cdf0e10cSrcweir namespace formula
44cdf0e10cSrcweir {
45cdf0e10cSrcweir //.........................................................................
46cdf0e10cSrcweir     using namespace ::com::sun::star;
47cdf0e10cSrcweir //=========================================================================
48cdf0e10cSrcweir //= OModuleImpl
49cdf0e10cSrcweir //=========================================================================
50cdf0e10cSrcweir /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
51cdf0e10cSrcweir */
52cdf0e10cSrcweir class OModuleImpl
53cdf0e10cSrcweir {
54cdf0e10cSrcweir 	ResMgr*	m_pRessources;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir public:
57cdf0e10cSrcweir 	/// ctor
58cdf0e10cSrcweir 	OModuleImpl();
59cdf0e10cSrcweir 	~OModuleImpl();
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	/// get the manager for the ressources of the module
62cdf0e10cSrcweir 	ResMgr*	getResManager();
63cdf0e10cSrcweir };
64cdf0e10cSrcweir 
DBG_NAME(rpt_OModuleImpl)65cdf0e10cSrcweir DBG_NAME( rpt_OModuleImpl )
66cdf0e10cSrcweir //-------------------------------------------------------------------------
67cdf0e10cSrcweir OModuleImpl::OModuleImpl()
68cdf0e10cSrcweir 	:m_pRessources(NULL)
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     DBG_CTOR( rpt_OModuleImpl,NULL);
71cdf0e10cSrcweir 
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir //-------------------------------------------------------------------------
~OModuleImpl()75cdf0e10cSrcweir OModuleImpl::~OModuleImpl()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	if (m_pRessources)
78cdf0e10cSrcweir 		delete m_pRessources;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     DBG_DTOR( rpt_OModuleImpl,NULL);
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir //-------------------------------------------------------------------------
getResManager()84cdf0e10cSrcweir ResMgr*	OModuleImpl::getResManager()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	// note that this method is not threadsafe, which counts for the whole class !
87cdf0e10cSrcweir 
88cdf0e10cSrcweir 	if (!m_pRessources)
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir 		// create a manager with a fixed prefix
9124c56ab9SHerbert Dürr 		m_pRessources = ResMgr::CreateResMgr( "forui");
92cdf0e10cSrcweir 	}
93cdf0e10cSrcweir 	return m_pRessources;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir //=========================================================================
97cdf0e10cSrcweir //= OModule
98cdf0e10cSrcweir //=========================================================================
99cdf0e10cSrcweir ::osl::Mutex	OModule::s_aMutex;
100cdf0e10cSrcweir sal_Int32		OModule::s_nClients = 0;
101cdf0e10cSrcweir OModuleImpl*	OModule::s_pImpl = NULL;
102cdf0e10cSrcweir //-------------------------------------------------------------------------
getResManager()103cdf0e10cSrcweir ResMgr*	OModule::getResManager()
104cdf0e10cSrcweir {
105cdf0e10cSrcweir 	ENTER_MOD_METHOD();
106cdf0e10cSrcweir 	return s_pImpl->getResManager();
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir //-------------------------------------------------------------------------
registerClient()110cdf0e10cSrcweir void OModule::registerClient()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir 	::osl::MutexGuard aGuard(s_aMutex);
113cdf0e10cSrcweir 	++s_nClients;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir //-------------------------------------------------------------------------
revokeClient()117cdf0e10cSrcweir void OModule::revokeClient()
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	::osl::MutexGuard aGuard(s_aMutex);
120cdf0e10cSrcweir 	if (!--s_nClients && s_pImpl)
121cdf0e10cSrcweir 	{
122cdf0e10cSrcweir 		delete s_pImpl;
123cdf0e10cSrcweir 		s_pImpl = NULL;
124cdf0e10cSrcweir 	}
125cdf0e10cSrcweir }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir //-------------------------------------------------------------------------
ensureImpl()128cdf0e10cSrcweir void OModule::ensureImpl()
129cdf0e10cSrcweir {
130cdf0e10cSrcweir 	if (s_pImpl)
131cdf0e10cSrcweir 		return;
132cdf0e10cSrcweir 	s_pImpl = new OModuleImpl();
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir //.........................................................................
136cdf0e10cSrcweir }	// namespace formula
137cdf0e10cSrcweir //.........................................................................
138cdf0e10cSrcweir 
139