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 // MARKER(update_precomp.py): autogen include statement, do not remove 23 #include "precompiled_dbui.hxx" 24 25 #ifndef _DBAUI_MODULE_DBU_HXX_ 26 #include "moduledbu.hxx" 27 #endif 28 29 #ifndef _TOOLS_RESMGR_HXX 30 #include <tools/resmgr.hxx> 31 #endif 32 #ifndef _SOLAR_HRC 33 #include <svl/solar.hrc> 34 #endif 35 #ifndef _TOOLS_DEBUG_HXX 36 #include <tools/debug.hxx> 37 #endif 38 39 #define ENTER_MOD_METHOD() \ 40 ::osl::MutexGuard aGuard(s_aMutex); \ 41 ensureImpl() 42 43 //......................................................................... 44 namespace dbaui 45 { 46 //......................................................................... 47 48 //========================================================================= 49 //= OModuleImpl 50 //========================================================================= 51 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by its owner 52 */ 53 class OModuleImpl 54 { 55 ResMgr* m_pRessources; 56 57 public: 58 // ctor 59 OModuleImpl(); 60 ~OModuleImpl(); 61 62 // get the manager for the resources of the module 63 ResMgr* getResManager(); 64 }; 65 66 DBG_NAME(OModuleImpl) 67 //------------------------------------------------------------------------- 68 OModuleImpl::OModuleImpl() 69 :m_pRessources(NULL) 70 { 71 DBG_CTOR(OModuleImpl,NULL); 72 73 } 74 75 //------------------------------------------------------------------------- 76 OModuleImpl::~OModuleImpl() 77 { 78 if (m_pRessources) 79 delete m_pRessources; 80 81 DBG_DTOR(OModuleImpl,NULL); 82 } 83 84 //------------------------------------------------------------------------- 85 ResMgr* OModuleImpl::getResManager() 86 { 87 // note that this method is not threadsafe, which counts for the whole class! 88 89 if (!m_pRessources) 90 { 91 // create a manager with a fixed prefix 92 ByteString aMgrName = ByteString( "dbu" ); 93 m_pRessources = ResMgr::CreateResMgr(aMgrName.GetBuffer()); 94 } 95 return m_pRessources; 96 } 97 98 //========================================================================= 99 //= OModule 100 //========================================================================= 101 ::osl::Mutex OModule::s_aMutex; 102 sal_Int32 OModule::s_nClients = 0; 103 OModuleImpl* OModule::s_pImpl = NULL; 104 //------------------------------------------------------------------------- 105 ResMgr* OModule::getResManager() 106 { 107 ENTER_MOD_METHOD(); 108 return s_pImpl->getResManager(); 109 } 110 111 //------------------------------------------------------------------------- 112 void OModule::registerClient() 113 { 114 ::osl::MutexGuard aGuard(s_aMutex); 115 ++s_nClients; 116 } 117 118 //------------------------------------------------------------------------- 119 void OModule::revokeClient() 120 { 121 ::osl::MutexGuard aGuard(s_aMutex); 122 if (!--s_nClients && s_pImpl) 123 { 124 delete s_pImpl; 125 s_pImpl = NULL; 126 } 127 } 128 129 //------------------------------------------------------------------------- 130 void OModule::ensureImpl() 131 { 132 if (s_pImpl) 133 return; 134 s_pImpl = new OModuleImpl(); 135 } 136 137 } // namespace dbaui 138 139 /* vim: set noet sw=4 ts=4: */ 140