bump product version to 5.0.4.1
[LibreOffice.git] / reportdesign / source / core / sdr / ModuleHelper.cxx
blobecbd677ed606496ad6a386e7ba2b629c55e87ee9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include "ModuleHelper.hxx"
20 #include <comphelper/processfactory.hxx>
21 #include <osl/thread.h>
22 #include <com/sun/star/util/XMacroExpander.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/uno/XComponentContext.hpp>
25 #include <rtl/instance.hxx>
26 #include <rtl/uri.hxx>
27 #include <tools/debug.hxx>
28 #include <svl/solar.hrc>
30 #define ENTER_MOD_METHOD() \
31 ::osl::MutexGuard aGuard(theOModuleMutex::get()); \
32 ensureImpl()
35 namespace rptui
38 using namespace ::com::sun::star;
40 //= OModuleImpl
42 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by its owner
44 class OModuleImpl
46 ResMgr* m_pResources;
48 public:
49 /// ctor
50 OModuleImpl();
51 ~OModuleImpl();
53 /// get the manager for the resources of the module
54 ResMgr* getResManager();
58 OModuleImpl::OModuleImpl()
59 :m_pResources(NULL)
64 OModuleImpl::~OModuleImpl()
66 if (m_pResources)
67 delete m_pResources;
71 ResMgr* OModuleImpl::getResManager()
73 // note that this method is not threadsafe, which counts for the whole class !
75 if (!m_pResources)
77 // create a manager with a fixed prefix
78 m_pResources = ResMgr::CreateResMgr("rptui");
80 return m_pResources;
84 //= OModule
87 namespace
89 // access safety
90 struct theOModuleMutex : public rtl::Static< osl::Mutex, theOModuleMutex > {};
93 sal_Int32 OModule::s_nClients = 0;
94 OModuleImpl* OModule::s_pImpl = NULL;
96 ResMgr* OModule::getResManager()
98 ENTER_MOD_METHOD();
99 return s_pImpl->getResManager();
103 void OModule::registerClient()
105 ::osl::MutexGuard aGuard(theOModuleMutex::get());
106 ++s_nClients;
110 void OModule::revokeClient()
112 ::osl::MutexGuard aGuard(theOModuleMutex::get());
113 if (!--s_nClients && s_pImpl)
115 delete s_pImpl;
116 s_pImpl = NULL;
121 void OModule::ensureImpl()
123 if (s_pImpl)
124 return;
125 s_pImpl = new OModuleImpl();
129 } // namespace dbaui
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */