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