xref: /trunk/main/dbaccess/source/ui/misc/moduledbu.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #ifndef _DBAUI_MODULE_DBU_HXX_
32 #include "moduledbu.hxx"
33 #endif
34 
35 #ifndef _TOOLS_RESMGR_HXX
36 #include <tools/resmgr.hxx>
37 #endif
38 #ifndef _SOLAR_HRC
39 #include <svl/solar.hrc>
40 #endif
41 #ifndef _TOOLS_DEBUG_HXX
42 #include <tools/debug.hxx>
43 #endif
44 
45 #define ENTER_MOD_METHOD()	\
46 	::osl::MutexGuard aGuard(s_aMutex);	\
47 	ensureImpl()
48 
49 //.........................................................................
50 namespace dbaui
51 {
52 //.........................................................................
53 
54 //=========================================================================
55 //= OModuleImpl
56 //=========================================================================
57 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
58 */
59 class OModuleImpl
60 {
61 	ResMgr*	m_pRessources;
62 
63 public:
64 	/// ctor
65 	OModuleImpl();
66 	~OModuleImpl();
67 
68 	/// get the manager for the ressources of the module
69 	ResMgr*	getResManager();
70 };
71 
72 DBG_NAME(OModuleImpl)
73 //-------------------------------------------------------------------------
74 OModuleImpl::OModuleImpl()
75 	:m_pRessources(NULL)
76 {
77     DBG_CTOR(OModuleImpl,NULL);
78 
79 }
80 
81 //-------------------------------------------------------------------------
82 OModuleImpl::~OModuleImpl()
83 {
84 	if (m_pRessources)
85 		delete m_pRessources;
86 
87     DBG_DTOR(OModuleImpl,NULL);
88 }
89 
90 //-------------------------------------------------------------------------
91 ResMgr*	OModuleImpl::getResManager()
92 {
93 	// note that this method is not threadsafe, which counts for the whole class !
94 
95 	if (!m_pRessources)
96 	{
97 		// create a manager with a fixed prefix
98 		ByteString aMgrName = ByteString( "dbu" );
99 		m_pRessources = ResMgr::CreateResMgr(aMgrName.GetBuffer());
100 	}
101 	return m_pRessources;
102 }
103 
104 //=========================================================================
105 //= OModule
106 //=========================================================================
107 ::osl::Mutex	OModule::s_aMutex;
108 sal_Int32		OModule::s_nClients = 0;
109 OModuleImpl*	OModule::s_pImpl = NULL;
110 //-------------------------------------------------------------------------
111 ResMgr*	OModule::getResManager()
112 {
113 	ENTER_MOD_METHOD();
114 	return s_pImpl->getResManager();
115 }
116 
117 //-------------------------------------------------------------------------
118 void OModule::registerClient()
119 {
120 	::osl::MutexGuard aGuard(s_aMutex);
121 	++s_nClients;
122 }
123 
124 //-------------------------------------------------------------------------
125 void OModule::revokeClient()
126 {
127 	::osl::MutexGuard aGuard(s_aMutex);
128 	if (!--s_nClients && s_pImpl)
129 	{
130 		delete s_pImpl;
131 		s_pImpl = NULL;
132 	}
133 }
134 
135 //-------------------------------------------------------------------------
136 void OModule::ensureImpl()
137 {
138 	if (s_pImpl)
139 		return;
140 	s_pImpl = new OModuleImpl();
141 }
142 
143 //.........................................................................
144 }	// namespace dbaui
145 //.........................................................................
146 
147