1*96de5490SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*96de5490SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*96de5490SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*96de5490SAndrew Rist * distributed with this work for additional information 6*96de5490SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*96de5490SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*96de5490SAndrew Rist * "License"); you may not use this file except in compliance 9*96de5490SAndrew Rist * with the License. You may obtain a copy of the License at 10*96de5490SAndrew Rist * 11*96de5490SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*96de5490SAndrew Rist * 13*96de5490SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*96de5490SAndrew Rist * software distributed under the License is distributed on an 15*96de5490SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*96de5490SAndrew Rist * KIND, either express or implied. See the License for the 17*96de5490SAndrew Rist * specific language governing permissions and limitations 18*96de5490SAndrew Rist * under the License. 19*96de5490SAndrew Rist * 20*96de5490SAndrew Rist *************************************************************/ 21*96de5490SAndrew Rist 22*96de5490SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_ 28cdf0e10cSrcweir #include "moduledbu.hxx" 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir 31cdf0e10cSrcweir #ifndef _TOOLS_RESMGR_HXX 32cdf0e10cSrcweir #include <tools/resmgr.hxx> 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #ifndef _SOLAR_HRC 35cdf0e10cSrcweir #include <svl/solar.hrc> 36cdf0e10cSrcweir #endif 37cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX 38cdf0e10cSrcweir #include <tools/debug.hxx> 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir 41cdf0e10cSrcweir #define ENTER_MOD_METHOD() \ 42cdf0e10cSrcweir ::osl::MutexGuard aGuard(s_aMutex); \ 43cdf0e10cSrcweir ensureImpl() 44cdf0e10cSrcweir 45cdf0e10cSrcweir //......................................................................... 46cdf0e10cSrcweir namespace dbaui 47cdf0e10cSrcweir { 48cdf0e10cSrcweir //......................................................................... 49cdf0e10cSrcweir 50cdf0e10cSrcweir //========================================================================= 51cdf0e10cSrcweir //= OModuleImpl 52cdf0e10cSrcweir //========================================================================= 53cdf0e10cSrcweir /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner 54cdf0e10cSrcweir */ 55cdf0e10cSrcweir class OModuleImpl 56cdf0e10cSrcweir { 57cdf0e10cSrcweir ResMgr* m_pRessources; 58cdf0e10cSrcweir 59cdf0e10cSrcweir public: 60cdf0e10cSrcweir /// ctor 61cdf0e10cSrcweir OModuleImpl(); 62cdf0e10cSrcweir ~OModuleImpl(); 63cdf0e10cSrcweir 64cdf0e10cSrcweir /// get the manager for the ressources of the module 65cdf0e10cSrcweir ResMgr* getResManager(); 66cdf0e10cSrcweir }; 67cdf0e10cSrcweir DBG_NAME(OModuleImpl)68cdf0e10cSrcweirDBG_NAME(OModuleImpl) 69cdf0e10cSrcweir //------------------------------------------------------------------------- 70cdf0e10cSrcweir OModuleImpl::OModuleImpl() 71cdf0e10cSrcweir :m_pRessources(NULL) 72cdf0e10cSrcweir { 73cdf0e10cSrcweir DBG_CTOR(OModuleImpl,NULL); 74cdf0e10cSrcweir 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir //------------------------------------------------------------------------- ~OModuleImpl()78cdf0e10cSrcweirOModuleImpl::~OModuleImpl() 79cdf0e10cSrcweir { 80cdf0e10cSrcweir if (m_pRessources) 81cdf0e10cSrcweir delete m_pRessources; 82cdf0e10cSrcweir 83cdf0e10cSrcweir DBG_DTOR(OModuleImpl,NULL); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir //------------------------------------------------------------------------- getResManager()87cdf0e10cSrcweirResMgr* OModuleImpl::getResManager() 88cdf0e10cSrcweir { 89cdf0e10cSrcweir // note that this method is not threadsafe, which counts for the whole class ! 90cdf0e10cSrcweir 91cdf0e10cSrcweir if (!m_pRessources) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir // create a manager with a fixed prefix 94cdf0e10cSrcweir ByteString aMgrName = ByteString( "dbu" ); 95cdf0e10cSrcweir m_pRessources = ResMgr::CreateResMgr(aMgrName.GetBuffer()); 96cdf0e10cSrcweir } 97cdf0e10cSrcweir return m_pRessources; 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir //========================================================================= 101cdf0e10cSrcweir //= OModule 102cdf0e10cSrcweir //========================================================================= 103cdf0e10cSrcweir ::osl::Mutex OModule::s_aMutex; 104cdf0e10cSrcweir sal_Int32 OModule::s_nClients = 0; 105cdf0e10cSrcweir OModuleImpl* OModule::s_pImpl = NULL; 106cdf0e10cSrcweir //------------------------------------------------------------------------- getResManager()107cdf0e10cSrcweirResMgr* OModule::getResManager() 108cdf0e10cSrcweir { 109cdf0e10cSrcweir ENTER_MOD_METHOD(); 110cdf0e10cSrcweir return s_pImpl->getResManager(); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir 113cdf0e10cSrcweir //------------------------------------------------------------------------- registerClient()114cdf0e10cSrcweirvoid OModule::registerClient() 115cdf0e10cSrcweir { 116cdf0e10cSrcweir ::osl::MutexGuard aGuard(s_aMutex); 117cdf0e10cSrcweir ++s_nClients; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir //------------------------------------------------------------------------- revokeClient()121cdf0e10cSrcweirvoid OModule::revokeClient() 122cdf0e10cSrcweir { 123cdf0e10cSrcweir ::osl::MutexGuard aGuard(s_aMutex); 124cdf0e10cSrcweir if (!--s_nClients && s_pImpl) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir delete s_pImpl; 127cdf0e10cSrcweir s_pImpl = NULL; 128cdf0e10cSrcweir } 129cdf0e10cSrcweir } 130cdf0e10cSrcweir 131cdf0e10cSrcweir //------------------------------------------------------------------------- ensureImpl()132cdf0e10cSrcweirvoid OModule::ensureImpl() 133cdf0e10cSrcweir { 134cdf0e10cSrcweir if (s_pImpl) 135cdf0e10cSrcweir return; 136cdf0e10cSrcweir s_pImpl = new OModuleImpl(); 137cdf0e10cSrcweir } 138cdf0e10cSrcweir 139cdf0e10cSrcweir //......................................................................... 140cdf0e10cSrcweir } // namespace dbaui 141cdf0e10cSrcweir //......................................................................... 142cdf0e10cSrcweir 143