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 : #include "ModuleHelper.hxx"
20 : #include <comphelper/configurationhelper.hxx>
21 : #include <comphelper/processfactory.hxx>
22 : #include <osl/thread.h>
23 : #include <com/sun/star/util/XMacroExpander.hpp>
24 : #include <com/sun/star/beans/XPropertySet.hpp>
25 : #include <com/sun/star/uno/XComponentContext.hpp>
26 : #include <rtl/instance.hxx>
27 : #include <rtl/uri.hxx>
28 : #include <tools/debug.hxx>
29 : #include <svl/solar.hrc>
30 :
31 : #define ENTER_MOD_METHOD() \
32 : ::osl::MutexGuard aGuard(theOModuleMutex::get()); \
33 : ensureImpl()
34 :
35 : //.........................................................................
36 : namespace rptui
37 : {
38 : //.........................................................................
39 : using namespace ::com::sun::star;
40 : //=========================================================================
41 : //= OModuleImpl
42 : //=========================================================================
43 : /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
44 : */
45 : class OModuleImpl
46 : {
47 : ResMgr* m_pResources;
48 :
49 : public:
50 : /// ctor
51 : OModuleImpl();
52 : ~OModuleImpl();
53 :
54 : /// get the manager for the resources of the module
55 : ResMgr* getResManager();
56 : };
57 :
58 : DBG_NAME( rpt_OModuleImpl )
59 : //-------------------------------------------------------------------------
60 0 : OModuleImpl::OModuleImpl()
61 0 : :m_pResources(NULL)
62 : {
63 : DBG_CTOR( rpt_OModuleImpl,NULL);
64 :
65 0 : }
66 :
67 : //-------------------------------------------------------------------------
68 0 : OModuleImpl::~OModuleImpl()
69 : {
70 0 : if (m_pResources)
71 0 : delete m_pResources;
72 :
73 : DBG_DTOR( rpt_OModuleImpl,NULL);
74 0 : }
75 :
76 : //-------------------------------------------------------------------------
77 0 : ResMgr* OModuleImpl::getResManager()
78 : {
79 : // note that this method is not threadsafe, which counts for the whole class !
80 :
81 0 : if (!m_pResources)
82 : {
83 : // create a manager with a fixed prefix
84 0 : m_pResources = ResMgr::CreateResMgr("rptui");
85 : }
86 0 : return m_pResources;
87 : }
88 :
89 : //=========================================================================
90 : //= OModule
91 : //=========================================================================
92 :
93 : namespace
94 : {
95 : // access safety
96 : struct theOModuleMutex : public rtl::Static< osl::Mutex, theOModuleMutex > {};
97 : }
98 :
99 : sal_Int32 OModule::s_nClients = 0;
100 : OModuleImpl* OModule::s_pImpl = NULL;
101 : //-------------------------------------------------------------------------
102 0 : ResMgr* OModule::getResManager()
103 : {
104 0 : ENTER_MOD_METHOD();
105 0 : return s_pImpl->getResManager();
106 : }
107 :
108 : //-------------------------------------------------------------------------
109 0 : void OModule::registerClient()
110 : {
111 0 : ::osl::MutexGuard aGuard(theOModuleMutex::get());
112 0 : ++s_nClients;
113 0 : }
114 :
115 : //-------------------------------------------------------------------------
116 0 : void OModule::revokeClient()
117 : {
118 0 : ::osl::MutexGuard aGuard(theOModuleMutex::get());
119 0 : if (!--s_nClients && s_pImpl)
120 : {
121 0 : delete s_pImpl;
122 0 : s_pImpl = NULL;
123 0 : }
124 0 : }
125 :
126 : //-------------------------------------------------------------------------
127 0 : void OModule::ensureImpl()
128 : {
129 0 : if (s_pImpl)
130 0 : return;
131 0 : s_pImpl = new OModuleImpl();
132 : }
133 :
134 : //.........................................................................
135 : } // namespace dbaui
136 : //.........................................................................
137 :
138 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|