1 | /* ***** BEGIN LICENSE BLOCK ***** |
---|
2 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 |
---|
3 | * |
---|
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/ |
---|
8 | * |
---|
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 |
---|
12 | * License. |
---|
13 | * |
---|
14 | * The Original Code is XPCOM |
---|
15 | * |
---|
16 | * The Initial Developer of the Original Code is Netscape Communications |
---|
17 | * Corporation. |
---|
18 | * Portions created by the Initial Developer are Copyright (C) 1998 |
---|
19 | * the Initial Developer. All Rights Reserved. |
---|
20 | * |
---|
21 | * Contributor(s): |
---|
22 | * |
---|
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. |
---|
34 | * |
---|
35 | * ***** END LICENSE BLOCK ***** */ |
---|
36 | |
---|
37 | |
---|
38 | #include "nsIServiceManager.h" |
---|
39 | #include "nsIServiceManagerObsolete.h" |
---|
40 | #include "nsComponentManager.h" |
---|
41 | |
---|
42 | extern PRBool gXPCOMShuttingDown; |
---|
43 | |
---|
44 | // Global service manager interface (see nsIServiceManagerObsolete.h) |
---|
45 | |
---|
46 | nsresult |
---|
47 | nsServiceManager::GetGlobalServiceManager(nsIServiceManager* *result) |
---|
48 | { |
---|
49 | if (gXPCOMShuttingDown) |
---|
50 | return NS_ERROR_UNEXPECTED; |
---|
51 | |
---|
52 | if (nsComponentManagerImpl::gComponentManager == nsnull) |
---|
53 | return NS_ERROR_UNEXPECTED; |
---|
54 | |
---|
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); |
---|
59 | return NS_OK; |
---|
60 | } |
---|
61 | |
---|
62 | nsresult |
---|
63 | nsServiceManager::ShutdownGlobalServiceManager(nsIServiceManager* *result) |
---|
64 | { |
---|
65 | return NS_OK; |
---|
66 | } |
---|
67 | |
---|
68 | nsresult |
---|
69 | nsServiceManager::GetService(const nsCID& aClass, const nsIID& aIID, |
---|
70 | nsISupports* *result, |
---|
71 | nsIShutdownListener* shutdownListener) |
---|
72 | { |
---|
73 | |
---|
74 | if (nsComponentManagerImpl::gComponentManager == nsnull) |
---|
75 | return NS_ERROR_UNEXPECTED; |
---|
76 | |
---|
77 | return nsComponentManagerImpl::gComponentManager->GetService(aClass, aIID, (void**)result); |
---|
78 | } |
---|
79 | |
---|
80 | nsresult |
---|
81 | nsServiceManager::ReleaseService(const nsCID& aClass, nsISupports* service, |
---|
82 | nsIShutdownListener* shutdownListener) |
---|
83 | { |
---|
84 | NS_IF_RELEASE(service); |
---|
85 | return NS_OK; |
---|
86 | } |
---|
87 | |
---|
88 | nsresult |
---|
89 | nsServiceManager::RegisterService(const nsCID& aClass, nsISupports* aService) |
---|
90 | { |
---|
91 | |
---|
92 | if (nsComponentManagerImpl::gComponentManager == nsnull) |
---|
93 | return NS_ERROR_UNEXPECTED; |
---|
94 | |
---|
95 | return nsComponentManagerImpl::gComponentManager->RegisterService(aClass, aService); |
---|
96 | } |
---|
97 | |
---|
98 | nsresult |
---|
99 | nsServiceManager::UnregisterService(const nsCID& aClass) |
---|
100 | { |
---|
101 | |
---|
102 | if (nsComponentManagerImpl::gComponentManager == nsnull) |
---|
103 | return NS_ERROR_UNEXPECTED; |
---|
104 | |
---|
105 | return nsComponentManagerImpl::gComponentManager->UnregisterService(aClass); |
---|
106 | } |
---|
107 | |
---|
108 | //////////////////////////////////////////////////////////////////////////////// |
---|
109 | // let's do it again, this time with ContractIDs... |
---|
110 | |
---|
111 | nsresult |
---|
112 | nsServiceManager::GetService(const char* aContractID, const nsIID& aIID, |
---|
113 | nsISupports* *result, |
---|
114 | nsIShutdownListener* shutdownListener) |
---|
115 | { |
---|
116 | |
---|
117 | if (nsComponentManagerImpl::gComponentManager == nsnull) |
---|
118 | return NS_ERROR_UNEXPECTED; |
---|
119 | |
---|
120 | return nsComponentManagerImpl::gComponentManager->GetServiceByContractID(aContractID, aIID, (void**)result); |
---|
121 | } |
---|
122 | |
---|
123 | nsresult |
---|
124 | nsServiceManager::ReleaseService(const char* aContractID, nsISupports* service, |
---|
125 | nsIShutdownListener* shutdownListener) |
---|
126 | { |
---|
127 | NS_RELEASE(service); |
---|
128 | return NS_OK; |
---|
129 | } |
---|
130 | |
---|
131 | nsresult |
---|
132 | nsServiceManager::RegisterService(const char* aContractID, nsISupports* aService) |
---|
133 | { |
---|
134 | |
---|
135 | if (nsComponentManagerImpl::gComponentManager == nsnull) |
---|
136 | return NS_ERROR_UNEXPECTED; |
---|
137 | |
---|
138 | return nsComponentManagerImpl::gComponentManager->RegisterService(aContractID, aService); |
---|
139 | } |
---|
140 | |
---|
141 | nsresult |
---|
142 | nsServiceManager::UnregisterService(const char* aContractID) |
---|
143 | { |
---|
144 | // Don't create the global service manager here because we might |
---|
145 | // be shutting down, and releasing all the services in its |
---|
146 | // destructor |
---|
147 | if (gXPCOMShuttingDown) |
---|
148 | return NS_OK; |
---|
149 | |
---|
150 | if (nsComponentManagerImpl::gComponentManager == nsnull) |
---|
151 | return NS_ERROR_UNEXPECTED; |
---|
152 | |
---|
153 | return nsComponentManagerImpl::gComponentManager->UnregisterService(aContractID); |
---|
154 | } |
---|
155 | |
---|