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