1 kumpf 1.1 //%2003////////////////////////////////////////////////////////////////////////
2 //
3 // 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 //
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 //
15 // 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 kumpf 1.1 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 //
24 //==============================================================================
25 //
26 // Author: Chip Vincent (cvincent@us.ibm.com)
27 // Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)
28 //
29 // Modified By:
30 //
31 //%/////////////////////////////////////////////////////////////////////////////
32
33 #include "BasicProviderManagerRouter.h"
34
35 #include <Pegasus/Common/Config.h>
36 #include <Pegasus/Common/CIMMessage.h>
37 #include <Pegasus/Common/Tracer.h>
38 #include <Pegasus/ProviderManager2/OperationResponseHandler.h>
39 #include <Pegasus/ProviderManager2/ProviderManagerModule.h>
40 #include <Pegasus/ProviderManager2/ProviderManager.h>
41
42 // ProviderManager library names. Should these be defined elsewhere?
43 kumpf 1.1 #if defined(PEGASUS_OS_OS400)
44 # define LIBRARY_NAME_DEFAULTPM "QSYS/QYCMDFTPVM"
45 # define LIBRARY_NAME_CMPIPM "QSYS/QYCMCMPIPM"
46 # define LIBRARY_NAME_JMPIPM "QSYS/QYCMJMPIPM"
47 #else
48 # define LIBRARY_NAME_DEFAULTPM "DefaultProviderManager"
49 # define LIBRARY_NAME_CMPIPM "CMPIProviderManager"
50 # define LIBRARY_NAME_JMPIPM "JMPIProviderManager"
51 #endif
52
53 PEGASUS_NAMESPACE_BEGIN
54
55 // BEGIN TEMP SECTION
56 class ProviderManagerContainer
57 {
58 public:
59 ProviderManagerContainer()
60 : _manager(0)
61 {
62 }
63
64 kumpf 1.1 ProviderManagerContainer(const ProviderManagerContainer & container)
65 : _manager(0)
66 {
67 *this = container;
68 }
69
70 ProviderManagerContainer(
71 const String& physicalName,
72 const String& logicalName,
73 const String& interfaceName,
74 PEGASUS_INDICATION_CALLBACK indicationCallback)
75 : _manager(0)
76 {
77 _physicalName = ProviderManager::_resolvePhysicalName(physicalName);
78
79 _logicalName = logicalName;
80 _interfaceName = interfaceName;
81
82 _module = ProviderManagerModule(_physicalName);
83 _module.load();
84
85 kumpf 1.1 _manager = _module.getProviderManager(_logicalName);
86 PEGASUS_ASSERT(_manager != 0);
87
88 _manager->setIndicationCallback(indicationCallback);
89 }
90
91 ~ProviderManagerContainer()
92 {
93 _module.unload();
94 }
95
96 ProviderManagerContainer& operator=(
97 const ProviderManagerContainer & container)
98 {
99 if (this == &container)
100 {
101 return *this;
102 }
103
104 _logicalName = container._logicalName;
105 _physicalName = container._physicalName;
106 kumpf 1.1 _interfaceName = container._interfaceName;
107
108 _module = container._module;
109 _manager = container._manager;
110
111 return *this;
112 }
113
114 ProviderManager* getProviderManager()
115 {
116 return _manager;
117 }
118
119 const String& getPhysicalName() const
120 {
121 return _physicalName;
122 }
123
124 const String& getLogicalName() const
125 {
126 return _logicalName;
127 kumpf 1.1 }
128
129 const String& getInterfaceName() const
130 {
131 return _interfaceName;
132 }
133
134 private:
135 String _physicalName;
136 String _logicalName;
137 String _interfaceName;
138
139 ProviderManagerModule _module;
140 ProviderManager* _manager;
141 };
142 // END TEMP SECTION
143
144
145 PEGASUS_INDICATION_CALLBACK BasicProviderManagerRouter::_indicationCallback = 0;
146
147 // Private, unimplemented constructor
148 kumpf 1.1 BasicProviderManagerRouter::BasicProviderManagerRouter()
149 {
150 }
151
152 BasicProviderManagerRouter::BasicProviderManagerRouter(
153 PEGASUS_INDICATION_CALLBACK indicationCallback)
154 {
155 PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
156 "BasicProviderManagerRouter::BasicProviderManagerRouter");
157
158 _indicationCallback = indicationCallback;
159
160 PEG_METHOD_EXIT();
161 }
162
163 BasicProviderManagerRouter::~BasicProviderManagerRouter()
164 {
165 PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
166 "BasicProviderManagerRouter::~BasicProviderManagerRouter");
167 PEG_METHOD_EXIT();
168 }
169 kumpf 1.1
170 Message* BasicProviderManagerRouter::processMessage(Message * message)
171 {
172 PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
173 "BasicProviderManagerRouter::processMessage");
174
175 CIMRequestMessage* request = dynamic_cast<CIMRequestMessage *>(message);
176 PEGASUS_ASSERT(request != 0);
177
178 Message* response = 0;
179
180 //
181 // Retrieve the ProviderManager routing information
182 //
183
184 CIMInstance providerModule;
185
186 if ((dynamic_cast<CIMOperationRequestMessage*>(request) != 0) ||
|
256 kumpf 1.1 }
257 else
258 {
259 // Retrieve the provider interface type
260 String interfaceType;
261 CIMValue itValue = providerModule.getProperty(
262 providerModule.findProperty("InterfaceType")).getValue();
263 itValue.get(interfaceType);
264
265 // Look up the appropriate ProviderManager by InterfaceType
266 ProviderManager* pm = _lookupProviderManager(interfaceType);
267 response = pm->processMessage(request);
268 }
269
270 // preserve message key
271 response->setKey(request->getKey());
272
273 // set HTTP method in response from request
274 response->setHttpMethod(request->getHttpMethod());
275
276 PEG_METHOD_EXIT();
277 kumpf 1.1 return response;
278 }
279
280 // ATTN: May need to add interfaceVersion parameter to further constrain lookup
281 ProviderManager* BasicProviderManagerRouter::_lookupProviderManager(
282 const String& interfaceType)
283 {
284 PEG_METHOD_ENTER(TRC_PROVIDERMANAGER,
285 "BasicProviderManagerRouter::_lookupProviderManager");
286
287 //
288 // Search for this InterfaceType in the table of loaded ProviderManagers
289 //
290 {
291 ReadLock tableLock(_providerManagerTableLock);
292
293 // find provider manager for specified provider interface type
294 for(Uint32 i = 0, n = _providerManagerTable.size(); i < n; i++)
295 {
296 if (interfaceType == _providerManagerTable[i]->getInterfaceName())
297 {
298 kumpf 1.1 ProviderManagerContainer* pmc=_providerManagerTable[i];
299 PEG_METHOD_EXIT();
300 return pmc->getProviderManager();
301 }
302 }
303 }
304
305 //
306 // Load the ProviderManager for this InterfaceType and add it to the table
307 //
308 {
309 WriteLock tableLock(_providerManagerTableLock);
310
311 // ATTN: this section is a temporary solution to populate the list of
312 // enabled provider managers for a given distribution. It includes
313 // another temporary solution for converting a generic file name into
314 // a file name useable by each platform.
315
316 #if defined(ENABLE_DEFAULT_PROVIDER_MANAGER)
317 if (interfaceType == "C++Default")
318 {
319 kumpf 1.1 ProviderManagerContainer* pmc = new ProviderManagerContainer(
320 LIBRARY_NAME_DEFAULTPM, "DEFAULT", "C++Default",
321 _indicationCallback);
322 _providerManagerTable.append(pmc);
323 return pmc->getProviderManager();
324 }
325 #endif
326
327 #if defined(ENABLE_CMPI_PROVIDER_MANAGER)
328 if (interfaceType == "CMPI")
329 {
330 ProviderManagerContainer* pmc = new ProviderManagerContainer(
331 LIBRARY_NAME_CMPIPM, "CMPI", "CMPI", _indicationCallback);
332 _providerManagerTable.append(pmc);
333 return pmc->getProviderManager();
334 }
335 #endif
336
337 #if defined(ENABLE_JMPI_PROVIDER_MANAGER)
338 if (interfaceType == "JMPI")
339 {
340 kumpf 1.1 ProviderManagerContainer* pmc = new ProviderManagerContainer(
341 LIBRARY_NAME_JMPIPM, "JMPI", "JMPI", _indicationCallback);
342 _providerManagerTable.append(pmc);
343 return pmc->getProviderManager();
344 }
345 #endif
346 // END TEMP SECTION
347 }
348
349 // Error: ProviderManager not found for the specified interface type
350 PEGASUS_ASSERT(0);
351 PEG_METHOD_EXIT();
352 return 0;
353 }
354
|