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 "ModuleHelper.hxx"
24 #include <comphelper/configurationhelper.hxx>
25 #include <comphelper/processfactory.hxx>
26 #include <osl/thread.h>
27 #include <com/sun/star/util/XMacroExpander.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <rtl/uri.hxx>
31 #include <tools/debug.hxx>
32 #ifndef _SOLAR_HRC
33 #include <svl/solar.hrc>
34 #endif
35 
36 #define EXPAND_PROTOCOL     "vnd.sun.star.expand:"
37 #define ENTER_MOD_METHOD()	\
38 	::osl::MutexGuard aGuard(s_aMutex);	\
39 	ensureImpl()
40 
41 //.........................................................................
42 namespace formula
43 {
44 //.........................................................................
45     using namespace ::com::sun::star;
46 //=========================================================================
47 //= OModuleImpl
48 //=========================================================================
49 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
50 */
51 class OModuleImpl
52 {
53 	ResMgr*	m_pRessources;
54 
55 public:
56 	/// ctor
57 	OModuleImpl();
58 	~OModuleImpl();
59 
60 	/// get the manager for the ressources of the module
61 	ResMgr*	getResManager();
62 };
63 
64 DBG_NAME( rpt_OModuleImpl )
65 //-------------------------------------------------------------------------
66 OModuleImpl::OModuleImpl()
67 	:m_pRessources(NULL)
68 {
69     DBG_CTOR( rpt_OModuleImpl,NULL);
70 
71 }
72 
73 //-------------------------------------------------------------------------
74 OModuleImpl::~OModuleImpl()
75 {
76 	if (m_pRessources)
77 		delete m_pRessources;
78 
79     DBG_DTOR( rpt_OModuleImpl,NULL);
80 }
81 
82 //-------------------------------------------------------------------------
83 ResMgr*	OModuleImpl::getResManager()
84 {
85 	// note that this method is not threadsafe, which counts for the whole class !
86 
87 	if (!m_pRessources)
88 	{
89 		// create a manager with a fixed prefix
90         rtl::OString sName = rtl::OString( "forui" );
91 		m_pRessources = ResMgr::CreateResMgr(sName);
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 //-------------------------------------------------------------------------
103 ResMgr*	OModule::getResManager()
104 {
105 	ENTER_MOD_METHOD();
106 	return s_pImpl->getResManager();
107 }
108 
109 //-------------------------------------------------------------------------
110 void OModule::registerClient()
111 {
112 	::osl::MutexGuard aGuard(s_aMutex);
113 	++s_nClients;
114 }
115 
116 //-------------------------------------------------------------------------
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 //-------------------------------------------------------------------------
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