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