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 formula
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("forui");
85 : }
86 0 : return m_pResources;
87 : }
88 :
89 : //=========================================================================
90 : //= OModule
91 : //=========================================================================
92 : namespace
93 : {
94 : // access safety
95 : struct theOModuleMutex : public rtl::Static< osl::Mutex, theOModuleMutex > {};
96 : }
97 : sal_Int32 OModule::s_nClients = 0;
98 : OModuleImpl* OModule::s_pImpl = NULL;
99 : //-------------------------------------------------------------------------
100 0 : ResMgr* OModule::getResManager()
101 : {
102 0 : ENTER_MOD_METHOD();
103 0 : return s_pImpl->getResManager();
104 : }
105 :
106 : //-------------------------------------------------------------------------
107 0 : void OModule::registerClient()
108 : {
109 0 : ::osl::MutexGuard aGuard(theOModuleMutex::get());
110 0 : ++s_nClients;
111 0 : }
112 :
113 : //-------------------------------------------------------------------------
114 0 : void OModule::revokeClient()
115 : {
116 0 : ::osl::MutexGuard aGuard(theOModuleMutex::get());
117 0 : if (!--s_nClients && s_pImpl)
118 : {
119 0 : delete s_pImpl;
120 0 : s_pImpl = NULL;
121 0 : }
122 0 : }
123 :
124 : //-------------------------------------------------------------------------
125 0 : void OModule::ensureImpl()
126 : {
127 0 : if (s_pImpl)
128 0 : return;
129 0 : s_pImpl = new OModuleImpl();
130 : }
131 :
132 : //.........................................................................
133 : } // namespace formula
134 : //.........................................................................
135 :
136 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|