1 karl 1.5 //%2003////////////////////////////////////////////////////////////////////////
|
2 chip 1.1 //
|
3 karl 1.5 // Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Development
4 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.
5 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
6 // IBM Corp.; EMC Corporation, The Open Group.
|
7 chip 1.1 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to
10 // deal in the Software without restriction, including without limitation the
11 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12 // sell copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
|
14 chip 1.6 //
|
15 chip 1.1 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
16 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
17 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
18 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
19 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Chip Vincent (cvincent@us.ibm.com)
27 //
28 // Modified By:
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31
32 #include "ProviderRegistrar.h"
33
34 #include <Pegasus/Common/Constants.h>
35 #include <Pegasus/Common/Tracer.h>
36 chip 1.1 #include <Pegasus/Common/Pair.h>
37
38 #include <Pegasus/Server/ProviderRegistrationManager/ProviderRegistrationManager.h>
|
39 schuur 1.7 #include <Pegasus/ProviderManager2/ProviderType.h>
|
40 chip 1.1
41 PEGASUS_NAMESPACE_BEGIN
42
|
43 chip 1.2 static ProviderRegistrationManager * _prm = 0;
|
44 chip 1.1
|
45 chip 1.2 static CIMValue _getPropertyValue(const CIMInstance & cimInstance, const String & propertyName)
|
46 chip 1.1 {
|
47 chip 1.2 CIMValue value;
48
49 Uint32 pos = 0;
50
51 // get ClassName property
52 if((pos = cimInstance.findProperty(propertyName)) != PEG_NOT_FOUND)
53 {
54 value = cimInstance.getProperty(pos).getValue();
55 }
56
57 return(value);
|
58 chip 1.1 }
59
|
60 chip 1.2 static ProviderName _lookupProvider(const CIMObjectPath & cimObjectPath)
|
61 chip 1.1 {
|
62 chip 1.2 String providerName;
63 String moduleName;
64
65 try
66 {
67 // get the PG_ProviderCapabilities instances for the specified namespace:class_name. use the matching
68 // instance to gather the PG_Provider instance name (logical name).
|
69 chip 1.1
|
70 chip 1.6 Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_ProviderCapabilities"));
|
71 chip 1.1
|
72 chip 1.6 for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
|
73 chip 1.2 {
|
74 chip 1.6 CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);
|
75 chip 1.2
76 // check ClassName property value
77 if(String::equalNoCase(cimObjectPath.getClassName().getString(), _getPropertyValue(cimInstance, "ClassName").toString()))
78 {
79 // check Namespaces property value
80 Array<String> nameSpaces;
81
82 _getPropertyValue(cimInstance, "Namespaces").get(nameSpaces);
83
|
84 chip 1.3 // ATTN: need to walk the array
85 if(String::equalNoCase(cimObjectPath.getNameSpace().getString(), nameSpaces[0]))
|
86 chip 1.2 {
|
87 chip 1.3 providerName = _getPropertyValue(cimInstance, "ProviderName").toString();
|
88 chip 1.2
|
89 chip 1.3 break;
|
90 chip 1.2 }
91 }
92 }
93 }
94 catch(...)
95 {
96 }
|
97 chip 1.1
|
98 chip 1.2 // ensure the provider name is valid
99 if(providerName.size() == 0)
100 {
101 throw Exception("Could not determine PG_Provider instance for specified class.");
102 }
|
103 chip 1.1
|
104 chip 1.2 try
105 {
106 // get the PG_Provider instances associated with the specified namespace:class_name. use the matching
107 // instance to gather the PG_ProviderModule instance name.
|
108 chip 1.1
|
109 chip 1.6 Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_Provider"));
|
110 chip 1.1
|
111 chip 1.6 for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
|
112 chip 1.2 {
|
113 chip 1.6 CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);
|
114 chip 1.2
115 if(String::equalNoCase(providerName, _getPropertyValue(cimInstance, "Name").toString()))
116 {
117 moduleName = _getPropertyValue(cimInstance, "ProviderModuleName").toString();
118
119 break;
120 }
121 }
122 }
123 catch(...)
|
124 chip 1.1 {
125 }
126
|
127 chip 1.2 // ensure the module name is valid
128 if(moduleName.size() == 0)
129 {
130 throw Exception("Could not determine PG_ProviderModule instance for specified class.");
131 }
|
132 chip 1.1
|
133 chip 1.2 String interfaceType;
134 String moduleLocation;
|
135 chip 1.1
|
136 chip 1.2 try
137 {
138 // get the PG_ProviderModule instances associated with the specified namespace:class_name. use the matching
139 // instance to gather the module status and location (physical name).
|
140 chip 1.1
|
141 chip 1.6 Array<CIMObjectPath> cimInstanceNames = _prm->enumerateInstanceNames(CIMObjectPath(String::EMPTY, "root/PG_Interop", "PG_ProviderModule"));
|
142 chip 1.1
|
143 chip 1.6 for(Uint32 i = 0, n = cimInstanceNames.size(); i < n; i++)
|
144 chip 1.2 {
|
145 chip 1.6 CIMInstance cimInstance = _prm->getInstance(cimInstanceNames[i]);
|
146 chip 1.2
147 if(String::equalNoCase(moduleName, _getPropertyValue(cimInstance, "Name").toString()))
148 {
|
149 chip 1.3 // ATTN: check operational status
150
151 // get interface
152 interfaceType = _getPropertyValue(cimInstance, "InterfaceType").toString();
|
153 chip 1.2
|
154 chip 1.3 // get location
155 moduleLocation = _getPropertyValue(cimInstance, "Location").toString();
|
156 chip 1.2
|
157 chip 1.3 break;
|
158 chip 1.2 }
159 }
|
160 chip 1.3 }
|
161 chip 1.2 catch(...)
|
162 chip 1.1 {
163 }
164
|
165 chip 1.2 // ensure the interface and location are valid
166 if((interfaceType.size() == 0) || (moduleLocation.size() == 0))
167 {
168 throw Exception("Could not determine PG_ProviderModule.InterfaceType or PG_ProviderModule.Location or module is disabled.");
169 }
|
170 chip 1.1
|
171 chip 1.6 // DEBUG
172 CString s1 = interfaceType.getCString();
173 const char * p1 = s1;
174
175 CString s2 = moduleLocation.getCString();
176 const char * p2 = s2;
177
|
178 chip 1.2 ProviderName temp(
179 cimObjectPath.toString(),
180 providerName,
181 moduleLocation,
182 interfaceType,
183 0);
|
184 chip 1.1
|
185 chip 1.2 return(temp);
186 }
187
188 ProviderRegistrar::ProviderRegistrar(void)
189 {
190 }
191
192 ProviderRegistrar::~ProviderRegistrar(void)
193 {
194 }
|
195 chip 1.1
|
196 chip 1.2 // need at least the object and the one capability.
197 // for example,
198 // "//localhost/root/cimv2:CIM_ComputerSystem", INSTANCE
199 // "//localhost/root/cimv2:CIM_ComputerSystem", METHOD
200 // "//localhost/root/cimv2:CIM_AssociatedComputerSystem", ASSOCIATION
201 // "//localhost/root/cimv2:CIM_ComputerSystemFailure", INDICATION
202
203 // the method will return the logical and physical provider names associated with the object and capability.
|
204 chip 1.1
|
205 chip 1.2 ProviderName ProviderRegistrar::findProvider(const ProviderName & providerName)
206 {
207 CIMObjectPath objectName = providerName.getObjectName();
208 Uint32 flags = providerName.getCapabilitiesMask();
|
209 chip 1.1
|
210 chip 1.2 // validate arguments
|
211 chip 1.3 if(objectName.getNameSpace().isNull() || objectName.getClassName().isNull())
|
212 chip 1.2 {
213 throw Exception("Invalid argument.");
214 }
|
215 schuur 1.7
216 CIMInstance provider;
217 CIMInstance providerModule;
218 ProviderName temp;
219
220 switch (flags) {
221 case 2: //ProviderType::INSTANCE
222 if (_prm->lookupInstanceProvider(objectName.getNameSpace(),objectName.getClassName(),
223 provider,providerModule,0)) {
224 return ProviderName(providerName.getObjectName(),
225 provider.getProperty(providerModule.findProperty
226 ("Name")).getValue ().toString (),
227 providerModule.getProperty(providerModule.findProperty
228 ("Location")).getValue().toString(),
229 providerModule.getProperty(providerModule.findProperty
230 ("InterfaceType")).getValue().toString(),
231 ProviderType::INSTANCE);
232 }
233 break;
234 case 5: //ProviderType::ASSOCIATION
235 if (_prm->lookupInstanceProvider(objectName.getNameSpace(),objectName.getClassName(),
236 schuur 1.7 provider,providerModule,1)) {
237 return ProviderName(providerName.getObjectName(),
238 provider.getProperty(providerModule.findProperty
239 ("Name")).getValue ().toString (),
240 providerModule.getProperty(providerModule.findProperty
241 ("Location")).getValue().toString(),
242 providerModule.getProperty(providerModule.findProperty
243 ("InterfaceType")).getValue().toString(),
244 ProviderType::ASSOCIATION);
245 }
246 break;
247 default:
248 temp = _lookupProvider(objectName);
249 }
250
|
251 chip 1.2 return(temp);
|
252 chip 1.1 }
253
|
254 chip 1.2 Boolean ProviderRegistrar::insertProvider(const ProviderName & providerName)
|
255 chip 1.1 {
|
256 chip 1.2 // assume the providerName is in ProviderName format
257 ProviderName name(providerName);
|
258 chip 1.1
259 return(false);
260 }
261
|
262 chip 1.2 Boolean ProviderRegistrar::removeProvider(const ProviderName & providerName)
|
263 chip 1.1 {
|
264 chip 1.2 // assume the providerName is in ProviderName format
265 ProviderName name(providerName);
|
266 chip 1.1
267 return(false);
268 }
|
269 chip 1.2
270 void SetProviderRegistrationManager(ProviderRegistrationManager * p)
|
271 chip 1.1 {
|
272 chip 1.2 _prm = p;
|
273 chip 1.1 }
274
|
275 chip 1.2 ProviderRegistrationManager * GetProviderRegistrationManager(void)
|
276 chip 1.1 {
|
277 chip 1.2 return(_prm);
|
278 chip 1.1 }
279
280 PEGASUS_NAMESPACE_END
|