12e2212a7SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 32e2212a7SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 42e2212a7SAndrew Rist * or more contributor license agreements. See the NOTICE file 52e2212a7SAndrew Rist * distributed with this work for additional information 62e2212a7SAndrew Rist * regarding copyright ownership. The ASF licenses this file 72e2212a7SAndrew Rist * to you under the Apache License, Version 2.0 (the 82e2212a7SAndrew Rist * "License"); you may not use this file except in compliance 92e2212a7SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 112e2212a7SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 132e2212a7SAndrew Rist * Unless required by applicable law or agreed to in writing, 142e2212a7SAndrew Rist * software distributed under the License is distributed on an 152e2212a7SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 162e2212a7SAndrew Rist * KIND, either express or implied. See the License for the 172e2212a7SAndrew Rist * specific language governing permissions and limitations 182e2212a7SAndrew Rist * under the License. 19cdf0e10cSrcweir * 202e2212a7SAndrew Rist *************************************************************/ 212e2212a7SAndrew Rist 222e2212a7SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _DBAUI_MODULE_DBU_HXX_ 25cdf0e10cSrcweir #define _DBAUI_MODULE_DBU_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #ifndef _OSL_MUTEX_HXX_ 28cdf0e10cSrcweir #include <osl/mutex.hxx> 29cdf0e10cSrcweir #endif 30cdf0e10cSrcweir #ifndef _TOOLS_RESID_HXX 31cdf0e10cSrcweir #include <tools/resid.hxx> 32cdf0e10cSrcweir #endif 33cdf0e10cSrcweir 34cdf0e10cSrcweir class ResMgr; 35cdf0e10cSrcweir 36cdf0e10cSrcweir //......................................................................... 37cdf0e10cSrcweir namespace dbaui 38cdf0e10cSrcweir { 39cdf0e10cSrcweir //......................................................................... 40cdf0e10cSrcweir 41cdf0e10cSrcweir //========================================================================= 42cdf0e10cSrcweir //= OModule 43cdf0e10cSrcweir //========================================================================= 44cdf0e10cSrcweir class OModuleImpl; 45cdf0e10cSrcweir class OModule 46cdf0e10cSrcweir { 47cdf0e10cSrcweir friend class OModuleClient; 48cdf0e10cSrcweir 49cdf0e10cSrcweir private: 50cdf0e10cSrcweir OModule(); 51cdf0e10cSrcweir // not implemented. OModule is a static class 52cdf0e10cSrcweir 53cdf0e10cSrcweir protected: 54cdf0e10cSrcweir static ::osl::Mutex s_aMutex; /// access safety 55cdf0e10cSrcweir static sal_Int32 s_nClients; /// number of registered clients 56cdf0e10cSrcweir static OModuleImpl* s_pImpl; /// impl class. lives as long as at least one client for the module is registered 57cdf0e10cSrcweir 58cdf0e10cSrcweir public: 59cdf0e10cSrcweir /// get the vcl res manager of the module 60cdf0e10cSrcweir static ResMgr* getResManager(); 61cdf0e10cSrcweir 62cdf0e10cSrcweir protected: 63cdf0e10cSrcweir /// register a client for the module 64cdf0e10cSrcweir static void registerClient(); 65cdf0e10cSrcweir /// revoke a client for the module 66cdf0e10cSrcweir static void revokeClient(); 67cdf0e10cSrcweir 68cdf0e10cSrcweir private: 69cdf0e10cSrcweir /** ensure that the impl class exists 70cdf0e10cSrcweir @precond m_aMutex is guarded when this method gets called 71cdf0e10cSrcweir */ 72cdf0e10cSrcweir static void ensureImpl(); 73cdf0e10cSrcweir }; 74cdf0e10cSrcweir 75cdf0e10cSrcweir //========================================================================= 76cdf0e10cSrcweir //= OModuleClient 77cdf0e10cSrcweir //========================================================================= 78*816026e9SJohn Bampton /** base class for objects which uses any global module-specific resources 79cdf0e10cSrcweir */ 80cdf0e10cSrcweir class OModuleClient 81cdf0e10cSrcweir { 82cdf0e10cSrcweir public: OModuleClient()83cdf0e10cSrcweir OModuleClient() { OModule::registerClient(); } ~OModuleClient()84cdf0e10cSrcweir ~OModuleClient() { OModule::revokeClient(); } 85cdf0e10cSrcweir }; 86cdf0e10cSrcweir 87cdf0e10cSrcweir //========================================================================= 88cdf0e10cSrcweir //= ModuleRes 89cdf0e10cSrcweir //========================================================================= 9002f6802cSJohn Bampton /** specialized ResId, using the resource manager provided by the global module 91cdf0e10cSrcweir */ 92cdf0e10cSrcweir class ModuleRes : public ::ResId 93cdf0e10cSrcweir { 94cdf0e10cSrcweir public: ModuleRes(sal_uInt16 _nId)95cdf0e10cSrcweir ModuleRes(sal_uInt16 _nId) : ResId(_nId, *OModule::getResManager()) { } 96cdf0e10cSrcweir }; 97cdf0e10cSrcweir 98cdf0e10cSrcweir //......................................................................... 99cdf0e10cSrcweir } // namespace dbaui 100cdf0e10cSrcweir //......................................................................... 101cdf0e10cSrcweir 102cdf0e10cSrcweir #endif // _DBAUI_MODULE_DBU_HXX_ 103