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_reportdesign.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 rptui
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         rtl::OString sName = rtl::OString( "rptui" );
92 		m_pRessources = ResMgr::CreateResMgr( sName.getStr());
93 	}
94 	return m_pRessources;
95 }
96 
97 //=========================================================================
98 //= OModule
99 //=========================================================================
100 ::osl::Mutex	OModule::s_aMutex;
101 sal_Int32		OModule::s_nClients = 0;
102 OModuleImpl*	OModule::s_pImpl = NULL;
103 //-------------------------------------------------------------------------
getResManager()104 ResMgr*	OModule::getResManager()
105 {
106 	ENTER_MOD_METHOD();
107 	return s_pImpl->getResManager();
108 }
109 
110 //-------------------------------------------------------------------------
registerClient()111 void OModule::registerClient()
112 {
113 	::osl::MutexGuard aGuard(s_aMutex);
114 	++s_nClients;
115 }
116 
117 //-------------------------------------------------------------------------
revokeClient()118 void OModule::revokeClient()
119 {
120 	::osl::MutexGuard aGuard(s_aMutex);
121 	if (!--s_nClients && s_pImpl)
122 	{
123 		delete s_pImpl;
124 		s_pImpl = NULL;
125 	}
126 }
127 
128 //-------------------------------------------------------------------------
ensureImpl()129 void OModule::ensureImpl()
130 {
131 	if (s_pImpl)
132 		return;
133 	s_pImpl = new OModuleImpl();
134 }
135 
136 //.........................................................................
137 }	// namespace dbaui
138 //.........................................................................
139