1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef __FRAMEWORK_CLASSES_SERVICEMANAGER_HXX_
29*cdf0e10cSrcweir #define __FRAMEWORK_CLASSES_SERVICEMANAGER_HXX_
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
32*cdf0e10cSrcweir //	my own includes
33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <macros/debug.hxx>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
38*cdf0e10cSrcweir //	interface includes
39*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43*cdf0e10cSrcweir //	other includes
44*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
45*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx>
46*cdf0e10cSrcweir #include <rtl/ustring.hxx>
47*cdf0e10cSrcweir #include <osl/mutex.hxx>
48*cdf0e10cSrcweir 
49*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
50*cdf0e10cSrcweir //	namespace
51*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir namespace framework{
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir #define	REFERENCE					::com::sun::star::uno::Reference
56*cdf0e10cSrcweir #define	XMULTISERVICEFACTORY		::com::sun::star::lang::XMultiServiceFactory
57*cdf0e10cSrcweir #define	OUSTRING					::rtl::OUString
58*cdf0e10cSrcweir #define	MUTEX						::osl::Mutex
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
61*cdf0e10cSrcweir //	exported const
62*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
65*cdf0e10cSrcweir //	exported definitions
66*cdf0e10cSrcweir //_________________________________________________________________________________________________________________
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir /*-************************************************************************************************************//**
69*cdf0e10cSrcweir 	@short			create a new global servicemanager
70*cdf0e10cSrcweir 	@descr			A global servicemanager is neccessary to instanciate UNO-services. To do this, you need
71*cdf0e10cSrcweir 					a factory to create new objects with special type. That's the reason for a servicemanager.
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	@implements		-
74*cdf0e10cSrcweir     @base           -
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir 	@devstatus		ready to use
77*cdf0e10cSrcweir *//*-*************************************************************************************************************/
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir class ServiceManager
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
82*cdf0e10cSrcweir 	//	public methods
83*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir 	public:
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
88*cdf0e10cSrcweir 		//	constructor / destructor
89*cdf0e10cSrcweir 		//---------------------------------------------------------------------------------------------------------
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
92*cdf0e10cSrcweir 			@short		standard constructor
93*cdf0e10cSrcweir 			@descr		This method don't initialize the new global servicemanager!
94*cdf0e10cSrcweir 						But we increase an internal ref count. These is needed in dtor to release
95*cdf0e10cSrcweir 						all created static references to created service mamanger!
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir 			@seealso	dtor
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 			@param		-
100*cdf0e10cSrcweir 			@return		-
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir 			@onerror	-
103*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	 	ServiceManager();
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
108*cdf0e10cSrcweir 			@short		standard destructor to delete instance
109*cdf0e10cSrcweir 			@descr		Here is a good place to destroy the global manager instances!
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir 			@seealso	ctor
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 			@param		-
114*cdf0e10cSrcweir 			@return		-
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 			@onerror	-
117*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir 		virtual ~ServiceManager();
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
122*cdf0e10cSrcweir 			@short		initialize global uno service manager and return it
123*cdf0e10cSrcweir 			@descr		This method create a new manager only at first call. We confiscate this with a static
124*cdf0e10cSrcweir 						pointer, which will be initialized only, if it NULL!
125*cdf0e10cSrcweir 						Then you can call this method everytime to get a reference to the manager.
126*cdf0e10cSrcweir 						If you will initialize an uno application you must set returned reference in ::comphelper::setProcessServiceFactory()!
127*cdf0e10cSrcweir 						The created manager use "applicat.rdb" and "userXX.rdb" automaticly.
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 			@seealso	-
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir 			@param		-
132*cdf0e10cSrcweir 			@return		A reference to the global servicemanager. It can be NULL!
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir 			@onerror	We return a null-reference.
135*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 		REFERENCE< XMULTISERVICEFACTORY > getGlobalUNOServiceManager();
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
140*cdf0e10cSrcweir 			@short		initialize global uno service manager and return it
141*cdf0e10cSrcweir 			@descr		Do the same like getGlobalUNOServiceManager() before, but use "applicat.rdb" only!
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir 			@seealso	-
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir 			@param		-
146*cdf0e10cSrcweir 			@return		A reference to the global servicemanager. It can be NULL!
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 			@onerror	We return a null-reference.
149*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir 		REFERENCE< XMULTISERVICEFACTORY > getSimpleGlobalUNOServiceManager();
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
154*cdf0e10cSrcweir 			@short		return a reference to a uno servicemanager instance which use your specified user registry file
155*cdf0e10cSrcweir 			@descr		This do the same like method before - but instead of "userXX.rdb" we use your file.
156*cdf0e10cSrcweir 						These is neccessary, if you will run more then one uno application at the same time in same environment!
157*cdf0e10cSrcweir 						All created servicemanager use the same "applicat.rdb" but different user registries.
158*cdf0e10cSrcweir 
159*cdf0e10cSrcweir 			@ATTENTION	Given file name must be a full qualified system file name. If file not already exist we create a new one!
160*cdf0e10cSrcweir 						"applicat.rdb", "userXX.rdb" are not valid values!
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir 			@seealso	method generateGlobalUNOServiceManager()
163*cdf0e10cSrcweir 			@seealso	method generatePrivateUNOServiceManager()
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir 			@param		"sUserRegistryFile", full qualified system file name of user registry
166*cdf0e10cSrcweir 			@return		A reference to the created servicemanager. It can be NULL!
167*cdf0e10cSrcweir 
168*cdf0e10cSrcweir 			@onerror	We return a null-reference.
169*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir 		REFERENCE< XMULTISERVICEFACTORY > getSharedUNOServiceManager( const OUSTRING& sUserRegistryFile );
172*cdf0e10cSrcweir 
173*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
174*cdf0e10cSrcweir 			@short		return a reference to a uno servicemanager instance which use your specified user registry file only
175*cdf0e10cSrcweir 			@descr		This do the same like methods before - but use your file as the only one registry.
176*cdf0e10cSrcweir 						"applicat.rdb" is used here!
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 			@ATTENTION	Given file name must be a full qualified system file name. If file not already exist we create a new one!
179*cdf0e10cSrcweir 						"applicat.rdb", "userXX.rdb" are not valid values!
180*cdf0e10cSrcweir 						If file was new created - you must register services at runtime himself.
181*cdf0e10cSrcweir 						Otherwise no service could be created by these manager ...
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 			@seealso	method generateGlobalUNOServiceManager()
184*cdf0e10cSrcweir 			@seealso	method generateSharedUNOServiceManager()
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir 			@param		"sUserRegistryFile", full qualified system file name of user registry
187*cdf0e10cSrcweir 			@return		A reference to the created servicemanager. It can be NULL!
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 			@onerror	We return a null-reference.
190*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir 		REFERENCE< XMULTISERVICEFACTORY > getPrivateUNOServiceManager( const OUSTRING& sUserRegistryFile );
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
195*cdf0e10cSrcweir 	//	protected methods
196*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
197*cdf0e10cSrcweir 
198*cdf0e10cSrcweir 	protected:
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
201*cdf0e10cSrcweir 	//	private methods
202*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
203*cdf0e10cSrcweir 
204*cdf0e10cSrcweir 	private:
205*cdf0e10cSrcweir 
206*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
207*cdf0e10cSrcweir 			@short		create our own global mutex to prevent us against multithreaded problems
208*cdf0e10cSrcweir 			@descr		We use some static member. For correct access to it we must use the global osl mutex ...
209*cdf0e10cSrcweir 						but its not fine to do so! These block ALL other operations, which need these mutex too.
210*cdf0e10cSrcweir 						That's the reason to create our own static mutex. Only first creation is protected
211*cdf0e10cSrcweir 						by the global mutex, using isn't it!
212*cdf0e10cSrcweir 
213*cdf0e10cSrcweir 			@seealso	using
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir 			@param		-
216*cdf0e10cSrcweir 			@return		reference to created static own global mutex
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir 			@onerror	No error should occure.
219*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir 		MUTEX& impl_getOwnGlobalMutex();
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
224*cdf0e10cSrcweir 			@short		create a new global servicemanager instance
225*cdf0e10cSrcweir 			@descr		Is a helper-method for getManager().
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir 			@seealso	method getManager()
228*cdf0e10cSrcweir 
229*cdf0e10cSrcweir 			@param		"sRegistryFile", file name of user registry.
230*cdf0e10cSrcweir 			@return		A reference to a new initialized servicemanager with a valid registry.
231*cdf0e10cSrcweir 						It can be NULL, if an error occured.
232*cdf0e10cSrcweir 
233*cdf0e10cSrcweir 			@onerror	Return a NULL-reference.
234*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 		REFERENCE< XMULTISERVICEFACTORY > impl_createManager( const OUSTRING& sRegistryFile );
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
239*cdf0e10cSrcweir 	//	debug methods
240*cdf0e10cSrcweir 	//	(should be private everyway!)
241*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 		/*-****************************************************************************************************//**
244*cdf0e10cSrcweir 			@short		debug-method to check incoming parameter of some other mehods of this class
245*cdf0e10cSrcweir 			@descr		The following methods are used to check parameters for other methods
246*cdf0e10cSrcweir 						of this class. The return value is used directly for an ASSERT(...).
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 			@seealso	ASSERTs in implementation!
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir 			@param		references to checking variables
251*cdf0e10cSrcweir 			@return		sal_False on invalid parameter<BR>
252*cdf0e10cSrcweir 						sal_True  otherway
253*cdf0e10cSrcweir 
254*cdf0e10cSrcweir 			@onerror	-
255*cdf0e10cSrcweir 		*//*-*****************************************************************************************************/
256*cdf0e10cSrcweir 
257*cdf0e10cSrcweir 	#ifdef ENABLE_ASSERTIONS
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir 	private:
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir 	#endif	//	#ifdef ENABLE_ASSERTIONS
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
264*cdf0e10cSrcweir 	//	private variables
265*cdf0e10cSrcweir 	//	(should be private everyway!)
266*cdf0e10cSrcweir 	//-------------------------------------------------------------------------------------------------------------
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir 	private:
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir 		static REFERENCE< XMULTISERVICEFACTORY >*	m_pGlobalServiceManager			;
271*cdf0e10cSrcweir 		static REFERENCE< XMULTISERVICEFACTORY >*	m_pSimpleGlobalServiceManager	;
272*cdf0e10cSrcweir 		static REFERENCE< XMULTISERVICEFACTORY >*	m_pSharedServiceManager			;
273*cdf0e10cSrcweir 		static REFERENCE< XMULTISERVICEFACTORY >*	m_pPrivateServiceManager		;
274*cdf0e10cSrcweir 		static sal_Int32							m_nRefCount						;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir };		//	class ServiceManager
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir }		//	namespace framework
279*cdf0e10cSrcweir 
280*cdf0e10cSrcweir #endif	//	#ifndef __FRAMEWORK_CLASSES_SERVICEMANAGER_HXX_
281