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