1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: servicemanager.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef __FRAMEWORK_CLASSES_SERVICEMANAGER_HXX_
32 #define __FRAMEWORK_CLASSES_SERVICEMANAGER_HXX_
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
38 #include <macros/debug.hxx>
40 //_________________________________________________________________________________________________________________
42 //_________________________________________________________________________________________________________________
43 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
45 //_________________________________________________________________________________________________________________
47 //_________________________________________________________________________________________________________________
48 #include <com/sun/star/uno/Reference.hxx>
49 #include <rtl/ustring.hxx>
50 #include <osl/mutex.hxx>
52 //_________________________________________________________________________________________________________________
54 //_________________________________________________________________________________________________________________
58 #define REFERENCE ::com::sun::star::uno::Reference
59 #define XMULTISERVICEFACTORY ::com::sun::star::lang::XMultiServiceFactory
60 #define OUSTRING ::rtl::OUString
61 #define MUTEX ::osl::Mutex
63 //_________________________________________________________________________________________________________________
65 //_________________________________________________________________________________________________________________
67 //_________________________________________________________________________________________________________________
68 // exported definitions
69 //_________________________________________________________________________________________________________________
71 /*-************************************************************************************************************//**
72 @short create a new global servicemanager
73 @descr A global servicemanager is neccessary to instanciate UNO-services. To do this, you need
74 a factory to create new objects with special type. That's the reason for a servicemanager.
79 @devstatus ready to use
80 *//*-*************************************************************************************************************/
84 //-------------------------------------------------------------------------------------------------------------
86 //-------------------------------------------------------------------------------------------------------------
90 //---------------------------------------------------------------------------------------------------------
91 // constructor / destructor
92 //---------------------------------------------------------------------------------------------------------
94 /*-****************************************************************************************************//**
95 @short standard constructor
96 @descr This method don't initialize the new global servicemanager!
97 But we increase an internal ref count. These is needed in dtor to release
98 all created static references to created service mamanger!
106 *//*-*****************************************************************************************************/
110 /*-****************************************************************************************************//**
111 @short standard destructor to delete instance
112 @descr Here is a good place to destroy the global manager instances!
120 *//*-*****************************************************************************************************/
122 virtual ~ServiceManager();
124 /*-****************************************************************************************************//**
125 @short initialize global uno service manager and return it
126 @descr This method create a new manager only at first call. We confiscate this with a static
127 pointer, which will be initialized only, if it NULL!
128 Then you can call this method everytime to get a reference to the manager.
129 If you will initialize an uno application you must set returned reference in ::comphelper::setProcessServiceFactory()!
130 The created manager use "applicat.rdb" and "userXX.rdb" automaticly.
135 @return A reference to the global servicemanager. It can be NULL!
137 @onerror We return a null-reference.
138 *//*-*****************************************************************************************************/
140 REFERENCE
< XMULTISERVICEFACTORY
> getGlobalUNOServiceManager();
142 /*-****************************************************************************************************//**
143 @short initialize global uno service manager and return it
144 @descr Do the same like getGlobalUNOServiceManager() before, but use "applicat.rdb" only!
149 @return A reference to the global servicemanager. It can be NULL!
151 @onerror We return a null-reference.
152 *//*-*****************************************************************************************************/
154 REFERENCE
< XMULTISERVICEFACTORY
> getSimpleGlobalUNOServiceManager();
156 /*-****************************************************************************************************//**
157 @short return a reference to a uno servicemanager instance which use your specified user registry file
158 @descr This do the same like method before - but instead of "userXX.rdb" we use your file.
159 These is neccessary, if you will run more then one uno application at the same time in same environment!
160 All created servicemanager use the same "applicat.rdb" but different user registries.
162 @ATTENTION Given file name must be a full qualified system file name. If file not already exist we create a new one!
163 "applicat.rdb", "userXX.rdb" are not valid values!
165 @seealso method generateGlobalUNOServiceManager()
166 @seealso method generatePrivateUNOServiceManager()
168 @param "sUserRegistryFile", full qualified system file name of user registry
169 @return A reference to the created servicemanager. It can be NULL!
171 @onerror We return a null-reference.
172 *//*-*****************************************************************************************************/
174 REFERENCE
< XMULTISERVICEFACTORY
> getSharedUNOServiceManager( const OUSTRING
& sUserRegistryFile
);
176 /*-****************************************************************************************************//**
177 @short return a reference to a uno servicemanager instance which use your specified user registry file only
178 @descr This do the same like methods before - but use your file as the only one registry.
179 "applicat.rdb" is used here!
181 @ATTENTION Given file name must be a full qualified system file name. If file not already exist we create a new one!
182 "applicat.rdb", "userXX.rdb" are not valid values!
183 If file was new created - you must register services at runtime himself.
184 Otherwise no service could be created by these manager ...
186 @seealso method generateGlobalUNOServiceManager()
187 @seealso method generateSharedUNOServiceManager()
189 @param "sUserRegistryFile", full qualified system file name of user registry
190 @return A reference to the created servicemanager. It can be NULL!
192 @onerror We return a null-reference.
193 *//*-*****************************************************************************************************/
195 REFERENCE
< XMULTISERVICEFACTORY
> getPrivateUNOServiceManager( const OUSTRING
& sUserRegistryFile
);
197 //-------------------------------------------------------------------------------------------------------------
199 //-------------------------------------------------------------------------------------------------------------
203 //-------------------------------------------------------------------------------------------------------------
205 //-------------------------------------------------------------------------------------------------------------
209 /*-****************************************************************************************************//**
210 @short create our own global mutex to prevent us against multithreaded problems
211 @descr We use some static member. For correct access to it we must use the global osl mutex ...
212 but its not fine to do so! These block ALL other operations, which need these mutex too.
213 That's the reason to create our own static mutex. Only first creation is protected
214 by the global mutex, using isn't it!
219 @return reference to created static own global mutex
221 @onerror No error should occure.
222 *//*-*****************************************************************************************************/
224 MUTEX
& impl_getOwnGlobalMutex();
226 /*-****************************************************************************************************//**
227 @short create a new global servicemanager instance
228 @descr Is a helper-method for getManager().
230 @seealso method getManager()
232 @param "sRegistryFile", file name of user registry.
233 @return A reference to a new initialized servicemanager with a valid registry.
234 It can be NULL, if an error occured.
236 @onerror Return a NULL-reference.
237 *//*-*****************************************************************************************************/
239 REFERENCE
< XMULTISERVICEFACTORY
> impl_createManager( const OUSTRING
& sRegistryFile
);
241 //-------------------------------------------------------------------------------------------------------------
243 // (should be private everyway!)
244 //-------------------------------------------------------------------------------------------------------------
246 /*-****************************************************************************************************//**
247 @short debug-method to check incoming parameter of some other mehods of this class
248 @descr The following methods are used to check parameters for other methods
249 of this class. The return value is used directly for an ASSERT(...).
251 @seealso ASSERTs in implementation!
253 @param references to checking variables
254 @return sal_False on invalid parameter<BR>
258 *//*-*****************************************************************************************************/
260 #ifdef ENABLE_ASSERTIONS
264 #endif // #ifdef ENABLE_ASSERTIONS
266 //-------------------------------------------------------------------------------------------------------------
268 // (should be private everyway!)
269 //-------------------------------------------------------------------------------------------------------------
273 static REFERENCE
< XMULTISERVICEFACTORY
>* m_pGlobalServiceManager
;
274 static REFERENCE
< XMULTISERVICEFACTORY
>* m_pSimpleGlobalServiceManager
;
275 static REFERENCE
< XMULTISERVICEFACTORY
>* m_pSharedServiceManager
;
276 static REFERENCE
< XMULTISERVICEFACTORY
>* m_pPrivateServiceManager
;
277 static sal_Int32 m_nRefCount
;
279 }; // class ServiceManager
281 } // namespace framework
283 #endif // #ifndef __FRAMEWORK_CLASSES_SERVICEMANAGER_HXX_