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 : #include "moduledbu.hxx"
21 :
22 : #include <tools/resmgr.hxx>
23 : #include <svl/solar.hrc>
24 : #include <tools/debug.hxx>
25 :
26 : #define ENTER_MOD_METHOD() \
27 : ::osl::MutexGuard aGuard(s_aMutex); \
28 : ensureImpl()
29 :
30 : namespace dbaui
31 : {
32 :
33 : // OModuleImpl
34 : /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by its owner
35 : */
36 : class OModuleImpl
37 : {
38 : ResMgr* m_pResources;
39 :
40 : public:
41 : /// ctor
42 : OModuleImpl();
43 : ~OModuleImpl();
44 :
45 : /// get the manager for the resources of the module
46 : ResMgr* getResManager();
47 : };
48 :
49 18 : OModuleImpl::OModuleImpl()
50 18 : :m_pResources(NULL)
51 : {
52 :
53 18 : }
54 :
55 14 : OModuleImpl::~OModuleImpl()
56 : {
57 14 : if (m_pResources)
58 14 : delete m_pResources;
59 :
60 14 : }
61 :
62 278 : ResMgr* OModuleImpl::getResManager()
63 : {
64 : // note that this method is not threadsafe, which counts for the whole class !
65 :
66 278 : if (!m_pResources)
67 : {
68 : // create a manager with a fixed prefix
69 18 : m_pResources = ResMgr::CreateResMgr("dbu");
70 : }
71 278 : return m_pResources;
72 : }
73 :
74 : // OModule
75 24 : ::osl::Mutex OModule::s_aMutex;
76 : sal_Int32 OModule::s_nClients = 0;
77 : OModuleImpl* OModule::s_pImpl = NULL;
78 278 : ResMgr* OModule::getResManager()
79 : {
80 278 : ENTER_MOD_METHOD();
81 278 : return s_pImpl->getResManager();
82 : }
83 :
84 54 : void OModule::registerClient()
85 : {
86 54 : ::osl::MutexGuard aGuard(s_aMutex);
87 54 : ++s_nClients;
88 54 : }
89 :
90 50 : void OModule::revokeClient()
91 : {
92 50 : ::osl::MutexGuard aGuard(s_aMutex);
93 50 : if (!--s_nClients && s_pImpl)
94 : {
95 14 : delete s_pImpl;
96 14 : s_pImpl = NULL;
97 50 : }
98 50 : }
99 :
100 278 : void OModule::ensureImpl()
101 : {
102 278 : if (s_pImpl)
103 538 : return;
104 18 : s_pImpl = new OModuleImpl();
105 : }
106 :
107 72 : } // namespace dbaui
108 :
109 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|