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 schuur 1.9 ProviderName ProviderRegistrar::findConsumerProvider(const String & destinationPath)
197 {
198 CIMInstance provider;
199 CIMInstance providerModule;
200 ProviderName temp;
201
202 if (_prm->lookupIndicationConsumer(destinationPath,provider,providerModule))
203 return ProviderName(temp.getObjectName(),
204 provider.getProperty(providerModule.findProperty
205 ("Name")).getValue ().toString (),
206 providerModule.getProperty(providerModule.findProperty
207 ("Location")).getValue().toString(),
208 providerModule.getProperty(providerModule.findProperty
209 ("InterfaceType")).getValue().toString(),
210 0);
211
212 return temp;
213 }
214
|
215 chip 1.2 // need at least the object and the one capability.
216 // for example,
217 // "//localhost/root/cimv2:CIM_ComputerSystem", INSTANCE
218 // "//localhost/root/cimv2:CIM_ComputerSystem", METHOD
219 // "//localhost/root/cimv2:CIM_AssociatedComputerSystem", ASSOCIATION
220 // "//localhost/root/cimv2:CIM_ComputerSystemFailure", INDICATION
221
222 // the method will return the logical and physical provider names associated with the object and capability.
|
223 chip 1.1
|
224 chip 1.2 ProviderName ProviderRegistrar::findProvider(const ProviderName & providerName)
225 {
226 CIMObjectPath objectName = providerName.getObjectName();
227 Uint32 flags = providerName.getCapabilitiesMask();
|
228 chip 1.1
|
229 chip 1.2 // validate arguments
|
230 chip 1.3 if(objectName.getNameSpace().isNull() || objectName.getClassName().isNull())
|
231 chip 1.2 {
232 throw Exception("Invalid argument.");
233 }
|
234 schuur 1.7
235 CIMInstance provider;
236 CIMInstance providerModule;
237 ProviderName temp;
|
238 schuur 1.8 Boolean hasNoQuery;
|
239 schuur 1.7
240 switch (flags) {
|
241 schuur 1.9 case ProviderType_INSTANCE:
|
242 schuur 1.7 if (_prm->lookupInstanceProvider(objectName.getNameSpace(),objectName.getClassName(),
243 provider,providerModule,0)) {
244 return ProviderName(providerName.getObjectName(),
245 provider.getProperty(providerModule.findProperty
246 ("Name")).getValue ().toString (),
247 providerModule.getProperty(providerModule.findProperty
248 ("Location")).getValue().toString(),
249 providerModule.getProperty(providerModule.findProperty
250 ("InterfaceType")).getValue().toString(),
251 ProviderType::INSTANCE);
252 }
253 break;
|
254 schuur 1.9 case ProviderType_ASSOCIATION:
|
255 schuur 1.7 if (_prm->lookupInstanceProvider(objectName.getNameSpace(),objectName.getClassName(),
256 provider,providerModule,1)) {
257 return ProviderName(providerName.getObjectName(),
258 provider.getProperty(providerModule.findProperty
259 ("Name")).getValue ().toString (),
260 providerModule.getProperty(providerModule.findProperty
261 ("Location")).getValue().toString(),
262 providerModule.getProperty(providerModule.findProperty
263 ("InterfaceType")).getValue().toString(),
264 ProviderType::ASSOCIATION);
|
265 schuur 1.8 }
266 break;
|
267 schuur 1.9 case ProviderType_QUERY:
|
268 schuur 1.8 if (_prm->lookupInstanceProvider(objectName.getNameSpace(),objectName.getClassName(),
269 provider,providerModule,0,&hasNoQuery)) {
270 return ProviderName(providerName.getObjectName(),
271 provider.getProperty(providerModule.findProperty
272 ("Name")).getValue ().toString (),
273 providerModule.getProperty(providerModule.findProperty
274 ("Location")).getValue().toString(),
275 providerModule.getProperty(providerModule.findProperty
276 ("InterfaceType")).getValue().toString(),
277 ProviderType::INSTANCE);
|
278 schuur 1.7 }
279 break;
280 default:
281 temp = _lookupProvider(objectName);
282 }
283
|
284 chip 1.2 return(temp);
|
285 chip 1.1 }
286
|
287 chip 1.2 Boolean ProviderRegistrar::insertProvider(const ProviderName & providerName)
|
288 chip 1.1 {
|
289 chip 1.2 // assume the providerName is in ProviderName format
290 ProviderName name(providerName);
|
291 chip 1.1
292 return(false);
293 }
294
|
295 chip 1.2 Boolean ProviderRegistrar::removeProvider(const ProviderName & providerName)
|
296 chip 1.1 {
|
297 chip 1.2 // assume the providerName is in ProviderName format
298 ProviderName name(providerName);
|
299 chip 1.1
300 return(false);
301 }
|
302 chip 1.2
303 void SetProviderRegistrationManager(ProviderRegistrationManager * p)
|
304 chip 1.1 {
|
305 chip 1.2 _prm = p;
|
306 chip 1.1 }
307
|
308 chip 1.2 ProviderRegistrationManager * GetProviderRegistrationManager(void)
|
309 chip 1.1 {
|
310 chip 1.2 return(_prm);
|
311 chip 1.1 }
312
313 PEGASUS_NAMESPACE_END
|