xref: /trunk/main/dbaccess/source/ui/inc/moduledbu.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _DBAUI_MODULE_DBU_HXX_
29 #define _DBAUI_MODULE_DBU_HXX_
30 
31 #ifndef _OSL_MUTEX_HXX_
32 #include <osl/mutex.hxx>
33 #endif
34 #ifndef _TOOLS_RESID_HXX
35 #include <tools/resid.hxx>
36 #endif
37 
38 class ResMgr;
39 
40 //.........................................................................
41 namespace dbaui
42 {
43 //.........................................................................
44 
45 //=========================================================================
46 //= OModule
47 //=========================================================================
48 class OModuleImpl;
49 class OModule
50 {
51 	friend class OModuleClient;
52 
53 private:
54 	OModule();
55 		// not implemented. OModule is a static class
56 
57 protected:
58 	static ::osl::Mutex	s_aMutex;		/// access safety
59 	static sal_Int32	s_nClients;		/// number of registered clients
60 	static OModuleImpl*	s_pImpl;		/// impl class. lives as long as at least one client for the module is registered
61 
62 public:
63 	/// get the vcl res manager of the module
64 	static ResMgr*	getResManager();
65 
66 protected:
67 	/// register a client for the module
68 	static void	registerClient();
69 	/// revoke a client for the module
70 	static void	revokeClient();
71 
72 private:
73 	/** ensure that the impl class exists
74 		@precond m_aMutex is guarded when this method gets called
75 	*/
76 	static void ensureImpl();
77 };
78 
79 //=========================================================================
80 //= OModuleClient
81 //=========================================================================
82 /** base class for objects which uses any global module-specific ressources
83 */
84 class OModuleClient
85 {
86 public:
87 	OModuleClient()		{ OModule::registerClient(); }
88 	~OModuleClient()	{ OModule::revokeClient(); }
89 };
90 
91 //=========================================================================
92 //= ModuleRes
93 //=========================================================================
94 /** specialized ResId, using the ressource manager provided by the global module
95 */
96 class ModuleRes : public ::ResId
97 {
98 public:
99 	ModuleRes(sal_uInt16 _nId) : ResId(_nId, *OModule::getResManager()) { }
100 };
101 
102 //.........................................................................
103 }	// namespace dbaui
104 //.........................................................................
105 
106 #endif // _DBAUI_MODULE_DBU_HXX_
107 
108