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