1
/* ***** BEGIN LICENSE BLOCK *****
2
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
4
* The contents of this file are subject to the Netscape Public License
5
* Version 1.1 (the "License"); you may not use this file except in
6
* compliance with the License. You may obtain a copy of the License at
7
* http://www.mozilla.org/NPL/
9
* Software distributed under the License is distributed on an "AS IS" basis,
10
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11
* for the specific language governing rights and limitations under the
14
* The Original Code is XPCOM
16
* The Initial Developer of the Original Code is Netscape Communications
18
* Portions created by the Initial Developer are Copyright (C) 1998
19
* the Initial Developer. All Rights Reserved.
23
* Alternatively, the contents of this file may be used under the terms of
24
* either the GNU General Public License Version 2 or later (the "GPL"), or
25
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
26
* in which case the provisions of the GPL or the LGPL are applicable instead
27
* of those above. If you wish to allow use of your version of this file only
28
* under the terms of either the GPL or the LGPL, and not to allow others to
29
* use your version of this file under the terms of the NPL, indicate your
30
* decision by deleting the provisions above and replace them with the notice
31
* and other provisions required by the GPL or the LGPL. If you do not delete
32
* the provisions above, a recipient may use your version of this file under
33
* the terms of any one of the NPL, the GPL or the LGPL.
35
* ***** END LICENSE BLOCK ***** */
38
#include "nsIServiceManager.h"
39
#include "nsIServiceManagerObsolete.h"
40
#include "nsComponentManager.h"
42
extern PRBool gXPCOMShuttingDown;
44
// Global service manager interface (see nsIServiceManagerObsolete.h)
47
nsServiceManager::GetGlobalServiceManager(nsIServiceManager* *result)
49
if (gXPCOMShuttingDown)
50
return NS_ERROR_UNEXPECTED;
52
if (nsComponentManagerImpl::gComponentManager == nsnull)
53
return NS_ERROR_UNEXPECTED;
55
// this method does not addref for historical reasons.
56
// we return the nsIServiceManagerObsolete interface via a cast.
57
*result = (nsIServiceManager*) NS_STATIC_CAST(nsIServiceManagerObsolete*,
58
nsComponentManagerImpl::gComponentManager);
63
nsServiceManager::ShutdownGlobalServiceManager(nsIServiceManager* *result)
69
nsServiceManager::GetService(const nsCID& aClass, const nsIID& aIID,
71
nsIShutdownListener* shutdownListener)
74
if (nsComponentManagerImpl::gComponentManager == nsnull)
75
return NS_ERROR_UNEXPECTED;
77
return nsComponentManagerImpl::gComponentManager->GetService(aClass, aIID, (void**)result);
81
nsServiceManager::ReleaseService(const nsCID& aClass, nsISupports* service,
82
nsIShutdownListener* shutdownListener)
84
NS_IF_RELEASE(service);
89
nsServiceManager::RegisterService(const nsCID& aClass, nsISupports* aService)
92
if (nsComponentManagerImpl::gComponentManager == nsnull)
93
return NS_ERROR_UNEXPECTED;
95
return nsComponentManagerImpl::gComponentManager->RegisterService(aClass, aService);
99
nsServiceManager::UnregisterService(const nsCID& aClass)
102
if (nsComponentManagerImpl::gComponentManager == nsnull)
103
return NS_ERROR_UNEXPECTED;
105
return nsComponentManagerImpl::gComponentManager->UnregisterService(aClass);
108
////////////////////////////////////////////////////////////////////////////////
109
// let's do it again, this time with ContractIDs...
112
nsServiceManager::GetService(const char* aContractID, const nsIID& aIID,
113
nsISupports* *result,
114
nsIShutdownListener* shutdownListener)
117
if (nsComponentManagerImpl::gComponentManager == nsnull)
118
return NS_ERROR_UNEXPECTED;
120
return nsComponentManagerImpl::gComponentManager->GetServiceByContractID(aContractID, aIID, (void**)result);
124
nsServiceManager::ReleaseService(const char* aContractID, nsISupports* service,
125
nsIShutdownListener* shutdownListener)
132
nsServiceManager::RegisterService(const char* aContractID, nsISupports* aService)
135
if (nsComponentManagerImpl::gComponentManager == nsnull)
136
return NS_ERROR_UNEXPECTED;
138
return nsComponentManagerImpl::gComponentManager->RegisterService(aContractID, aService);
142
nsServiceManager::UnregisterService(const char* aContractID)
144
// Don't create the global service manager here because we might
145
// be shutting down, and releasing all the services in its
147
if (gXPCOMShuttingDown)
150
if (nsComponentManagerImpl::gComponentManager == nsnull)
151
return NS_ERROR_UNEXPECTED;
153
return nsComponentManagerImpl::gComponentManager->UnregisterService(aContractID);