Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "moduledbu.hxx"
22 :
23 : #include <tools/resmgr.hxx>
24 : #include <svl/solar.hrc>
25 : #include <tools/debug.hxx>
26 :
27 : #define ENTER_MOD_METHOD() \
28 : ::osl::MutexGuard aGuard(s_aMutex); \
29 : ensureImpl()
30 :
31 : //.........................................................................
32 : namespace dbaui
33 : {
34 : //.........................................................................
35 :
36 : //=========================================================================
37 : //= OModuleImpl
38 : //=========================================================================
39 : /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
40 : */
41 : class OModuleImpl
42 : {
43 : ResMgr* m_pResources;
44 :
45 : public:
46 : /// ctor
47 : OModuleImpl();
48 : ~OModuleImpl();
49 :
50 : /// get the manager for the resources of the module
51 : ResMgr* getResManager();
52 : };
53 :
54 : DBG_NAME(OModuleImpl)
55 : //-------------------------------------------------------------------------
56 1 : OModuleImpl::OModuleImpl()
57 1 : :m_pResources(NULL)
58 : {
59 : DBG_CTOR(OModuleImpl,NULL);
60 :
61 1 : }
62 :
63 : //-------------------------------------------------------------------------
64 1 : OModuleImpl::~OModuleImpl()
65 : {
66 1 : if (m_pResources)
67 1 : delete m_pResources;
68 :
69 : DBG_DTOR(OModuleImpl,NULL);
70 1 : }
71 :
72 : //-------------------------------------------------------------------------
73 16 : ResMgr* OModuleImpl::getResManager()
74 : {
75 : // note that this method is not threadsafe, which counts for the whole class !
76 :
77 16 : if (!m_pResources)
78 : {
79 : // create a manager with a fixed prefix
80 1 : m_pResources = ResMgr::CreateResMgr("dbu");
81 : }
82 16 : return m_pResources;
83 : }
84 :
85 : //=========================================================================
86 : //= OModule
87 : //=========================================================================
88 4 : ::osl::Mutex OModule::s_aMutex;
89 : sal_Int32 OModule::s_nClients = 0;
90 : OModuleImpl* OModule::s_pImpl = NULL;
91 : //-------------------------------------------------------------------------
92 16 : ResMgr* OModule::getResManager()
93 : {
94 16 : ENTER_MOD_METHOD();
95 16 : return s_pImpl->getResManager();
96 : }
97 :
98 : //-------------------------------------------------------------------------
99 8 : void OModule::registerClient()
100 : {
101 8 : ::osl::MutexGuard aGuard(s_aMutex);
102 8 : ++s_nClients;
103 8 : }
104 :
105 : //-------------------------------------------------------------------------
106 8 : void OModule::revokeClient()
107 : {
108 8 : ::osl::MutexGuard aGuard(s_aMutex);
109 8 : if (!--s_nClients && s_pImpl)
110 : {
111 1 : delete s_pImpl;
112 1 : s_pImpl = NULL;
113 8 : }
114 8 : }
115 :
116 : //-------------------------------------------------------------------------
117 16 : void OModule::ensureImpl()
118 : {
119 16 : if (s_pImpl)
120 31 : return;
121 1 : s_pImpl = new OModuleImpl();
122 : }
123 :
124 : //.........................................................................
125 12 : } // namespace dbaui
126 : //.........................................................................
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|