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