update dev300-m58
[ooovba.git] / dbaccess / source / ui / misc / moduledbu.cxx
blob3f5e5197612443aec3196c09df7fd2b06cb6be4e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: moduledbu.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef _DBAUI_MODULE_DBU_HXX_
35 #include "moduledbu.hxx"
36 #endif
38 #ifndef _TOOLS_RESMGR_HXX
39 #include <tools/resmgr.hxx>
40 #endif
41 #ifndef _SOLAR_HRC
42 #include <svtools/solar.hrc>
43 #endif
44 #ifndef _TOOLS_DEBUG_HXX
45 #include <tools/debug.hxx>
46 #endif
48 #define ENTER_MOD_METHOD() \
49 ::osl::MutexGuard aGuard(s_aMutex); \
50 ensureImpl()
52 //.........................................................................
53 namespace dbaui
55 //.........................................................................
57 //=========================================================================
58 //= OModuleImpl
59 //=========================================================================
60 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
62 class OModuleImpl
64 ResMgr* m_pRessources;
66 public:
67 /// ctor
68 OModuleImpl();
69 ~OModuleImpl();
71 /// get the manager for the ressources of the module
72 ResMgr* getResManager();
75 DBG_NAME(OModuleImpl)
76 //-------------------------------------------------------------------------
77 OModuleImpl::OModuleImpl()
78 :m_pRessources(NULL)
80 DBG_CTOR(OModuleImpl,NULL);
84 //-------------------------------------------------------------------------
85 OModuleImpl::~OModuleImpl()
87 if (m_pRessources)
88 delete m_pRessources;
90 DBG_DTOR(OModuleImpl,NULL);
93 //-------------------------------------------------------------------------
94 ResMgr* OModuleImpl::getResManager()
96 // note that this method is not threadsafe, which counts for the whole class !
98 if (!m_pRessources)
100 // create a manager with a fixed prefix
101 ByteString aMgrName = ByteString( "dbu" );
102 m_pRessources = ResMgr::CreateResMgr(aMgrName.GetBuffer());
104 return m_pRessources;
107 //=========================================================================
108 //= OModule
109 //=========================================================================
110 ::osl::Mutex OModule::s_aMutex;
111 sal_Int32 OModule::s_nClients = 0;
112 OModuleImpl* OModule::s_pImpl = NULL;
113 //-------------------------------------------------------------------------
114 ResMgr* OModule::getResManager()
116 ENTER_MOD_METHOD();
117 return s_pImpl->getResManager();
120 //-------------------------------------------------------------------------
121 void OModule::registerClient()
123 ::osl::MutexGuard aGuard(s_aMutex);
124 ++s_nClients;
127 //-------------------------------------------------------------------------
128 void OModule::revokeClient()
130 ::osl::MutexGuard aGuard(s_aMutex);
131 if (!--s_nClients && s_pImpl)
133 delete s_pImpl;
134 s_pImpl = NULL;
138 //-------------------------------------------------------------------------
139 void OModule::ensureImpl()
141 if (s_pImpl)
142 return;
143 s_pImpl = new OModuleImpl();
146 //.........................................................................
147 } // namespace dbaui
148 //.........................................................................