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 0 : OModuleImpl::OModuleImpl()
57 0 : :m_pResources(NULL)
58 : {
59 : DBG_CTOR(OModuleImpl,NULL);
60 :
61 0 : }
62 :
63 : //-------------------------------------------------------------------------
64 0 : OModuleImpl::~OModuleImpl()
65 : {
66 0 : if (m_pResources)
67 0 : delete m_pResources;
68 :
69 : DBG_DTOR(OModuleImpl,NULL);
70 0 : }
71 :
72 : //-------------------------------------------------------------------------
73 0 : ResMgr* OModuleImpl::getResManager()
74 : {
75 : // note that this method is not threadsafe, which counts for the whole class !
76 :
77 0 : if (!m_pResources)
78 : {
79 : // create a manager with a fixed prefix
80 0 : m_pResources = ResMgr::CreateResMgr(rtl::OString("dbu").getStr());
81 : }
82 0 : return m_pResources;
83 : }
84 :
85 : //=========================================================================
86 : //= OModule
87 : //=========================================================================
88 0 : ::osl::Mutex OModule::s_aMutex;
89 : sal_Int32 OModule::s_nClients = 0;
90 : OModuleImpl* OModule::s_pImpl = NULL;
91 : //-------------------------------------------------------------------------
92 0 : ResMgr* OModule::getResManager()
93 : {
94 0 : ENTER_MOD_METHOD();
95 0 : return s_pImpl->getResManager();
96 : }
97 :
98 : //-------------------------------------------------------------------------
99 0 : void OModule::registerClient()
100 : {
101 0 : ::osl::MutexGuard aGuard(s_aMutex);
102 0 : ++s_nClients;
103 0 : }
104 :
105 : //-------------------------------------------------------------------------
106 0 : void OModule::revokeClient()
107 : {
108 0 : ::osl::MutexGuard aGuard(s_aMutex);
109 0 : if (!--s_nClients && s_pImpl)
110 : {
111 0 : delete s_pImpl;
112 0 : s_pImpl = NULL;
113 0 : }
114 0 : }
115 :
116 : //-------------------------------------------------------------------------
117 0 : void OModule::ensureImpl()
118 : {
119 0 : if (s_pImpl)
120 0 : return;
121 0 : s_pImpl = new OModuleImpl();
122 : }
123 :
124 : //.........................................................................
125 0 : } // namespace dbaui
126 : //.........................................................................
127 :
128 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|