Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / dbaccess / source / ui / misc / moduledbu.cxx
blob18c28882c9e37cf20c10b0ca1d7757b0ce389c29
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include "moduledbu.hxx"
32 #include <tools/resmgr.hxx>
33 #include <svl/solar.hrc>
34 #include <tools/debug.hxx>
36 #define ENTER_MOD_METHOD() \
37 ::osl::MutexGuard aGuard(s_aMutex); \
38 ensureImpl()
40 //.........................................................................
41 namespace dbaui
43 //.........................................................................
45 //=========================================================================
46 //= OModuleImpl
47 //=========================================================================
48 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
50 class OModuleImpl
52 ResMgr* m_pRessources;
54 public:
55 /// ctor
56 OModuleImpl();
57 ~OModuleImpl();
59 /// get the manager for the ressources of the module
60 ResMgr* getResManager();
63 DBG_NAME(OModuleImpl)
64 //-------------------------------------------------------------------------
65 OModuleImpl::OModuleImpl()
66 :m_pRessources(NULL)
68 DBG_CTOR(OModuleImpl,NULL);
72 //-------------------------------------------------------------------------
73 OModuleImpl::~OModuleImpl()
75 if (m_pRessources)
76 delete m_pRessources;
78 DBG_DTOR(OModuleImpl,NULL);
81 //-------------------------------------------------------------------------
82 ResMgr* OModuleImpl::getResManager()
84 // note that this method is not threadsafe, which counts for the whole class !
86 if (!m_pRessources)
88 // create a manager with a fixed prefix
89 m_pRessources = ResMgr::CreateResMgr(rtl::OString("dbu").getStr());
91 return m_pRessources;
94 //=========================================================================
95 //= OModule
96 //=========================================================================
97 ::osl::Mutex OModule::s_aMutex;
98 sal_Int32 OModule::s_nClients = 0;
99 OModuleImpl* OModule::s_pImpl = NULL;
100 //-------------------------------------------------------------------------
101 ResMgr* OModule::getResManager()
103 ENTER_MOD_METHOD();
104 return s_pImpl->getResManager();
107 //-------------------------------------------------------------------------
108 void OModule::registerClient()
110 ::osl::MutexGuard aGuard(s_aMutex);
111 ++s_nClients;
114 //-------------------------------------------------------------------------
115 void OModule::revokeClient()
117 ::osl::MutexGuard aGuard(s_aMutex);
118 if (!--s_nClients && s_pImpl)
120 delete s_pImpl;
121 s_pImpl = NULL;
125 //-------------------------------------------------------------------------
126 void OModule::ensureImpl()
128 if (s_pImpl)
129 return;
130 s_pImpl = new OModuleImpl();
133 //.........................................................................
134 } // namespace dbaui
135 //.........................................................................
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */