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