1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 #include "ModuleHelper.hxx" 24 #include <comphelper/configurationhelper.hxx> 25 #include <comphelper/processfactory.hxx> 26 #include <osl/thread.h> 27 #include <com/sun/star/util/XMacroExpander.hpp> 28 #include <com/sun/star/beans/XPropertySet.hpp> 29 #include <com/sun/star/uno/XComponentContext.hpp> 30 #include <rtl/uri.hxx> 31 #include <tools/debug.hxx> 32 #ifndef _SOLAR_HRC 33 #include <svl/solar.hrc> 34 #endif 35 36 #define EXPAND_PROTOCOL "vnd.sun.star.expand:" 37 #define ENTER_MOD_METHOD() \ 38 ::osl::MutexGuard aGuard(s_aMutex); \ 39 ensureImpl() 40 41 //......................................................................... 42 namespace formula 43 { 44 //......................................................................... 45 using namespace ::com::sun::star; 46 //========================================================================= 47 //= OModuleImpl 48 //========================================================================= 49 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner 50 */ 51 class OModuleImpl 52 { 53 ResMgr* m_pRessources; 54 55 public: 56 /// ctor 57 OModuleImpl(); 58 ~OModuleImpl(); 59 60 /// get the manager for the ressources of the module 61 ResMgr* getResManager(); 62 }; 63 DBG_NAME(rpt_OModuleImpl)64DBG_NAME( rpt_OModuleImpl ) 65 //------------------------------------------------------------------------- 66 OModuleImpl::OModuleImpl() 67 :m_pRessources(NULL) 68 { 69 DBG_CTOR( rpt_OModuleImpl,NULL); 70 71 } 72 73 //------------------------------------------------------------------------- ~OModuleImpl()74OModuleImpl::~OModuleImpl() 75 { 76 if (m_pRessources) 77 delete m_pRessources; 78 79 DBG_DTOR( rpt_OModuleImpl,NULL); 80 } 81 82 //------------------------------------------------------------------------- getResManager()83ResMgr* OModuleImpl::getResManager() 84 { 85 // note that this method is not threadsafe, which counts for the whole class ! 86 87 if (!m_pRessources) 88 { 89 // create a manager with a fixed prefix 90 m_pRessources = ResMgr::CreateResMgr( "forui"); 91 } 92 return m_pRessources; 93 } 94 95 //========================================================================= 96 //= OModule 97 //========================================================================= 98 ::osl::Mutex OModule::s_aMutex; 99 sal_Int32 OModule::s_nClients = 0; 100 OModuleImpl* OModule::s_pImpl = NULL; 101 //------------------------------------------------------------------------- getResManager()102ResMgr* OModule::getResManager() 103 { 104 ENTER_MOD_METHOD(); 105 return s_pImpl->getResManager(); 106 } 107 108 //------------------------------------------------------------------------- registerClient()109void OModule::registerClient() 110 { 111 ::osl::MutexGuard aGuard(s_aMutex); 112 ++s_nClients; 113 } 114 115 //------------------------------------------------------------------------- revokeClient()116void OModule::revokeClient() 117 { 118 ::osl::MutexGuard aGuard(s_aMutex); 119 if (!--s_nClients && s_pImpl) 120 { 121 delete s_pImpl; 122 s_pImpl = NULL; 123 } 124 } 125 126 //------------------------------------------------------------------------- ensureImpl()127void OModule::ensureImpl() 128 { 129 if (s_pImpl) 130 return; 131 s_pImpl = new OModuleImpl(); 132 } 133 134 //......................................................................... 135 } // namespace formula 136 //......................................................................... 137 138