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